+import logging
+from Queue import Queue, Empty
+
+from .command import NullQueue
+
+
+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 the
+ name of 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
+ self.explicit_user_call = True
+ """Message is explicitly user-executed. This is useful for
+ distinguishing auto-generated calls (for which
+ `explicit_user_call` should be `False` such as the GUIs
+ current status requests.
+ """
+
+ def __str__(self):
+ return str(self.__unicode__())
+
+ def __unicode__(self):
+ """Return a unicode representation of the `CommandMessage`.
+
+ Examples
+ --------
+ >>> from .compat.odict import odict
+ >>> cm = CommandMessage('command A')
+ >>> print(unicode(cm))
+ <CommandMessage command A>
+ >>> cm.arguments = odict([('param a','value a'), ('param b', 'value b')])
+ >>> print(unicode(cm))
+ <CommandMessage command A {param a: value a, param b: value b}>
+
+ The parameters are sorted by name, so you won't be surprised
+ in any doctests, etc.
+
+ >>> cm.arguments = odict([('param b','value b'), ('param a', 'value a')])
+ >>> print(unicode(cm))
+ <CommandMessage command A {param a: value a, param b: value b}>
+ """
+ if len(self.arguments) > 0:
+ return u'<%s %s {%s}>' % (
+ self.__class__.__name__, self.command,
+ ', '.join(['%s: %s' % (key, value)
+ for key,value in sorted(self.arguments.items())]))
+ return u'<%s %s>' % (self.__class__.__name__, self.command)
+
+ def __repr__(self):
+ return self.__str__()
+