__main__.py 3.93 KB
Newer Older
1 2 3 4 5
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

6 7 8 9 10 11 12
from exampleLoaderTemplate import Ui_Form
import os, sys
from collections import OrderedDict

examples = OrderedDict([
    ('Command-line usage', 'CLIexample.py'),
    ('Basic Plotting', 'Plotting.py'),
Luke Campagnola's avatar
Luke Campagnola committed
13 14
    ('ImageView', 'ImageView.py'),
    ('ParameterTree', '../parametertree'),
15 16 17
    ('Crosshair / Mouse interaction', 'crosshair.py'),
    ('Video speed test', 'VideoSpeedTest.py'),
    ('Plot speed test', 'PlotSpeedTest.py'),
Luke Campagnola's avatar
Luke Campagnola committed
18
    ('Data Slicing', 'DataSlicing.py'),
19
    ('Plot Customization', 'customPlot.py'),
20
    ('GraphicsItems', OrderedDict([
Luke Campagnola's avatar
Luke Campagnola committed
21
        ('Scatter Plot', 'ScatterPlot.py'),
Luke Campagnola's avatar
Luke Campagnola committed
22
        #('PlotItem', 'PlotItem.py'),
23
        ('IsocurveItem', 'isocurve.py'),
24 25
        ('ImageItem - video', 'ImageItem.py'),
        ('ImageItem - draw', 'Draw.py'),
Luke Campagnola's avatar
Luke Campagnola committed
26
        ('Region-of-Interest', 'ROIExamples.py'),
27
        ('GraphicsLayout', 'GraphicsLayout.py'),
Luke Campagnola's avatar
Luke Campagnola committed
28
        ('Text Item', 'text.py'),
29
        ('Linked Views', 'linkedViews.py'),
30
        ('Arrow', 'Arrow.py'),
Luke Campagnola's avatar
Luke Campagnola committed
31 32 33 34 35
        ('ViewBox', 'ViewBox.py'),
    ])),
    ('3D Graphics', OrderedDict([
        ('Volumetric', 'GLVolumeItem.py'),
        ('Isosurface', 'GLMeshItem.py'),
36 37 38
    ])),
    ('Widgets', OrderedDict([
        ('PlotWidget', 'PlotWidget.py'),
Luke Campagnola's avatar
Luke Campagnola committed
39 40 41
        ('SpinBox', 'SpinBox.py'),
        ('TreeWidget', 'TreeWidget.py'),
        ('DataTreeWidget', 'DataTreeWidget.py'),
42
        ('GradientWidget', 'GradientWidget.py'),
Luke Campagnola's avatar
Luke Campagnola committed
43
        #('TableWidget', '../widgets/TableWidget.py'),
Luke Campagnola's avatar
Luke Campagnola committed
44
        ('ColorButton', 'ColorButton.py'),
Luke Campagnola's avatar
Luke Campagnola committed
45 46
        #('CheckTable', '../widgets/CheckTable.py'),
        #('VerticalLabel', '../widgets/VerticalLabel.py'),
47
        ('JoystickButton', 'JoystickButton.py'),
48
    ])),
49
    
50 51
    ('GraphicsScene', 'GraphicsScene.py'),
    ('Flowcharts', 'Flowchart.py'),
Luke Campagnola's avatar
Luke Campagnola committed
52 53
    #('Canvas', '../canvas'),
    #('MultiPlotWidget', 'MultiPlotWidget.py'),
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
])

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):
79
        for key, val in examples.items():
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
            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
99 100 101 102
        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)
103 104 105 106 107 108 109
        
            
    def showFile(self):
        fn = self.currentFile()
        if fn is None:
            self.ui.codeView.clear()
            return
Luke Campagnola's avatar
Luke Campagnola committed
110 111
        if os.path.isdir(fn):
            fn = os.path.join(fn, '__main__.py')
112 113 114 115 116 117 118
        text = open(fn).read()
        self.ui.codeView.setPlainText(text)

def run():
    app = QtGui.QApplication([])
    loader = ExampleLoader()
    
Luke Campagnola's avatar
Luke Campagnola committed
119
    app.exec_()
120 121

if __name__ == '__main__':
122
    run()