-
Notifications
You must be signed in to change notification settings - Fork 0
/
omRenameAnchors.py
executable file
·89 lines (59 loc) · 2.01 KB
/
omRenameAnchors.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#MenuTitle: Rename Anchors from Selection
# -*- coding: utf-8 -*-
# Code by Olli Meier, January 2016, Version 1.00
__doc__="""
Rename anchors for all master layers in selection.
"""
from GlyphsApp import *
try:
from vanilla import *
except:
Glyphs.displayDialog_(u'Vanilla for python is missing.')
font = Glyphs.font
def change_anchorName(font, glyph, x, y):
for master in font.masters:
mID = master.id
masterlayer = font.glyphs[glyph.name].layers[mID]
for anchor in masterlayer.anchors:
if anchor.name == x:
print anchor.name
anchor.name = str(y)
print anchor
print anchor.name
print ('Glyph: ' + glyph.name + ' change anchor from \'' + x + '\' to \'' + y + '\'' )
class WindowComb(object):
def __init__(self):
a = 400
b = a/2 - 100
self.w = Window((a, b), "Rename Anchors")
self.w.w_width = TextBox((10, 13, -10, 17), "Old name of anchor: ")
self.w.textEditor_old = EditText((a*2/4, 10, -10, 22))
self.w.textEditor_old.set('top')
self.w.w_shift = TextBox((10, 43, -10, 17), "New name for anchor: ")
self.w.textEditor_new = EditText((a*2/4, 40, -10, 22))
self.w.textEditor_new.set('topCase')
self.w.Button = Button((10, b - 30, -10, -10), "process", callback = self.Button)
self.w.open()
def Button(self, sender):
x = self.w.textEditor_old.get()
y = self.w.textEditor_new.get()
#### start: main part
if y is not '' and x is not '':
glyphSelection = []
for glyph in font.selection:
change_anchorName(font, glyph, x, y)
print "Done."
self.w.close()
else:
if x is '' and y is not '':
text = 'You forgot to define an anchor for changing.'
if y is '' and x is not '':
text = 'You forgot to define a new name for you anchors.'
if y is '' and x is '':
text = 'Please define a name for the old anchor and a new name for the old anchor name.'
w = Window((200, 100), "Error")
w.w_error_character = TextBox((10, 10, -10, -10), text)
w.center()
w.open()
#### end: main part
WindowComb()