Skip to content

Commit 87f3470

Browse files
committed
Latest version
1 parent dc474b5 commit 87f3470

File tree

1 file changed

+37
-13
lines changed

1 file changed

+37
-13
lines changed

Nastaliq Connection Editor.py

+37-13
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
"""
77
import sys
88
from AppKit import NSObject
9-
from PyObjCTools import AppHelper
109
import vanilla
1110
import csv
1211
from io import StringIO
1312
import re
14-
from AppKit import NSView, NSColor, NSRectFill
13+
from AppKit import NSView, NSColor, NSRectFill, NSBezierPath, NSAffineTransform
1514
from vanilla.vanillaBase import VanillaBaseObject, VanillaCallbackWrapper
1615
import traceback
1716

@@ -26,10 +25,16 @@ def glyphsort(x):
2625
if "GlyphView" not in locals():
2726

2827
class GlyphView(NSView):
28+
@objc.python_method
2929
def setGlyphs(self, glyphs):
3030
self.glyphs = glyphs
3131
self.setNeedsDisplay_(True)
3232

33+
@objc.python_method
34+
def setMaster(self, master_id):
35+
self.master = master_id
36+
self.setNeedsDisplay_(True)
37+
3338
def drawRect_(self, rect):
3439
try:
3540
NSColor.whiteColor().set()
@@ -39,10 +44,10 @@ def drawRect_(self, rect):
3944
xcursor = 0
4045
ycursor = 0
4146
for i, g in enumerate(self.glyphs):
42-
layer = g.layers[0]
47+
layer = g.layers[self.master]
4348
if i > 0:
4449
# Do anchor correction here
45-
prevlayer = self.glyphs[i - 1].layers[0]
50+
prevlayer = self.glyphs[i - 1].layers[self.master]
4651
entry = prevlayer.anchors["entry"]
4752
exit = layer.anchors["exit"]
4853
if entry and exit:
@@ -63,7 +68,7 @@ def drawRect_(self, rect):
6368

6469
t = NSAffineTransform.transform()
6570
if xcursor > 0:
66-
master = self.glyphs[0].layers[0].master
71+
master = self.glyphs[0].layers[self.master].master
6772
vscale = self.bounds().size.height / (
6873
master.ascender - master.descender
6974
)
@@ -84,7 +89,7 @@ def __init__(self, connections):
8489
for x in self.connections["colnames"]
8590
]
8691
columns[0]["width"] = 100
87-
self.w = vanilla.Window((950, 600), "Nastaliq Editor", closable=True)
92+
self.w = vanilla.Window((1000, 1000), "Nastaliq Editor", closable=True)
8893
self.w.LeftLabel = vanilla.TextBox((-200, 10, 200, 17), "", alignment="center")
8994
self.w.LeftButton = vanilla.Button(
9095
(-200, 30, 30, 17), "<", callback=self.decrement
@@ -94,7 +99,7 @@ def __init__(self, connections):
9499
(-30, 30, 30, 17), ">", callback=self.increment
95100
)
96101
self.w.myList = vanilla.List(
97-
(0, 0, -200, -0),
102+
(0, 0, -300, -0),
98103
self.connections["rows"],
99104
columnDescriptions=columns,
100105
editCallback=self.editCallback,
@@ -112,12 +117,22 @@ def __init__(self, connections):
112117

113118
self.glyphView = GlyphView.alloc().init()
114119
self.glyphView.glyphs = []
115-
self.glyphView.setFrame_(((0, 0), (400, 400)))
116-
self.w.scrollView = vanilla.ScrollView((-200, 50, 200, 400), self.glyphView)
120+
self.glyphView.master = Glyphs.font.masters[0].id
121+
self.glyphView.setFrame_(((0, 0), (600, 400)))
122+
self.w.scrollView = vanilla.ScrollView((-280, 50, 300, 400), self.glyphView)
123+
124+
self.w.masterDropdown = vanilla.PopUpButton((-250, 500, -100, 20),
125+
[x.name for x in Glyphs.font.masters],
126+
callback=self.setMaster
127+
)
117128
self.selectedPair = None
118129
self.inAdd = False
119130
self.w.open()
120131

132+
def setMaster(self, sender):
133+
master_ix = sender.get()
134+
self.glyphView.setMaster(Glyphs.font.masters[master_ix].id)
135+
121136
def editCallback(self, sender):
122137
if self.inAdd:
123138
return
@@ -136,10 +151,19 @@ def clickCallback(self, sender):
136151
self.setNewPair(crow, ccol)
137152

138153
def decrement(self, sender):
139-
self.add(-1)
154+
try:
155+
self.add(-1)
156+
except Exception as e:
157+
print("Oops!", sys.exc_info()[0], "occured.")
158+
traceback.print_exc(file=sys.stdout)
140159

141160
def increment(self, sender):
142-
self.add(1)
161+
try:
162+
self.add(1)
163+
except Exception as e:
164+
print("Oops!", sys.exc_info()[0], "occured.")
165+
traceback.print_exc(file=sys.stdout)
166+
143167

144168
def add(self, increment):
145169
if not self.selectedPair:
@@ -248,11 +272,11 @@ def kickoff():
248272
return
249273

250274
connectables = [
251-
x.name for x in Glyphs.font.glyphs if re.match(r".*[mif](sd)?[0-9]+$", x.name)
275+
x.name for x in Glyphs.font.glyphs if re.match(r".*[mif](sd?)?[0-9]+$", x.name)
252276
]
253277
medials = [x for x in connectables if re.match(r".*m(sd)?[0-9]+$", x)]
254278
initials = [x for x in connectables if re.match(r".*i(sd)?[0-9]+$", x)]
255-
finals = [x for x in connectables if re.match(r".*f(sd)?[0-9]+$", x)]
279+
finals = [x for x in connectables if re.match(r".*f(sd?)?[0-9]+$", x)]
256280
medialstems = sorted(set([re.sub("(sd)?[0-9]+$", "", x) for x in medials]))
257281
initialstems = sorted(set([re.sub("(sd)?[0-9]+$", "", x) for x in initials]))
258282

0 commit comments

Comments
 (0)