Advertisement
guidoferreyra

Compare Sets

Nov 21st, 2015
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.53 KB | None | 0 0
  1. #MenuTitle: Compare SetsFranco
  2. # -*- coding: utf-8 -*-
  3. __doc__="""
  4. Shows diffrences between glyph sets and allows to add glyphs to fonts.
  5. """
  6.  
  7. from GlyphsApp import *
  8. from vanilla import *
  9.  
  10. class ListDemo(object):
  11.  
  12.     font1 = Glyphs.fonts[0]
  13.     font2 = Glyphs.fonts[1]
  14.     masterName1 = font1.masters[0].name
  15.     masterName2 = font2.masters[0].name
  16.     # acá están como atributos del objeto
  17.     lista1 = []
  18.     lista2 = []
  19.    
  20.     def __init__(self):
  21.  
  22.         self.createLists()
  23.        
  24.  
  25.         #User interface elements
  26.         self.w = Window((320, 300))
  27.         self.w.textBox = TextBox((10, 10, -10, 34), "Missing on \n" + font2.familyName + " " + masterName2)
  28.         self.w.myList = List((10, 55, 140, -40), self.lista1)
  29.         self.w.button = Button((10, -30, 140, 20), "Add to font",
  30.                             callback=self.button1Callback)
  31.                      
  32.         self.w.textBox2 = TextBox((170, 10, -10, 34), "Missing on \n" + font1.familyName + " " + masterName1)                    
  33.         self.w.myList2 = List((170, 55, 140, -40), self.lista2)
  34.         self.w.button2 = Button((170, -30, 140, 20), "Add to font",callback=self.button2Callback1)          
  35.         self.w.open()
  36.  
  37.     #Respuestas de los botones
  38.     def button1Callback(self, sender):
  39.         seleccion = self.w.myList.getSelection()
  40.         for i in seleccion:
  41.             name = self.w.myList[i]
  42.             font2.glyphs.append(GSGlyph(name))
  43.             self.createLists()
  44.             print self.lista1
  45.             print self.lista2
  46.             for layer in font2.glyphs[name].layers:
  47.                 layer.makeComponents()
  48.  
  49.  
  50.     def button2Callback1(self, sender):
  51.         #Variable que recoge la Lista de la selección hecha.
  52.         seleccion = self.w.myList2.getSelection()
  53.         #iteracion sobre la lista para vincularla con su nombre de glifo
  54.         for i in seleccion:
  55.             name = self.w.myList2[i]
  56.             #Agrega el elemento de  la lista (glifo) a la fuente
  57.             font1.glyphs.append(GSGlyph(name))
  58.             self.createLists()
  59.             print self.lista1
  60.             print self.lista2
  61.             #funcion de Glyphs para crear componentes
  62.             for layer in font1.glyphs[name].layers:
  63.                 layer.makeComponents()
  64.    
  65.     def createLists(self):
  66.         for a in font1.glyphs:
  67.             b = str(a).split('"')
  68.             self.lista1.append(b[1]) #A, B, C, D, etc.
  69.         for a in font2.glyphs:
  70.             b = str(a).split('"')
  71.             self.lista2.append(b[1])
  72.         #Hago sets de las listas
  73.         font1Set = set(self.lista1)
  74.         font2Set = set(self.lista2)
  75.        
  76.         #Hace sets con las difrencias
  77.         OneDiff = font1Set.difference(font2Set)
  78.         TwoDiff = font2Set.difference(font1Set)
  79.  
  80.         #Transforma los sets en listas de nuevo
  81.         self.lista1 = list(OneDiff)
  82.         self.lista2 = list(TwoDiff)
  83.  
  84.  
  85. Glyphs.clearLog()
  86. Glyphs.showMacroWindow()
  87. ListDemo()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement