Pass scene-points to `.select_box` as per prior comments
As mentioned in a prior commit this was the (seemingly, and so far) only way to make our `.select_box` annotator shift-click rect work properly (and the same as) by adopting the code around `ViewBox.rbScaleBox` (which we now also disable). That means also passing the scene coords to the `SelectRect.set_scen_pos()`. Also add in the proper `ev: pyqtgraph.GraphicsScene.mouseEvents.MouseDragEvent` so we can actually figure out wut the hell all this pg custom mouse-event stuff is XDdistribute_dis
parent
1f346483a0
commit
e7fa841263
|
@ -30,7 +30,11 @@ from typing import (
|
||||||
)
|
)
|
||||||
|
|
||||||
import pyqtgraph as pg
|
import pyqtgraph as pg
|
||||||
# from pyqtgraph.GraphicsScene import mouseEvents
|
# NOTE XXX: pg is super annoying and re-implements it's own mouse
|
||||||
|
# event subsystem.. we should really look into re-working/writing
|
||||||
|
# this down the road.. Bo
|
||||||
|
from pyqtgraph.GraphicsScene import mouseEvents as mevs
|
||||||
|
# from pyqtgraph.GraphicsScene.mouseEvents import MouseDragEvent
|
||||||
from PyQt5.QtWidgets import QGraphicsSceneMouseEvent as gs_mouse
|
from PyQt5.QtWidgets import QGraphicsSceneMouseEvent as gs_mouse
|
||||||
from PyQt5.QtGui import (
|
from PyQt5.QtGui import (
|
||||||
QWheelEvent,
|
QWheelEvent,
|
||||||
|
@ -466,6 +470,7 @@ class ChartView(ViewBox):
|
||||||
mode_name: str = 'view'
|
mode_name: str = 'view'
|
||||||
def_delta: float = 616 * 6
|
def_delta: float = 616 * 6
|
||||||
def_scale_factor: float = 1.016 ** (def_delta * -1 / 20)
|
def_scale_factor: float = 1.016 ** (def_delta * -1 / 20)
|
||||||
|
# annots: dict[int, GraphicsObject] = {}
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
@ -486,6 +491,7 @@ class ChartView(ViewBox):
|
||||||
# defaultPadding=0.,
|
# defaultPadding=0.,
|
||||||
**kwargs
|
**kwargs
|
||||||
)
|
)
|
||||||
|
|
||||||
# for "known y-range style"
|
# for "known y-range style"
|
||||||
self._static_yrange = static_yrange
|
self._static_yrange = static_yrange
|
||||||
|
|
||||||
|
@ -500,7 +506,7 @@ class ChartView(ViewBox):
|
||||||
|
|
||||||
# add our selection box annotator
|
# add our selection box annotator
|
||||||
self.select_box = SelectRect(self)
|
self.select_box = SelectRect(self)
|
||||||
self.select_box.add_to_view(self)
|
# self.select_box.add_to_view(self)
|
||||||
# self.addItem(
|
# self.addItem(
|
||||||
# self.select_box,
|
# self.select_box,
|
||||||
# ignoreBounds=True,
|
# ignoreBounds=True,
|
||||||
|
@ -715,17 +721,18 @@ class ChartView(ViewBox):
|
||||||
|
|
||||||
def mouseDragEvent(
|
def mouseDragEvent(
|
||||||
self,
|
self,
|
||||||
ev,
|
ev: mevs.MouseDragEvent,
|
||||||
axis: int | None = None,
|
axis: int | None = None,
|
||||||
|
|
||||||
) -> None:
|
) -> None:
|
||||||
pos = ev.pos()
|
pos: Point = ev.pos()
|
||||||
lastPos = ev.lastPos()
|
lastPos: Point = ev.lastPos()
|
||||||
dif = pos - lastPos
|
dif: Point = (pos - lastPos) * -1
|
||||||
dif = dif * -1
|
# dif: Point = pos - lastPos
|
||||||
|
# dif: Point = dif * -1
|
||||||
|
|
||||||
# NOTE: if axis is specified, event will only affect that axis.
|
# NOTE: if axis is specified, event will only affect that axis.
|
||||||
button = ev.button()
|
btn = ev.button()
|
||||||
|
|
||||||
# Ignore axes if mouse is disabled
|
# Ignore axes if mouse is disabled
|
||||||
mouseEnabled = np.array(
|
mouseEnabled = np.array(
|
||||||
|
@ -737,7 +744,7 @@ class ChartView(ViewBox):
|
||||||
mask[1-axis] = 0.0
|
mask[1-axis] = 0.0
|
||||||
|
|
||||||
# Scale or translate based on mouse button
|
# Scale or translate based on mouse button
|
||||||
if button & (
|
if btn & (
|
||||||
QtCore.Qt.LeftButton | QtCore.Qt.MidButton
|
QtCore.Qt.LeftButton | QtCore.Qt.MidButton
|
||||||
):
|
):
|
||||||
# zoom y-axis ONLY when click-n-drag on it
|
# zoom y-axis ONLY when click-n-drag on it
|
||||||
|
@ -760,15 +767,18 @@ class ChartView(ViewBox):
|
||||||
# XXX: WHY
|
# XXX: WHY
|
||||||
ev.accept()
|
ev.accept()
|
||||||
|
|
||||||
down_pos = ev.buttonDownPos()
|
down_pos: Point = ev.buttonDownPos(
|
||||||
|
btn=btn,
|
||||||
|
)
|
||||||
|
scen_pos: Point = ev.scenePos()
|
||||||
|
scen_down_pos: Point = ev.buttonDownScenePos(
|
||||||
|
btn=btn,
|
||||||
|
)
|
||||||
|
|
||||||
# This is the final position in the drag
|
# This is the final position in the drag
|
||||||
if ev.isFinish():
|
if ev.isFinish():
|
||||||
|
|
||||||
self.select_box.mouse_drag_released(
|
# import pdbp; pdbp.set_trace()
|
||||||
down_pos,
|
|
||||||
pos,
|
|
||||||
)
|
|
||||||
|
|
||||||
# NOTE: think of this as a `.mouse_drag_release()`
|
# NOTE: think of this as a `.mouse_drag_release()`
|
||||||
# (bc HINT that's what i called the shit ass
|
# (bc HINT that's what i called the shit ass
|
||||||
|
@ -776,34 +786,36 @@ class ChartView(ViewBox):
|
||||||
# fucking call] originally.. you bish, guille)
|
# fucking call] originally.. you bish, guille)
|
||||||
# Bo.. oraleeee
|
# Bo.. oraleeee
|
||||||
self.select_box.set_scen_pos(
|
self.select_box.set_scen_pos(
|
||||||
down_pos,
|
# down_pos,
|
||||||
pos,
|
# pos,
|
||||||
|
scen_down_pos,
|
||||||
|
scen_pos,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# this is the zoom transform cmd
|
||||||
ax = QtCore.QRectF(down_pos, pos)
|
ax = QtCore.QRectF(down_pos, pos)
|
||||||
ax = self.childGroup.mapRectFromParent(ax)
|
ax = self.childGroup.mapRectFromParent(ax)
|
||||||
|
# self.showAxRect(ax)
|
||||||
# this is the zoom transform cmd
|
|
||||||
self.showAxRect(ax)
|
|
||||||
|
|
||||||
# axis history tracking
|
# axis history tracking
|
||||||
self.axHistoryPointer += 1
|
self.axHistoryPointer += 1
|
||||||
self.axHistory = self.axHistory[
|
self.axHistory = self.axHistory[
|
||||||
:self.axHistoryPointer] + [ax]
|
:self.axHistoryPointer] + [ax]
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print('drag finish?')
|
|
||||||
self.select_box.set_scen_pos(
|
self.select_box.set_scen_pos(
|
||||||
down_pos,
|
# down_pos,
|
||||||
pos,
|
# pos,
|
||||||
|
scen_down_pos,
|
||||||
|
scen_pos,
|
||||||
)
|
)
|
||||||
|
|
||||||
# update shape of scale box
|
# update shape of scale box
|
||||||
# self.updateScaleBox(ev.buttonDownPos(), ev.pos())
|
# self.updateScaleBox(ev.buttonDownPos(), ev.pos())
|
||||||
self.updateScaleBox(
|
# breakpoint()
|
||||||
down_pos,
|
# self.updateScaleBox(
|
||||||
ev.pos(),
|
# down_pos,
|
||||||
)
|
# ev.pos(),
|
||||||
|
# )
|
||||||
|
|
||||||
# PANNING MODE
|
# PANNING MODE
|
||||||
else:
|
else:
|
||||||
|
@ -842,7 +854,7 @@ class ChartView(ViewBox):
|
||||||
# ev.accept()
|
# ev.accept()
|
||||||
|
|
||||||
# WEIRD "RIGHT-CLICK CENTER ZOOM" MODE
|
# WEIRD "RIGHT-CLICK CENTER ZOOM" MODE
|
||||||
elif button & QtCore.Qt.RightButton:
|
elif btn & QtCore.Qt.RightButton:
|
||||||
|
|
||||||
if self.state['aspectLocked'] is not False:
|
if self.state['aspectLocked'] is not False:
|
||||||
mask[0] = 0
|
mask[0] = 0
|
||||||
|
|
Loading…
Reference in New Issue