don't cast buttons, enums and flags to int
This commit is contained in:
parent
3ce7f58384
commit
0fa4557ad6
@ -165,7 +165,7 @@ class GraphicsScene(QtGui.QGraphicsScene):
|
||||
## set focus on the topmost focusable item under this click
|
||||
items = self.items(ev.scenePos())
|
||||
for i in items:
|
||||
if i.isEnabled() and i.isVisible() and int(i.flags() & i.ItemIsFocusable) > 0:
|
||||
if i.isEnabled() and i.isVisible() and (i.flags() & i.ItemIsFocusable):
|
||||
i.setFocus(QtCore.Qt.MouseFocusReason)
|
||||
break
|
||||
|
||||
@ -194,7 +194,7 @@ class GraphicsScene(QtGui.QGraphicsScene):
|
||||
QtGui.QGraphicsScene.mouseMoveEvent(self, ev)
|
||||
# Next Deliver our own Hover Events
|
||||
self.sendHoverEvents(ev)
|
||||
if int(ev.buttons()) != 0:
|
||||
if ev.buttons():
|
||||
# button is pressed' send mouseMoveEvents and mouseDragEvents
|
||||
QtGui.QGraphicsScene.mouseMoveEvent(self, ev)
|
||||
if self.mouseGrabberItem() is None:
|
||||
@ -202,17 +202,17 @@ class GraphicsScene(QtGui.QGraphicsScene):
|
||||
init = False
|
||||
## keep track of which buttons are involved in dragging
|
||||
for btn in [QtCore.Qt.LeftButton, QtCore.Qt.MiddleButton, QtCore.Qt.RightButton]:
|
||||
if int(ev.buttons() & btn) == 0:
|
||||
if not (ev.buttons() & btn):
|
||||
continue
|
||||
if int(btn) not in self.dragButtons: ## see if we've dragged far enough yet
|
||||
cev = [e for e in self.clickEvents if int(e.button()) == int(btn)]
|
||||
if btn not in self.dragButtons: ## see if we've dragged far enough yet
|
||||
cev = [e for e in self.clickEvents if e.button() == btn]
|
||||
if cev:
|
||||
cev = cev[0]
|
||||
dist = Point(ev.scenePos() - cev.scenePos()).length()
|
||||
if dist == 0 or (dist < self._moveDistance and now - cev.time() < self.minDragTime):
|
||||
continue
|
||||
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(btn)
|
||||
## if we have dragged buttons, deliver a drag event
|
||||
if len(self.dragButtons) > 0:
|
||||
if self.sendDragEvent(ev, init=init):
|
||||
@ -235,14 +235,14 @@ class GraphicsScene(QtGui.QGraphicsScene):
|
||||
ev.accept()
|
||||
self.dragButtons.remove(ev.button())
|
||||
else:
|
||||
cev = [e for e in self.clickEvents if int(e.button()) == int(ev.button())]
|
||||
cev = [e for e in self.clickEvents if e.button() == ev.button()]
|
||||
if cev:
|
||||
if self.sendClickEvent(cev[0]):
|
||||
#print "sent click event"
|
||||
ev.accept()
|
||||
self.clickEvents.remove(cev[0])
|
||||
|
||||
if int(ev.buttons()) == 0:
|
||||
if not ev.buttons():
|
||||
self.dragItem = None
|
||||
self.dragButtons = []
|
||||
self.clickEvents = []
|
||||
@ -264,7 +264,7 @@ class GraphicsScene(QtGui.QGraphicsScene):
|
||||
items = []
|
||||
event = HoverEvent(None, acceptable)
|
||||
else:
|
||||
acceptable = int(ev.buttons()) == 0 ## if we are in mid-drag, do not allow items to accept the hover event.
|
||||
acceptable = not ev.buttons() ## if we are in mid-drag, do not allow items to accept the hover event.
|
||||
event = HoverEvent(ev, acceptable)
|
||||
items = self.itemsNearEvent(event, hoverable=True)
|
||||
self.sigMouseHover.emit(items)
|
||||
@ -306,7 +306,7 @@ class GraphicsScene(QtGui.QGraphicsScene):
|
||||
# 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)):
|
||||
(ev.type() == ev.GraphicsSceneMouseMove and not ev.buttons())):
|
||||
self.lastHoverEvent = event ## save this so we can ask about accepted events later.
|
||||
|
||||
def sendDragEvent(self, ev, init=False, final=False):
|
||||
@ -344,7 +344,7 @@ class GraphicsScene(QtGui.QGraphicsScene):
|
||||
if event.isAccepted():
|
||||
#print " --> accepted"
|
||||
self.dragItem = item
|
||||
if int(item.flags() & item.ItemIsFocusable) > 0:
|
||||
if item.flags() & item.ItemIsFocusable:
|
||||
item.setFocus(QtCore.Qt.MouseFocusReason)
|
||||
break
|
||||
elif self.dragItem is not None:
|
||||
@ -389,7 +389,7 @@ class GraphicsScene(QtGui.QGraphicsScene):
|
||||
debug.printExc("Error sending click event:")
|
||||
|
||||
if ev.isAccepted():
|
||||
if int(item.flags() & item.ItemIsFocusable) > 0:
|
||||
if item.flags() & item.ItemIsFocusable:
|
||||
item.setFocus(QtCore.Qt.MouseFocusReason)
|
||||
break
|
||||
self.sigMouseClicked.emit(ev)
|
||||
|
@ -19,8 +19,8 @@ class MouseDragEvent(object):
|
||||
self._buttonDownScenePos = {}
|
||||
self._buttonDownScreenPos = {}
|
||||
for btn in [QtCore.Qt.LeftButton, QtCore.Qt.MiddleButton, QtCore.Qt.RightButton]:
|
||||
self._buttonDownScenePos[int(btn)] = moveEvent.buttonDownScenePos(btn)
|
||||
self._buttonDownScreenPos[int(btn)] = moveEvent.buttonDownScreenPos(btn)
|
||||
self._buttonDownScenePos[btn] = moveEvent.buttonDownScenePos(btn)
|
||||
self._buttonDownScreenPos[btn] = moveEvent.buttonDownScreenPos(btn)
|
||||
self._scenePos = moveEvent.scenePos()
|
||||
self._screenPos = moveEvent.screenPos()
|
||||
if lastEvent is None:
|
||||
@ -61,7 +61,7 @@ class MouseDragEvent(object):
|
||||
"""
|
||||
if btn is None:
|
||||
btn = self.button()
|
||||
return Point(self._buttonDownScenePos[int(btn)])
|
||||
return Point(self._buttonDownScenePos[btn])
|
||||
|
||||
def buttonDownScreenPos(self, btn=None):
|
||||
"""
|
||||
@ -70,7 +70,7 @@ class MouseDragEvent(object):
|
||||
"""
|
||||
if btn is None:
|
||||
btn = self.button()
|
||||
return Point(self._buttonDownScreenPos[int(btn)])
|
||||
return Point(self._buttonDownScreenPos[btn])
|
||||
|
||||
def lastScenePos(self):
|
||||
"""
|
||||
@ -119,7 +119,7 @@ class MouseDragEvent(object):
|
||||
"""
|
||||
if btn is None:
|
||||
btn = self.button()
|
||||
return Point(self.currentItem.mapFromScene(self._buttonDownScenePos[int(btn)]))
|
||||
return Point(self.currentItem.mapFromScene(self._buttonDownScenePos[btn]))
|
||||
|
||||
def isStart(self):
|
||||
"""Returns True if this event is the first since a drag was initiated."""
|
||||
@ -137,7 +137,7 @@ class MouseDragEvent(object):
|
||||
else:
|
||||
lp = self.lastPos()
|
||||
p = self.pos()
|
||||
return "<MouseDragEvent (%g,%g)->(%g,%g) buttons=%d start=%s finish=%s>" % (lp.x(), lp.y(), p.x(), p.y(), int(self.buttons()), str(self.isStart()), str(self.isFinish()))
|
||||
return "<MouseDragEvent (%g,%g)->(%g,%g) buttons=%s start=%s finish=%s>" % (lp.x(), lp.y(), p.x(), p.y(), str(self.buttons()), str(self.isStart()), str(self.isFinish()))
|
||||
|
||||
def modifiers(self):
|
||||
"""Return any keyboard modifiers currently pressed.
|
||||
@ -230,9 +230,9 @@ class MouseClickEvent(object):
|
||||
p = self._scenePos
|
||||
else:
|
||||
p = self.pos()
|
||||
return "<MouseClickEvent (%g,%g) button=%d>" % (p.x(), p.y(), int(self.button()))
|
||||
return "<MouseClickEvent (%g,%g) button=%s>" % (p.x(), p.y(), str(self.button()))
|
||||
except:
|
||||
return "<MouseClickEvent button=%d>" % (int(self.button()))
|
||||
return "<MouseClickEvent button=%s>" % (str(self.button()))
|
||||
|
||||
def time(self):
|
||||
return self._time
|
||||
@ -362,7 +362,7 @@ class HoverEvent(object):
|
||||
else:
|
||||
lp = self.lastPos()
|
||||
p = self.pos()
|
||||
return "<HoverEvent (%g,%g)->(%g,%g) buttons=%d enter=%s exit=%s>" % (lp.x(), lp.y(), p.x(), p.y(), int(self.buttons()), str(self.isEnter()), str(self.isExit()))
|
||||
return "<HoverEvent (%g,%g)->(%g,%g) buttons=%s enter=%s exit=%s>" % (lp.x(), lp.y(), p.x(), p.y(), str(self.buttons()), str(self.isEnter()), str(self.isExit()))
|
||||
|
||||
def modifiers(self):
|
||||
"""Return any keyboard modifiers currently pressed.
|
||||
|
@ -128,7 +128,8 @@ class Exporter(object):
|
||||
while len(childs) > 0:
|
||||
ch = childs.pop(0)
|
||||
tree = self.getPaintItems(ch)
|
||||
if int(ch.flags() & ch.ItemStacksBehindParent) > 0 or (ch.zValue() < 0 and int(ch.flags() & ch.ItemNegativeZStacksBehindParent) > 0):
|
||||
if (ch.flags() & ch.ItemStacksBehindParent) or \
|
||||
(ch.zValue() < 0 and (ch.flags() & ch.ItemNegativeZStacksBehindParent)):
|
||||
preItems.extend(tree)
|
||||
else:
|
||||
postItems.extend(tree)
|
||||
|
@ -251,7 +251,7 @@ def _generateItemSvg(item, nodes=None, root=None, options={}):
|
||||
childGroup = g1 ## add children directly to this node unless we are clipping
|
||||
if not isinstance(item, QtGui.QGraphicsScene):
|
||||
## See if this item clips its children
|
||||
if int(item.flags() & item.ItemClipsChildrenToShape) > 0:
|
||||
if item.flags() & item.ItemClipsChildrenToShape:
|
||||
## Generate svg for just the path
|
||||
path = QtGui.QGraphicsPathItem(item.mapToScene(item.shape()))
|
||||
item.scene().addItem(path)
|
||||
@ -414,7 +414,7 @@ def itemTransform(item, root):
|
||||
return tr
|
||||
|
||||
|
||||
if int(item.flags() & item.ItemIgnoresTransformations) > 0:
|
||||
if item.flags() & item.ItemIgnoresTransformations:
|
||||
pos = item.pos()
|
||||
parent = item.parentItem()
|
||||
if parent is not None:
|
||||
@ -431,7 +431,7 @@ def itemTransform(item, root):
|
||||
if nextRoot is None:
|
||||
nextRoot = root
|
||||
break
|
||||
if nextRoot is root or int(nextRoot.flags() & nextRoot.ItemIgnoresTransformations) > 0:
|
||||
if nextRoot is root or (nextRoot.flags() & nextRoot.ItemIgnoresTransformations):
|
||||
break
|
||||
|
||||
if isinstance(nextRoot, QtGui.QGraphicsScene):
|
||||
|
@ -245,7 +245,7 @@ class LinearRegionItem(GraphicsObject):
|
||||
self.sigRegionChangeFinished.emit(self)
|
||||
|
||||
def mouseDragEvent(self, ev):
|
||||
if not self.movable or int(ev.button() & QtCore.Qt.LeftButton) == 0:
|
||||
if not self.movable or ev.button() != QtCore.Qt.LeftButton:
|
||||
return
|
||||
ev.accept()
|
||||
|
||||
|
@ -722,7 +722,7 @@ class ROI(GraphicsObject):
|
||||
hover=True
|
||||
|
||||
for btn in [QtCore.Qt.LeftButton, QtCore.Qt.RightButton, QtCore.Qt.MiddleButton]:
|
||||
if int(self.acceptedMouseButtons() & btn) > 0 and ev.acceptClicks(btn):
|
||||
if (self.acceptedMouseButtons() & btn) and ev.acceptClicks(btn):
|
||||
hover=True
|
||||
if self.contextMenuEnabled():
|
||||
ev.acceptClicks(QtCore.Qt.RightButton)
|
||||
@ -794,7 +794,7 @@ class ROI(GraphicsObject):
|
||||
if ev.button() == QtCore.Qt.RightButton and self.contextMenuEnabled():
|
||||
self.raiseContextMenu(ev)
|
||||
ev.accept()
|
||||
elif int(ev.button() & self.acceptedMouseButtons()) > 0:
|
||||
elif ev.button() & self.acceptedMouseButtons():
|
||||
ev.accept()
|
||||
self.sigClicked.emit(self, ev)
|
||||
else:
|
||||
@ -1343,7 +1343,7 @@ class Handle(UIGraphicsItem):
|
||||
if ev.acceptDrags(QtCore.Qt.LeftButton):
|
||||
hover=True
|
||||
for btn in [QtCore.Qt.LeftButton, QtCore.Qt.RightButton, QtCore.Qt.MiddleButton]:
|
||||
if int(self.acceptedMouseButtons() & btn) > 0 and ev.acceptClicks(btn):
|
||||
if (self.acceptedMouseButtons() & btn) and ev.acceptClicks(btn):
|
||||
hover=True
|
||||
|
||||
if hover:
|
||||
@ -1358,7 +1358,7 @@ class Handle(UIGraphicsItem):
|
||||
self.isMoving = False ## prevents any further motion
|
||||
self.movePoint(self.startPos, finish=True)
|
||||
ev.accept()
|
||||
elif int(ev.button() & self.acceptedMouseButtons()) > 0:
|
||||
elif ev.button() & self.acceptedMouseButtons():
|
||||
ev.accept()
|
||||
if ev.button() == QtCore.Qt.RightButton and self.deletable:
|
||||
self.raiseContextMenu(ev)
|
||||
|
@ -1397,7 +1397,7 @@ class ViewBox(GraphicsWidget):
|
||||
|
||||
itemBounds.append((bounds, useX, useY, pxPad))
|
||||
else:
|
||||
if int(item.flags() & item.ItemHasNoContents) > 0:
|
||||
if item.flags() & item.ItemHasNoContents:
|
||||
continue
|
||||
bounds = self.mapFromItemToView(item, item.boundingRect()).boundingRect()
|
||||
itemBounds.append((bounds, True, True, 0))
|
||||
|
Loading…
Reference in New Issue
Block a user