def test_monitor_success_pyface_task_action(self): def do_nothing(): pass action_name = "Do nothing action" action = MonitoredTaskAction(name=action_name, on_perform=do_nothing) action.perform(ActionEvent()) self.assert_do_nothing_action_monitored(action_name)
def _on_tool(self, event): """ Called when the tool palette button is clicked. """ action = self.item.action action_event = ActionEvent() # Perform the action! action.checked = self.tool_palette.get_tool_state(self.tool_id) == 1 action.perform(action_event) return
def _on_menu(self, event): """ Called when the menu item is clicked. """ # if the ugly flag is set, do not perform the menu event if self._skip_menu_event: return action = self.item.action action_event = ActionEvent() is_checkable = action.style in ['radio', 'toggle'] # Perform the action! if self.controller is not None: if is_checkable: # fixme: There is a difference here between having a controller # and not in that in this case we do not set the checked state # of the action! This is confusing if you start off without a # controller and then set one as the action now behaves # differently! self.checked = self.control.IsChecked() == 1 # Most of the time, action's do no care about the event (it # contains information about the time the event occurred etc), so # we only pass it if the perform method requires it. This is also # useful as Traits UI controllers *never* require the event. args, varargs, varkw, dflts = getargspec(self.controller.perform) # If the only arguments are 'self' and 'action' then don't pass # the event! if len(args) == 2: self.controller.perform(action) else: self.controller.perform(action, action_event) else: if is_checkable: action.checked = self.control.IsChecked() == 1 # Most of the time, action's do no care about the event (it # contains information about the time the event occurred etc), so # we only pass it if the perform method requires it. args, varargs, varkw, dflts = getargspec(action.perform) # If the only argument is 'self' then don't pass the event! if len(args) == 1: action.perform() else: action.perform(action_event) return
def test_monitor_raise_pyface_task_action(self): msg = "EXPECTED FAILURE: PLEASE IGNORE." def raise_error(): raise ValueError(msg) action_name = "Raise error action" action = MonitoredTaskAction(name=action_name, on_perform=raise_error, allow_gui=False) action.perform(ActionEvent()) self.assert_raise_action_monitored(action_name, msg)
def _on_tool(self, event): """ Called when the tool bar tool is clicked. """ action = self.item.action action_event = ActionEvent() is_checkable = (action.style == 'radio' or action.style == 'check') # Perform the action! if self.controller is not None: # fixme: There is a difference here between having a controller # and not in that in this case we do not set the checked state # of the action! This is confusing if you start off without a # controller and then set one as the action now behaves # differently! self.checked = self.tool_bar.GetToolState(self.control_id) == 1 # Most of the time, action's do no care about the event (it # contains information about the time the event occurred etc), so # we only pass it if the perform method requires it. This is also # useful as Traits UI controllers *never* require the event. args, varargs, varkw, dflts = getargspec(self.controller.perform) # If the only arguments are 'self' and 'action' then don't pass # the event! if len(args) == 2: self.controller.perform(action) else: self.controller.perform(action, action_event) else: action.checked = self.tool_bar.GetToolState(self.control_id) == 1 # Most of the time, action's do no care about the event (it # contains information about the time the event occurred etc), so # we only pass it if the perform method requires it. args, varargs, varkw, dflts = getargspec(action.perform) # If the only argument is 'self' then don't pass the event! if len(args) == 1: action.perform() else: action.perform(action_event) return
def _qt4_on_triggered(self): """ Called when the menu item has been clicked. """ action = self.item.action action_event = ActionEvent() is_checkable = action.style in ['radio', 'toggle'] # Perform the action! if self.controller is not None: if is_checkable: self.checked = action.checked = self.control.isChecked() # Most of the time, action's do no care about the event (it # contains information about the time the event occurred etc), so # we only pass it if the perform method requires it. This is also # useful as Traits UI controllers *never* require the event. args, varargs, varkw, dflts = getargspec(self.controller.perform) # If the only arguments are 'self' and 'action' then don't pass # the event! if len(args) == 2: self.controller.perform(action) else: self.controller.perform(action, action_event) else: if is_checkable: self.checked = action.checked = self.control.isChecked() # Most of the time, action's do no care about the event (it # contains information about the time the event occurred etc), so # we only pass it if the perform method requires it. args, varargs, varkw, dflts = getargspec(action.perform) # If the only argument is 'self' then don't pass the event! if len(args) == 1: action.perform() else: action.perform(action_event)
def _qt4_on_triggered(self): """ Called when the tool bar tool is clicked. """ action = self.item.action action_event = ActionEvent() # Perform the action! if self.controller is not None: self.checked = action.checked = self.control.isChecked() # Most of the time, action's do no care about the event (it # contains information about the time the event occurred etc), so # we only pass it if the perform method requires it. This is also # useful as Traits UI controllers *never* require the event. argspec = getfullargspec(self.controller.perform) # If the only arguments are 'self' and 'action' then don't pass # the event! if len(argspec.args) == 2: self.controller.perform(action) else: self.controller.perform(action, action_event) else: self.checked = action.checked = self.control.isChecked() # Most of the time, action's do no care about the event (it # contains information about the time the event occurred etc), so # we only pass it if the perform method requires it. argspec = getfullargspec(action.perform) # If the only argument is 'self' then don't pass the event! if len(argspec.args) == 1: action.perform() else: action.perform(action_event)
def test_perform_none(self): action = Action(name="Test") event = ActionEvent() # does nothing, but shouldn't error self.action_controller.perform(action, event)
def test_perform(self): # test whether function is called by updating list # XXX should really use mock event = ActionEvent() self.action_controller.perform(self.action, event) self.assertEqual(self.memo, ["called"])