Python: module rox.Menu

rox.Menu | index

`The Menu widget provides an easy way to create menus that allow the user to
define keyboard shortcuts, and saves the shortcuts automatically. You only define
each Menu once, and attach it to windows as required.
Example:
from rox.Menu import Menu, set_save_name, Action, Separator, SubMenu
set_save_name('Edit')
menu = Menu('main', [
SubMenu('File', Menu([
Action('Save', 'save'),
Action('Open Parent', 'up'),
Action('Close', 'close'),
Separator(),
Action('New', 'new')
])),
SubMenu('/Edit', Menu([
Action('Undo', 'undo'),
Action('Redo', 'redo'),
Separator(),
Action('Search...', 'search'),
Action('Goto line...', 'goto'),
Separator(),
Action('Process...', 'process'),
])),
Action('Options', 'show_options', 'F1', stock=g.STOCK_HELP)),
Action('Quit', 'quit', stock=g.STOCK_QUIT),
])
There is also an older syntax, where you pass tuples of strings
to the Menu constructor. This has not been required since 1.9.13.`

Classes
`` |  | Menu MenuItem Action Separator SubMenu ToggleItem
class Action(MenuItem)
`` | `A leaf menu item, possibly with a stock icon, which calls a method when clicked.`
| Methods defined here: __init__(self, label, callback_name, key=None, stock=None, values=()) `object.callback(*values) is called when the item is activated.` activate(self, caller)
class Menu
`` | `A popup menu. This wraps GtkMenu. It handles setting, loading and saving of keyboard-shortcuts, applies translations, and has a simpler API.`
| Methods defined here: __init__(self, name, items) `names should be unique (eg, 'popup', 'main', etc). items is a list of menu items: [(name, callback_name, type, key), ...]. 'name' is the item's path. 'callback_name' is the NAME of a method to call. 'type' is as for g.ItemFactory. 'key' is only used if no bindings are in Choices.` attach(self, window, object) `Keypresses on this window will be treated as menu shortcuts for this object, calling 'object.<callback_name>' when used.` popup(self, caller, event, position_fn=None) `Display the menu. Call 'caller.<callback_name>' when an item is chosen. For applets, position_fn should be my_applet.position_menu).`
class MenuItem
`` | `Base class for menu items. You should normally use one of the subclasses...`
| Methods defined here: __init__(self, label, callback_name, type='', key=None, stock=None) activate(self, caller)
class Separator(MenuItem)
`` | `A line dividing two parts of the menu.`
| Methods defined here: __init__(self)
class SubMenu(MenuItem)
`` | `A branch menu item leading to a submenu.`
| Methods defined here: __init__(self, label, submenu)
class ToggleItem(MenuItem)
`` | `A menu item that has a check icon and toggles state each time it is activated.`
| Methods defined here: __init__(self, label, property_name) `property_name is a boolean property on the caller object. You can use the built-in Python class property() if you want to perform calculations when getting or setting the value.` activate(self, caller) update(self, menu, widget) `Called when then menu is opened.`

Functions
`` |  | set_save_name(prog, leaf='menus', site=None) `Set the directory/leafname (see choices) used to save the menu keys. Call this before creating any menus. If 'site' is given, the basedir module is used for saving bindings (the new system). Otherwise, the deprecated choices module is used.`