In a plugin, since one is able to set context menu items, I believe it would be useful to also be able to set the state of the NSMenuItem. NSMenuItems can have three states: on, off, and mixed. On shows a checkmark like the one next to Export in the context menu. Mixed shows a minus sign. Off shows no image. At least by default.
It would simplify being able to toggle settings in a plugin without having to include a view in the context menu. In addition to name and action, you could also have state settings in the context menus lists for setUpMenuHelper() to process.
Hope that makes sense. Let me know if you want more details, Georg.
Answering to myself, in the case someone will need it in the future.
from Cocoa import NSMenuItem, NSOnState, NSOffState
@objc.python_method
def settings(self):
# make menu item with the plugin-level access, to change its state later
self.menuName = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("Menu item name", self.actionName, "")
self.generalContextMenus = [{"menu": self.menuName}]
def actionName(self):
if self.menuName.state() == 0:
# change state to checked
self.menuName.setState_(NSOnState)
# do whatever menu item should do
else:
# change state to unchecked
self.menuName.setState_(NSOffState)
# do whatever menu item should do