Create popup menu with 2 levels

I would like to create popup menu with 2 levels :
– Command1
– Command11
– Command12
– Command2
– Command21
– Command22

Command11
Command12
become visible when Command1 is selected

is it possible with system.gui.createPopupMenu ?

Here’s an example that replaces the first menu with a new menu when you select one of its items:

Use in mouseReleased of a label (right-click to activate):

def subMenu(event):
	import system
	
	def sayHello(event):
		import system
		system.gui.messageBox("Hello World")
	def sayGoodbye(event):
		import system
		system.gui.messageBox("Goodbye Cruel World")
	submenu = system.gui.createPopupMenu({"Hello":sayHello, "Goodbye":sayGoodbye})
	submenu.show(event)
menu = system.gui.createPopupMenu({"SUB MENU":subMenu})
menu.show(event)

Here is another way to do the same thing, just shows previous levels.

if event.popupTrigger:
       # Create the main menu
	names = []
	funcs = []
	
	##############################################################
	# Create the first sub menu
	subnames = []
	subfuncs = []
	
	##############################################################
	# Add some functions to this menu
	def sayHello(event):
		import system
		system.gui.messageBox("Hello World")
	subnames.append("Hello")
	subfuncs.append(sayHello)
	
	def sayGoodbye(event):
		import system
		system.gui.messageBox("Goodbye Cruel World")
	subnames.append("Goodbye")
	subfuncs.append(sayGoodbye)
	
	##############################################################
	# create English sub menu
	names.append("English")
	funcs.append([subnames,subfuncs])
	
	
	# Add a seperator
	names.append(None)
	funcs.append(None)
	
	##############################################################
	# Create another sub menu
	subnames = []
	subfuncs = []
	
	##############################################################
	# Add functions to this submenu
	def sayHello(event):
		import system
		system.gui.messageBox("Guten Tag")
	subnames.append("Guten Tag")
	subfuncs.append(sayHello)
	
	def sayGoodbye(event):
		import system
		system.gui.messageBox("Guten Abend")
	subnames.append("Guten Abend")
	subfuncs.append(sayGoodbye)
	
	names.append("German")
	funcs.append([subnames,subfuncs])

	##############################################################
	# create the popup menu
	menu = system.gui.createPopupMenu(names, funcs)
	menu.show(event)

Cheers,
Chris

1 Like