Added CommandStack.explicit_user_call to distinguish user- from UI-generated calls.
authorW. Trevor King <wking@drexel.edu>
Fri, 27 Aug 2010 11:03:36 +0000 (07:03 -0400)
committerW. Trevor King <wking@drexel.edu>
Fri, 27 Aug 2010 11:03:36 +0000 (07:03 -0400)
hooke/engine.py
hooke/plugin/command_stack.py
hooke/ui/__init__.py
hooke/ui/gui/__init__.py

index 4687431356073c9d0c10c6a9f75dc42ea4db4708..883e8c19bec93ebffa94020f31f4198f0952d654 100644 (file)
@@ -46,6 +46,12 @@ class CommandMessage (QueueMessage):
         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__())
index 8a3ecb829c6d8527224a7b779e860356b91303c4..b5c987cdc94632c4ce2c5358e4ccb0ce1e69c3da 100644 (file)
@@ -81,7 +81,8 @@ class CaptureCommand (CommandStackCommand):
                 return
             assert isinstance(msg, CommandMessage), type(msg)
             cmd = hooke.command_by_name[msg.command]
-            if isinstance(cmd, CommandStackCommand):
+            if (cmd.explicit_user_call == False
+                or isinstance(cmd, CommandStackCommand)):
                 if isinstance(cmd, StopCaptureCommand):
                     outqueue = Queue()  # Grab StopCaptureCommand's completion.
                 cmd.run(hooke, inqueue, outqueue, **msg.arguments)
@@ -282,8 +283,6 @@ current stack.
 """.strip()),
                 ],
             help=self.__doc__, plugin=plugin)
-        stack = [a for a in self.arguments if a.name == 'stack'][0]
-        stack.default = False
 
     def _run(self, hooke, inqueue, outqueue, params):
         params = self.__setup_params(hooke=hooke, params=params)
index cfdac7293bbc07ceb28cafa9cadd6597c081b7e6..31fcae6fd9c859778b37c05819ef147235a22e91 100644 (file)
@@ -83,9 +83,15 @@ class UserInterface (object):
 
     # Assorted useful tidbits for subclasses
 
-    def _submit_command(self, command_message, ui_to_command_queue):
+    def _submit_command(self, command_message, ui_to_command_queue,
+                        explicit_user_call=True):
         log = logging.getLogger('hooke')
-        log.debug('executing %s' % command_message)
+        if explicit_user_call == True:
+            executor = 'user'
+        else:
+            executor = 'UI'
+        command_message.explicit_user_call = explicit_user_call
+        log.debug('executing (for the %s) %s' % (executor, command_message))
         ui_to_command_queue.put(command_message)
 
     def _set_config(self, option, value, ui_to_command_queue, response_handler,
@@ -100,7 +106,8 @@ class UserInterface (object):
             command='set config',
             arguments={'section': section, 'option': option, 'value': value})
         self._submit_command(command_message=cm,
-                             ui_to_command_queue=ui_to_command_queue)
+                             ui_to_command_queue=ui_to_command_queue,
+                             explicit_user_call=False)
         response_handler(command_message=cm)
 
     def _splash_text(self, extra_info, **kwargs):
index c96e78c3436c5fcdc2e38b4cf01aaf855b48351a..1cdeb05ef69ca31d1046fdc1f1ee9500d3b141f5 100644 (file)
@@ -165,7 +165,7 @@ class HookeFrame (wx.Frame):
                     commands=self.commands,
                     selected=self.gui.config['selected command'],
                     callbacks={
-                        'execute': self.execute_command,
+                        'execute': self.explicit_execute_command,
                         'select_plugin': self.select_plugin,
                         'select_command': self.select_command,
 #                        'selection_changed': self.panelProperties.select(self, method, command),  #SelectedTreeItem = selected_item,
@@ -300,8 +300,14 @@ class HookeFrame (wx.Frame):
             raise Exception('Multiple commands named "%s"' % name)
         return cs[0]
 
+    def explicit_execute_command(self, _class=None, method=None,
+                                 command=None, args=None):
+        return self.execute_command(
+            _class=_class, method=method, command=command, args=args,
+            explicit_user_call=True)
+
     def execute_command(self, _class=None, method=None,
-                        command=None, args=None):
+                        command=None, args=None, explicit_user_call=False):
         if args == None:
             args = {}
         if ('property editor' in self._c
@@ -337,7 +343,11 @@ class HookeFrame (wx.Frame):
                     if len(args[arg.name]) == 0:
                         args[arg.name] = arg.default
         cm = CommandMessage(command.name, args)
-        self.gui._submit_command(cm, self.inqueue)
+        self.gui._submit_command(
+            cm, self.inqueue, explicit_user_call=explicit_user_call)
+        # TODO: skip responses for commands that were captured by the
+        # command stack.  We'd need to poll on each request, remember
+        # capture state, or add a flag to the response...
         return self._handle_response(command_message=cm)
 
     def _handle_response(self, command_message):