Skip to content

Commit

Permalink
Schema for Pyface Actions.
Browse files Browse the repository at this point in the history
    An action schema cannot have children. It is used as an action factory
    to make sure a larger schema (e.g., a menu schema) can be used multiple
    times. Without using an ActionSchema, a reference to the copy is added
    to every menu created from the schema. When one of the menus is destroyed,
    the action is also destroyed and is made unusable.
  • Loading branch information
pberkes committed Dec 18, 2012
1 parent c472fde commit cfd3b29
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pyface/tasks/action/api.py
@@ -1,7 +1,7 @@
# Local imports.
from dock_pane_toggle_group import DockPaneToggleGroup
from schema import GroupSchema, MenuSchema, MenuBarSchema, ToolBarSchema, \
SGroup, SMenu, SMenuBar, SToolBar
from schema import ActionSchema, GroupSchema, MenuSchema, MenuBarSchema, \
ToolBarSchema, SGroup, SMenu, SMenuBar, SToolBar
from schema_addition import SchemaAddition
from task_action import CentralPaneAction, DockPaneAction, EditorAction, \
TaskAction, TaskWindowAction
Expand Down
26 changes: 25 additions & 1 deletion pyface/tasks/action/schema.py
Expand Up @@ -2,7 +2,7 @@
from pyface.action.api import Action, ActionItem, Group, \
MenuManager, MenuBarManager, ToolBarManager
from traits.api import Bool, Callable, Enum, HasTraits, Instance, \
List, Str, Trait, Tuple, Unicode
List, Property, Str, Trait, Tuple, Unicode

# Trait definitions.
SubSchema = Trait(None, Action, ActionItem, Group, MenuManager,
Expand Down Expand Up @@ -35,6 +35,30 @@ def create(self, children):
raise NotImplementedError


class ActionSchema(Schema):
""" Action schema for Pyface Actions.
An action schema cannot have children. It is used as an action factory
to make sure a larger schema (e.g., a menu schema) can be used multiple
times. Without using an ActionSchema, a reference to the copy is added
to menus created from the schema. When the menus are destroyed, the action
is made unusable.
"""

#: A factory for the Action instance.
action_factory = Callable(Action)

items = Property()
def _get_items(self):
return []

def create(self, children):
""" Create the appropriate PyFace Action instance. """

return self.action_factory()


class GroupSchema(Schema):
""" A schema for a Pyface Group.
"""
Expand Down

0 comments on commit cfd3b29

Please sign in to comment.