Simplify line editor to track lines instead of create them
parent
97ebd03508
commit
68e23fc567
|
@ -28,7 +28,7 @@ from PyQt5.QtCore import QPointF
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from ._style import hcolor, _font
|
from ._style import hcolor, _font
|
||||||
from ._lines import order_line, LevelLine
|
from ._lines import LevelLine
|
||||||
from ..log import get_logger
|
from ..log import get_logger
|
||||||
|
|
||||||
|
|
||||||
|
@ -97,78 +97,21 @@ class LineEditor:
|
||||||
|
|
||||||
def stage_line(
|
def stage_line(
|
||||||
self,
|
self,
|
||||||
action: str,
|
line: LevelLine,
|
||||||
|
|
||||||
color: str = 'alert_yellow',
|
|
||||||
hl_on_hover: bool = False,
|
|
||||||
dotted: bool = False,
|
|
||||||
|
|
||||||
# fields settings
|
|
||||||
size: Optional[int] = None,
|
|
||||||
|
|
||||||
) -> LevelLine:
|
) -> LevelLine:
|
||||||
"""Stage a line at the current chart's cursor position
|
"""Stage a line at the current chart's cursor position
|
||||||
and return it.
|
and return it.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if self.chart is None:
|
|
||||||
log.error('No chart interaction yet available')
|
|
||||||
return None
|
|
||||||
|
|
||||||
# chart.setCursor(QtCore.Qt.PointingHandCursor)
|
|
||||||
cursor = self.chart.linked.cursor
|
|
||||||
if not cursor:
|
|
||||||
return None
|
|
||||||
|
|
||||||
chart = cursor.active_plot
|
|
||||||
y = cursor._datum_xy[1]
|
|
||||||
|
|
||||||
symbol = chart.linked.symbol
|
|
||||||
|
|
||||||
# add a "staged" cursor-tracking line to view
|
# add a "staged" cursor-tracking line to view
|
||||||
# and cash it in a a var
|
# and cash it in a a var
|
||||||
if self._active_staged_line:
|
if self._active_staged_line:
|
||||||
self.unstage_line()
|
self.unstage_line()
|
||||||
|
|
||||||
line = order_line(
|
|
||||||
chart,
|
|
||||||
|
|
||||||
# TODO: convert these values into human-readable form
|
|
||||||
# (i.e. with k, m, M, B) type embedded suffixes
|
|
||||||
level=y,
|
|
||||||
level_digits=symbol.digits(),
|
|
||||||
|
|
||||||
size=size,
|
|
||||||
# TODO: we need truncation checks in the EMS for this?
|
|
||||||
# size_digits=min(symbol.lot_digits(), 3),
|
|
||||||
|
|
||||||
# just for the stage line to avoid
|
|
||||||
# flickering while moving the cursor
|
|
||||||
# around where it might trigger highlight
|
|
||||||
# then non-highlight depending on sensitivity
|
|
||||||
always_show_labels=True,
|
|
||||||
|
|
||||||
# kwargs
|
|
||||||
color=color,
|
|
||||||
# don't highlight the "staging" line
|
|
||||||
hl_on_hover=hl_on_hover,
|
|
||||||
dotted=dotted,
|
|
||||||
exec_type='dark' if dotted else 'live',
|
|
||||||
action=action,
|
|
||||||
show_markers=True,
|
|
||||||
|
|
||||||
# prevent flickering of marker while moving/tracking cursor
|
|
||||||
only_show_markers_on_hover=False,
|
|
||||||
)
|
|
||||||
|
|
||||||
self._active_staged_line = line
|
self._active_staged_line = line
|
||||||
|
|
||||||
# hide crosshair y-line and label
|
|
||||||
cursor.hide_xhair()
|
|
||||||
|
|
||||||
# add line to cursor trackers
|
|
||||||
cursor._trackers.add(line)
|
|
||||||
|
|
||||||
return line
|
return line
|
||||||
|
|
||||||
def unstage_line(self) -> LevelLine:
|
def unstage_line(self) -> LevelLine:
|
||||||
|
@ -190,42 +133,17 @@ class LineEditor:
|
||||||
# show the crosshair y line and label
|
# show the crosshair y line and label
|
||||||
cursor.show_xhair()
|
cursor.show_xhair()
|
||||||
|
|
||||||
def create_order_line(
|
def submit_line(
|
||||||
self,
|
self,
|
||||||
|
line: LevelLine,
|
||||||
uuid: str,
|
uuid: str,
|
||||||
level: float,
|
|
||||||
chart: 'ChartPlotWidget', # noqa
|
|
||||||
size: float,
|
|
||||||
action: str,
|
|
||||||
) -> LevelLine:
|
) -> LevelLine:
|
||||||
|
|
||||||
line = self._active_staged_line
|
staged_line = self._active_staged_line
|
||||||
if not line:
|
if not staged_line:
|
||||||
raise RuntimeError("No line is currently staged!?")
|
raise RuntimeError("No line is currently staged!?")
|
||||||
|
|
||||||
sym = chart.linked.symbol
|
|
||||||
|
|
||||||
line = order_line(
|
|
||||||
chart,
|
|
||||||
|
|
||||||
# label fields default values
|
|
||||||
level=level,
|
|
||||||
level_digits=sym.digits(),
|
|
||||||
|
|
||||||
size=size,
|
|
||||||
# TODO: we need truncation checks in the EMS for this?
|
|
||||||
# size_digits=sym.lot_digits(),
|
|
||||||
|
|
||||||
# LevelLine kwargs
|
|
||||||
color=line.color,
|
|
||||||
dotted=line._dotted,
|
|
||||||
|
|
||||||
show_markers=True,
|
|
||||||
only_show_markers_on_hover=True,
|
|
||||||
|
|
||||||
action=action,
|
|
||||||
)
|
|
||||||
|
|
||||||
# for now, until submission reponse arrives
|
# for now, until submission reponse arrives
|
||||||
line.hide_labels()
|
line.hide_labels()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue