Port all to use new cursor and ohlc refs

asyncify_input_modes
Tyler Goodlet 2021-06-22 07:17:49 -04:00
parent b6eeed1ae0
commit 8b966cd7e4
5 changed files with 65 additions and 31 deletions

View File

@ -133,7 +133,7 @@ class DynamicDateAxis(Axis):
# try:
chart = self.linkedsplits.chart
bars = chart._ohlc
bars = chart._arrays['ohlc']
shm = self.linkedsplits.chart._shm
first = shm._first.value
@ -232,7 +232,6 @@ class AxisLabel(pg.GraphicsObject):
p.setPen(self.fg_color)
p.drawText(self.rect, self.text_flags, self.label_str)
def draw(
self,
p: QtGui.QPainter,
@ -250,9 +249,9 @@ class AxisLabel(pg.GraphicsObject):
# reason; ok by us
p.setOpacity(self.opacity)
# this cause the L1 labels to glitch out if used
# in the subtype and it will leave a small black strip
# with the arrow path if done before the above
# this cause the L1 labels to glitch out if used in the subtype
# and it will leave a small black strip with the arrow path if
# done before the above
p.fillRect(self.rect, self.bg_color)
@ -295,8 +294,8 @@ class AxisLabel(pg.GraphicsObject):
self.rect = QtCore.QRectF(
0, 0,
(w or txt_w) + self._x_margin /2,
(h or txt_h) + self._y_margin /2,
(w or txt_w) + self._x_margin / 2,
(h or txt_h) + self._y_margin / 2,
)
# print(self.rect)
# hb = self.path.controlPointRect()

View File

@ -111,12 +111,12 @@ class LineEditor:
"""
# chart.setCursor(QtCore.Qt.PointingHandCursor)
if not self.chart._cursor:
cursor = self.chart.linked.cursor
if not cursor:
return None
chart = self.chart._cursor.active_plot
cursor = chart._cursor
y = chart._cursor._datum_xy[1]
chart = cursor.active_plot
y = cursor._datum_xy[1]
symbol = chart._lc.symbol
@ -168,7 +168,7 @@ class LineEditor:
"""
# chart = self.chart._cursor.active_plot
# # chart.setCursor(QtCore.Qt.ArrowCursor)
cursor = self.chart._cursor
cursor = self.chart.linked.cursor
# delete "staged" cursor tracking line from view
line = self._active_staged_line
@ -251,7 +251,7 @@ class LineEditor:
"""
# Delete any hoverable under the cursor
return self.chart._cursor._hovered
return self.chart.linked.cursor._hovered
def all_lines(self) -> tuple[LevelLine]:
return tuple(self._order_lines.values())
@ -275,13 +275,14 @@ class LineEditor:
if line:
# if hovered remove from cursor set
hovered = self.chart._cursor._hovered
cursor = self.chart.linked.cursor
hovered = cursor._hovered
if line in hovered:
hovered.remove(line)
# make sure the xhair doesn't get left off
# just because we never got a un-hover event
self.chart._cursor.show_xhair()
cursor.show_xhair()
line.delete()
return line
@ -411,7 +412,7 @@ class SelectRect(QtGui.QGraphicsRectItem):
ixmn, ixmx = round(xmn), round(xmx)
nbars = ixmx - ixmn + 1
data = self._chart._ohlc[ixmn:ixmx]
data = self._chart._arrays['ohlc'][ixmn:ixmx]
if len(data):
std = data['close'].std()

View File

@ -259,10 +259,10 @@ class LevelLine(pg.InfiniteLine):
detailed control and start end signalling.
"""
chart = self._chart
cursor = self._chart.linked.cursor
# hide y-crosshair
chart._cursor.hide_xhair()
cursor.hide_xhair()
# highlight
self.currentPen = self.hoverPen
@ -308,7 +308,7 @@ class LevelLine(pg.InfiniteLine):
# This is the final position in the drag
if ev.isFinish():
# show y-crosshair again
chart._cursor.show_xhair()
cursor.show_xhair()
def delete(self) -> None:
"""Remove this line from containing chart/view/scene.
@ -326,7 +326,7 @@ class LevelLine(pg.InfiniteLine):
# remove from chart/cursor states
chart = self._chart
cur = chart._cursor
cur = chart.linked.cursor
if self in cur._hovered:
cur._hovered.remove(self)
@ -457,8 +457,7 @@ class LevelLine(pg.InfiniteLine):
"""Mouse hover callback.
"""
chart = self._chart
cur = chart._cursor
cur = self._chart.linked.cursor
# hovered
if (not ev.isExit()) and ev.acceptDrags(QtCore.Qt.LeftButton):
@ -648,7 +647,10 @@ def order_line(
# use ``QPathGraphicsItem``s to draw markers in scene coords
# instead of the old way that was doing the same but by
# resetting the graphics item transform intermittently
# XXX: this is our new approach but seems slower?
# line.add_marker(mk_marker(marker_style, marker_size))
assert not line.markers
# the old way which is still somehow faster?
@ -659,7 +661,10 @@ def order_line(
marker_size,
use_qgpath=False,
)
# manually append for later ``.pain()`` drawing
# manually append for later ``InfiniteLine.paint()`` drawing
# XXX: this was manually tested as faster then using the
# QGraphicsItem around a painter path.. probably needs further
# testing to figure out why tf that's true.
line.markers.append((path, 0, marker_size))
orient_v = 'top' if action == 'sell' else 'bottom'
@ -754,9 +759,29 @@ def position_line(
ymn, ymx = vr[1]
level = line.value()
if level > ymx or level < ymn:
line._marker.hide()
if gt := level > ymx or (lt := level < ymn):
if chartview.mode.name == 'order':
# provide "nav hub" like indicator for where
# the position is on the y-dimension
if gt:
# pin to top of view since position is above current
# y-range
pass
elif lt:
# pin to bottom of view since position is above
# below y-range
pass
else:
# order mode is not active
# so hide the pp market
line._marker.hide()
else:
# pp line is viewable so show marker
line._marker.show()
vb.sigYRangeChanged.connect(update_pp_nav)
@ -787,6 +812,7 @@ def position_line(
style = '>|'
arrow_path = mk_marker(style, size=arrow_size)
# XXX: uses new marker drawing approach
line.add_marker(arrow_path)
line.set_level(level)

View File

@ -46,7 +46,6 @@ async def handle_viewmode_inputs(
) -> None:
mode = view.mode
status_bar = main_window().status_bar
# track edge triggered keys
# (https://en.wikipedia.org/wiki/Interrupt#Triggering_methods)
@ -148,6 +147,14 @@ async def handle_viewmode_inputs(
if key in pressed:
pressed.remove(key)
# QUERY MODE #
if {Qt.Key_Q}.intersection(pressed):
view.linkedsplits.cursor.in_query_mode = True
else:
view.linkedsplits.cursor.in_query_mode = False
# SELECTION MODE #
if shift:
@ -297,7 +304,7 @@ class ChartView(ViewBox):
log.debug("Max zoom bruh...")
return
if ev.delta() < 0 and vl >= len(chart._ohlc) + 666:
if ev.delta() < 0 and vl >= len(chart._arrays['ohlc']) + 666:
log.debug("Min zoom bruh...")
return

View File

@ -124,7 +124,7 @@ class OrderMode:
"""
# not initialized yet
if not self.chart._cursor:
if not self.chart.linked.cursor:
return
self._action = action
@ -210,7 +210,7 @@ class OrderMode:
if msg is not None:
self.lines.remove_line(uuid=uuid)
self.chart._cursor.show_xhair()
self.chart.linked.cursor.show_xhair()
pending = self._pending_submissions.pop(uuid, None)
if pending:
@ -238,8 +238,9 @@ class OrderMode:
size = size or self._size
chart = self.chart._cursor.active_plot
y = chart._cursor._datum_xy[1]
cursor = self.chart.linked.cursor
chart = cursor.active_plot
y = cursor._datum_xy[1]
symbol = self.chart._lc._symbol