Flowchart.py 1.94 KB
Newer Older
1
# -*- coding: utf-8 -*-
2
import initExample ## Add path to library (just for examples; you do not need this)
3
4
5


from pyqtgraph.flowchart import Flowchart
6
from pyqtgraph.Qt import QtGui, QtCore
7
8
import pyqtgraph as pg
import numpy as np
9
10
11

app = QtGui.QApplication([])

12
13
14
15
16
17

win = QtGui.QMainWindow()
cw = QtGui.QWidget()
win.setCentralWidget(cw)
layout = QtGui.QGridLayout()
cw.setLayout(layout)
18
19
20
21
22
23
24

fc = Flowchart(terminals={
    'dataIn': {'io': 'in'},
    'dataOut': {'io': 'out'}    
})
w = fc.widget()

25
26
27
28
29
30
31
32
33
34
35
36
37
layout.addWidget(fc.widget(), 0, 0, 2, 1)

pw1 = pg.PlotWidget()
pw2 = pg.PlotWidget()
layout.addWidget(pw1, 0, 1)
layout.addWidget(pw2, 1, 1)

win.show()


data = np.random.normal(size=1000)
data[200:300] += 1
data += np.sin(np.linspace(0, 100, 1000))
38

39
fc.setInput(dataIn=data)
40

41
42
pw1Node = fc.createNode('PlotWidget', pos=(0, -150))
pw1Node.setPlot(pw1)
43

44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
pw2Node = fc.createNode('PlotWidget', pos=(150, -150))
pw2Node.setPlot(pw2)

fNode = fc.createNode('GaussianFilter', pos=(0, 0))
fc.connectTerminals(fc.dataIn, fNode.In)
fc.connectTerminals(fc.dataIn, pw1Node.In)
fc.connectTerminals(fNode.Out, pw2Node.In)
fc.connectTerminals(fNode.Out, fc.dataOut)


#n1 = fc.createNode('Add', pos=(0,-80))
#n2 = fc.createNode('Subtract', pos=(140,-10))
#n3 = fc.createNode('Abs', pos=(0, 80))
#n4 = fc.createNode('Add', pos=(140,100))

#fc.connectTerminals(fc.dataIn, n1.A)
#fc.connectTerminals(fc.dataIn, n1.B)
#fc.connectTerminals(fc.dataIn, n2.A)
#fc.connectTerminals(n1.Out, n4.A)
#fc.connectTerminals(n1.Out, n2.B)
#fc.connectTerminals(n2.Out, n3.In)
#fc.connectTerminals(n3.Out, n4.B)
#fc.connectTerminals(n4.Out, fc.dataOut)


#def process(**kargs):
    #return fc.process(**kargs)
71
72

    
73
#print process(dataIn=7)
74

75
#fc.setInput(dataIn=3)
76

77
78
#s = fc.saveState()
#fc.clear()
79

80
#fc.restoreState(s)
81

82
#fc.setInput(dataIn=3)
83
84


85
86
87
## Start Qt event loop unless running in interactive mode or using pyside.
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
88
    app.exec_()