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__())
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)
""".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)
# 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,
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):
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,
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
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):