traitsui.menu module

Defines the standard menu bar for use with Traits UI windows and panels, and standard actions and buttons.

class traitsui.menu.Action[source]

Bases: Action

An action on a menu bar in a Traits UI window or panel.

action = Str()

The method to call to perform the action, on the Handler for the window. The method must accept a single parameter, which is a UIInfo object. Because Actions are associated with Views rather than Handlers, you must ensure that the Handler object for a particular window has a method with the correct name, for each Action defined on the View for that window.

checked_when = Str()

Boolean expression indicating when the action is displayed with a check mark beside it. This attribute applies only to actions that are included in menus.

defined_when = Str()

Pre-condition for including the action in the menu bar or toolbar. If the expression evaluates to False, the action is not defined in the display. Conditions for defined_when are evaluated only once, when the display is first constructed.

enabled_when = Str()

Pre-condition for enabling the action. If the expression evaluates to False, the action is disabled, that is, it cannot be selected. All enabled_when conditions are checked each time that any trait value on an object in the UI’s context is changed. Therefore, you can use enabled_when conditions to enable or disable actions in response to user input. Be aware that this only applies to traits in the UI’s context. As a result, changes to nested traits that don’t also change a trait on some object in the context may not trigger the expression to be checked. Additionally, the expression needs to be a valid python expression given the context. i.e. eval(visible_when, globals=globals(), locals=context) should succeed.

visible_when = Str()

Pre-condition for showing the action. If the expression evaluates to False, the action is not visible (and disappears if it was previously visible). If the value evaluates to True, the action becomes visible. All visible_when conditions are checked each time that any trait value on an object in the UI’s context is changed. Therefore, you can use visible_when conditions to hide or show actions in response to user input. Be aware that this only applies to traits in the UI’s context. As a result, changes to nested traits that don’t also change a trait on some object in the context may not trigger the expression to be checked. Additionally, the expression needs to be a valid python expression given the context. i.e. eval(visible_when, globals=globals(), locals=context) should succeed.

traitsui.menu.ApplyButton = <traitsui.menu.Action object>

When the user clicks the Apply button, all changes made in the window are applied to the model. This option is meaningful only for modal windows.

traitsui.menu.CancelButton = <traitsui.menu.Action object>

When the user clicks the Cancel button, all changes made in the window are discarded; if the window is live, the model is restored to the values it held before the window was opened. The window is then closed.

traitsui.menu.CloseAction = <traitsui.menu.Action object>

The standard “close window” action

traitsui.menu.HelpAction = <traitsui.menu.Action object>

The standard “show help” action

traitsui.menu.HelpButton = <traitsui.menu.Action object>

When the user clicks the Help button, the current help handler is invoked. If the default help handler is used, a pop-up window is displayed, which contains the help text for the top-level Group (if any), and for the items in the view. If the default help handler has been overridden, the action is determined by the custom help handler. See traitsui.help.

traitsui.menu.NoButtons = [<traitsui.menu.Action object>]

The window has no command buttons

traitsui.menu.OKButton = <traitsui.menu.Action object>

When the user clicks the OK button, all changes made in the window are applied to the model, and the window is closed.

traitsui.menu.RedoAction = <traitsui.menu.Action object>

The standard “redo last undo” action

traitsui.menu.RevertAction = <traitsui.menu.Action object>

The standard “revert all changes” action

traitsui.menu.RevertButton = <traitsui.menu.Action object>

When the user clicks the Revert button, all changes made in the window are cancelled and the original values are restored. If the changes have been applied to the model (because the user clicked Apply or because the window is live), the model data is restored as well. The window remains open.

traitsui.menu.Separator[source]

Menu separator

traitsui.menu.StandardMenuBar = <pyface.ui.null.action.menu_bar_manager.MenuBarManager object>

The standard Traits UI menu bar

traitsui.menu.UndoAction = <traitsui.menu.Action object>

The standard “undo last change” action

traitsui.menu.UndoButton = <traitsui.menu.Action object>

Undo and Redo. When Undo is clicked, the most recent change to the data is cancelled, restoring the previous value. Redo cancels the most recent “undo” operation.

Type:

Appears as two buttons