Skip to content

Commit

Permalink
Merge tag 'pyqtgraph-0.9.10' into core
Browse files Browse the repository at this point in the history
Conflicts:
	graphicsItems/ViewBox/ViewBox.py
	parametertree/SystemSolver.py
	widgets/SpinBox.py
  • Loading branch information
campagnola committed May 13, 2015
2 parents ca3fbe2 + 70cfdb4 commit 2e37d9b
Show file tree
Hide file tree
Showing 29 changed files with 410 additions and 4,469 deletions.
41 changes: 17 additions & 24 deletions GraphicsScene/GraphicsScene.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ def registerObject(cls, obj):
cls._addressCache[sip.unwrapinstance(sip.cast(obj, QtGui.QGraphicsItem))] = obj


def __init__(self, clickRadius=2, moveDistance=5):
QtGui.QGraphicsScene.__init__(self)
def __init__(self, clickRadius=2, moveDistance=5, parent=None):
QtGui.QGraphicsScene.__init__(self, parent)
self.setClickRadius(clickRadius)
self.setMoveDistance(moveDistance)
self.exportDirectory = None
Expand Down Expand Up @@ -135,8 +135,13 @@ def setMoveDistance(self, d):
def mousePressEvent(self, ev):
#print 'scenePress'
QtGui.QGraphicsScene.mousePressEvent(self, ev)
#print "mouseGrabberItem: ", self.mouseGrabberItem()
if self.mouseGrabberItem() is None: ## nobody claimed press; we are free to generate drag/click events
if self.lastHoverEvent is not None:
# If the mouse has moved since the last hover event, send a new one.
# This can happen if a context menu is open while the mouse is moving.
if ev.scenePos() != self.lastHoverEvent.scenePos():
self.sendHoverEvents(ev)

self.clickEvents.append(MouseClickEvent(ev))

## set focus on the topmost focusable item under this click
Expand All @@ -145,10 +150,6 @@ def mousePressEvent(self, ev):
if i.isEnabled() and i.isVisible() and int(i.flags() & i.ItemIsFocusable) > 0:
i.setFocus(QtCore.Qt.MouseFocusReason)
break
#else:
#addr = sip.unwrapinstance(sip.cast(self.mouseGrabberItem(), QtGui.QGraphicsItem))
#item = GraphicsScene._addressCache.get(addr, self.mouseGrabberItem())
#print "click grabbed by:", item

def mouseMoveEvent(self, ev):
self.sigMouseMoved.emit(ev.scenePos())
Expand Down Expand Up @@ -189,7 +190,6 @@ def leaveEvent(self, ev): ## inform items that mouse is gone
def mouseReleaseEvent(self, ev):
#print 'sceneRelease'
if self.mouseGrabberItem() is None:
#print "sending click/drag event"
if ev.button() in self.dragButtons:
if self.sendDragEvent(ev, final=True):
#print "sent drag event"
Expand Down Expand Up @@ -231,6 +231,8 @@ def sendHoverEvents(self, ev, exitOnly=False):

prevItems = list(self.hoverItems.keys())

#print "hover prev items:", prevItems
#print "hover test items:", items
for item in items:
if hasattr(item, 'hoverEvent'):
event.currentItem = item
Expand All @@ -248,6 +250,7 @@ def sendHoverEvents(self, ev, exitOnly=False):

event.enter = False
event.exit = True
#print "hover exit items:", prevItems
for item in prevItems:
event.currentItem = item
try:
Expand All @@ -257,9 +260,13 @@ def sendHoverEvents(self, ev, exitOnly=False):
finally:
del self.hoverItems[item]

if hasattr(ev, 'buttons') and int(ev.buttons()) == 0:
# Update last hover event unless:
# - mouse is dragging (move+buttons); in this case we want the dragged
# item to continue receiving events until the drag is over
# - event is not a mouse event (QEvent.Leave sometimes appears here)
if (ev.type() == ev.GraphicsSceneMousePress or
(ev.type() == ev.GraphicsSceneMouseMove and int(ev.buttons()) == 0)):
self.lastHoverEvent = event ## save this so we can ask about accepted events later.


def sendDragEvent(self, ev, init=False, final=False):
## Send a MouseDragEvent to the current dragItem or to
Expand Down Expand Up @@ -323,7 +330,6 @@ def sendClickEvent(self, ev):
acceptedItem = self.lastHoverEvent.clickItems().get(ev.button(), None)
else:
acceptedItem = None

if acceptedItem is not None:
ev.currentItem = acceptedItem
try:
Expand All @@ -345,22 +351,9 @@ def sendClickEvent(self, ev):
if int(item.flags() & item.ItemIsFocusable) > 0:
item.setFocus(QtCore.Qt.MouseFocusReason)
break
#if not ev.isAccepted() and ev.button() is QtCore.Qt.RightButton:
#print "GraphicsScene emitting sigSceneContextMenu"
#self.sigMouseClicked.emit(ev)
#ev.accept()
self.sigMouseClicked.emit(ev)
return ev.isAccepted()

#def claimEvent(self, item, button, eventType):
#key = (button, eventType)
#if key in self.claimedEvents:
#return False
#self.claimedEvents[key] = item
#print "event", key, "claimed by", item
#return True


def items(self, *args):
#print 'args:', args
items = QtGui.QGraphicsScene.items(self, *args)
Expand Down
3 changes: 3 additions & 0 deletions GraphicsScene/mouseEvents.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,9 @@ def lastPos(self):
return Point(self.currentItem.mapFromScene(self._lastScenePos))

def __repr__(self):
if self.exit:
return "<HoverEvent exit=True>"

if self.currentItem is None:
lp = self._lastScenePos
p = self._scenePos
Expand Down
Loading

0 comments on commit 2e37d9b

Please sign in to comment.