6
6
"""
7
7
import sys
8
8
from AppKit import NSObject
9
- from PyObjCTools import AppHelper
10
9
import vanilla
11
10
import csv
12
11
from io import StringIO
13
12
import re
14
- from AppKit import NSView , NSColor , NSRectFill
13
+ from AppKit import NSView , NSColor , NSRectFill , NSBezierPath , NSAffineTransform
15
14
from vanilla .vanillaBase import VanillaBaseObject , VanillaCallbackWrapper
16
15
import traceback
17
16
@@ -26,10 +25,16 @@ def glyphsort(x):
26
25
if "GlyphView" not in locals ():
27
26
28
27
class GlyphView (NSView ):
28
+ @objc .python_method
29
29
def setGlyphs (self , glyphs ):
30
30
self .glyphs = glyphs
31
31
self .setNeedsDisplay_ (True )
32
32
33
+ @objc .python_method
34
+ def setMaster (self , master_id ):
35
+ self .master = master_id
36
+ self .setNeedsDisplay_ (True )
37
+
33
38
def drawRect_ (self , rect ):
34
39
try :
35
40
NSColor .whiteColor ().set ()
@@ -39,10 +44,10 @@ def drawRect_(self, rect):
39
44
xcursor = 0
40
45
ycursor = 0
41
46
for i , g in enumerate (self .glyphs ):
42
- layer = g .layers [0 ]
47
+ layer = g .layers [self . master ]
43
48
if i > 0 :
44
49
# Do anchor correction here
45
- prevlayer = self .glyphs [i - 1 ].layers [0 ]
50
+ prevlayer = self .glyphs [i - 1 ].layers [self . master ]
46
51
entry = prevlayer .anchors ["entry" ]
47
52
exit = layer .anchors ["exit" ]
48
53
if entry and exit :
@@ -63,7 +68,7 @@ def drawRect_(self, rect):
63
68
64
69
t = NSAffineTransform .transform ()
65
70
if xcursor > 0 :
66
- master = self .glyphs [0 ].layers [0 ].master
71
+ master = self .glyphs [0 ].layers [self . master ].master
67
72
vscale = self .bounds ().size .height / (
68
73
master .ascender - master .descender
69
74
)
@@ -84,7 +89,7 @@ def __init__(self, connections):
84
89
for x in self .connections ["colnames" ]
85
90
]
86
91
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 )
88
93
self .w .LeftLabel = vanilla .TextBox ((- 200 , 10 , 200 , 17 ), "" , alignment = "center" )
89
94
self .w .LeftButton = vanilla .Button (
90
95
(- 200 , 30 , 30 , 17 ), "<" , callback = self .decrement
@@ -94,7 +99,7 @@ def __init__(self, connections):
94
99
(- 30 , 30 , 30 , 17 ), ">" , callback = self .increment
95
100
)
96
101
self .w .myList = vanilla .List (
97
- (0 , 0 , - 200 , - 0 ),
102
+ (0 , 0 , - 300 , - 0 ),
98
103
self .connections ["rows" ],
99
104
columnDescriptions = columns ,
100
105
editCallback = self .editCallback ,
@@ -112,12 +117,22 @@ def __init__(self, connections):
112
117
113
118
self .glyphView = GlyphView .alloc ().init ()
114
119
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
+ )
117
128
self .selectedPair = None
118
129
self .inAdd = False
119
130
self .w .open ()
120
131
132
+ def setMaster (self , sender ):
133
+ master_ix = sender .get ()
134
+ self .glyphView .setMaster (Glyphs .font .masters [master_ix ].id )
135
+
121
136
def editCallback (self , sender ):
122
137
if self .inAdd :
123
138
return
@@ -136,10 +151,19 @@ def clickCallback(self, sender):
136
151
self .setNewPair (crow , ccol )
137
152
138
153
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 )
140
159
141
160
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
+
143
167
144
168
def add (self , increment ):
145
169
if not self .selectedPair :
@@ -248,11 +272,11 @@ def kickoff():
248
272
return
249
273
250
274
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 )
252
276
]
253
277
medials = [x for x in connectables if re .match (r".*m(sd)?[0-9]+$" , x )]
254
278
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 )]
256
280
medialstems = sorted (set ([re .sub ("(sd)?[0-9]+$" , "" , x ) for x in medials ]))
257
281
initialstems = sorted (set ([re .sub ("(sd)?[0-9]+$" , "" , x ) for x in initials ]))
258
282
0 commit comments