Add preliminary support for alert line management

basic_alerts
Tyler Goodlet 2021-01-03 11:12:51 -05:00
parent 88d48bd188
commit 97b2f86cfe
1 changed files with 75 additions and 17 deletions

View File

@ -26,6 +26,7 @@ import numpy as np
from ..log import get_logger from ..log import get_logger
from ._style import _min_points_to_show, hcolor, _font from ._style import _min_points_to_show, hcolor, _font
from ._graphics._lines import level_line
log = get_logger(__name__) log = get_logger(__name__)
@ -215,7 +216,8 @@ class ChartView(ViewBox):
self.addItem(self.select_box, ignoreBounds=True) self.addItem(self.select_box, ignoreBounds=True)
self._chart: 'ChartPlotWidget' = None # noqa self._chart: 'ChartPlotWidget' = None # noqa
self._keys_on = {} self._key_buffer = []
self._active_staged_line: 'LevelLine' = None # noqa
@property @property
def chart(self) -> 'ChartPlotWidget': # type: ignore # noqa def chart(self) -> 'ChartPlotWidget': # type: ignore # noqa
@ -394,10 +396,32 @@ class ChartView(ViewBox):
self.raiseContextMenu(ev) self.raiseContextMenu(ev)
elif button == QtCore.Qt.LeftButton: elif button == QtCore.Qt.LeftButton:
print(f'clicked {pos}')
ev.accept()
line = self._active_staged_line
if line:
chart = self.chart._cursor.active_plot
y = chart._cursor._datum_xy[1]
# XXX: should make this an explicit attr
# it's assigned inside ``.add_plot()``
self.linked_charts._to_router.send_nowait({'alert': y})
line = level_line(
chart,
level=y,
color='alert_yellow',
)
log.info(f'clicked {pos}')
def keyReleaseEvent(self, ev): def keyReleaseEvent(self, ev):
# print(f'release: {ev.text().encode()}') """
Key release to normally to trigger release of input mode
"""
# TODO: is there a global setting for this?
if ev.isAutoRepeat(): if ev.isAutoRepeat():
ev.ignore() ev.ignore()
return return
@ -405,7 +429,7 @@ class ChartView(ViewBox):
ev.accept() ev.accept()
text = ev.text() text = ev.text()
key = ev.key() key = ev.key()
mods = ev.modifiers() # mods = ev.modifiers()
if key == QtCore.Qt.Key_Shift: if key == QtCore.Qt.Key_Shift:
if self.state['mouseMode'] == ViewBox.RectMode: if self.state['mouseMode'] == ViewBox.RectMode:
@ -413,16 +437,29 @@ class ChartView(ViewBox):
if text == 'a': if text == 'a':
# how y line
chart = self.chart._cursor.active_plot chart = self.chart._cursor.active_plot
hl = chart._cursor.graphics[chart]['hl'] chart.setCursor(QtCore.Qt.ArrowCursor)
cursor = chart._cursor
# delete "staged" cursor tracking line from view
line = self._active_staged_line
cursor._trackers.remove(line)
if line:
line.delete()
self._active_staged_line = None
# show the crosshair y line
hl = cursor.graphics[chart]['hl']
hl.show() hl.show()
def keyPressEvent(self, ev): def keyPressEvent(self, ev):
""" """
This routine should capture key presses in the current view box. This routine should capture key presses in the current view box.
""" """
# print(ev.text().encode()) # TODO: is there a global setting for this?
if ev.isAutoRepeat(): if ev.isAutoRepeat():
ev.ignore() ev.ignore()
return return
@ -448,26 +485,47 @@ class ChartView(ViewBox):
# alt # alt
if mods == QtCore.Qt.AltModifier: if mods == QtCore.Qt.AltModifier:
pass pass
# print("ALT")
# esc # esc
if key == QtCore.Qt.Key_Escape: if key == QtCore.Qt.Key_Escape:
self.select_box.clear() self.select_box.clear()
self._key_buffer.append(text)
# order modes
if text == 'r': if text == 'r':
self.chart.default_view() self.chart.default_view()
if text == 'a': elif text == 'a':
self._keys_on['a'] = True
# hide y line
chart = self.chart._cursor.active_plot chart = self.chart._cursor.active_plot
print(f'on chart: {chart.name}') chart.setCursor(QtCore.Qt.PointingHandCursor)
chart._cursor.graphics[chart]['hl'].hide() cursor = chart._cursor
# XXX: should make this an explicit attr # add a "staged" cursor-tracking alert line
# it's assigned inside ``.add_plot()``
self.linked_charts._to_router.send_nowait('yo') line = level_line(
chart,
level=chart._cursor._datum_xy[1],
color='alert_yellow',
)
self._active_staged_line = line
# hide crosshair y-line
cursor.graphics[chart]['hl'].hide()
# add line to cursor trackers
cursor._trackers.add(line)
elif text == 'd':
# Delete any hoverable under the cursor
cursor = self.chart._cursor
chart = cursor.active_plot
for item in cursor._hovered:
# hovered items must also offer
# a ``.delete()`` method
item.delete()
# Leaving this for light reference purposes # Leaving this for light reference purposes