Release: 16/10/2001
Menus can be attached to windows and submenus can be shared between menus. Both of these features are demonstrated by the menus.py demonstration. The most interesting part of the program is the dynamic menu:
def create_submenu(args): # The arguments passed were just three lists text = args[0] flags = args[1] links = args[2]
# The last three items are the x and y screen coordinates of the # menu location and the menu code. # Look up the menu object for alteration menu = app.menus[args[-1]] # Read the screen position x, y = args[-3], args[-2]
# Write the new menu title
menu.title = 'Dynamic menu at ('+str(x)+', '+str(y)+')'
# Write the lists to the menu's items list menu.items = [] for i in range(0, len(text)): menu.items.append( (text[i], flags[i], links[i], None, None) )
# Return value is currently unimportant return 'Done'
dynamic_submenu = app.Menu( None, None, None, None, 'Dynamic menu', [] )
# Make the submenu dynamic by adding a message handler. The arguments
# are passed in a list. In this case we are passing three lists of items.
# Not really a good demonstration of the dynamic nature of the menu, but
# illustrates the argument passing feature.
dynamic_submenu.add_messageaction('MenuWarning', create_submenu,
[
['My', 'dynamic', 'menu'],
['shaded', 'dotted', ''],
[None, None, 'another']
] )
app.add_menu(dynamic_submenu, 'dynamic submenu')