__main__.py 4.28 KB
Newer Older
1 2 3
import sys, os
## make sure this pyqtgraph is importable before any others
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
4
from pyqtgraph.Qt import QtCore, QtGui, USE_PYSIDE
5

6 7 8 9 10
if USE_PYSIDE:
    from exampleLoaderTemplate_pyside import Ui_Form
else:
    from exampleLoaderTemplate_pyqt import Ui_Form
    
11
import os, sys
12
from pyqtgraph.pgcollections import OrderedDict
13 14 15 16

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

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

def run():
    app = QtGui.QApplication([])
    loader = ExampleLoader()
    
Luke Campagnola's avatar
Luke Campagnola committed
129
    app.exec_()
130 131

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