Need help with Glyph API and Python

I’d like to have a simple segment like this and to be able to drag around the offcurves with the mouse:

I think I understand how to draw it, but not how to make the offcruves draggable.

What exactly do you want to do?

For dragging and moving stuff, this might get you started: Handling Mouse Events

1 Like

Hi @HugoJ I really like this idea of having a plugin that helps keep track of progress! Anything to help gamify the mundane tasks.

If you don’t mind, I’d like to maybe drop in some ideas for brainstorming. If you have a github set up for this, I can make suggestions there. Also, if it is possible, I’d love to test the palette view version.

I wonder if each category in the palette view could get a button/checkbox next to it? So if you’re going through glyphs then you can easily click to sort/resort which glyphs go in which category.

To add a bit of extra functionality to the dashboard, maybe clicking on each progress bar can give a pop-up to show make a new tab with glyphs that are marked or not marked…sort of like how in the GutenTag plugin you can select a tag and have it show all of those glyphs. For example: I can imagine clicking on the Check Anchors label to open a new tab and bring up all the anchors that are not checked.

1 Like

Hi @GeorgSeifert,

I’m trying to work again on this plugin. But I’m really struggling with drawing Rectangle.
I know Python and Vanilla Library, but absolutely not Swift.

I understood that Vanilla is a bridge between Python and Swift, and coding rectangle is not included in Vanilla.

Could you please send me a very basic example to draw a Rectangle using NSView ?
Just to understand the logic behind.

I’m waiting to finish this plugin to write a complete article/tutorial about how color Labels can improve efficiency and organisation of a project.

Thanks

I found a very low-end alternative solution meanwhile.
Drawing ImageView object with an image of a solid color.

You mean “python and ObjctiveC” and not “Swift”.

How to draw stuff

This is the documentation from Apple: Introduction to Cocoa Drawing Guide

rect = NSMakeRect(10, 10, 20, 20)
NSColor.colorWithRed_green_blue_alpha_(0.2, 0.8, 0.4, 1).set()
path = NSBezierPath.bezierPathWithRect_(rect)
path.fill()
2 Likes

Thanks @GeorgSeifert,
This work perfectly using Skedge Plugin to preview it.

But how to implement it in a Vanilla Window ?
Here is my code :

import AppKit 
from AppKit import NSMakeRect, NSColor, NSBezierPath
from vanilla import FloatingWindow, Button, TextBox


class FloatingWindowDemo:

	def __init__(self):
		self.w = FloatingWindow((500, 500), "FloatingWindow Demo")
		self.w.myButton = Button((10, 10, -10, 20), "My Button")
		self.w.myTextBox = TextBox((10, 40, -10, 17), "My Text Box")
		
		rect = NSMakeRect(100, 100, 2000, 2000)
		NSColor.colorWithRed_green_blue_alpha_(0.2, 0.8, 0.4, 1).set()
		path = NSBezierPath.bezierPathWithRect_(rect)
		path.fill()
			
		self.w.open()

FloatingWindowDemo()


What do you like to achieve? Can you post a screenshot?

My goal is to code a Palette Plugin displaying a Progress Bar showing LayerColor labels of selected Master.

I finally managed to code it, but I’m still struggling with one thing.

Plugin works on start (when Glyph3 app is open) , but I don’t know how to update the view (I mean the progress bar) after that.

I coded a check to only run code if selectedMaster is changed.
(To avoid to set again the dictionary including for each color the number of layers)

You misunderstood how drawing in macOS/cocoa works. You can’t just call the draw() method. You need to tell the self.paletteView.frame.swatches view to update. So in the observer, you add a self.update method and in it you call self.paletteView.frame.swatches.update().

1 Like

Thanks for you help @GeorgSeifert !
New version is out and work as excepted :slight_smile:
I mixed my idea with the initial plugin LabelKey from Robert Pratley.

Cut the new version needs way too much space. You might not need the top bar that shows all colors at once. And out the names and the bars on one line. That reduces the size of the bars but it will probably be enough here.

1 Like

Something like this ?
I think top bar could be useful to show a global overview.

But, putting name and bars on same line, could create problem if user change name, for a longer text that can overlap the bar.

Capture d’écran 2022-05-31 à 12.42.32

better.

I wonder why would you need both?

Then you need to set it up to adapt to it. Either by measuring the string length or by using auto layout.

1 Like

I think you are right, global bar is not needed.
About name and bar, I switched position to avoid overlap problem for the moment.

I have a question, there is better way to create a dic with number of LayerColor for the selected master ?

font = Glyphs.font
LayerColorLabel = {"0":0,"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"None":0}

for glyph in font.glyphs:
    for layer in glyph.layers:
        if layer.isMasterLayer and layer.layerId == font.selectedFontMaster.id:
            LayerColorLabel[str(layer.color)] += 1
print(LayerColorLabel)

Because with font project with large glyphset, switching master is a bit laggy.

1 Like

I found a solution, script is 10 times faster now:

font = Glyphs.font
LayerColorLabel = {"0":0,"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"None":0}
	for glyph in font.glyphs:
		color = glyph.layers[font.selectedFontMaster.id].color
		LayerColorLabel[str(color)] += 1
print(LayerColorLabel)
1 Like

Move the font.selectedFontMaster.id out of the loop.

font = Glyphs.font
LayerColorLabel = {"0":0,"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"None":0}
masterId = font.selectedFontMaster.id
for glyph in font.glyphs:
	color = glyph.layers[masterId].color
	LayerColorLabel[str(color)] += 1
print(LayerColorLabel)

And I think you can use the color as a key directly:

font = Glyphs.font
LayerColorLabel = {0:0,1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:0,9:0,10:0,11:0,None:0}
masterId = font.selectedFontMaster.id
for glyph in font.glyphs:
	color = glyph.layers[masterId].color
	LayerColorLabel[color] += 1
print(LayerColorLabel)

and have a look at the Counter object. it could be used like this:

import collections

LayerColorLabel = collections.Counter()
masterId = font.selectedFontMaster.id
for glyph in font.glyphs:
	color = glyph.layers[masterId].color
	LayerColorLabel.update(color)
print(LayerColorLabel)
1 Like