2012-03-02 03:53:52 +00:00
|
|
|
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
|
|
|
|
|
2012-03-02 02:55:32 +00:00
|
|
|
from exampleLoaderTemplate import Ui_Form
|
|
|
|
import os, sys
|
|
|
|
from collections import OrderedDict
|
|
|
|
|
|
|
|
examples = OrderedDict([
|
|
|
|
('Command-line usage', 'CLIexample.py'),
|
|
|
|
('Basic Plotting', 'Plotting.py'),
|
2012-03-24 16:32:53 +00:00
|
|
|
('ImageView', 'ImageView.py'),
|
|
|
|
('ParameterTree', '../parametertree'),
|
2012-04-04 16:22:43 +00:00
|
|
|
('Crosshair / Mouse interaction', 'crosshair.py'),
|
|
|
|
('Video speed test', 'VideoSpeedTest.py'),
|
|
|
|
('Plot speed test', 'PlotSpeedTest.py'),
|
2012-04-18 04:09:37 +00:00
|
|
|
('Data Slicing', 'DataSlicing.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'),
|
|
|
|
('Region-of-Interest', 'ROItypes.py'),
|
|
|
|
('GraphicsLayout', 'GraphicsLayout.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'),
|
|
|
|
])),
|
|
|
|
('3D Graphics', OrderedDict([
|
|
|
|
('Volumetric', 'GLVolumeItem.py'),
|
|
|
|
('Isosurface', 'GLMeshItem.py'),
|
2012-03-02 02:55:32 +00:00
|
|
|
])),
|
|
|
|
('Widgets', OrderedDict([
|
|
|
|
('PlotWidget', 'PlotWidget.py'),
|
2012-03-23 07:21:04 +00:00
|
|
|
#('SpinBox', '../widgets/SpinBox.py'),
|
2012-03-02 02:55:32 +00:00
|
|
|
('TreeWidget', '../widgets/TreeWidget.py'),
|
|
|
|
('DataTreeWidget', '../widgets/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-03-02 02:55:32 +00:00
|
|
|
('ColorButton', '../widgets/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-03-24 16:32:53 +00:00
|
|
|
|
2012-03-02 02:55:32 +00:00
|
|
|
('GraphicsScene', 'GraphicsScene.py'),
|
|
|
|
('Flowcharts', 'Flowchart.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()
|
|
|
|
|
|
|
|
self.resize(900,500)
|
|
|
|
self.show()
|
|
|
|
self.ui.splitter.setSizes([150,750])
|
|
|
|
self.ui.loadBtn.clicked.connect(self.loadFile)
|
|
|
|
self.ui.exampleTree.currentItemChanged.connect(self.showFile)
|
|
|
|
self.ui.exampleTree.itemDoubleClicked.connect(self.loadFile)
|
|
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
if fn is None:
|
|
|
|
return
|
2012-04-04 16:22:43 +00:00
|
|
|
if sys.platform.startswith('win'):
|
|
|
|
os.spawnl(os.P_NOWAIT, sys.executable, sys.executable, '"' + fn + '"')
|
|
|
|
else:
|
|
|
|
os.spawnl(os.P_NOWAIT, sys.executable, sys.executable, fn)
|
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
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2012-03-02 03:53:52 +00:00
|
|
|
run()
|