Skip to content
Browse files

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 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...
1 parent c472fde commit cfd3b2910fd33cab7b2e58760503b2a05155c0dd @pberkes pberkes committed Dec 18, 2012
Showing with 27 additions and 3 deletions.
  1. +2 −2 pyface/tasks/action/api.py
  2. +25 −1 pyface/tasks/action/schema.py
View
4 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
View
26 pyface/tasks/action/schema.py
@@ -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,
@@ -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.
"""

0 comments on commit cfd3b29

Please sign in to comment.
Something went wrong with that request. Please try again.