pyface.action.action module

The base class for all actions.

class pyface.action.action.Action[source]

Bases: traits.has_traits.HasTraits

The base class for all actions.

An action is the non-UI side of a command which can be triggered by the end user. Actions are typically associated with buttons, menu items and tool bar tools.

When the user triggers the command via the UI, the action’s ‘perform’ method is invoked to do the actual work.

accelerator = Str()

Keyboard accelerator (by default the action has NO accelerator).

checked = Bool(False)

Is the action checked? This is only relevant if the action style is ‘radio’ or ‘toggle’.

description = Str()

A longer description of the action (used for context sensitive help etc). If no description is specified, the tooltip is used instead (and if there is no tooltip, then well, maybe you just hate your users ;^).

enabled = Bool(True)

Is the action enabled?

visible = Bool(True)

Is the action visible?

id = Str()

The action’s unique identifier (may be None).

image = Image

The action’s image (displayed on tool bar tools etc).

name = Str()

The action’s name (displayed on menus/tool bar tools etc).

on_perform = Callable

An (optional) callable that will be invoked when the action is performed.

style = Enum("push", "radio", "toggle", "widget")

The action’s style.

tooltip = Str()

A short description of the action used for tooltip text etc.

control_factory = Callable

An (optional) callable to create the toolkit control for widget style.


Called when creating a “widget” style action.

By default this will call whatever callable is supplied via the ‘control_factory’ trait which is a callable that should take the parent control and the action as arguments and return an appropriate toolkit control. Some operating systems (Mac OS in particular) may limit what widgets can be displayed in menus.

This method is only used when the ‘style’ is “widget” and is ignored by other styles.


parent (toolkit control) – The toolkit control, usually a toolbar.


control – A toolkit control or None.

Return type

toolkit control


Called when the action is no longer required.

By default this method does nothing, but this would be a great place to unhook trait listeners etc.


Performs the action.


event (ActionEvent instance) – The event which triggered the action.

classmethod factory(*args, **kwargs)[source]

Create a factory for an action with the given arguments.

This is particularly useful for passing context to Tasks schema additions.