Flowchart.py 2.34 KB
Newer Older
1
# -*- coding: utf-8 -*-
2
3
4
5
6
7
8
9
10
11
12
"""
This example demonstrates a very basic use of flowcharts: filter data,
displaying both the input and output of the filter. The behavior of
he filter can be reprogrammed by the user.

Basic steps are:
  - create a flowchart and two plots
  - input noisy data to the flowchart
  - flowchart connects data to the first plot, where it is displayed
  - add a gaussian filter to lowpass the data, then display it in the second plot.
"""
13
import initExample ## Add path to library (just for examples; you do not need this)
14
15
16


from pyqtgraph.flowchart import Flowchart
17
from pyqtgraph.Qt import QtGui, QtCore
18
19
import pyqtgraph as pg
import numpy as np
20
import pyqtgraph.metaarray as metaarray
21
22
23

app = QtGui.QApplication([])

24
## Create main window with grid layout
25
26
27
28
29
win = QtGui.QMainWindow()
cw = QtGui.QWidget()
win.setCentralWidget(cw)
layout = QtGui.QGridLayout()
cw.setLayout(layout)
30

31
## Create flowchart, define input/output terminals
32
33
34
35
36
37
fc = Flowchart(terminals={
    'dataIn': {'io': 'in'},
    'dataOut': {'io': 'out'}    
})
w = fc.widget()

38
## Add flowchart control panel to the main window
39
40
layout.addWidget(fc.widget(), 0, 0, 2, 1)

41
## Add two plot widgets
42
43
44
45
46
47
48
pw1 = pg.PlotWidget()
pw2 = pg.PlotWidget()
layout.addWidget(pw1, 0, 1)
layout.addWidget(pw2, 1, 1)

win.show()

49
## generate signal data to pass through the flowchart
50
51
52
data = np.random.normal(size=1000)
data[200:300] += 1
data += np.sin(np.linspace(0, 100, 1000))
53
data = metaarray.MetaArray(data, info=[{'name': 'Time', 'values': np.linspace(0, 1.0, len(data))}, {}])
54

55
## Feed data into the input terminal of the flowchart
56
fc.setInput(dataIn=data)
57

58
59
## populate the flowchart with a basic set of processing nodes. 
## (usually we let the user do this)
60
61
pw1Node = fc.createNode('PlotWidget', pos=(0, -150))
pw1Node.setPlot(pw1)
62

63
64
65
66
pw2Node = fc.createNode('PlotWidget', pos=(150, -150))
pw2Node.setPlot(pw2)

fNode = fc.createNode('GaussianFilter', pos=(0, 0))
67
fNode.ctrls['sigma'].setValue(5)
68
69
70
71
fc.connectTerminals(fc['dataIn'], fNode['In'])
fc.connectTerminals(fc['dataIn'], pw1Node['In'])
fc.connectTerminals(fNode['Out'], pw2Node['In'])
fc.connectTerminals(fNode['Out'], fc['dataOut'])
72
73
74



75
## Start Qt event loop unless running in interactive mode or using pyside.
76
77
78
79
if __name__ == '__main__':
    import sys
    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
        QtGui.QApplication.instance().exec_()