Add a private level change cb, fix marker hidingn

fsp_feeds
Tyler Goodlet 2021-08-12 20:16:13 -04:00
parent 7fc7f72643
commit 3ddd4bc2c2
1 changed files with 23 additions and 19 deletions

View File

@ -81,8 +81,11 @@ class LevelLine(pg.InfiniteLine):
self._dotted = dotted self._dotted = dotted
self._hide_xhair_on_hover = hide_xhair_on_hover self._hide_xhair_on_hover = hide_xhair_on_hover
# callback that can be assigned by user code
# to get updates from each level change
self._on_level_change: Callable[[float], None] = lambda y: None
self._marker = None self._marker = None
# self._default_mkr_size = marker_size
self._moh = only_show_markers_on_hover self._moh = only_show_markers_on_hover
self.show_markers: bool = True # presuming the line is hovered at init self.show_markers: bool = True # presuming the line is hovered at init
@ -187,6 +190,7 @@ class LevelLine(pg.InfiniteLine):
def set_level( def set_level(
self, self,
level: float, level: float,
) -> None: ) -> None:
last = self.value() last = self.value()
@ -202,6 +206,9 @@ class LevelLine(pg.InfiniteLine):
self.level = self.value() self.level = self.value()
self.update() self.update()
# invoke any user code
self._on_level_change(level)
def on_tracked_source( def on_tracked_source(
self, self,
@ -213,15 +220,11 @@ class LevelLine(pg.InfiniteLine):
this is called by our ``Cursor`` type once this line is set to this is called by our ``Cursor`` type once this line is set to
track the cursor: for every movement this callback is invoked to track the cursor: for every movement this callback is invoked to
reposition the line reposition the line with the current view coordinates.
''' '''
self.movable = True self.movable = True
self.set_level(y) # implictly calls reposition handler self.set_level(y) # implictly calls reposition handler
self._chart.linked.godwidget.pp_config.model.get_order_info(
price=y
)
def mouseDragEvent(self, ev): def mouseDragEvent(self, ev):
"""Override the ``InfiniteLine`` handler since we need more """Override the ``InfiniteLine`` handler since we need more
detailed control and start end signalling. detailed control and start end signalling.
@ -388,7 +391,8 @@ class LevelLine(pg.InfiniteLine):
super().hide() super().hide()
if self._marker: if self._marker:
self._marker.hide() self._marker.hide()
# self._marker.label.hide() # needed for ``order_line()`` lines currently
self._marker.label.hide()
def show(self) -> None: def show(self) -> None:
super().show() super().show()
@ -493,6 +497,7 @@ class LevelLine(pg.InfiniteLine):
if self._marker: if self._marker:
self._marker.hide() self._marker.hide()
self._marker.label.hide()
if self not in cur._trackers: if self not in cur._trackers:
cur.show_xhair(y_label_level=self.value()) cur.show_xhair(y_label_level=self.value())
@ -643,7 +648,7 @@ def order_line(
# resetting the graphics item transform intermittently # resetting the graphics item transform intermittently
# the old way which is still somehow faster? # the old way which is still somehow faster?
path = QGraphicsPathItem( marker = QGraphicsPathItem(
mk_marker_path( mk_marker_path(
marker_style, marker_style,
# the "position" here is now ignored since we modified # the "position" here is now ignored since we modified
@ -654,15 +659,15 @@ def order_line(
# use_qgpath=False, # use_qgpath=False,
) )
) )
path.scale(marker_size, marker_size) marker.scale(marker_size, marker_size)
# XXX: this is our new approach but seems slower? # XXX: this is our new approach but seems slower?
path = line.add_marker(path) marker = line.add_marker(marker)
# XXX: old # XXX: old
# path = line.add_marker(mk_marker(marker_style, marker_size)) # marker = line.add_marker(mk_marker(marker_style, marker_size))
line._marker = path line._marker = marker
assert not line.markers assert not line.markers
@ -670,7 +675,7 @@ def order_line(
# # XXX: this was manually tested as faster then using the # # XXX: this was manually tested as faster then using the
# # QGraphicsItem around a painter path.. probably needs further # # QGraphicsItem around a painter path.. probably needs further
# # testing to figure out why tf that's true. # # testing to figure out why tf that's true.
# line.markers.append((path, 0, marker_size)) # line.markers.append((marker, 0, marker_size))
orient_v = 'top' if action == 'sell' else 'bottom' orient_v = 'top' if action == 'sell' else 'bottom'
@ -699,7 +704,7 @@ def order_line(
llabel.render() llabel.render()
llabel.show() llabel.show()
path.label = llabel marker.label = llabel
else: else:
@ -709,16 +714,15 @@ def order_line(
# display the order pos size, which is some multiple # display the order pos size, which is some multiple
# of the user defined base unit size # of the user defined base unit size
fmt_str=(':{size:.0f}'), fmt_str=('{size:.{size_digits}f}'), # old
# fmt_str=('{size:.{size_digits}f}'), # old
color=line.color, color=line.color,
) )
path.label = rlabel marker.label = rlabel
rlabel.scene_anchor = partial( rlabel.scene_anchor = partial(
gpath_pin, gpath_pin,
location_description='right-of-path-centered', location_description='right-of-path-centered',
gpath=path, gpath=marker,
label=rlabel, label=rlabel,
) )
@ -726,7 +730,7 @@ def order_line(
rlabel.fields = { rlabel.fields = {
'size': size, 'size': size,
# 'size_digits': size_digits, 'size_digits': 0,
} }
rlabel.orient_v = orient_v rlabel.orient_v = orient_v