Make ArrowEditor.add()` expect a `PlotItem` as input for render

history_view
Tyler Goodlet 2022-09-06 21:21:25 -04:00
parent 271e378ce3
commit 412197019e
1 changed files with 14 additions and 13 deletions

View File

@ -45,16 +45,18 @@ log = get_logger(__name__)
class ArrowEditor(Struct): class ArrowEditor(Struct):
chart: 'ChartPlotWidget' # noqa godw: GodWidget = None # type: ignore # noqa
_arrows: dict[str, pg.ArrowItem] _arrows: dict[str, list[pg.ArrowItem]] = {}
def add( def add(
self, self,
plot: pg.PlotItem,
uid: str, uid: str,
x: float, x: float,
y: float, y: float,
color='default', color='default',
pointing: Optional[str] = None, pointing: Optional[str] = None,
) -> pg.ArrowItem: ) -> pg.ArrowItem:
''' '''
Add an arrow graphic to view at given (x, y). Add an arrow graphic to view at given (x, y).
@ -82,16 +84,16 @@ class ArrowEditor(Struct):
brush=pg.mkBrush(hcolor(color)), brush=pg.mkBrush(hcolor(color)),
) )
arrow.setPos(x, y) arrow.setPos(x, y)
self._arrows.setdefault(uid, []).append(arrow)
self._arrows[uid] = arrow
# render to view # render to view
self.chart.plotItem.addItem(arrow) plot.addItem(arrow)
return arrow return arrow
def remove(self, arrow) -> bool: def remove(self, arrow) -> bool:
self.chart.plotItem.removeItem(arrow) for linked in self.godw.iter_linked():
linked.chart.plotItem.removeItem(arrow)
class LineEditor(Struct): class LineEditor(Struct):
@ -128,6 +130,8 @@ class LineEditor(Struct):
''' '''
cursor = self.godw.get_cursor() cursor = self.godw.get_cursor()
if not cursor:
return None
# delete "staged" cursor tracking line from view # delete "staged" cursor tracking line from view
line = self._active_staged_line line = self._active_staged_line
@ -212,26 +216,23 @@ class LineEditor(Struct):
''' '''
# try to look up line from our registry # try to look up line from our registry
# line = self._order_lines.pop(uuid, line)
lines = self._order_lines.pop(uuid) lines = self._order_lines.pop(uuid)
# if line:
if lines: if lines:
cursor = self.godw.get_cursor() cursor = self.godw.get_cursor()
for line in lines: for line in lines:
# if hovered remove from cursor set # if hovered remove from cursor set
# cursor = self.godw.get_cursor()
hovered = cursor._hovered hovered = cursor._hovered
if line in hovered: if line in hovered:
hovered.remove(line) hovered.remove(line)
# make sure the xhair doesn't get left off
# just because we never got a un-hover event
cursor.show_xhair()
log.debug(f'deleting {line} with oid: {uuid}') log.debug(f'deleting {line} with oid: {uuid}')
line.delete() line.delete()
# make sure the xhair doesn't get left off
# just because we never got a un-hover event
cursor.show_xhair()
else: else:
log.warning(f'Could not find line for {line}') log.warning(f'Could not find line for {line}')