Vanilla list update and smart glyph adding

Hi everyone!
I’m practicing trying to create a script that compares the glyph set of two open fonts and trough a button allows to add glyphs to fonts.
Here my questions.

  1. When I add a glyph it only creates the glyph but not filled with the components in the case of accented glyphs. I want to achieve the smart behavior of Glyphs. Is this possible?

  2. I don’t know how to update the list after adding items, I’ve tried with self.w.myList.remove but after this, for instance, I get “out of range” errors.

I think is more easy to understand and find errors looking to the code. Here the script and a screenshot.

compareSets.py.zip (871 Bytes)

Thanks in advance, Best regards.

myLayer.makeComponents()

Why not just rebuild the list? Just reuse the method you have for building the lists in the first place.

Thanks! I’ve been trying to implement this but without success yet.
I don’t know why myLayer.makeComponents() works only for one master.
This is what Im doing in the button callback function. What im doing wrong?

def button2Callback1(self, sender):
		seleccion = self.w.myList2.getSelection()
		for i in seleccion:
			name = self.w.myList2[i]
			font1.glyphs.append(GSGlyph(name))
			for layer in font1.glyphs[name].layers:
				layer.makeComponents()

Im following your suggestion for my other question, creating a function for building the list but I don’t know how to reuse it after clicking the button. I need to improve my python skills. back to Codecademy!! haha.

Regards.

Create one class method buildList(self) and have every method that does anything with the list also call self.buildList().

I will try to do this. Thank you!

Well, I’ve tried what you say and and finally I managed to call the function that build the lists when I hit the button, thanks!
The lists are updated but for some reason the UI list is not updated.

Could you help me pointing me what I’m doing wrong?

http://pastebin.com/aF5X1ri5

Thanks in advance. Best regards.

Type this in the Macro window and press the Run button:

import vanilla
help(vanilla.List)

What you want is probably the myList.remove(thisItem) method.

Also, take a look at how you implement the variables. You can initialise class variables in init, but you need to prefix them with self.

Thanks for all the help you gave me.
I have a question related to the myLayer.makeComponents() function.
When the glyph is added to the font and later I run the function of makeComponentes, it only works for one layer because until I enter to the added glyph or switch masters, the layers for other masters are not created. There is a way to “enter” the glyph with the code.

Here is the script posted https://github.com/guidoferreyra/Glyphs-Scripts/blob/master/CompareSets.py

Thanks in advance, best regards.

myLayer.makeComponents() is a method of the layer. You need to iterate over all layers and call it on each of them

Hi Georg, this is what I’m doing. Is this what are you saying?

for layer in font1.glyphs[name].layers:
     layer.makeComponents()

Yes.

This is what I done, but is not working. Any idea?

Can you try this:

glyph = Font.glyphs["n"]
for master in Font.masters:
	layer = glyph.layers[master.id]
	layer.makeComponents()

It works, thanks a lot Georg!
Later I will be posting the updated version on github, maybe is useful for someone else.

Best regards.