def test_help_handler(self): object = SampleObject() handler = SampleHandler() action = HelpAction event = ActionEvent() ui = UI(handler=handler, context={"object": object}) info = ui.info handler.perform(info, action, event) self.assertTrue(handler.help_performed)
def test_perform_pyface_action(self): object = SampleObject() handler = SampleHandler() action = PyfaceAction() event = ActionEvent() ui = UI(handler=handler, context={"object": object}) info = ui.info handler.perform(info, action, event) self.assertTrue(action.performed)
def test_close_handler(self): object = SampleObject() handler = SampleHandler() action = CloseAction event = ActionEvent() ui = UI(handler=handler, context={'object': object}) info = ui.info handler.perform(info, action, event) self.assertTrue(handler.close_performed)
def test_perform_object_handler(self): object = SampleObject() handler = SampleHandler() action = TraitsUIAction(name="action", action="object_action_handler") event = ActionEvent() ui = UI(handler=handler, context={"object": object}) info = ui.info handler.perform(info, action, event) self.assertTrue(object.object_action_performed) self.assertFalse(action.performed)
def on_keyboard_shortcut(self, event): id = event.GetId() log.debug("Keyboard shortcut! %s", id) try: action = self.keyboard_shortcut_map[id] except KeyError: log.error("Keyboard shortcut for %s not in this task" % id) return event = ActionEvent(task=self) # Set the task so that dependent traits (e.g. active_editor for # EditorActions) will be available action.task = self action.perform(event)
def popup_context_menu_from_actions(self, control, actions, popup_data=None): """Popup a simple context menu with menu items defined by actions. Each entry is either None to indicate a separator, or an action to be used as the menu item. Note that the action may be either an Action instance or the class of that Action. If it is a class, a temporary instance of that class will be created. """ popup = wx.Menu() context_menu_data = dict() def add_to_menu(menu, action, context_menu_data): i = wx.NewId() if not hasattr(action, 'task'): action = action(task=self.task) try: action.on_popup_menu_update(self, popup_data) except AttributeError: pass # wxpython popup entries can't have empty name name = action.name if action.name else " " item = menu.Append(i, name) item.Enable(action.enabled) context_menu_data[i] = action def loop_over_actions(popup, actions): for action in actions: if action is None: popup.AppendSeparator() elif hasattr(action, '__iter__'): submenu = wx.Menu() title = action[0] popup.Append(wx.NewId(), title, submenu) loop_over_actions(submenu, action[1:]) else: add_to_menu(popup, action, context_menu_data) loop_over_actions(popup, actions) ret = self.do_popup(control, popup) if ret is not None: action = context_menu_data[ret] action_event = ActionEvent(task=self.task, popup_data=popup_data) action.perform(action_event)
def test_perform_traitsui_action(self): object = SampleObject() handler = SampleHandler() action = TraitsUIAction() event = ActionEvent() ui = UI(handler=handler, context={"object": object}) info = ui.info handler.perform(info, action, event) self.assertTrue(action.performed) self.assertFalse(handler.action_performed) self.assertFalse(handler.info_action_performed) self.assertFalse(handler.click_performed) self.assertFalse(object.action_performed) self.assertFalse(object.info_action_performed) self.assertFalse(object.click_performed)
def _create_action_event(self, obj): """ Return a new action event for the specified object. """ return ActionEvent(widget=self, context=obj)