scallop dome pyformex logo

Previous topic

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

Next topic

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

[FSF Associate Member]

Valid XHTML 1.0 Transitional

19. menu — Menus for the pyFormex GUI.

This modules implements specialized classes and functions for building the pyFormex GUI menu system.

Classes defined in module menu

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.

Return a list with the current actions.

Return a list with the current actions of given class.

Return a list with the submenus

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

Parameters:

  • items: a list of menuitem tuples. Each item is a tuple of two or three elements: (text, action, options):
    • text: the text that will be displayed in the menu item. It is 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.
    • options: optional dictionary with following honoured fields:
      • icon: the name of an icon to be displayed with the item text. This name should be that of one of the icons in the pyFormex icondir.
      • shortcut: is an optional key combination to select the item.
      • tooltip: a text that is displayed as popup help.
  • before: if specified, should be the text or the action of one of the items in the Menu (not the items list!): the new list of items will be inserted before the specified item.

A popup/pulldown menu.

Return a list with the current actions.

Return a list with the current actions of given class.

Return a list with the submenus

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

Parameters:

  • items: a list of menuitem tuples. Each item is a tuple of two or three elements: (text, action, options):
    • text: the text that will be displayed in the menu item. It is 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.
    • options: optional dictionary with following honoured fields:
      • icon: the name of an icon to be displayed with the item text. This name should be that of one of the icons in the pyFormex icondir.
      • shortcut: is an optional key combination to select the item.
      • tooltip: a text that is displayed as popup help.
  • before: if specified, should be the text or the action of one of the items in the Menu (not the items list!): the new list of items will be inserted before the specified item.

A menu bar allowing easy menu creation.

Return a list with the current actions.

Return a list with the current actions of given class.

Return a list with the submenus

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

Parameters:

  • items: a list of menuitem tuples. Each item is a tuple of two or three elements: (text, action, options):
    • text: the text that will be displayed in the menu item. It is 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.
    • options: optional dictionary with following honoured fields:
      • icon: the name of an icon to be displayed with the item text. This name should be that of one of the icons in the pyFormex icondir.
      • shortcut: is an optional key combination to select the item.
      • tooltip: a text that is displayed as popup help.
  • before: if specified, should be the text or the action of one of the items in the Menu (not the items list!): the new list of items will be inserted before the specified item.

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.

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.

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.

Create a new toolbar corresponding to the menu.

Functions defined in module menu

Reset the warning filters to the default.

Returns the default pyFormex GUI menu data.