2012-11-29 21:50:42 +00:00
|
|
|
import sys, os, subprocess, time
|
2012-12-26 22:51:52 +00:00
|
|
|
|
|
|
|
import initExample
|
2012-09-09 23:07:36 +00:00
|
|
|
from pyqtgraph.Qt import QtCore, QtGui, USE_PYSIDE
|
2012-03-02 03:53:52 +00:00
|
|
|
|
2012-09-09 23:07:36 +00:00
|
|
|
if USE_PYSIDE:
|
|
|
|
from exampleLoaderTemplate_pyside import Ui_Form
|
|
|
|
else:
|
|
|
|
from exampleLoaderTemplate_pyqt import Ui_Form
|
|
|
|
|
2012-03-02 02:55:32 +00:00
|
|
|
import os, sys
|
2012-09-13 14:12:59 +00:00
|
|
|
from pyqtgraph.pgcollections import OrderedDict
|
2012-03-02 02:55:32 +00:00
|
|
|
|
|
|
|
examples = OrderedDict([
|
|
|
|
('Command-line usage', 'CLIexample.py'),
|
|
|
|
('Basic Plotting', 'Plotting.py'),
|
2012-03-24 16:32:53 +00:00
|
|
|
('ImageView', 'ImageView.py'),
|
2012-07-09 21:14:41 +00:00
|
|
|
('ParameterTree', 'parametertree.py'),
|
2012-04-04 16:22:43 +00:00
|
|
|
('Crosshair / Mouse interaction', 'crosshair.py'),
|
2012-04-18 04:09:37 +00:00
|
|
|
('Data Slicing', 'DataSlicing.py'),
|
2012-07-09 12:38:30 +00:00
|
|
|
('Plot Customization', 'customPlot.py'),
|
2012-07-10 20:30:03 +00:00
|
|
|
('Dock widgets', 'dockarea.py'),
|
2012-08-03 04:08:05 +00:00
|
|
|
('Console', 'ConsoleWidget.py'),
|
2012-10-22 18:10:16 +00:00
|
|
|
('Histograms', 'histogram.py'),
|
2013-01-10 21:10:27 +00:00
|
|
|
('Remote Plotting', 'RemoteSpeedTest.py'),
|
2012-03-02 02:55:32 +00:00
|
|
|
('GraphicsItems', OrderedDict([
|
2012-03-24 16:32:53 +00:00
|
|
|
('Scatter Plot', 'ScatterPlot.py'),
|
2012-03-12 16:23:25 +00:00
|
|
|
#('PlotItem', 'PlotItem.py'),
|
2012-04-04 16:22:43 +00:00
|
|
|
('IsocurveItem', 'isocurve.py'),
|
2012-03-02 02:55:32 +00:00
|
|
|
('ImageItem - video', 'ImageItem.py'),
|
|
|
|
('ImageItem - draw', 'Draw.py'),
|
2012-05-31 20:05:19 +00:00
|
|
|
('Region-of-Interest', 'ROIExamples.py'),
|
2012-03-02 02:55:32 +00:00
|
|
|
('GraphicsLayout', 'GraphicsLayout.py'),
|
2012-10-19 03:18:20 +00:00
|
|
|
('LegendItem', 'Legend.py'),
|
2012-03-18 03:10:00 +00:00
|
|
|
('Text Item', 'text.py'),
|
2012-03-21 03:38:04 +00:00
|
|
|
('Linked Views', 'linkedViews.py'),
|
2012-03-02 02:55:32 +00:00
|
|
|
('Arrow', 'Arrow.py'),
|
2012-03-24 16:32:53 +00:00
|
|
|
('ViewBox', 'ViewBox.py'),
|
|
|
|
])),
|
2012-10-22 18:10:16 +00:00
|
|
|
('Benchmarks', OrderedDict([
|
|
|
|
('Video speed test', 'VideoSpeedTest.py'),
|
|
|
|
('Line Plot update', 'PlotSpeedTest.py'),
|
|
|
|
('Scatter Plot update', 'ScatterPlotSpeedTest.py'),
|
|
|
|
])),
|
2012-03-24 16:32:53 +00:00
|
|
|
('3D Graphics', OrderedDict([
|
|
|
|
('Volumetric', 'GLVolumeItem.py'),
|
2012-11-23 22:34:22 +00:00
|
|
|
('Isosurface', 'GLIsosurface.py'),
|
|
|
|
('Surface Plot', 'GLSurfacePlot.py'),
|
2012-10-19 03:18:20 +00:00
|
|
|
('Scatter Plot', 'GLScatterPlotItem.py'),
|
2012-11-23 22:34:22 +00:00
|
|
|
('Shaders', 'GLshaders.py'),
|
2012-12-26 20:26:04 +00:00
|
|
|
('Line Plot', 'GLLinePlotItem.py'),
|
2012-11-23 22:34:22 +00:00
|
|
|
('Mesh', 'GLMeshItem.py'),
|
|
|
|
('Image', 'GLImageItem.py'),
|
2012-03-02 02:55:32 +00:00
|
|
|
])),
|
|
|
|
('Widgets', OrderedDict([
|
|
|
|
('PlotWidget', 'PlotWidget.py'),
|
2012-05-31 20:05:19 +00:00
|
|
|
('SpinBox', 'SpinBox.py'),
|
2012-06-19 00:01:32 +00:00
|
|
|
('ConsoleWidget', 'ConsoleWidget.py'),
|
2012-05-31 20:05:19 +00:00
|
|
|
('TreeWidget', 'TreeWidget.py'),
|
|
|
|
('DataTreeWidget', 'DataTreeWidget.py'),
|
2012-05-11 22:05:41 +00:00
|
|
|
('GradientWidget', 'GradientWidget.py'),
|
2012-03-23 07:21:04 +00:00
|
|
|
#('TableWidget', '../widgets/TableWidget.py'),
|
2012-05-31 20:05:19 +00:00
|
|
|
('ColorButton', 'ColorButton.py'),
|
2012-03-23 07:21:04 +00:00
|
|
|
#('CheckTable', '../widgets/CheckTable.py'),
|
|
|
|
#('VerticalLabel', '../widgets/VerticalLabel.py'),
|
2012-04-06 03:04:26 +00:00
|
|
|
('JoystickButton', 'JoystickButton.py'),
|
2012-03-02 02:55:32 +00:00
|
|
|
])),
|
2012-07-09 12:38:30 +00:00
|
|
|
|
2012-03-02 02:55:32 +00:00
|
|
|
('GraphicsScene', 'GraphicsScene.py'),
|
|
|
|
('Flowcharts', 'Flowchart.py'),
|
2013-01-12 19:35:32 +00:00
|
|
|
('Custom Flowchart Nodes', 'FlowchartCustomNode.py'),
|
2012-03-23 07:21:04 +00:00
|
|
|
#('Canvas', '../canvas'),
|
|
|
|
#('MultiPlotWidget', 'MultiPlotWidget.py'),
|
2012-03-02 02:55:32 +00:00
|
|
|
])
|
|
|
|
|
|
|
|
path = os.path.abspath(os.path.dirname(__file__))
|
|
|
|
|
|
|
|
class ExampleLoader(QtGui.QMainWindow):
|
|
|
|
def __init__(self):
|
|
|
|
QtGui.QMainWindow.__init__(self)
|
|
|
|
self.ui = Ui_Form()
|
|
|
|
self.cw = QtGui.QWidget()
|
|
|
|
self.setCentralWidget(self.cw)
|
|
|
|
self.ui.setupUi(self.cw)
|
|
|
|
|
|
|
|
global examples
|
|
|
|
self.populateTree(self.ui.exampleTree.invisibleRootItem(), examples)
|
|
|
|
self.ui.exampleTree.expandAll()
|
|
|
|
|
2012-07-10 20:30:03 +00:00
|
|
|
self.resize(1000,500)
|
2012-03-02 02:55:32 +00:00
|
|
|
self.show()
|
2012-07-10 20:30:03 +00:00
|
|
|
self.ui.splitter.setSizes([250,750])
|
2012-03-02 02:55:32 +00:00
|
|
|
self.ui.loadBtn.clicked.connect(self.loadFile)
|
|
|
|
self.ui.exampleTree.currentItemChanged.connect(self.showFile)
|
|
|
|
self.ui.exampleTree.itemDoubleClicked.connect(self.loadFile)
|
2012-10-26 12:55:53 +00:00
|
|
|
self.ui.pyqtCheck.toggled.connect(self.pyqtToggled)
|
|
|
|
self.ui.pysideCheck.toggled.connect(self.pysideToggled)
|
2012-03-02 02:55:32 +00:00
|
|
|
|
2012-10-26 12:55:53 +00:00
|
|
|
def pyqtToggled(self, b):
|
|
|
|
if b:
|
|
|
|
self.ui.pysideCheck.setChecked(False)
|
|
|
|
|
|
|
|
def pysideToggled(self, b):
|
|
|
|
if b:
|
|
|
|
self.ui.pyqtCheck.setChecked(False)
|
|
|
|
|
2012-03-02 02:55:32 +00:00
|
|
|
|
|
|
|
def populateTree(self, root, examples):
|
2012-05-11 22:05:41 +00:00
|
|
|
for key, val in examples.items():
|
2012-03-02 02:55:32 +00:00
|
|
|
item = QtGui.QTreeWidgetItem([key])
|
|
|
|
if isinstance(val, basestring):
|
|
|
|
item.file = val
|
|
|
|
else:
|
|
|
|
self.populateTree(item, val)
|
|
|
|
root.addChild(item)
|
|
|
|
|
|
|
|
|
|
|
|
def currentFile(self):
|
|
|
|
item = self.ui.exampleTree.currentItem()
|
|
|
|
if hasattr(item, 'file'):
|
|
|
|
global path
|
|
|
|
return os.path.join(path, item.file)
|
|
|
|
return None
|
|
|
|
|
|
|
|
def loadFile(self):
|
|
|
|
fn = self.currentFile()
|
2012-10-26 12:55:53 +00:00
|
|
|
extra = []
|
|
|
|
if self.ui.pyqtCheck.isChecked():
|
|
|
|
extra.append('pyqt')
|
|
|
|
elif self.ui.pysideCheck.isChecked():
|
|
|
|
extra.append('pyside')
|
2012-12-25 05:43:31 +00:00
|
|
|
|
|
|
|
if self.ui.forceGraphicsCheck.isChecked():
|
|
|
|
extra.append(str(self.ui.forceGraphicsCombo.currentText()))
|
2012-10-26 12:55:53 +00:00
|
|
|
|
2012-03-02 02:55:32 +00:00
|
|
|
if fn is None:
|
|
|
|
return
|
2012-04-04 16:22:43 +00:00
|
|
|
if sys.platform.startswith('win'):
|
2012-11-23 22:34:22 +00:00
|
|
|
os.spawnl(os.P_NOWAIT, sys.executable, '"'+sys.executable+'"', '"' + fn + '"', *extra)
|
2012-04-04 16:22:43 +00:00
|
|
|
else:
|
2012-10-26 12:55:53 +00:00
|
|
|
os.spawnl(os.P_NOWAIT, sys.executable, sys.executable, fn, *extra)
|
2012-03-02 02:55:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
def showFile(self):
|
|
|
|
fn = self.currentFile()
|
|
|
|
if fn is None:
|
|
|
|
self.ui.codeView.clear()
|
|
|
|
return
|
2012-03-24 16:32:53 +00:00
|
|
|
if os.path.isdir(fn):
|
|
|
|
fn = os.path.join(fn, '__main__.py')
|
2012-03-02 02:55:32 +00:00
|
|
|
text = open(fn).read()
|
|
|
|
self.ui.codeView.setPlainText(text)
|
|
|
|
|
|
|
|
def run():
|
|
|
|
app = QtGui.QApplication([])
|
|
|
|
loader = ExampleLoader()
|
|
|
|
|
2012-03-23 08:04:04 +00:00
|
|
|
app.exec_()
|
2012-03-02 02:55:32 +00:00
|
|
|
|
2012-11-29 21:50:42 +00:00
|
|
|
def buildFileList(examples, files=None):
|
|
|
|
if files == None:
|
|
|
|
files = []
|
|
|
|
for key, val in examples.items():
|
|
|
|
#item = QtGui.QTreeWidgetItem([key])
|
|
|
|
if isinstance(val, basestring):
|
|
|
|
#item.file = val
|
|
|
|
files.append((key,val))
|
|
|
|
else:
|
|
|
|
buildFileList(val, files)
|
|
|
|
return files
|
|
|
|
|
2012-12-26 18:48:12 +00:00
|
|
|
def testFile(name, f, exe, lib, graphicsSystem=None):
|
2012-11-29 21:50:42 +00:00
|
|
|
global path
|
|
|
|
fn = os.path.join(path,f)
|
|
|
|
#print "starting process: ", fn
|
2012-12-25 05:43:31 +00:00
|
|
|
os.chdir(path)
|
2012-12-05 05:25:45 +00:00
|
|
|
sys.stdout.write(name)
|
|
|
|
sys.stdout.flush()
|
|
|
|
|
2012-12-25 05:43:31 +00:00
|
|
|
import1 = "import %s" % lib if lib != '' else ''
|
|
|
|
import2 = os.path.splitext(os.path.split(fn)[1])[0]
|
|
|
|
graphicsSystem = '' if graphicsSystem is None else "pg.QtGui.QApplication.setGraphicsSystem('%s')" % graphicsSystem
|
2012-12-05 05:25:45 +00:00
|
|
|
code = """
|
|
|
|
try:
|
2012-12-25 05:43:31 +00:00
|
|
|
%s
|
2013-01-12 01:21:11 +00:00
|
|
|
import initExample
|
2012-12-25 05:43:31 +00:00
|
|
|
import pyqtgraph as pg
|
2012-12-05 05:25:45 +00:00
|
|
|
%s
|
|
|
|
import %s
|
2012-12-22 21:51:25 +00:00
|
|
|
import sys
|
2012-12-05 05:25:45 +00:00
|
|
|
print("test complete")
|
2012-12-22 21:51:25 +00:00
|
|
|
sys.stdout.flush()
|
|
|
|
import time
|
2012-12-05 05:25:45 +00:00
|
|
|
while True: ## run a little event loop
|
|
|
|
pg.QtGui.QApplication.processEvents()
|
|
|
|
time.sleep(0.01)
|
|
|
|
except:
|
|
|
|
print("test failed")
|
|
|
|
raise
|
|
|
|
|
2012-12-26 18:48:12 +00:00
|
|
|
""" % (import1, graphicsSystem, import2)
|
|
|
|
|
2012-12-22 21:51:25 +00:00
|
|
|
process = subprocess.Popen(['exec %s -i' % (exe)], shell=True, stdin=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
|
2012-12-05 05:25:45 +00:00
|
|
|
process.stdin.write(code.encode('UTF-8'))
|
|
|
|
#process.stdin.close()
|
|
|
|
output = ''
|
|
|
|
fail = False
|
|
|
|
while True:
|
|
|
|
c = process.stdout.read(1).decode()
|
|
|
|
output += c
|
|
|
|
#sys.stdout.write(c)
|
|
|
|
#sys.stdout.flush()
|
|
|
|
if output.endswith('test complete'):
|
|
|
|
break
|
|
|
|
if output.endswith('test failed'):
|
|
|
|
fail = True
|
|
|
|
break
|
2012-11-29 21:50:42 +00:00
|
|
|
time.sleep(1)
|
2012-12-22 21:51:25 +00:00
|
|
|
process.kill()
|
|
|
|
#process.wait()
|
2012-11-29 21:50:42 +00:00
|
|
|
res = process.communicate()
|
2012-12-22 21:51:25 +00:00
|
|
|
|
|
|
|
if fail or 'exception' in res[1].decode().lower() or 'error' in res[1].decode().lower():
|
2012-12-05 05:25:45 +00:00
|
|
|
print('.' * (50-len(name)) + 'FAILED')
|
|
|
|
print(res[0].decode())
|
|
|
|
print(res[1].decode())
|
2012-11-29 21:50:42 +00:00
|
|
|
else:
|
2012-12-05 05:25:45 +00:00
|
|
|
print('.' * (50-len(name)) + 'passed')
|
2012-11-29 21:50:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2012-03-02 02:55:32 +00:00
|
|
|
if __name__ == '__main__':
|
2012-11-29 21:50:42 +00:00
|
|
|
if '--test' in sys.argv[1:]:
|
|
|
|
files = buildFileList(examples)
|
2012-12-05 05:25:45 +00:00
|
|
|
if '--pyside' in sys.argv[1:]:
|
|
|
|
lib = 'PySide'
|
|
|
|
elif '--pyqt' in sys.argv[1:]:
|
|
|
|
lib = 'PyQt4'
|
|
|
|
else:
|
|
|
|
lib = ''
|
|
|
|
|
|
|
|
exe = sys.executable
|
|
|
|
print("Running tests:", lib, sys.executable)
|
2012-11-29 21:50:42 +00:00
|
|
|
for f in files:
|
2012-12-05 05:25:45 +00:00
|
|
|
testFile(f[0], f[1], exe, lib)
|
2012-11-29 21:50:42 +00:00
|
|
|
else:
|
|
|
|
run()
|