Skip to content

Commit

Permalink
Merge pull request #74 from enthought/action-schema
Browse files Browse the repository at this point in the history
Schema for Pyface Actions.
  • Loading branch information
nmichaud committed Dec 27, 2012
2 parents c472fde + dda7317 commit 0173533
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pyface/tasks/action/api.py
Original file line number Diff line number Diff line change
@@ -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
29 changes: 28 additions & 1 deletion pyface/tasks/action/schema.py
Original file line number Diff line number Diff line change
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,33 @@ 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 action 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.
"""

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

#: Items is overwritten to be empty and read-only to avoid assigning to
#: it by mistake.
items = Property()
def _get_items(self):
return []

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

traits = dict(id=self.id)
return self.action_factory(**traits)


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

0 comments on commit 0173533

Please sign in to comment.