Added hooke.plugin.playlist.ApplyCommandStack and related changes.
[hooke.git] / hooke / command_stack.py
index 1e6c27c937a790eaeb0b91f68f061e90389c433e..dcf2ce2a64a58e0794f282b20aed55c859fdc359 100644 (file)
@@ -32,12 +32,12 @@ class CommandStack (list):
     >>> c.append(CommandMessage('CommandA', {'param':'C'}))
     >>> c.append(CommandMessage('CommandB', {'param':'D'}))
 
-    Implement a dummy :meth:`_execute` for testing.
+    Implement a dummy :meth:`execute_command` for testing.
     
-    >>> def execute(hooke, command_message):
+    >>> def execute_cmd(hooke, command_message):
     ...     cm = command_message
     ...     print 'EXECUTE', cm.command, cm.arguments
-    >>> c._execute = execute
+    >>> c.execute_command = execute_cmd
 
     >>> c.execute(hooke=None)  # doctest: +ELLIPSIS
     EXECUTE CommandA {'param': 'A'}
@@ -55,10 +55,24 @@ class CommandStack (list):
     ...     return command_message.command == 'CommandB'
     >>> c.filter = filter
 
-    Apply the stack to the current curve
+    Apply the stack to the current curve.
+
     >>> c.execute(hooke=None)  # doctest: +ELLIPSIS
     EXECUTE CommandB {'param': 'B'}
     EXECUTE CommandB {'param': 'D'}
+
+    Execute a new command and add it to the stack.
+
+    >>> cm = CommandMessage('CommandC', {'param':'E'})
+    >>> c.execute_command(hooke=None, command_message=cm)
+    EXECUTE CommandC {'param': 'E'}
+    >>> c.append(cm)
+    >>> print [repr(cm) for cm in c]  # doctest: +NORMALIZE_WHITESPACE
+    ["<CommandMessage CommandA {'param': 'A'}>",
+     "<CommandMessage CommandB {'param': 'B'}>",
+     "<CommandMessage CommandA {'param': 'C'}>",
+     "<CommandMessage CommandB {'param': 'D'}>",
+     "<CommandMessage CommandC {'param': 'E'}>"]
     """
     def execute(self, hooke):
         """Execute a stack of commands.
@@ -69,7 +83,8 @@ class CommandStack (list):
         """
         for command_message in self:
             if self.filter(hooke, command_message) == True:
-                self._execute(hooke, command_message)
+                self.execute_command(
+                    hooke=hooke, command_message=command_message)
 
     def filter(self, hooke, command_message):
         """Return `True` to execute `command_message`, `False` otherwise.
@@ -78,5 +93,6 @@ class CommandStack (list):
         """
         return True
 
-    def _execute(self, hooke, command_message):
-        hooke.run_command(command_message.command, command_message.arguments)
+    def execute_command(self, hooke, command_message):
+        hooke.run_command(command=command_message.command,
+                          arguments=command_message.arguments)