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
set_save_name('Edit')
menu = Menu('main', [
('/File', '', '<Branch>'),
('/File/Save', 'save', ''),
('/File/Open Parent', 'up', ''),
('/File/Close', 'close', ''),
('/File/', '', '<Separator>'),
('/File/New', 'new', ''),
('/Edit', '', '<Branch>'),
('/Edit/Undo', 'undo', ''),
('/Edit/Redo', 'redo', ''),
('/Edit/', '', '<Separator>'),
('/Edit/Search...', 'search', ''),
('/Edit/Goto line...', 'goto', ''),
('/Edit/', '', '<Separator>'),
('/Edit/Process...', 'process', ''),
('/Options', 'show_options', ''),
('/Help', 'help', '<StockItem>', 'F1', g.STOCK_HELP),
])
There is also a new syntax, supported from 1.9.13, where you pass instances of MenuItem
instead of tuples to the Menu constructor. Be sure to require version 1.9.13 if
using this feature.`

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.`