14. menu — Menus for the pyFormex GUI.

Menus for the pyFormex GUI.

A general menu class.

A hierarchical menu that keeps a list of its item names and actions. The item names are normalized by removing all ‘&’ characters and converting the result to lower case. It thus becomes easy to search for an existing item in a menu.

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.

Methods

Create a menu.

Methods

BaseMenu objects have the following methods:

Return a list with the current actions.

Return the index of the specified item in the actionlist.

If the requested item is not in the actionlist, -1 is returned.

Return the action with specified text.

First, a normal action is tried. If none is found, a separator is tried.

Return the item with specified text.

For a normal action or a separator, an qction is returned. For a menu action, a menu is returned.

Returns the name of the next item.

This can be used to replace the current item with another menu. If the item is the last, None is returned.

Remove an item from this menu.
Create and insert a separator
Insert an existing menu.
Insert an action.
Create and insert an action.

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,
  • an existing Menu,
  • 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.

A popup/pulldown menu.

Methods

Create a popup/pulldown menu.

If parent==None, the menu is a standalone popup menu. If parent is given, the menu will be inserted in the parent menu. If parent==pyformex.GUI, the menu is inserted in the main menu bar. If a parent is given, and tearoff==True, the menu can be teared-off.

If insert == True, the menu will be inserted in the main menubar before the item specified by before. If before is None or not the normalized text of an item of the main menu, the new menu will be inserted at the end. Calling the close() function of an inserted menu will remove it from the main menu.

If insert == False, the created menu will be an independent dialog and the user will have to process it explicitely.

Methods

Menu objects have the following methods:

A menu bar allowing easy menu creation.

Methods

Create the menubar.

Methods

MenuBar objects have the following methods:

A DAction is a QAction that emits a signal with a string parameter.

When triggered, this action sends a signal (default ‘Clicked’) with a custom string as parameter. The connected slot can then act depending on this parameter.

Methods

Create a new DAction with name, icon and string data.

If the DAction is used in a menu, a name is sufficient. For use in a toolbar, you will probably want to specify an icon. When the action is triggered, the data is sent as a parameter to the SLOT function connected with the ‘Clicked’ signal. If no data is specified, the name is used as data.

See the views.py module for an example.

Methods

DAction objects have the following methods:

Menu and toolbar with named actions.

An action list is a list of strings, each connected to some action. The actions can be presented in a menu and/or a toolbar. On activating one of the menu or toolbar buttons, a given signal is emitted with the button string as parameter. A fixed function can be connected to this signal to act dependent on the string value.

Methods

Create an new action list, empty by default.

A list of strings can be passed to initialize the actions. If a menu and/or toolbar are passed, a button is added to them for each string in the action list. If a function is passed, it will be called with the string as parameter when the item is triggered.

If no icon names are specified, they are taken equal to the action names. Icons will be taken from the installed icon directory. If you want to specify other icons, use the add() method.

Methods

ActionList objects have the following methods:

Add a new name to the actions list and create a matching DAction.

If the actions list has an associated menu or toolbar, a matching button will be inserted in each of these. If an icon is specified, it will be used on the menu and toolbar. The icon is either a filename or a QIcon object. If text is specified, it is displayed instead of the action’s name.

Return an ordered list of names of the action items.

Functions defined in the module menu

Reset the GUI to its default operating mode.

When an exception is raised during the execution of a script, the GUI may be left in a non-consistent state. This function may be called to reset most of the GUI components to their default operating mode.

Returns the default pyFormex GUI menu data.

Documentation

Previous topic

13. widgets — A collection of custom widgets used in the pyFormex GUI

Next topic

15. colorscale — Color mapping of a range of values.

This Page