-
Notifications
You must be signed in to change notification settings - Fork 4
/
importAnchors.py
executable file
·94 lines (74 loc) · 2.63 KB
/
importAnchors.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
89
90
91
92
93
94
#MenuTitle: Import Anchors
# -*- coding: utf-8 -*-
__doc__="""
(UI) Import anchors from antother font.
"""
from GlyphsApp import *
from vanilla import *
from Foundation import NSPoint
font = Glyphs.font
class AnchorTeleporter(object):
def __init__(self):
infoText = ""
self.w = FloatingWindow((240, 190), "Import Anchors")
self.w.textBox = TextBox((10, 10, -10, 17), "Import Anchors from")
self.w.popUpFont = PopUpButton((10, 35, -10, 20),
self.createFontList(),
callback=self.popUpButtonCallback)
self.w.textBox2 = TextBox((10, 65, -10, 17), "Layer:")
self.w.popUpButton = PopUpButton((10, 85, -10, 20),[""])
self.w.restoreButton = Button((10, 115, -10, 20), "Copy Anchors", callback=self.cloneCallback)
self.w.line2 = HorizontalLine((10, 145, -10, 1))
self.w.box = Box((10, 155, -10, 24))
self.w.box.infoBox = TextBox((0, 0, -10, -0), infoText, alignment='center', sizeStyle='small')
self.w.popUpButton.enable( False )
self.w.restoreButton.enable( False )
self.w.open()
def popUpButtonCallback(self, sender):
selectedFont = Glyphs.fonts[sender.get()]
selectedLayers = selectedFont.selectedLayers
for thisLayer in selectedLayers:
layerList = []
glyph = thisLayer.parent
for layer in glyph.layers:
layerList.append(layer.name)
self.w.popUpButton.setItems( layerList )
self.w.popUpButton.enable( True )
self.w.restoreButton.enable( True )
def createFontList(self):
fonts = Glyphs.fonts
fontList = []
for thisFont in fonts:
fontList.append(thisFont.familyName)
return fontList
def reloadButtonCallback( self, sender ):
layerList = self.createLayerList()
self.w.popUpButton.setItems( layerList )
self.w.box.infoBox.set("Anchor list reloaded")
def cloneCallback(self, sender):
selectedLayers = Glyphs.font.selectedLayers
self.w.box.infoBox.set("Anchors Copied!")
def copyToFront( thisLayer, anchorName, x, y):
newAnchor = GSAnchor.alloc().init()
newAnchor.name = anchorName
thisLayer.addAnchor_( newAnchor )
newPosition = NSPoint( x, y)
newAnchor.setPosition_( newPosition )
for thisLayer in selectedLayers:
glyph = thisLayer.parent
layerIndex = self.w.popUpButton.get()
popchoose = self.w.popUpButton.getItems()
try:
for i in Glyphs.fonts[1].glyphs[glyph.name].layers:
if i.name == list(popchoose) [layerIndex]:
backupLayer = i
break
allAnchors = backupLayer.anchors
for thisAnchor in allAnchors:
anchorName = thisAnchor.name
x = thisAnchor.position.x
y = thisAnchor.position.y
copyToFront (thisLayer, anchorName, x, y)
except:
pass
AnchorTeleporter()