8.13.30 BaseMenu class: A general menu class.

This class is not intended for direct use, but through subclasses. Subclasses should implement at least the following methods: addSeparator() insertSeperator(before) addAction(text,action) insertAction(before,text,action) addMenu(text,menu) insertMenu(before,text,menu)

QtGui.Menu and QtGui.MenuBar provide these methods.

The BaseMenu class has this constructor:

class BaseMenu( title='AMenu',parent=None,before=None,items=None)
Create a menu.

This is a hierarchical menu that keeps a list of its item names and actions.

BaseMenu objects have the following methods:

item( text)
Get the menu item with given normalized text.

Text normalization removes all '&' characters and converts to lower case.

itemAction( item)
Return the action corresponding to item.

item is either one of the menu's item texts, or one of its values. This method guarantees that the return value is either the corresponding Action, or None.

insert_sep( before=None)
Create and insert a separator

insert_menu( menu,before=None)
Insert an existing menu.

insert_action( action,before=None)
Insert an action.

create_insert_action( str,val,before=None)
Create and insert an action.

insertItems( items,before=None)
Insert a list of items in the menu.

Each item is a tuple of two to five elements: Text, Action, [ Icon, ShortCut, ToolTip ].

Item text is the text that will be displayed in the menu. It will be stored in a normalized way: all lower case and with '&' removed.

Action can be any of the following: - a Python function or instance method : it will be called when the item is selected, - a string with the name of a function/method, - a list of Menu Items: a popup Menu will be created that will appear when the item is selected, - None : this will create a separator item with no action.

Icon is the name of one of the icons in the installed icondir. ShortCut is an optional key combination to select the item. Tooltip is a popup help string.

If before is given, it specifies the text OR the action of one of the items in the menu: the new items will be inserted before that one.