>>> 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'}
... 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.
"""
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.
"""
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)