First pass at implementing the diff from PR307
This commit is contained in:
parent
b41c4a71e5
commit
ce6da3e93f
@ -1,4 +1,5 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
import time
|
||||||
import weakref
|
import weakref
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
@ -8,6 +9,9 @@ from .. import functions as fn
|
|||||||
from .. import ptime as ptime
|
from .. import ptime as ptime
|
||||||
from .mouseEvents import *
|
from .mouseEvents import *
|
||||||
from .. import debug as debug
|
from .. import debug as debug
|
||||||
|
from .. import getConfigOption
|
||||||
|
|
||||||
|
getMillis = lambda: int(round(time.time() * 1000))
|
||||||
|
|
||||||
|
|
||||||
if hasattr(QtCore, 'PYQT_VERSION'):
|
if hasattr(QtCore, 'PYQT_VERSION'):
|
||||||
@ -114,6 +118,7 @@ class GraphicsScene(QtGui.QGraphicsScene):
|
|||||||
self.contextMenu[0].triggered.connect(self.showExportDialog)
|
self.contextMenu[0].triggered.connect(self.showExportDialog)
|
||||||
|
|
||||||
self.exportDialog = None
|
self.exportDialog = None
|
||||||
|
self._lastMoveEventTime = 0
|
||||||
|
|
||||||
def render(self, *args):
|
def render(self, *args):
|
||||||
self.prepareForPaint()
|
self.prepareForPaint()
|
||||||
@ -162,16 +167,33 @@ class GraphicsScene(QtGui.QGraphicsScene):
|
|||||||
i.setFocus(QtCore.Qt.MouseFocusReason)
|
i.setFocus(QtCore.Qt.MouseFocusReason)
|
||||||
break
|
break
|
||||||
|
|
||||||
|
def _moveEventIsAllowed(self):
|
||||||
|
# For ignoring events that are too close together
|
||||||
|
|
||||||
|
# Max number of events per second
|
||||||
|
rateLimit = getConfigOption('mouseRateLimit')
|
||||||
|
if rateLimit <= 0:
|
||||||
|
return True
|
||||||
|
|
||||||
|
# Delay between events (in milliseconds)
|
||||||
|
delay = 1000.0 / rateLimit
|
||||||
|
if getMillis() - self._lastMoveEventTime >= delay:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def mouseMoveEvent(self, ev):
|
def mouseMoveEvent(self, ev):
|
||||||
|
# ignore high frequency events
|
||||||
|
if self._moveEventIsAllowed():
|
||||||
|
self._lastMoveEventTime = getMillis()
|
||||||
self.sigMouseMoved.emit(ev.scenePos())
|
self.sigMouseMoved.emit(ev.scenePos())
|
||||||
|
|
||||||
## First allow QGraphicsScene to deliver hoverEnter/Move/ExitEvents
|
# First allow QGraphicsScene to eliver hoverEvent/Move/Exit Events
|
||||||
QtGui.QGraphicsScene.mouseMoveEvent(self, ev)
|
QtGui.QGraphicsScene.mouseMoveEvent(self, ev)
|
||||||
|
# Next Deliver our own Hover Events
|
||||||
## Next deliver our own HoverEvents
|
|
||||||
self.sendHoverEvents(ev)
|
self.sendHoverEvents(ev)
|
||||||
|
if int(ev.buttons()) != 0:
|
||||||
if int(ev.buttons()) != 0: ## button is pressed; send mouseMoveEvents and mouseDragEvents
|
# button is pressed' send mouseMoveEvents and mouseDragEvents
|
||||||
QtGui.QGraphicsScene.mouseMoveEvent(self, ev)
|
QtGui.QGraphicsScene.mouseMoveEvent(self, ev)
|
||||||
if self.mouseGrabberItem() is None:
|
if self.mouseGrabberItem() is None:
|
||||||
now = ptime.time()
|
now = ptime.time()
|
||||||
@ -189,12 +211,16 @@ class GraphicsScene(QtGui.QGraphicsScene):
|
|||||||
continue
|
continue
|
||||||
init = init or (len(self.dragButtons) == 0) ## If this is the first button to be dragged, then init=True
|
init = init or (len(self.dragButtons) == 0) ## If this is the first button to be dragged, then init=True
|
||||||
self.dragButtons.append(int(btn))
|
self.dragButtons.append(int(btn))
|
||||||
|
## if we have dragged buttons, deliver a drag event
|
||||||
## If we have dragged buttons, deliver a drag event
|
|
||||||
if len(self.dragButtons) > 0:
|
if len(self.dragButtons) > 0:
|
||||||
if self.sendDragEvent(ev, init=init):
|
if self.sendDragEvent(ev, init=init):
|
||||||
ev.accept()
|
ev.accept()
|
||||||
|
|
||||||
|
else:
|
||||||
|
QtGui.QGraphicsScene.mouseMoveEvent(self, ev)
|
||||||
|
# if you do not accept event (which is ignored) then cursor will disappear
|
||||||
|
ev.accept()
|
||||||
|
|
||||||
def leaveEvent(self, ev): ## inform items that mouse is gone
|
def leaveEvent(self, ev): ## inform items that mouse is gone
|
||||||
if len(self.dragButtons) == 0:
|
if len(self.dragButtons) == 0:
|
||||||
self.sendHoverEvents(ev, exitOnly=True)
|
self.sendHoverEvents(ev, exitOnly=True)
|
||||||
|
@ -56,6 +56,7 @@ CONFIG_OPTIONS = {
|
|||||||
'exitCleanup': True, ## Attempt to work around some exit crash bugs in PyQt and PySide
|
'exitCleanup': True, ## Attempt to work around some exit crash bugs in PyQt and PySide
|
||||||
'enableExperimental': False, ## Enable experimental features (the curious can search for this key in the code)
|
'enableExperimental': False, ## Enable experimental features (the curious can search for this key in the code)
|
||||||
'crashWarning': False, # If True, print warnings about situations that may result in a crash
|
'crashWarning': False, # If True, print warnings about situations that may result in a crash
|
||||||
|
'mouseRateLimit': 100, # For ignoring frequent mouse events, max number of mouse move events per second, if <= 0, then it is switched off
|
||||||
'imageAxisOrder': 'col-major', # For 'row-major', image data is expected in the standard (row, col) order.
|
'imageAxisOrder': 'col-major', # For 'row-major', image data is expected in the standard (row, col) order.
|
||||||
# For 'col-major', image data is expected in reversed (col, row) order.
|
# For 'col-major', image data is expected in reversed (col, row) order.
|
||||||
# The default is 'col-major' for backward compatibility, but this may
|
# The default is 'col-major' for backward compatibility, but this may
|
||||||
|
@ -5,6 +5,9 @@ pg.mkQApp()
|
|||||||
|
|
||||||
|
|
||||||
def test_InfiniteLine():
|
def test_InfiniteLine():
|
||||||
|
# disable delay of mouse move events because events is called immediately in test
|
||||||
|
pg.setConfigOption('mouseRateLimit', -1)
|
||||||
|
|
||||||
# Test basic InfiniteLine API
|
# Test basic InfiniteLine API
|
||||||
plt = pg.plot()
|
plt = pg.plot()
|
||||||
plt.setXRange(-10, 10)
|
plt.setXRange(-10, 10)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user