fixes for pyside compatibility

This commit is contained in:
Luke Campagnola 2012-03-01 22:53:52 -05:00
parent 9baa011638
commit dc597ac584
15 changed files with 35 additions and 22 deletions

8
Qt.py
View File

@ -1,6 +1,6 @@
## Do all Qt imports from here to allow easier PyQt / PySide compatibility ## Do all Qt imports from here to allow easier PyQt / PySide compatibility
#from PySide import QtGui, QtCore, QtOpenGL, QtSvg from PySide import QtGui, QtCore, QtOpenGL, QtSvg
from PyQt4 import QtGui, QtCore, QtOpenGL, QtSvg #from PyQt4 import QtGui, QtCore, QtOpenGL, QtSvg
if not hasattr(QtCore, 'Signal'): #if not hasattr(QtCore, 'Signal'):
QtCore.Signal = QtCore.pyqtSignal # QtCore.Signal = QtCore.pyqtSignal

View File

@ -4,7 +4,7 @@ import sys, os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..')) sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
import numpy as np import numpy as np
from PyQt4 import QtGui, QtCore from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg import pyqtgraph as pg

View File

@ -3,7 +3,7 @@ import sys, os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..')) 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 numpy as np
import pyqtgraph as pg import pyqtgraph as pg

View File

@ -4,7 +4,7 @@ import sys, os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..')) sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
import numpy as np import numpy as np
from PyQt4 import QtGui, QtCore from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg import pyqtgraph as pg

View File

@ -2,7 +2,7 @@
import sys, os import sys, os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..')) 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 pyqtgraph as pg
import user import user

View File

@ -5,7 +5,7 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
import numpy as np import numpy as np
import scipy.ndimage as ndi import scipy.ndimage as ndi
from PyQt4 import QtGui, QtCore from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg import pyqtgraph as pg

View File

@ -7,7 +7,7 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
from scipy import random from scipy import random
from numpy import linspace from numpy import linspace
from PyQt4 import QtGui, QtCore from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg import pyqtgraph as pg
from pyqtgraph import MultiPlotWidget from pyqtgraph import MultiPlotWidget
try: try:

View File

@ -5,7 +5,7 @@ import sys, os, time
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..')) 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 numpy as np
import pyqtgraph as pg import pyqtgraph as pg

View File

@ -5,7 +5,7 @@ import sys, os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..')) 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 numpy as np
import pyqtgraph as pg import pyqtgraph as pg

View File

@ -5,7 +5,7 @@ import sys, os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..')) 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 numpy as np
import pyqtgraph as pg import pyqtgraph as pg

View File

@ -3,7 +3,7 @@ import sys, os
## Add path to library (just for examples; you do not need this) ## Add path to library (just for examples; you do not need this)
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..')) 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 pyqtgraph as pg
import numpy as np import numpy as np

View File

@ -5,7 +5,7 @@ import sys, os, time
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..')) 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 numpy as np
import pyqtgraph as pg import pyqtgraph as pg
from pyqtgraph import RawImageWidget from pyqtgraph import RawImageWidget

View File

@ -8,7 +8,7 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
#from scipy import random #from scipy import random
import numpy as np import numpy as np
from PyQt4 import QtGui, QtCore from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg import pyqtgraph as pg
app = QtGui.QApplication([]) app = QtGui.QApplication([])

View File

@ -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 from exampleLoaderTemplate import Ui_Form
import os, sys import os, sys
from collections import OrderedDict from collections import OrderedDict
@ -98,4 +102,4 @@ def run():
app.exec_() app.exec_()
if __name__ == '__main__': if __name__ == '__main__':
run() run()

View File

@ -51,7 +51,6 @@ class GraphicsItemMethods(object):
if hasattr(p, 'implements') and p.implements('ViewBox'): if hasattr(p, 'implements') and p.implements('ViewBox'):
self._viewBox = weakref.ref(p) self._viewBox = weakref.ref(p)
break break
return self._viewBox() ## If we made it this far, _viewBox is definitely not None return self._viewBox() ## If we made it this far, _viewBox is definitely not None
def forgetViewBox(self): def forgetViewBox(self):
@ -78,7 +77,10 @@ class GraphicsItemMethods(object):
if view is None: if view is None:
return None return None
if hasattr(view, 'implements') and view.implements('ViewBox'): 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: else:
return self.sceneTransform() return self.sceneTransform()
#return self.deviceTransform(view.viewportTransform()) #return self.deviceTransform(view.viewportTransform())
@ -102,7 +104,11 @@ class GraphicsItemMethods(object):
view = self.getViewBox() view = self.getViewBox()
if view is None: if view is None:
return None return None
bounds = self.mapRectFromView(view.viewRect()).normalized() bounds = self.mapRectFromView(view.viewRect())
if bounds is None:
return None
bounds = bounds.normalized()
## nah. ## nah.
#for p in self.getBoundingParents(): #for p in self.getBoundingParents():
@ -246,7 +252,10 @@ class GraphicsItemMethods(object):
if relativeItem is None: if relativeItem is None:
relativeItem = self.parentItem() 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)) vec = tr.map(Point(1,0)) - tr.map(Point(0,0))
return Point(vec).angle(Point(1,0)) return Point(vec).angle(Point(1,0))