def test_redo_key_press_non_default(self): self.tool.redo_keys = [KeySpec('Right', 'control')] key_event = self.create_key_press('Right', control_down=True) self.component.dispatch(key_event, 'key_pressed') self.assertTrue(key_event.handled) self.assertFalse(self.undo_manager.undo.called) self.assertTrue(self.undo_manager.redo.called)
def test_undo_key_press_non_default(self): self.tool.undo_keys = [KeySpec("Left", "control")] key_event = self.create_key_press("Left", control_down=True) self.component.dispatch(key_event, "key_pressed") self.assertTrue(self.undo_manager.undo.called) self.assertFalse(self.undo_manager.redo.called) self.assertTrue(key_event.handled)
class DataTool(BaseTool): new_value = Event last_mouse_position = Tuple visible = Bool(True) inspector_key = KeySpec('i') parent = Any plot = Any plotid = Int use_date_str = True normalize_time = False x_format = '{:0.2f}' def normal_key_pressed(self, event): if self.inspector_key.match(event): self.visible = not self.visible event.handled = True def normal_mouse_move(self, event): comp = self.component plot = self.plot if comp is not None: d = dict() x, y = comp.map_data([event.x, event.y + 2]) comps = comp.container.components_at(event.x, event.y) # print comps if not self.component in comps: self.new_value = d return ind = plot.index.metadata.get('hover') if ind is not None: y = plot.value.get_data()[ind][0] x = plot.index.get_data()[ind][0] if self.normalize_time: try: sx = plot.index.get_data()[0] x -= sx except IndexError: return if self.use_date_str: # convert timestamp to str date = datetime.fromtimestamp(x) xi = date.strftime('%d/%m %H:%M:%S') else: xi = self.x_format.format(x) d['xy'] = (xi, '{:0.3f}'.format(y)) self.new_value = d self.last_mouse_position = (event.x, event.y)
Tool that triggers undo or redo when keys are pressed. """ from __future__ import (division, absolute_import, print_function, unicode_literals) # Enthought library imports from traits.api import Instance, List # Local library imports from enable.base_tool import KeySpec from .command_tool import BaseUndoTool # default undo/redo/clear key specifications ctrl_z = KeySpec('z', 'control') ctrl_shift_z = KeySpec('z', 'control', 'shift') class UndoTool(BaseUndoTool): """ Tool that triggers undo or redo when keys are pressed """ #: the key sequences which trigger undo actions undo_keys = List(Instance(KeySpec), [ctrl_z]) #: the key sequences which trigger redo actions redo_keys = List(Instance(KeySpec), [ctrl_shift_z]) def normal_key_pressed(self, event): """ Respond to key presses which match either the undo or redo keys """ if self.undo_manager is not None:
class DataTool(BaseTool): new_value = Event last_mouse_position = Tuple visible = Bool(True) inspector_key = KeySpec('i') parent = Any plot = Any plotid = Int use_date_str = True normalize_time = False x_format = '{:0.2f}' predict_value_func = None filter_components = True def normal_key_pressed(self, event): if self.inspector_key.match(event): self.visible = not self.visible event.handled = True def normal_mouse_move(self, event): comp = self.component plot = self.plot if comp is not None: d = dict() x, y = comp.map_data([event.x, event.y]) if self.filter_components: comps = comp.container.components_at(event.x, event.y) if comp not in comps: self.new_value = d return ind = plot.index.metadata.get('hover') if ind is not None: y = plot.value.get_data()[ind][0] x = plot.index.get_data()[ind][0] d['text'] = self._make_text(plot, x, y) self.new_value = d self.last_mouse_position = (event.x, event.y) def _make_text(self, plot, x, y): if self.normalize_time: try: sx = plot.index.get_data()[0] x -= sx except IndexError: return if self.use_date_str: # convert timestamp to str date = datetime.fromtimestamp(x) xi = date.strftime('%d/%m %H:%M:%S') else: try: xi = self.x_format.format(x) except ValueError: xi = '' ret = '{},{:0.3f}'.format(xi, y) if self.predict_value_func: ret = '{},{}'.format(ret, self.predict_value_func(x, y)) return ret
def _get__cancel_keys(self): return [KeySpec(key) for key in self.cancel_keys]
""" UndoTool ======== Tool that triggers undo or redo when keys are pressed. """ # Enthought library imports from traits.api import Instance, List # Local library imports from enable.base_tool import KeySpec from .command_tool import BaseUndoTool # default undo/redo/clear key specifications ctrl_z = KeySpec("z", "control") ctrl_shift_z = KeySpec("z", "control", "shift") class UndoTool(BaseUndoTool): """ Tool that triggers undo or redo when keys are pressed """ #: the key sequences which trigger undo actions undo_keys = List(Instance(KeySpec), [ctrl_z]) #: the key sequences which trigger redo actions redo_keys = List(Instance(KeySpec), [ctrl_shift_z]) def normal_key_pressed(self, event): """ Respond to key presses which match either the undo or redo keys