import logging
-from .ui import CloseEngine, CommandMessage
+
+class QueueMessage (object):
+ def __str__(self):
+ return self.__class__.__name__
+
+
+class CloseEngine (QueueMessage):
+ pass
+
+
+class CommandMessage (QueueMessage):
+ """A message storing a command to run, `command` should be a
+ :class:`hooke.command.Command` instance, and `arguments` should be
+ a :class:`dict` with `argname` keys and `value` values to be
+ passed to the command.
+ """
+ def __init__(self, command, arguments=None):
+ self.command = command
+ if arguments == None:
+ arguments = {}
+ self.arguments = arguments
class CommandEngine (object):
def run(self, hooke, ui_to_command_queue, command_to_ui_queue):
- """Get a :class:`hooke.ui.QueueMessage` from the incoming
+ """Get a :class:`QueueMessage` from the incoming
`ui_to_command_queue` and act accordingly.
- If the message is a :class:`hooke.ui.CommandMessage` instance,
- the command run may read subsequent input from
+ If the message is a :class:`CommandMessage` instance, the
+ command run may read subsequent input from
`ui_to_command_queue` (if it is an interactive command). The
command may also put assorted data into `command_to_ui_queue`.
When the command completes, it will put a
:class:`hooke.command.CommandExit` instance into
`command_to_ui_queue`, at which point the `CommandEngine` will
- be ready to receive the next :class:`hooke.ui.QueueMessage`.
+ be ready to receive the next :class:`QueueMessage`.
"""
log = logging.getLogger('hooke')
while True: