-
Notifications
You must be signed in to change notification settings - Fork 4
/
CompareSets.py
71 lines (58 loc) · 2.06 KB
/
CompareSets.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
#MenuTitle: CompareSets
# -*- coding: utf-8 -*-
__doc__="""
(UI) Shows diffrences between glyph sets and allows to add glyphs to fonts.
"""
from GlyphsApp import *
from vanilla import *
font1 = Glyphs.fonts[0]
font2 = Glyphs.fonts[1]
styleName1 = font1.instances[0].name
styleName2 = font2.instances[0].name
class ListDemo(object):
lista1 = []
lista2 = []
def __init__(self):
self.createLists()
DiffLists = (self.lista1, self.lista2)
#User interface elements
self.w = Window((220, 400),"Compare Sets", minSize=(220,400), maxSize=(330,1000))
self.w.textBox = TextBox((10, 10, -10, 55), "Missing on \n" + font1.familyName + " " + styleName1 + "\nvs. " + font2.familyName + " " + styleName2)
self.w.myList = List((10, 75, -10, -40), self.lista2)
self.w.button = Button((10, -30, -10, 20), "Add to font",
callback=self.button1Callback)
self.w.open()
#Button Callbacks
def button1Callback(self, sender):
seleccion = self.w.myList.getSelection()
trash = []
# Iterate over the selection, add glyph to font and append to trash list.
for i in seleccion:
name = self.w.myList.__getitem__(i)
font1.glyphs.append(GSGlyph(name))
trash.append(name)
#Add automatic components to the created glyph.
for master in font1.masters:
layer = font1.glyphs[name].layers[master.id]
layer.makeComponents()
#Iterates over the trash list and remove the element from the UI list.
for ii in trash:
self.w.myList.remove(ii)
def createLists(self):
# Create lists with the name of the glyphs of each font
for a in font1.glyphs:
self.lista1.append(a.name) #A, B, C, D, etc.
for a in font2.glyphs:
self.lista2.append(a.name)
#Create sets of the lists for later comparision.
font1Set = set(self.lista1)
font2Set = set(self.lista2)
#Create new sets with the differences.
OneDiff = font1Set.difference(font2Set)
TwoDiff = font2Set.difference(font1Set)
#Transorm the sets in list again to send it to the UI
self.lista1 = list(OneDiff)
self.lista2 = list(TwoDiff)
# Glyphs.clearLog()
# Glyphs.showMacroWindow()
ListDemo()