Factor press and release handling into same qtloop
parent
376aa66a73
commit
68093d55f2
|
@ -48,11 +48,103 @@ async def handle_viewmode_inputs(
|
|||
|
||||
if etype in {QEvent.KeyPress}:
|
||||
|
||||
await view.on_key_press(text, key, mods)
|
||||
# await view.on_key_press(text, key, mods)
|
||||
|
||||
if mods == Qt.ShiftModifier:
|
||||
if view.state['mouseMode'] == ViewBox.PanMode:
|
||||
view.setMouseMode(ViewBox.RectMode)
|
||||
|
||||
# ctrl
|
||||
ctrl = False
|
||||
if mods == Qt.ControlModifier:
|
||||
ctrl = True
|
||||
view.mode._exec_mode = 'live'
|
||||
|
||||
view._key_active = True
|
||||
|
||||
# ctrl + alt
|
||||
# ctlalt = False
|
||||
# if (QtCore.Qt.AltModifier | QtCore.Qt.ControlModifier) == mods:
|
||||
# ctlalt = True
|
||||
|
||||
# ctlr-<space>/<l> for "lookup", "search" -> open search tree
|
||||
if ctrl and key in {
|
||||
Qt.Key_L,
|
||||
Qt.Key_Space,
|
||||
}:
|
||||
search = view._chart._lc.godwidget.search
|
||||
search.focus()
|
||||
|
||||
# esc
|
||||
if key == Qt.Key_Escape or (ctrl and key == Qt.Key_C):
|
||||
# ctrl-c as cancel
|
||||
# https://forum.qt.io/topic/532/how-to-catch-ctrl-c-on-a-widget/9
|
||||
view.select_box.clear()
|
||||
|
||||
# cancel order or clear graphics
|
||||
if key == Qt.Key_C or key == Qt.Key_Delete:
|
||||
# delete any lines under the cursor
|
||||
mode = view.mode
|
||||
for line in mode.lines.lines_under_cursor():
|
||||
mode.book.cancel(uuid=line.oid)
|
||||
|
||||
view._key_buffer.append(text)
|
||||
|
||||
# View modes
|
||||
if key == Qt.Key_R:
|
||||
view.chart.default_view()
|
||||
|
||||
# Order modes: stage orders at the current cursor level
|
||||
|
||||
elif key == Qt.Key_D: # for "damp eet"
|
||||
view.mode.set_exec('sell')
|
||||
|
||||
elif key == Qt.Key_F: # for "fillz eet"
|
||||
view.mode.set_exec('buy')
|
||||
|
||||
elif key == Qt.Key_A:
|
||||
view.mode.set_exec('alert')
|
||||
|
||||
# XXX: Leaving this for light reference purposes, there
|
||||
# seems to be some work to at least gawk at for history mgmt.
|
||||
|
||||
# Key presses are used only when mouse mode is RectMode
|
||||
# The following events are implemented:
|
||||
# ctrl-A : zooms out to the default "full" view of the plot
|
||||
# ctrl-+ : moves forward in the zooming stack (if it exists)
|
||||
# ctrl-- : moves backward in the zooming stack (if it exists)
|
||||
|
||||
# view.scaleHistory(-1)
|
||||
# elif ev.text() in ['+', '=']:
|
||||
# view.scaleHistory(1)
|
||||
# elif ev.key() == QtCore.Qt.Key_Backspace:
|
||||
# view.scaleHistory(len(view.axHistory))
|
||||
else:
|
||||
# maybe propagate to parent widget
|
||||
# event.ignore()
|
||||
view._key_active = False
|
||||
|
||||
elif etype in {QEvent.KeyRelease}:
|
||||
|
||||
await view.on_key_release(text, key, mods)
|
||||
# await view.on_key_release(text, key, mods)
|
||||
if key == Qt.Key_Shift:
|
||||
# if view.state['mouseMode'] == ViewBox.RectMode:
|
||||
view.setMouseMode(ViewBox.PanMode)
|
||||
|
||||
# ctlalt = False
|
||||
# if (QtCore.Qt.AltModifier | QtCore.Qt.ControlModifier) == mods:
|
||||
# ctlalt = True
|
||||
|
||||
# if view.state['mouseMode'] == ViewBox.RectMode:
|
||||
# if key == QtCore.Qt.Key_Space:
|
||||
if mods == Qt.ControlModifier or key == QtCore.Qt.Key_Control:
|
||||
view.mode._exec_mode = 'dark'
|
||||
|
||||
if key in {Qt.Key_A, Qt.Key_F, Qt.Key_D}:
|
||||
# remove "staged" level line under cursor position
|
||||
view.mode.lines.unstage_line()
|
||||
|
||||
view._key_active = False
|
||||
|
||||
|
||||
class ChartView(ViewBox):
|
||||
|
@ -315,129 +407,12 @@ class ChartView(ViewBox):
|
|||
ev.accept()
|
||||
self.mode.submit_exec()
|
||||
|
||||
# def keyReleaseEvent(self, ev: QtCore.QEvent):
|
||||
def keyReleaseEvent(self, event: QtCore.QEvent) -> None:
|
||||
'''This routine is rerouted to an async handler.
|
||||
'''
|
||||
pass
|
||||
|
||||
async def on_key_release(
|
||||
|
||||
self,
|
||||
|
||||
text: str,
|
||||
key: int, # 3-digit
|
||||
mods: int, # 7-digit
|
||||
|
||||
) -> None:
|
||||
"""
|
||||
Key release to normally to trigger release of input mode
|
||||
|
||||
"""
|
||||
if key == Qt.Key_Shift:
|
||||
# if self.state['mouseMode'] == ViewBox.RectMode:
|
||||
self.setMouseMode(ViewBox.PanMode)
|
||||
|
||||
# ctlalt = False
|
||||
# if (QtCore.Qt.AltModifier | QtCore.Qt.ControlModifier) == mods:
|
||||
# ctlalt = True
|
||||
|
||||
# if self.state['mouseMode'] == ViewBox.RectMode:
|
||||
# if key == QtCore.Qt.Key_Space:
|
||||
if mods == Qt.ControlModifier or key == QtCore.Qt.Key_Control:
|
||||
self.mode._exec_mode = 'dark'
|
||||
|
||||
if key in {Qt.Key_A, Qt.Key_F, Qt.Key_D}:
|
||||
# remove "staged" level line under cursor position
|
||||
self.mode.lines.unstage_line()
|
||||
|
||||
self._key_active = False
|
||||
|
||||
def keyPressEvent(self, event: QtCore.QEvent) -> None:
|
||||
'''This routine is rerouted to an async handler.
|
||||
'''
|
||||
pass
|
||||
|
||||
async def on_key_press(
|
||||
|
||||
self,
|
||||
|
||||
text: str,
|
||||
key: int, # 3-digit
|
||||
mods: int, # 7-digit
|
||||
|
||||
) -> None:
|
||||
|
||||
if mods == Qt.ShiftModifier:
|
||||
if self.state['mouseMode'] == ViewBox.PanMode:
|
||||
self.setMouseMode(ViewBox.RectMode)
|
||||
|
||||
# ctrl
|
||||
ctrl = False
|
||||
if mods == Qt.ControlModifier:
|
||||
ctrl = True
|
||||
self.mode._exec_mode = 'live'
|
||||
|
||||
self._key_active = True
|
||||
|
||||
# ctrl + alt
|
||||
# ctlalt = False
|
||||
# if (QtCore.Qt.AltModifier | QtCore.Qt.ControlModifier) == mods:
|
||||
# ctlalt = True
|
||||
|
||||
# ctlr-<space>/<l> for "lookup", "search" -> open search tree
|
||||
if ctrl and key in {
|
||||
Qt.Key_L,
|
||||
Qt.Key_Space,
|
||||
}:
|
||||
search = self._chart._lc.godwidget.search
|
||||
search.focus()
|
||||
|
||||
# esc
|
||||
if key == Qt.Key_Escape or (ctrl and key == Qt.Key_C):
|
||||
# ctrl-c as cancel
|
||||
# https://forum.qt.io/topic/532/how-to-catch-ctrl-c-on-a-widget/9
|
||||
self.select_box.clear()
|
||||
|
||||
# cancel order or clear graphics
|
||||
if key == Qt.Key_C or key == Qt.Key_Delete:
|
||||
# delete any lines under the cursor
|
||||
mode = self.mode
|
||||
for line in mode.lines.lines_under_cursor():
|
||||
mode.book.cancel(uuid=line.oid)
|
||||
|
||||
self._key_buffer.append(text)
|
||||
|
||||
# View modes
|
||||
if key == Qt.Key_R:
|
||||
self.chart.default_view()
|
||||
|
||||
# Order modes: stage orders at the current cursor level
|
||||
|
||||
elif key == Qt.Key_D: # for "damp eet"
|
||||
self.mode.set_exec('sell')
|
||||
|
||||
elif key == Qt.Key_F: # for "fillz eet"
|
||||
self.mode.set_exec('buy')
|
||||
|
||||
elif key == Qt.Key_A:
|
||||
self.mode.set_exec('alert')
|
||||
|
||||
# XXX: Leaving this for light reference purposes, there
|
||||
# seems to be some work to at least gawk at for history mgmt.
|
||||
|
||||
# Key presses are used only when mouse mode is RectMode
|
||||
# The following events are implemented:
|
||||
# ctrl-A : zooms out to the default "full" self of the plot
|
||||
# ctrl-+ : moves forward in the zooming stack (if it exists)
|
||||
# ctrl-- : moves backward in the zooming stack (if it exists)
|
||||
|
||||
# self.scaleHistory(-1)
|
||||
# elif ev.text() in ['+', '=']:
|
||||
# self.scaleHistory(1)
|
||||
# elif ev.key() == QtCore.Qt.Key_Backspace:
|
||||
# self.scaleHistory(len(self.axHistory))
|
||||
else:
|
||||
# maybe propagate to parent widget
|
||||
# event.ignore()
|
||||
self._key_active = False
|
||||
|
|
Loading…
Reference in New Issue