Get menu state of a plugin

Hi! I’m trying to get state of menu:

index = Glyphs.menu[ VIEW_MENU ].submenu().indexOfItemWithTitle_(’ some title ’)
print( Glyphs.menu[ VIEW_MENU ].submenu().itemAtIndex_( index ).state() )

And noticed that it doesn’t always update the state of plugins (works perfectly for built-in menus, but not so much for plugins). So I’m wondering is there a more reliable way to check the menu state of the reporter plugin (the one from which I’m calling it)?

Thank you!

Is this a reporter plugin and the menu item is the one made by Glyphs?

What are you trying to do?

Yes, just a normal reporter with menu defined by menuName in def settings.

It has some KVO stuff for kerning, which is outside of the given drawing callbacks, so I guess in this case I need to know the menu state to turn it on or off.

I thought about using General plugin instead, but Reporter already has a convenient on-off checkbox kind of menu, and writing it for General seems like more work than just getting Reporter’s state, or am I wrong?

So you like to know if your plugin is active?

You should get willActivate() and willDeactivate() calls. So you can keep track of your state.

Or you can check

NSArray *visibleReporterIdentifiers = [[NSUserDefaults standardUserDefaults] objectForKey:@"visibleReporters"];

if visibleReporterIdentifiers contains your bundle identifier.

1 Like

Hi Georg, does willActivate() work in Glyphs 3? Transferring my plugins to G3 and this doesn’t seem to respond to activating the plugin in menu (Reporter):

	@objc.python_method
	def willActivate( self ):
		print('hi!')

You should not mark that method with @objc.python_method.

This decorator is only used for methods that are only ever used inside of the plugin. It hides them from outside python, so glyphs will not see it.

2 Likes