From 7e40b329e95a49f3700fd4c019a9c7afee15937c Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Sat, 28 Feb 2015 11:05:57 -0500 Subject: [PATCH] more examples working under pyqt5 --- examples/ScatterPlotSpeedTest.py | 4 +++- examples/VideoSpeedTest.py | 4 +++- examples/__main__.py | 12 ++++++++---- examples/parametertree.py | 2 +- pyqtgraph/Qt.py | 12 ++++++------ pyqtgraph/WidgetGroup.py | 28 +++++++--------------------- 6 files changed, 28 insertions(+), 34 deletions(-) diff --git a/examples/ScatterPlotSpeedTest.py b/examples/ScatterPlotSpeedTest.py index 4dbe57db..9cbf0c63 100644 --- a/examples/ScatterPlotSpeedTest.py +++ b/examples/ScatterPlotSpeedTest.py @@ -12,7 +12,7 @@ For testing rapid updates of ScatterPlotItem under various conditions. import initExample -from pyqtgraph.Qt import QtGui, QtCore, USE_PYSIDE +from pyqtgraph.Qt import QtGui, QtCore, USE_PYSIDE, USE_PYQT5 import numpy as np import pyqtgraph as pg from pyqtgraph.ptime import time @@ -22,6 +22,8 @@ app = QtGui.QApplication([]) #mw.resize(800,800) if USE_PYSIDE: from ScatterPlotSpeedTestTemplate_pyside import Ui_Form +elif USE_PYQT5: + from ScatterPlotSpeedTestTemplate_pyqt5 import Ui_Form else: from ScatterPlotSpeedTestTemplate_pyqt import Ui_Form diff --git a/examples/VideoSpeedTest.py b/examples/VideoSpeedTest.py index 6fce8a86..d26f507e 100644 --- a/examples/VideoSpeedTest.py +++ b/examples/VideoSpeedTest.py @@ -10,13 +10,15 @@ is used by the view widget import initExample ## Add path to library (just for examples; you do not need this) -from pyqtgraph.Qt import QtGui, QtCore, USE_PYSIDE +from pyqtgraph.Qt import QtGui, QtCore, USE_PYSIDE, USE_PYQT5 import numpy as np import pyqtgraph as pg import pyqtgraph.ptime as ptime if USE_PYSIDE: import VideoTemplate_pyside as VideoTemplate +elif USE_PYQT5: + import VideoTemplate_pyqt5 as VideoTemplate else: import VideoTemplate_pyqt as VideoTemplate diff --git a/examples/__main__.py b/examples/__main__.py index 52048593..a1ebb40a 100644 --- a/examples/__main__.py +++ b/examples/__main__.py @@ -268,15 +268,19 @@ except: if __name__ == '__main__': - if '--test' in sys.argv[1:]: + args = sys.argv[1:] + + if '--test' in args: # get rid of orphaned cache files first pg.renamePyc(path) - + files = buildFileList(examples) - if '--pyside' in sys.argv[1:]: + if '--pyside' in args: lib = 'PySide' - elif '--pyqt' in sys.argv[1:]: + elif '--pyqt' in args or '--pyqt4' in args: lib = 'PyQt4' + elif '--pyqt5' in args: + lib = 'PyQt5' else: lib = '' diff --git a/examples/parametertree.py b/examples/parametertree.py index b8638e02..8d8a7352 100644 --- a/examples/parametertree.py +++ b/examples/parametertree.py @@ -124,7 +124,7 @@ p.sigTreeStateChanged.connect(change) def valueChanging(param, value): - print "Value changing (not finalized):", param, value + print("Value changing (not finalized): %s %s" % (param, value)) # Too lazy for recursion: for child in p.children(): diff --git a/pyqtgraph/Qt.py b/pyqtgraph/Qt.py index 5fdce579..a25edead 100644 --- a/pyqtgraph/Qt.py +++ b/pyqtgraph/Qt.py @@ -139,13 +139,13 @@ elif QT_LIB == PYQT5: self.setTransform(tr) QtWidgets.QGraphicsItem.translate = translate - #def setMargin(self, i): - #self.setContentsMargins(i, i, i, i) - #QtWidgets.QGridLayout.setMargin = setMargin + def setMargin(self, i): + self.setContentsMargins(i, i, i, i) + QtWidgets.QGridLayout.setMargin = setMargin - #def setResizeMode(self, mode): - #self.setSectionResizeMode(mode) - #QtWidgets.QHeaderView.setResizeMode = setResizeMode + def setResizeMode(self, mode): + self.setSectionResizeMode(mode) + QtWidgets.QHeaderView.setResizeMode = setResizeMode QtGui.QApplication = QtWidgets.QApplication diff --git a/pyqtgraph/WidgetGroup.py b/pyqtgraph/WidgetGroup.py index 17e2b2bd..d7e265c5 100644 --- a/pyqtgraph/WidgetGroup.py +++ b/pyqtgraph/WidgetGroup.py @@ -60,9 +60,13 @@ def setComboState(w, v): class WidgetGroup(QtCore.QObject): - """This class takes a list of widgets and keeps an internal record of their state which is always up to date. Allows reading and writing from groups of widgets simultaneously.""" + """This class takes a list of widgets and keeps an internal record of their + state that is always up to date. - ## List of widget types which can be handled by WidgetGroup. + Allows reading and writing from groups of widgets simultaneously. + """ + + ## List of widget types that can be handled by WidgetGroup. ## The value for each type is a tuple (change signal function, get function, set function, [auto-add children]) ## The change signal function that takes an object and returns a signal that is emitted any time the state of the widget changes, not just ## when it is changed by user interaction. (for example, 'clicked' is not a valid signal here) @@ -200,53 +204,35 @@ class WidgetGroup(QtCore.QObject): if hasattr(obj, 'widgetGroupInterface'): return True return False - #return (type(obj) in WidgetGroup.classes) def setScale(self, widget, scale): val = self.readWidget(widget) self.scales[widget] = scale self.setWidget(widget, val) - #print "scaling %f to %f" % (val, self.readWidget(widget)) - def mkChangeCallback(self, w): return lambda *args: self.widgetChanged(w, *args) def widgetChanged(self, w, *args): - #print "widget changed" n = self.widgetList[w] v1 = self.cache[n] v2 = self.readWidget(w) if v1 != v2: - #print "widget", n, " = ", v2 if not USE_PYQT5: - #I don't think this line have any different from the next line + # Old signal kept for backward compatibility. self.emit(QtCore.SIGNAL('changed'), self.widgetList[w], v2) self.sigChanged.emit(self.widgetList[w], v2) def state(self): for w in self.uncachedWidgets: self.readWidget(w) - - #cc = self.cache.copy() - #if 'averageGroup' in cc: - #val = cc['averageGroup'] - #w = self.findWidget('averageGroup') - #self.readWidget(w) - #if val != self.cache['averageGroup']: - #print " AverageGroup did not match cached value!" - #else: - #print " AverageGroup OK" return self.cache.copy() def setState(self, s): - #print "SET STATE", self, s for w in self.widgetList: n = self.widgetList[w] - #print " restore %s?" % n if n not in s: continue - #print " restore state", w, n, s[n] self.setWidget(w, s[n]) def readWidget(self, w):