pyface.action.action_manager module

Abstract base class for all action managers.

class pyface.action.action_manager.ActionManager(*args, **traits)[source]

Bases: HasTraits

Abstract base class for all action managers.

An action manager contains a list of groups, with each group containing a list of items.

There are currently three concrete sub-classes:

  1. ‘MenuBarManager’

  2. ‘MenuManager’

  3. ‘ToolBarManager’

DEFAULT_GROUP = Constant("additions")

The Id of the default group.

controller = Instance(ActionController)

The action controller (if any) used to control how actions are performed.

enabled = Bool(True)

Is the action manager enabled?

groups = Property(List(Instance(Group)), observe='_groups.items')

All of the contribution groups in the manager.

id = Str()

The manager’s unique identifier (if it has one).

visible = Bool(True)

Is the action manager visible?

changed = Event()

fixme: We probably need more granular events than this!

append(item)[source]

Append an item to the manager.

Parameters

item (string, Group instance or ActionManagerItem) – The item to append.

Notes

If the item is a group, the Group is appended to the manager’s list of groups. It the item is a string, then a group is created with the string as the id and the new group is appended to the list of groups. If the item is an ActionManagerItem then the item is appended to the manager’s default group.

destroy()[source]

Called when the manager is no longer required.

By default this method simply calls ‘destroy’ on all of the manager’s groups.

insert(index, item)[source]

Insert an item into the manager at the specified index.

Parameters
  • index (int) – The position at which to insert the object

  • item (string, Group instance or ActionManagerItem) – The item to insert.

Notes

If the item is a group, the Group is inserted into the manager’s list of groups. It the item is a string, then a group is created with the string as the id and the new group is inserted into the list of groups. If the item is an ActionManagerItem then the item is inserted into the manager’s defualt group.

find_group(id)[source]

Find a group with a specified Id.

Parameters

id (str) – The id of the group to find.

Returns

group – The group which matches the id, or None if no such group exists.

Return type

Group

find_item(path)[source]

Find an item using a path.

Parameters

path (str) – A ‘/’ separated list of contribution Ids.

Returns

item – Returns the matching ActionManagerItem, or None if any component of the path is not found.

Return type

ActionManagerItem or None

walk(fn)[source]

Walk the manager applying a function at every item.

The components are walked in pre-order.

Parameters

fn (Callable) – A callable to apply to the tree of groups and items, starting with the manager.

walk_group(group, fn)[source]

Walk a group applying a function at every item.

The components are walked in pre-order.

Parameters
  • group (Group) – The group to walk.

  • fn (Callable) – A callable to apply to the tree of groups and items.

walk_item(item, fn)[source]

Walk an item (may be a sub-menu manager remember!).

The components are walked in pre-order.

Parameters
  • item (item) – The item to walk. This may be a submenu or similar in addition to simple Action items.

  • fn (Callable) – A callable to apply to the tree of items and subgroups.

dump(indent='')[source]

Render a manager!

render_group(group, indent='')[source]

Render a group!

render_item(item, indent='')[source]

Render an item!