From 52c4e278936755f9e8e9bfb00ea4e995bda6847a Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 27 Aug 2010 07:03:36 -0400 Subject: [PATCH] Added CommandStack.explicit_user_call to distinguish user- from UI-generated calls. --- hooke/engine.py | 6 ++++++ hooke/plugin/command_stack.py | 5 ++--- hooke/ui/__init__.py | 13 ++++++++++--- hooke/ui/gui/__init__.py | 16 +++++++++++++--- 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/hooke/engine.py b/hooke/engine.py index 4687431..883e8c1 100644 --- a/hooke/engine.py +++ b/hooke/engine.py @@ -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__()) diff --git a/hooke/plugin/command_stack.py b/hooke/plugin/command_stack.py index 8a3ecb8..b5c987c 100644 --- a/hooke/plugin/command_stack.py +++ b/hooke/plugin/command_stack.py @@ -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) diff --git a/hooke/ui/__init__.py b/hooke/ui/__init__.py index cfdac72..31fcae6 100644 --- a/hooke/ui/__init__.py +++ b/hooke/ui/__init__.py @@ -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): diff --git a/hooke/ui/gui/__init__.py b/hooke/ui/gui/__init__.py index c96e78c..1cdeb05 100644 --- a/hooke/ui/gui/__init__.py +++ b/hooke/ui/gui/__init__.py @@ -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): -- 2.26.2