From e474d8c30903bf8c2645117c95d65726a017ef3c Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Fri, 1 Jan 2021 13:05:50 -0500 Subject: [PATCH] Remove horizontal crosshair on "a" hotkey --- piker/ui/_interaction.py | 56 +++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 10 deletions(-) diff --git a/piker/ui/_interaction.py b/piker/ui/_interaction.py index f501238f..249acf49 100644 --- a/piker/ui/_interaction.py +++ b/piker/ui/_interaction.py @@ -215,12 +215,14 @@ class ChartView(ViewBox): self.addItem(self.select_box, ignoreBounds=True) self._chart: 'ChartPlotWidget' = None # noqa + self._keys_on = {} + @property - def chart(self) -> 'ChartPlotWidget': # noqa + def chart(self) -> 'ChartPlotWidget': # type: ignore # noqa return self._chart @chart.setter - def chart(self, chart: 'ChartPlotWidget') -> None: # noqa + def chart(self, chart: 'ChartPlotWidget') -> None: # type: ignore # noqa self._chart = chart self.select_box.chart = chart @@ -305,7 +307,7 @@ class ChartView(ViewBox): if axis == 1: # set a static y range special value on chart widget to # prevent sizing to data in view. - self._chart._static_yrange = 'axis' + self.chart._static_yrange = 'axis' scale_y = 1.3 ** (dif.y() * -1 / 20) self.setLimits(yMin=None, yMax=None) @@ -374,24 +376,46 @@ class ChartView(ViewBox): def keyReleaseEvent(self, ev): # print(f'release: {ev.text().encode()}') + if ev.isAutoRepeat(): + ev.ignore() + return + ev.accept() - if ev.key() == QtCore.Qt.Key_Shift: + text = ev.text() + key = ev.key() + mods = ev.modifiers() + + if key == QtCore.Qt.Key_Shift: if self.state['mouseMode'] == ViewBox.RectMode: self.setMouseMode(ViewBox.PanMode) + if text == 'a': + + # how y line + chart = self.chart._cursor.active_plot + hl = chart._cursor.graphics[chart]['hl'] + hl.show() + def keyPressEvent(self, ev): """ This routine should capture key presses in the current view box. """ # print(ev.text().encode()) - ev.accept() + if ev.isAutoRepeat(): + ev.ignore() + return - if ev.modifiers() == QtCore.Qt.ShiftModifier: + ev.accept() + text = ev.text() + key = ev.key() + mods = ev.modifiers() + + if mods == QtCore.Qt.ShiftModifier: if self.state['mouseMode'] == ViewBox.PanMode: self.setMouseMode(ViewBox.RectMode) # ctl - if ev.modifiers() == QtCore.Qt.ControlModifier: + if mods == QtCore.Qt.ControlModifier: # print("CTRL") # TODO: ctrl-c as cancel? # https://forum.qt.io/topic/532/how-to-catch-ctrl-c-on-a-widget/9 @@ -400,17 +424,29 @@ class ChartView(ViewBox): pass # alt - if ev.modifiers() == QtCore.Qt.AltModifier: + if mods == QtCore.Qt.AltModifier: pass # print("ALT") # esc - if ev.key() == QtCore.Qt.Key_Escape: + if key == QtCore.Qt.Key_Escape: self.select_box.clear() - if ev.text() == 'r': + if text == 'r': self.chart.default_view() + if text == 'a': + self._keys_on['a'] = True + + # hide y line + chart = self.chart._cursor.active_plot + print(f'on chart: {chart.name}') + chart._cursor.graphics[chart]['hl'].hide() + + # XXX: should make this an explicit attr + # it's assigned inside ``.add_plot()`` + self.linked_charts._to_router.send_nowait('yo') + # Leaving this for light reference purposes # Key presses are used only when mouse mode is RectMode