Allow passing in parent to `Label`
parent
fd31b843b9
commit
7b21ddd27f
|
@ -34,7 +34,7 @@ from ._style import (
|
||||||
|
|
||||||
|
|
||||||
class Label:
|
class Label:
|
||||||
"""
|
'''
|
||||||
A plain ol' "scene label" using an underlying ``QGraphicsTextItem``.
|
A plain ol' "scene label" using an underlying ``QGraphicsTextItem``.
|
||||||
|
|
||||||
After hacking for many days on multiple "label" systems inside
|
After hacking for many days on multiple "label" systems inside
|
||||||
|
@ -50,10 +50,8 @@ class Label:
|
||||||
small, re-usable label components that can actually be used to build
|
small, re-usable label components that can actually be used to build
|
||||||
production grade UIs...
|
production grade UIs...
|
||||||
|
|
||||||
"""
|
'''
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
|
|
||||||
self,
|
self,
|
||||||
view: pg.ViewBox,
|
view: pg.ViewBox,
|
||||||
fmt_str: str,
|
fmt_str: str,
|
||||||
|
@ -63,6 +61,7 @@ class Label:
|
||||||
font_size: str = 'small',
|
font_size: str = 'small',
|
||||||
opacity: float = 1,
|
opacity: float = 1,
|
||||||
fields: dict = {},
|
fields: dict = {},
|
||||||
|
parent: pg.GraphicsObject = None,
|
||||||
update_on_range_change: bool = True,
|
update_on_range_change: bool = True,
|
||||||
|
|
||||||
) -> None:
|
) -> None:
|
||||||
|
@ -71,11 +70,13 @@ class Label:
|
||||||
self._fmt_str = fmt_str
|
self._fmt_str = fmt_str
|
||||||
self._view_xy = QPointF(0, 0)
|
self._view_xy = QPointF(0, 0)
|
||||||
|
|
||||||
self.scene_anchor: Optional[Callable[..., QPointF]] = None
|
self.scene_anchor: Optional[
|
||||||
|
Callable[..., QPointF]
|
||||||
|
] = None
|
||||||
|
|
||||||
self._x_offset = x_offset
|
self._x_offset = x_offset
|
||||||
|
|
||||||
txt = self.txt = QtWidgets.QGraphicsTextItem()
|
txt = self.txt = QtWidgets.QGraphicsTextItem(parent=parent)
|
||||||
txt.setCacheMode(QtWidgets.QGraphicsItem.DeviceCoordinateCache)
|
txt.setCacheMode(QtWidgets.QGraphicsItem.DeviceCoordinateCache)
|
||||||
|
|
||||||
vb.scene().addItem(txt)
|
vb.scene().addItem(txt)
|
||||||
|
@ -86,7 +87,6 @@ class Label:
|
||||||
)
|
)
|
||||||
dpi_font.configure_to_dpi()
|
dpi_font.configure_to_dpi()
|
||||||
txt.setFont(dpi_font.font)
|
txt.setFont(dpi_font.font)
|
||||||
|
|
||||||
txt.setOpacity(opacity)
|
txt.setOpacity(opacity)
|
||||||
|
|
||||||
# register viewbox callbacks
|
# register viewbox callbacks
|
||||||
|
@ -109,7 +109,7 @@ class Label:
|
||||||
# self.setTextInteractionFlags(QtGui.Qt.TextEditorInteraction)
|
# self.setTextInteractionFlags(QtGui.Qt.TextEditorInteraction)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def color(self):
|
def color(self) -> str:
|
||||||
return self._hcolor
|
return self._hcolor
|
||||||
|
|
||||||
@color.setter
|
@color.setter
|
||||||
|
@ -118,9 +118,10 @@ class Label:
|
||||||
self._hcolor = color
|
self._hcolor = color
|
||||||
|
|
||||||
def update(self) -> None:
|
def update(self) -> None:
|
||||||
'''Update this label either by invoking its
|
'''
|
||||||
user defined anchoring function, or by positioning
|
Update this label either by invoking its user defined anchoring
|
||||||
to the last recorded data view coordinates.
|
function, or by positioning to the last recorded data view
|
||||||
|
coordinates.
|
||||||
|
|
||||||
'''
|
'''
|
||||||
# move label in scene coords to desired position
|
# move label in scene coords to desired position
|
||||||
|
@ -234,7 +235,8 @@ class Label:
|
||||||
|
|
||||||
|
|
||||||
class FormatLabel(QLabel):
|
class FormatLabel(QLabel):
|
||||||
'''Kinda similar to above but using the widget apis.
|
'''
|
||||||
|
Kinda similar to above but using the widget apis.
|
||||||
|
|
||||||
'''
|
'''
|
||||||
def __init__(
|
def __init__(
|
||||||
|
@ -273,8 +275,8 @@ class FormatLabel(QLabel):
|
||||||
QSizePolicy.Expanding,
|
QSizePolicy.Expanding,
|
||||||
QSizePolicy.Expanding,
|
QSizePolicy.Expanding,
|
||||||
)
|
)
|
||||||
self.setAlignment(Qt.AlignVCenter
|
self.setAlignment(
|
||||||
| Qt.AlignLeft
|
Qt.AlignVCenter | Qt.AlignLeft
|
||||||
)
|
)
|
||||||
self.setText(self.fmt_str)
|
self.setText(self.fmt_str)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue