more examples working under pyqt5
This commit is contained in:
parent
058dd183d3
commit
7e40b329e9
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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 = ''
|
||||
|
||||
|
@ -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():
|
||||
|
@ -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
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user