diff --git a/GraphicsScene/GraphicsScene.py b/GraphicsScene/GraphicsScene.py index c80e97e5..73867059 100644 --- a/GraphicsScene/GraphicsScene.py +++ b/GraphicsScene/GraphicsScene.py @@ -13,10 +13,13 @@ from .mouseEvents import * import pyqtgraph.debug as debug from . import exportDialog -try: - import sip - HAVE_SIP = True -except: +if hasattr(QtCore, 'PYQT_VERSION'): + try: + import sip + HAVE_SIP = True + except ImportError: + HAVE_SIP = False +else: HAVE_SIP = False diff --git a/__init__.py b/__init__.py index 4c768a54..51a0fe5c 100644 --- a/__init__.py +++ b/__init__.py @@ -193,7 +193,10 @@ show = image ## for backward compatibility def mkQApp(): global QAPP - if QtGui.QApplication.instance() is None: + inst = QtGui.QApplication.instance() + if inst is None: QAPP = QtGui.QApplication([]) + else: + QAPP = inst return QAPP diff --git a/graphicsItems/GraphicsItem.py b/graphicsItems/GraphicsItem.py index 0d0491f1..ba4858cf 100644 --- a/graphicsItems/GraphicsItem.py +++ b/graphicsItems/GraphicsItem.py @@ -76,7 +76,7 @@ class GraphicsItem(object): if view is None: return None viewportTransform = view.viewportTransform() - dt = QtGui.QGraphicsObject.deviceTransform(self, viewportTransform) + dt = self._qtBaseClass.deviceTransform(self, viewportTransform) #xmag = abs(dt.m11())+abs(dt.m12()) #ymag = abs(dt.m21())+abs(dt.m22()) @@ -274,19 +274,26 @@ class GraphicsItem(object): return vt.mapRect(obj) def pos(self): - return Point(QtGui.QGraphicsObject.pos(self)) + return Point(self._qtBaseClass.pos(self)) def viewPos(self): return self.mapToView(self.mapFromParent(self.pos())) def parentItem(self): ## PyQt bug -- some items are returned incorrectly. - return GraphicsScene.translateGraphicsItem(QtGui.QGraphicsObject.parentItem(self)) + return GraphicsScene.translateGraphicsItem(self._qtBaseClass.parentItem(self)) + def setParentItem(self, parent): + ## Workaround for Qt bug: https://bugreports.qt-project.org/browse/QTBUG-18616 + if parent is not None: + pscene = parent.scene() + if pscene is not None and self.scene() is not pscene: + pscene.addItem(self) + return self._qtBaseClass.setParentItem(self, parent) def childItems(self): ## PyQt bug -- some child items are returned incorrectly. - return list(map(GraphicsScene.translateGraphicsItem, QtGui.QGraphicsObject.childItems(self))) + return list(map(GraphicsScene.translateGraphicsItem, self._qtBaseClass.childItems(self))) def sceneTransform(self): @@ -296,7 +303,7 @@ class GraphicsItem(object): if self.scene() is None: return self.transform() else: - return QtGui.QGraphicsObject.sceneTransform(self) + return self._qtBaseClass.sceneTransform(self) def transformAngle(self, relativeItem=None): @@ -315,7 +322,7 @@ class GraphicsItem(object): #def itemChange(self, change, value): - #ret = QtGui.QGraphicsObject.itemChange(self, change, value) + #ret = self._qtBaseClass.itemChange(self, change, value) #if change == self.ItemParentHasChanged or change == self.ItemSceneHasChanged: #print "Item scene changed:", self #self.setChildScene(self) ## This is bizarre. diff --git a/graphicsItems/GraphicsObject.py b/graphicsItems/GraphicsObject.py index 91354cfb..f893d8dc 100644 --- a/graphicsItems/GraphicsObject.py +++ b/graphicsItems/GraphicsObject.py @@ -8,6 +8,7 @@ class GraphicsObject(GraphicsItem, QtGui.QGraphicsObject): Extension of QGraphicsObject with some useful methods (provided by :class:`GraphicsItem `) """ + _qtBaseClass = QtGui.QGraphicsObject def __init__(self, *args): QtGui.QGraphicsObject.__init__(self, *args) GraphicsItem.__init__(self) @@ -17,13 +18,3 @@ class GraphicsObject(GraphicsItem, QtGui.QGraphicsObject): if change in [self.ItemParentHasChanged, self.ItemSceneHasChanged]: self._updateView() return ret - - - - def setParentItem(self, parent): - ## Workaround for Qt bug: https://bugreports.qt-project.org/browse/QTBUG-18616 - if parent is not None: - pscene = parent.scene() - if pscene is not None and self.scene() is not pscene: - pscene.addItem(self) - return QtGui.QGraphicsObject.setParentItem(self, parent) diff --git a/graphicsItems/GraphicsWidget.py b/graphicsItems/GraphicsWidget.py index c131a54a..8f28d208 100644 --- a/graphicsItems/GraphicsWidget.py +++ b/graphicsItems/GraphicsWidget.py @@ -5,6 +5,8 @@ from .GraphicsItem import GraphicsItem __all__ = ['GraphicsWidget'] class GraphicsWidget(GraphicsItem, QtGui.QGraphicsWidget): + + _qtBaseClass = QtGui.QGraphicsWidget def __init__(self, *args, **kargs): """ **Bases:** :class:`GraphicsItem `, :class:`QtGui.QGraphicsWidget` @@ -14,7 +16,9 @@ class GraphicsWidget(GraphicsItem, QtGui.QGraphicsWidget): """ QtGui.QGraphicsWidget.__init__(self, *args, **kargs) GraphicsItem.__init__(self) - GraphicsScene.registerObject(self) ## workaround for pyqt bug in graphicsscene.items() + + ## done by GraphicsItem init + #GraphicsScene.registerObject(self) ## workaround for pyqt bug in graphicsscene.items() ## Removed because this causes segmentation faults. Don't know why. # def itemChange(self, change, value): @@ -52,11 +56,3 @@ class GraphicsWidget(GraphicsItem, QtGui.QGraphicsWidget): return p - - def setParentItem(self, parent): - ## Workaround for Qt bug: https://bugreports.qt-project.org/browse/QTBUG-18616 - if parent is not None: - pscene = parent.scene() - if pscene is not None and self.scene() is not pscene: - pscene.addItem(self) - return QtGui.QGraphicsObject.setParentItem(self, parent)