Explicitly accept interaction events in our chart view

plotitem_overlays
Tyler Goodlet 2022-01-24 15:19:45 -05:00
parent 1ccff37677
commit 3225f254f4
1 changed files with 20 additions and 6 deletions

View File

@ -18,6 +18,7 @@
Chart view box primitives Chart view box primitives
""" """
from __future__ import annotations
from contextlib import asynccontextmanager from contextlib import asynccontextmanager
import time import time
from typing import Optional, Callable from typing import Optional, Callable
@ -399,7 +400,12 @@ class ChartView(ViewBox):
self._chart = chart self._chart = chart
self.select_box.chart = chart self.select_box.chart = chart
def wheelEvent(self, ev, axis=None): def wheelEvent(
self,
ev,
axis=None,
relayed_from: ChartView = None,
):
'''Override "center-point" location for scrolling. '''Override "center-point" location for scrolling.
This is an override of the ``ViewBox`` method simply changing This is an override of the ``ViewBox`` method simply changing
@ -476,16 +482,16 @@ class ChartView(ViewBox):
self._resetTarget() self._resetTarget()
self.scaleBy(s, focal) self.scaleBy(s, focal)
ev.accept()
self.sigRangeChangedManually.emit(mask) self.sigRangeChangedManually.emit(mask)
ev.accept()
def mouseDragEvent( def mouseDragEvent(
self, self,
ev, ev,
axis: Optional[int] = None, axis: Optional[int] = None,
relayed_from: ChartView = None,
) -> None: ) -> None:
# if axis is specified, event will only affect that axis. # if axis is specified, event will only affect that axis.
ev.accept() # we accept all buttons
button = ev.button() button = ev.button()
pos = ev.pos() pos = ev.pos()
@ -514,7 +520,10 @@ class ChartView(ViewBox):
# print(scale_y) # print(scale_y)
self.scaleBy((0, scale_y)) self.scaleBy((0, scale_y))
# SELECTION MODE
if self.state['mouseMode'] == ViewBox.RectMode: if self.state['mouseMode'] == ViewBox.RectMode:
# XXX: WHY
ev.accept()
down_pos = ev.buttonDownPos() down_pos = ev.buttonDownPos()
@ -538,8 +547,11 @@ class ChartView(ViewBox):
# update shape of scale box # update shape of scale box
# self.updateScaleBox(ev.buttonDownPos(), ev.pos()) # self.updateScaleBox(ev.buttonDownPos(), ev.pos())
# PANNING MODE
else: else:
# default bevavior: click to pan view # XXX: WHY
ev.accept()
tr = self.childGroup.transform() tr = self.childGroup.transform()
tr = fn.invertQTransform(tr) tr = fn.invertQTransform(tr)
tr = tr.map(dif*mask) - tr.map(Point(0, 0)) tr = tr.map(dif*mask) - tr.map(Point(0, 0))
@ -554,10 +566,9 @@ class ChartView(ViewBox):
self.sigRangeChangedManually.emit(self.state['mouseEnabled']) self.sigRangeChangedManually.emit(self.state['mouseEnabled'])
# WEIRD "RIGHT-CLICK CENTER ZOOM" MODE
elif button & QtCore.Qt.RightButton: elif button & QtCore.Qt.RightButton:
# right click zoom to center behaviour
if self.state['aspectLocked'] is not False: if self.state['aspectLocked'] is not False:
mask[0] = 0 mask[0] = 0
@ -577,6 +588,9 @@ class ChartView(ViewBox):
self.scaleBy(x=x, y=y, center=center) self.scaleBy(x=x, y=y, center=center)
self.sigRangeChangedManually.emit(self.state['mouseEnabled']) self.sigRangeChangedManually.emit(self.state['mouseEnabled'])
# XXX: WHY
ev.accept()
# def mouseClickEvent(self, event: QtCore.QEvent) -> None: # def mouseClickEvent(self, event: QtCore.QEvent) -> None:
# '''This routine is rerouted to an async handler. # '''This routine is rerouted to an async handler.
# ''' # '''