Script notifications

I have a script which opens a floating window. The contents and behaviour of that window need to be refreshed when the user chooses a different glyph to edit in the edit view. Is it possible to get a notification when we’re editing a new glyph?

There is a notification for this:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(update:) name:@"GSUpdateInterface" object:nil];

I am curious about that too. Currently trying to rewrite it to python, but wonder where the arguments come from?
NSNotificationCenter.defaultCenter().addObserver_selector_name_object_(self, ???, ???, None)

Ah i found some working things. Just wondering if instead of "GSUpdateInterface" there is another notification that only call when you are changing the active glyph (like Simon asked).
"GSUpdateInterface" calls are too often in this case.

Huh. I couldn’t get it to work; in my case, the script exits before any notifications are sent.

But: put your script stuff into a class. Use self to refer to the class, and objc.selector( self.whatever, "v@:@") as the selector to be called on notification.

the selector can be a method in your class, like self.updateInterface. The third parameter is the name of the notification you like to receive:

NSNotificationCenter.defaultCenter().addObserver_selector_name_object_(self, self.updateInterface, "GSUpdateInterface", None)

And I added it to the wrapper. So soon you can use this:

Glyphs.addCallback(self.updateInterface, "GSUpdateInterface")

Thanks guys! This helps a lot. I got it working in a Plugin, not yet in a Script though, will keep trying.

So, @GeorgSeifert: "GSUpdateInterface" is called too often (for this particular case). I guess we are asking for an event that only calls when the active Glyph in the Editor is changed, not when any change happens.

And BTW: what does this signature="v@:" or "v@:@" actually mean?

About selectors:

You could check the change date of the tab.activeLayer.parent and only do your processing if it has changed.

Thanks for the link. I am starting to slowly get into them.

Regarding the tab.activeLayer.parent: I cannot get it to work, only until the activeLayer, adding the .parent to it, returns an AttributeError. Anyway, it reads as if it’s not what I seek. I search for a notification for this:
You have a glyph active to edit. now you either fn+left/right to activate the next glyph, or double click another glyph in the edit view. Is your suggestion doing this?

I am storing the current layerName now and permanently check if it changed. Just asking if there is already a GSUpdateWhatever matching this. If not, no problem, works like a charm now, this speeded up the plugin like crazy, no observer needed. :slight_smile:

Use the layer directly, not its name. And compare it using is instead of ==:

if oldLayer is activeLayer:
    oldLayer = activeLayer

Ah, good point! Yet I need the name here, because it is about the glyph change, not the layer (or master change) :slight_smile: but your version is usefull too.

mine is:

def observeGlyphChange(self, layer):
    global currentGlyphName
    lName =
    if currentGlyphName is not lName:
        currentGlyphName = lName
        self.activeGlyphChanged = True

and then I use if self.activeGlyphChanged: ... at several places. Don’t know if a global variable is necessary, but it works.

Thanks so much for the help!

Is there a way to check if the Font Overview is currently open? From a reporter. I guess when you are in that particular tab, the reporter is disabled but not deactivated. Hence I cannot check the Font Overview status from within a reporter.

What exactly are you trying to do?

I have a reporter with a UI (and it will keep it, cuz it makes quite some sense :slight_smile: ) and this UI is not needed in Font Overview.

I don’t understand what you are trying to do but you can check if Font.currentTab == None:.

I tried that, doesn’t work. A reporter does not run any code when in Font Overview.

I want to render the same behaviour as Speedpunk’s UI does: When you get into Font Overview, it hides. Speedpunk is not a reporter though.

Hiding and showing is not the issue, but the trigger or notification once the user gets into the font overview is.

You like to hide the dialog window. I thought ‘render UI’ means drawing something in edit view. I’ll see about that.

No, sorry for not being clear. Exactly, i want to hide it, but cannot, since the reporter code (that might check for the tab status) is inactive then.

Any news about this?

Bumping the request. Still not possible to check against a tab’s existence, since reporter code is not executed when in Font Overview.