Skip to content

Commit

Permalink
Allow passing in parent to Label
Browse files Browse the repository at this point in the history
  • Loading branch information
goodboy committed Jan 25, 2022
1 parent 20e42cb commit 3623e41
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions piker/ui/_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@


class Label:
"""
'''
A plain ol' "scene label" using an underlying ``QGraphicsTextItem``.
After hacking for many days on multiple "label" systems inside
Expand All @@ -50,10 +50,8 @@ class Label:
small, re-usable label components that can actually be used to build
production grade UIs...
"""

'''
def __init__(

self,
view: pg.ViewBox,
fmt_str: str,
Expand All @@ -63,6 +61,7 @@ def __init__(
font_size: str = 'small',
opacity: float = 1,
fields: dict = {},
parent: pg.GraphicsObject = None,
update_on_range_change: bool = True,

) -> None:
Expand All @@ -71,11 +70,13 @@ def __init__(
self._fmt_str = fmt_str
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

txt = self.txt = QtWidgets.QGraphicsTextItem()
txt = self.txt = QtWidgets.QGraphicsTextItem(parent=parent)
txt.setCacheMode(QtWidgets.QGraphicsItem.DeviceCoordinateCache)

vb.scene().addItem(txt)
Expand All @@ -86,7 +87,6 @@ def __init__(
)
dpi_font.configure_to_dpi()
txt.setFont(dpi_font.font)

txt.setOpacity(opacity)

# register viewbox callbacks
Expand All @@ -109,7 +109,7 @@ def __init__(
# self.setTextInteractionFlags(QtGui.Qt.TextEditorInteraction)

@property
def color(self):
def color(self) -> str:
return self._hcolor

@color.setter
Expand All @@ -118,9 +118,10 @@ def color(self, color: str) -> None:
self._hcolor = color

def update(self) -> None:
'''Update this label either by invoking its
user defined anchoring function, or by positioning
to the last recorded data view coordinates.
'''
Update this label either by invoking its user defined anchoring
function, or by positioning to the last recorded data view
coordinates.
'''
# move label in scene coords to desired position
Expand Down Expand Up @@ -234,7 +235,8 @@ def delete(self) -> None:


class FormatLabel(QLabel):
'''Kinda similar to above but using the widget apis.
'''
Kinda similar to above but using the widget apis.
'''
def __init__(
Expand Down Expand Up @@ -273,8 +275,8 @@ def __init__(
QSizePolicy.Expanding,
QSizePolicy.Expanding,
)
self.setAlignment(Qt.AlignVCenter
| Qt.AlignLeft
self.setAlignment(
Qt.AlignVCenter | Qt.AlignLeft
)
self.setText(self.fmt_str)

Expand Down

0 comments on commit 3623e41

Please sign in to comment.