I’m beginning with scripting in Python and Glyph API.
I would like to code a script to know how many glyphs had specific layer color.
I don’t know how to code the equivalent of “Check for each glyph in the font, if has the Layer color “Light Green” and return a list of them.”
For the moment I just have this little code
for glyph in font.glyphs:
if Layer.color == 4:
print(str(glyph.name))
else:
pass
for glyph in font.glyphs:
layer = glyph.layers[0]
…
But to get to all master layers, do this:
for master in font.masters:
colorCount = 0
for glyph in font.glyphs:
layer = glyph.layers[master.id]
if layer.color == 4: # add on of the color constants
colorCount += 1
print("master %s: %d of %d done" % (master.name, colorCount, len(font.glyphs)))
…
Thanks, this will clean a lot my code !
I read the topic about Plugin Palette in GlyphsSDK, but I don’t know if my UI intention need to use Interface Builder or if it’s possible with only Vanilla?
You can do that with vanilla. But for either solution you will need a custom view class for the progress bar (don’t bother with the built-in progress bar. Just make one from scratch will be easier.)
But I see some problems with putting it in a sidebar panel:
the bars will not change a lot so you look at the same data most of the time.
I don’t see a good way to trigger an update when the layer color changes and computing it all the time is too slow.
I would like to finish this Plugin now that I am more comfortable with Python and GlyphAPI.
But just one thing, I don’t know how to draw shapes with Python (and without drawBot)
Georg, can I ask, with NSView, is there any method for dragging NSPoints with the cursor? I have a similar idea of some custom UI elements for a plugin, except I’d like to control them directly with the mouse, which is a little beyond my knowledge so far.
Not quite, I’d like to control offcurves of a bezier segment as a UI element (remember, “curves” controller in Photoshop). For now, I’ve solved that with sliders, but it’s not as intuitive.