Python plugin way to nestle two tools unders same icon?

Is there a way to do this like with the oval/rectangle tool. I have a selectTool that will draw something at the cursor and I’d like to toggle between two settings with a shortcut, my current solution is to just provide two plugins even though there is only one difference in the two plugins.

One option is to build one tool that has two different states. It returns a different toolbar icon according to the state and reacts accordingly. To get the small triangle and the popup menu, implement this method:

def toolbarMenu(self):
    	theMenu = NSMenu.alloc().initWithTitle_(self.title())
	newMenuItem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("Erase", self.setErease , "") # self.setErease is a method in your plugin class
	newMenuItem.setImage_(self.toolbarErase) # it has to be an NSImage, this is optional

	newMenuItem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("Knife", self.setKnife , "")
	newMenuItem.setImage_(self.toolbarKnife) # it has to be an NSImage, this is optional

	return theMenu;

(typed in Safari, so it might not run as is)


Sorry I really don’t know anything about PyObjC, my plugin is drawing something in the foreground, do I write two different foreground methods?

No, you do:

def foreground(self):
    if self.toolOneActive:
        # draw for first tool
        # draw for second tool
1 Like

thanks, so toolOneActive is an exisiting state depending on the toolbarMenu() ? I don’t have to define this?

and do i put self.foreground here

newMenuItem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("Tool 1", self.foreground , "")

or is it supposed to be a method that will define the toolOneActive as true?

self.toolOneActive is a viable that stores what tool is active (just pick a different name if you like). You set it in the methods you assigned in the menu item. You should never call the foreground methods yourself. The menu items get a method each that sets the current tool.