From dc597ac58406ed3a377a46ed76dada077bfe4a53 Mon Sep 17 00:00:00 2001 From: Luke Campagnola <> Date: Thu, 1 Mar 2012 22:53:52 -0500 Subject: [PATCH] fixes for pyside compatibility --- Qt.py | 8 ++++---- examples/Arrow.py | 2 +- examples/CLIexample.py | 2 +- examples/GradientEditor.py | 2 +- examples/GraphicsLayout.py | 2 +- examples/HistogramLUT.py | 2 +- examples/MultiPlotWidget.py | 2 +- examples/PlotSpeedTest.py | 2 +- examples/PlotWidget.py | 2 +- examples/Plotting.py | 2 +- examples/ScatterPlot.py | 2 +- examples/VideoSpeedTest.py | 2 +- examples/ViewBox.py | 2 +- examples/__main__.py | 8 ++++++-- graphicsItems/GraphicsItemMethods.py | 17 +++++++++++++---- 15 files changed, 35 insertions(+), 22 deletions(-) diff --git a/Qt.py b/Qt.py index eb63b7c1..068662b2 100644 --- a/Qt.py +++ b/Qt.py @@ -1,6 +1,6 @@ ## Do all Qt imports from here to allow easier PyQt / PySide compatibility -#from PySide import QtGui, QtCore, QtOpenGL, QtSvg -from PyQt4 import QtGui, QtCore, QtOpenGL, QtSvg -if not hasattr(QtCore, 'Signal'): - QtCore.Signal = QtCore.pyqtSignal +from PySide import QtGui, QtCore, QtOpenGL, QtSvg +#from PyQt4 import QtGui, QtCore, QtOpenGL, QtSvg +#if not hasattr(QtCore, 'Signal'): +# QtCore.Signal = QtCore.pyqtSignal diff --git a/examples/Arrow.py b/examples/Arrow.py index f9384008..4f7b970a 100755 --- a/examples/Arrow.py +++ b/examples/Arrow.py @@ -4,7 +4,7 @@ import sys, os sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..')) import numpy as np -from PyQt4 import QtGui, QtCore +from pyqtgraph.Qt import QtGui, QtCore import pyqtgraph as pg diff --git a/examples/CLIexample.py b/examples/CLIexample.py index f2def91a..1957328d 100644 --- a/examples/CLIexample.py +++ b/examples/CLIexample.py @@ -3,7 +3,7 @@ import sys, os sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..')) -from PyQt4 import QtGui, QtCore +from pyqtgraph.Qt import QtGui, QtCore import numpy as np import pyqtgraph as pg diff --git a/examples/GradientEditor.py b/examples/GradientEditor.py index f22479db..935d5611 100644 --- a/examples/GradientEditor.py +++ b/examples/GradientEditor.py @@ -4,7 +4,7 @@ import sys, os sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..')) import numpy as np -from PyQt4 import QtGui, QtCore +from pyqtgraph.Qt import QtGui, QtCore import pyqtgraph as pg diff --git a/examples/GraphicsLayout.py b/examples/GraphicsLayout.py index 940d450f..0602dd87 100755 --- a/examples/GraphicsLayout.py +++ b/examples/GraphicsLayout.py @@ -2,7 +2,7 @@ import sys, os sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..')) -from PyQt4 import QtGui, QtCore +from pyqtgraph.Qt import QtGui, QtCore import pyqtgraph as pg import user diff --git a/examples/HistogramLUT.py b/examples/HistogramLUT.py index 114da050..c83b3133 100644 --- a/examples/HistogramLUT.py +++ b/examples/HistogramLUT.py @@ -5,7 +5,7 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..')) import numpy as np import scipy.ndimage as ndi -from PyQt4 import QtGui, QtCore +from pyqtgraph.Qt import QtGui, QtCore import pyqtgraph as pg diff --git a/examples/MultiPlotWidget.py b/examples/MultiPlotWidget.py index 9e5878a2..2175241d 100644 --- a/examples/MultiPlotWidget.py +++ b/examples/MultiPlotWidget.py @@ -7,7 +7,7 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..')) from scipy import random from numpy import linspace -from PyQt4 import QtGui, QtCore +from pyqtgraph.Qt import QtGui, QtCore import pyqtgraph as pg from pyqtgraph import MultiPlotWidget try: diff --git a/examples/PlotSpeedTest.py b/examples/PlotSpeedTest.py index 3010270b..866f30d2 100644 --- a/examples/PlotSpeedTest.py +++ b/examples/PlotSpeedTest.py @@ -5,7 +5,7 @@ import sys, os, time sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..')) -from PyQt4 import QtGui, QtCore +from pyqtgraph.Qt import QtGui, QtCore import numpy as np import pyqtgraph as pg diff --git a/examples/PlotWidget.py b/examples/PlotWidget.py index cecbb58e..15d0a036 100644 --- a/examples/PlotWidget.py +++ b/examples/PlotWidget.py @@ -5,7 +5,7 @@ import sys, os sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..')) -from PyQt4 import QtGui, QtCore +from pyqtgraph.Qt import QtGui, QtCore import numpy as np import pyqtgraph as pg diff --git a/examples/Plotting.py b/examples/Plotting.py index cfeb4786..b4018b7d 100644 --- a/examples/Plotting.py +++ b/examples/Plotting.py @@ -5,7 +5,7 @@ import sys, os sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..')) -from PyQt4 import QtGui, QtCore +from pyqtgraph.Qt import QtGui, QtCore import numpy as np import pyqtgraph as pg diff --git a/examples/ScatterPlot.py b/examples/ScatterPlot.py index da9d4750..365b7ed6 100755 --- a/examples/ScatterPlot.py +++ b/examples/ScatterPlot.py @@ -3,7 +3,7 @@ import sys, os ## Add path to library (just for examples; you do not need this) sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..')) -from PyQt4 import QtGui, QtCore +from pyqtgraph.Qt import QtGui, QtCore import pyqtgraph as pg import numpy as np diff --git a/examples/VideoSpeedTest.py b/examples/VideoSpeedTest.py index 4a1d5fb4..49d4c715 100644 --- a/examples/VideoSpeedTest.py +++ b/examples/VideoSpeedTest.py @@ -5,7 +5,7 @@ import sys, os, time sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..')) -from PyQt4 import QtGui, QtCore +from pyqtgraph.Qt import QtGui, QtCore import numpy as np import pyqtgraph as pg from pyqtgraph import RawImageWidget diff --git a/examples/ViewBox.py b/examples/ViewBox.py index 6e30a7e6..13c8ce1c 100755 --- a/examples/ViewBox.py +++ b/examples/ViewBox.py @@ -8,7 +8,7 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..')) #from scipy import random import numpy as np -from PyQt4 import QtGui, QtCore +from pyqtgraph.Qt import QtGui, QtCore import pyqtgraph as pg app = QtGui.QApplication([]) diff --git a/examples/__main__.py b/examples/__main__.py index f8fe4c76..b245beae 100644 --- a/examples/__main__.py +++ b/examples/__main__.py @@ -1,4 +1,8 @@ -from PyQt4 import QtCore, QtGui +import sys, os +## make sure this pyqtgraph is importable before any others +sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..')) +from pyqtgraph.Qt import QtCore, QtGui + from exampleLoaderTemplate import Ui_Form import os, sys from collections import OrderedDict @@ -98,4 +102,4 @@ def run(): app.exec_() if __name__ == '__main__': - run() \ No newline at end of file + run() diff --git a/graphicsItems/GraphicsItemMethods.py b/graphicsItems/GraphicsItemMethods.py index 49da713b..76a54ccf 100644 --- a/graphicsItems/GraphicsItemMethods.py +++ b/graphicsItems/GraphicsItemMethods.py @@ -51,7 +51,6 @@ class GraphicsItemMethods(object): if hasattr(p, 'implements') and p.implements('ViewBox'): self._viewBox = weakref.ref(p) break - return self._viewBox() ## If we made it this far, _viewBox is definitely not None def forgetViewBox(self): @@ -78,7 +77,10 @@ class GraphicsItemMethods(object): if view is None: return None if hasattr(view, 'implements') and view.implements('ViewBox'): - return self.itemTransform(view.innerSceneItem())[0] + tr = self.itemTransform(view.innerSceneItem()) + if isinstance(tr, tuple): + tr = tr[0] ## difference between pyside and pyqt + return tr else: return self.sceneTransform() #return self.deviceTransform(view.viewportTransform()) @@ -102,7 +104,11 @@ class GraphicsItemMethods(object): view = self.getViewBox() if view is None: return None - bounds = self.mapRectFromView(view.viewRect()).normalized() + bounds = self.mapRectFromView(view.viewRect()) + if bounds is None: + return None + + bounds = bounds.normalized() ## nah. #for p in self.getBoundingParents(): @@ -246,7 +252,10 @@ class GraphicsItemMethods(object): if relativeItem is None: relativeItem = self.parentItem() - tr = self.itemTransform(relativeItem)[0] + + tr = self.itemTransform(relativeItem) + if isinstance(tr, tuple): ## difference between pyside and pyqt + tr = tr[0] vec = tr.map(Point(1,0)) - tr.map(Point(0,0)) return Point(vec).angle(Point(1,0))