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
|
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 numpy as np
|
||||||
import pyqtgraph as pg
|
import pyqtgraph as pg
|
||||||
from pyqtgraph.ptime import time
|
from pyqtgraph.ptime import time
|
||||||
@ -22,6 +22,8 @@ app = QtGui.QApplication([])
|
|||||||
#mw.resize(800,800)
|
#mw.resize(800,800)
|
||||||
if USE_PYSIDE:
|
if USE_PYSIDE:
|
||||||
from ScatterPlotSpeedTestTemplate_pyside import Ui_Form
|
from ScatterPlotSpeedTestTemplate_pyside import Ui_Form
|
||||||
|
elif USE_PYQT5:
|
||||||
|
from ScatterPlotSpeedTestTemplate_pyqt5 import Ui_Form
|
||||||
else:
|
else:
|
||||||
from ScatterPlotSpeedTestTemplate_pyqt import Ui_Form
|
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)
|
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 numpy as np
|
||||||
import pyqtgraph as pg
|
import pyqtgraph as pg
|
||||||
import pyqtgraph.ptime as ptime
|
import pyqtgraph.ptime as ptime
|
||||||
|
|
||||||
if USE_PYSIDE:
|
if USE_PYSIDE:
|
||||||
import VideoTemplate_pyside as VideoTemplate
|
import VideoTemplate_pyside as VideoTemplate
|
||||||
|
elif USE_PYQT5:
|
||||||
|
import VideoTemplate_pyqt5 as VideoTemplate
|
||||||
else:
|
else:
|
||||||
import VideoTemplate_pyqt as VideoTemplate
|
import VideoTemplate_pyqt as VideoTemplate
|
||||||
|
|
||||||
|
@ -268,15 +268,19 @@ except:
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
if '--test' in sys.argv[1:]:
|
args = sys.argv[1:]
|
||||||
|
|
||||||
|
if '--test' in args:
|
||||||
# get rid of orphaned cache files first
|
# get rid of orphaned cache files first
|
||||||
pg.renamePyc(path)
|
pg.renamePyc(path)
|
||||||
|
|
||||||
files = buildFileList(examples)
|
files = buildFileList(examples)
|
||||||
if '--pyside' in sys.argv[1:]:
|
if '--pyside' in args:
|
||||||
lib = 'PySide'
|
lib = 'PySide'
|
||||||
elif '--pyqt' in sys.argv[1:]:
|
elif '--pyqt' in args or '--pyqt4' in args:
|
||||||
lib = 'PyQt4'
|
lib = 'PyQt4'
|
||||||
|
elif '--pyqt5' in args:
|
||||||
|
lib = 'PyQt5'
|
||||||
else:
|
else:
|
||||||
lib = ''
|
lib = ''
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ p.sigTreeStateChanged.connect(change)
|
|||||||
|
|
||||||
|
|
||||||
def valueChanging(param, value):
|
def valueChanging(param, value):
|
||||||
print "Value changing (not finalized):", param, value
|
print("Value changing (not finalized): %s %s" % (param, value))
|
||||||
|
|
||||||
# Too lazy for recursion:
|
# Too lazy for recursion:
|
||||||
for child in p.children():
|
for child in p.children():
|
||||||
|
@ -139,13 +139,13 @@ elif QT_LIB == PYQT5:
|
|||||||
self.setTransform(tr)
|
self.setTransform(tr)
|
||||||
QtWidgets.QGraphicsItem.translate = translate
|
QtWidgets.QGraphicsItem.translate = translate
|
||||||
|
|
||||||
#def setMargin(self, i):
|
def setMargin(self, i):
|
||||||
#self.setContentsMargins(i, i, i, i)
|
self.setContentsMargins(i, i, i, i)
|
||||||
#QtWidgets.QGridLayout.setMargin = setMargin
|
QtWidgets.QGridLayout.setMargin = setMargin
|
||||||
|
|
||||||
#def setResizeMode(self, mode):
|
def setResizeMode(self, mode):
|
||||||
#self.setSectionResizeMode(mode)
|
self.setSectionResizeMode(mode)
|
||||||
#QtWidgets.QHeaderView.setResizeMode = setResizeMode
|
QtWidgets.QHeaderView.setResizeMode = setResizeMode
|
||||||
|
|
||||||
|
|
||||||
QtGui.QApplication = QtWidgets.QApplication
|
QtGui.QApplication = QtWidgets.QApplication
|
||||||
|
@ -60,9 +60,13 @@ def setComboState(w, v):
|
|||||||
|
|
||||||
|
|
||||||
class WidgetGroup(QtCore.QObject):
|
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 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
|
## 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)
|
## 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'):
|
if hasattr(obj, 'widgetGroupInterface'):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
#return (type(obj) in WidgetGroup.classes)
|
|
||||||
|
|
||||||
def setScale(self, widget, scale):
|
def setScale(self, widget, scale):
|
||||||
val = self.readWidget(widget)
|
val = self.readWidget(widget)
|
||||||
self.scales[widget] = scale
|
self.scales[widget] = scale
|
||||||
self.setWidget(widget, val)
|
self.setWidget(widget, val)
|
||||||
#print "scaling %f to %f" % (val, self.readWidget(widget))
|
|
||||||
|
|
||||||
|
|
||||||
def mkChangeCallback(self, w):
|
def mkChangeCallback(self, w):
|
||||||
return lambda *args: self.widgetChanged(w, *args)
|
return lambda *args: self.widgetChanged(w, *args)
|
||||||
|
|
||||||
def widgetChanged(self, w, *args):
|
def widgetChanged(self, w, *args):
|
||||||
#print "widget changed"
|
|
||||||
n = self.widgetList[w]
|
n = self.widgetList[w]
|
||||||
v1 = self.cache[n]
|
v1 = self.cache[n]
|
||||||
v2 = self.readWidget(w)
|
v2 = self.readWidget(w)
|
||||||
if v1 != v2:
|
if v1 != v2:
|
||||||
#print "widget", n, " = ", v2
|
|
||||||
if not USE_PYQT5:
|
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.emit(QtCore.SIGNAL('changed'), self.widgetList[w], v2)
|
||||||
self.sigChanged.emit(self.widgetList[w], v2)
|
self.sigChanged.emit(self.widgetList[w], v2)
|
||||||
|
|
||||||
def state(self):
|
def state(self):
|
||||||
for w in self.uncachedWidgets:
|
for w in self.uncachedWidgets:
|
||||||
self.readWidget(w)
|
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()
|
return self.cache.copy()
|
||||||
|
|
||||||
def setState(self, s):
|
def setState(self, s):
|
||||||
#print "SET STATE", self, s
|
|
||||||
for w in self.widgetList:
|
for w in self.widgetList:
|
||||||
n = self.widgetList[w]
|
n = self.widgetList[w]
|
||||||
#print " restore %s?" % n
|
|
||||||
if n not in s:
|
if n not in s:
|
||||||
continue
|
continue
|
||||||
#print " restore state", w, n, s[n]
|
|
||||||
self.setWidget(w, s[n])
|
self.setWidget(w, s[n])
|
||||||
|
|
||||||
def readWidget(self, w):
|
def readWidget(self, w):
|
||||||
|
Loading…
Reference in New Issue
Block a user