Add support for a marker "on paint" callback

ordermodepps_backup
Tyler Goodlet 2021-07-22 18:42:23 -04:00
parent 37cd800135
commit 1048ea14d3
1 changed files with 18 additions and 19 deletions

View File

@ -18,10 +18,10 @@
Annotations for ur faces. Annotations for ur faces.
""" """
from typing import Callable from typing import Callable, Optional
from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import QPointF from PyQt5.QtCore import QPointF, QRectF
from PyQt5.QtWidgets import QGraphicsPathItem from PyQt5.QtWidgets import QGraphicsPathItem
from pyqtgraph import Point, functions as fn, Color from pyqtgraph import Point, functions as fn, Color
import numpy as np import numpy as np
@ -100,6 +100,7 @@ class LevelMarker(QGraphicsPathItem):
get_level: Callable[..., float], get_level: Callable[..., float],
size: float = 20, size: float = 20,
keep_in_view: bool = True, keep_in_view: bool = True,
on_paint: Optional[Callable] = None,
) -> None: ) -> None:
@ -114,12 +115,11 @@ class LevelMarker(QGraphicsPathItem):
self.chart = chart self.chart = chart
self.get_level = get_level self.get_level = get_level
self._on_paint = on_paint
self.scene_x = lambda: marker_right_points(chart)[1] self.scene_x = lambda: marker_right_points(chart)[1]
self.level: float = 0 self.level: float = 0
self.keep_in_view = keep_in_view self.keep_in_view = keep_in_view
assert self.path_br
@property @property
def style(self) -> str: def style(self) -> str:
return self._style return self._style
@ -131,9 +131,12 @@ class LevelMarker(QGraphicsPathItem):
self.setPath(polygon) self.setPath(polygon)
self._style = value self._style = value
# get the path for the opaque path **without** weird def path_br(self) -> QRectF:
# surrounding margin '''Return the bounding rect for the opaque path part
self.path_br = self.mapToScene( of this item.
'''
return self.mapToScene(
self.path() self.path()
).boundingRect() ).boundingRect()
@ -142,11 +145,11 @@ class LevelMarker(QGraphicsPathItem):
@property @property
def h(self) -> float: def h(self) -> float:
return self.path_br.height() return self.path_br().height()
@property @property
def w(self) -> float: def w(self) -> float:
return self.path_br.width() return self.path_br().width()
def position_in_view( def position_in_view(
self, self,
@ -195,13 +198,6 @@ class LevelMarker(QGraphicsPathItem):
).y() ).y()
) )
# marker = line._marker
if getattr(self, 'label', None):
label = self.label
# re-anchor label (i.e. trigger call of ``arrow_tr()`` from above
label.update()
def paint( def paint(
self, self,
@ -224,7 +220,10 @@ class LevelMarker(QGraphicsPathItem):
self.mapToScene(QPointF(0, self.get_level())).y() self.mapToScene(QPointF(0, self.get_level())).y()
) )
return super().paint(p, opt, w) super().paint(p, opt, w)
if self._on_paint:
self._on_paint(self)
def qgo_draw_markers( def qgo_draw_markers(