minor code cleanup

bugfixes for pyside-specific issues
This commit is contained in:
Luke Campagnola 2012-06-18 19:40:15 -04:00
parent a90d00a536
commit 3f486d9a65
5 changed files with 30 additions and 30 deletions

View File

@ -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

View File

@ -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

View File

@ -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.

View File

@ -8,6 +8,7 @@ class GraphicsObject(GraphicsItem, QtGui.QGraphicsObject):
Extension of QGraphicsObject with some useful methods (provided by :class:`GraphicsItem <pyqtgraph.graphicsItems.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)

View File

@ -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 <pyqtgraph.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)