Hey guys, somehow I cannot roll out the popUpButton menu item.
Any idea how can I do that?
import AppKit
import vanilla
from mojo.UI import MenuBuilder
def callback(sender):
print(sender)
def popUpButtonCallback(sender):
print(sender.get())
popUpButtonMenuItem = AppKit.NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("popUpButton", '', '')
popUpButton = vanilla.PopUpButton((0, 0, 100, 30), ['a','b','v'] ,callback=popUpButtonCallback)
view = popUpButton.getNSPopUpButton()
view.setFrame_(((0, 0), (100, 30)))
popUpButtonMenuItem.setView_(view)
builder = MenuBuilder([
("test", callback),
("test 2", callback),
("test 3", callback),
popUpButtonMenuItem,
])
menu = builder.getMenu()
print(menu)
name = "My Menu With popUpButton"
# get the menu bar
menubar = AppKit.NSApp().mainMenu()
newItem = menubar.itemWithTitle_(name)
if not newItem:
# if not, create one and append it before `Help`
newItem = AppKit.NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(name, '', '')
menubar.insertItem_atIndex_(newItem, menubar.numberOfItems()-1)
menu.setTitle_(name)
# set the menu as submenu
newItem.setSubmenu_(menu)