2012-03-02 02:55:32 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2012-04-05 02:20:21 +00:00
|
|
|
"""
|
|
|
|
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.
|
|
|
|
"""
|
2012-04-05 01:03:31 +00:00
|
|
|
import initExample ## Add path to library (just for examples; you do not need this)
|
2012-03-02 02:55:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
from pyqtgraph.flowchart import Flowchart
|
2012-04-05 01:59:37 +00:00
|
|
|
from pyqtgraph.Qt import QtGui, QtCore
|
2012-04-05 01:03:31 +00:00
|
|
|
import pyqtgraph as pg
|
|
|
|
import numpy as np
|
2012-06-18 17:45:47 +00:00
|
|
|
import pyqtgraph.metaarray as metaarray
|
2012-03-02 02:55:32 +00:00
|
|
|
|
|
|
|
app = QtGui.QApplication([])
|
|
|
|
|
2013-01-04 17:05:36 +00:00
|
|
|
## Create main window with grid layout
|
2012-04-05 01:03:31 +00:00
|
|
|
win = QtGui.QMainWindow()
|
2013-02-25 04:09:03 +00:00
|
|
|
win.setWindowTitle('pyqtgraph example: Flowchart')
|
2012-04-05 01:03:31 +00:00
|
|
|
cw = QtGui.QWidget()
|
|
|
|
win.setCentralWidget(cw)
|
|
|
|
layout = QtGui.QGridLayout()
|
|
|
|
cw.setLayout(layout)
|
2012-03-02 02:55:32 +00:00
|
|
|
|
2013-01-04 17:05:36 +00:00
|
|
|
## Create flowchart, define input/output terminals
|
2012-03-02 02:55:32 +00:00
|
|
|
fc = Flowchart(terminals={
|
|
|
|
'dataIn': {'io': 'in'},
|
|
|
|
'dataOut': {'io': 'out'}
|
|
|
|
})
|
|
|
|
w = fc.widget()
|
|
|
|
|
2013-01-04 17:05:36 +00:00
|
|
|
## Add flowchart control panel to the main window
|
2012-04-05 01:03:31 +00:00
|
|
|
layout.addWidget(fc.widget(), 0, 0, 2, 1)
|
|
|
|
|
2013-01-04 17:05:36 +00:00
|
|
|
## Add two plot widgets
|
2012-04-05 01:03:31 +00:00
|
|
|
pw1 = pg.PlotWidget()
|
|
|
|
pw2 = pg.PlotWidget()
|
|
|
|
layout.addWidget(pw1, 0, 1)
|
|
|
|
layout.addWidget(pw2, 1, 1)
|
|
|
|
|
|
|
|
win.show()
|
|
|
|
|
2013-01-04 17:05:36 +00:00
|
|
|
## generate signal data to pass through the flowchart
|
2012-04-05 01:03:31 +00:00
|
|
|
data = np.random.normal(size=1000)
|
|
|
|
data[200:300] += 1
|
|
|
|
data += np.sin(np.linspace(0, 100, 1000))
|
2012-06-18 17:45:47 +00:00
|
|
|
data = metaarray.MetaArray(data, info=[{'name': 'Time', 'values': np.linspace(0, 1.0, len(data))}, {}])
|
2012-03-02 02:55:32 +00:00
|
|
|
|
2013-01-04 17:05:36 +00:00
|
|
|
## Feed data into the input terminal of the flowchart
|
2012-04-05 01:03:31 +00:00
|
|
|
fc.setInput(dataIn=data)
|
2012-03-02 02:55:32 +00:00
|
|
|
|
2013-01-04 17:05:36 +00:00
|
|
|
## populate the flowchart with a basic set of processing nodes.
|
|
|
|
## (usually we let the user do this)
|
2013-12-28 02:07:03 +00:00
|
|
|
plotList = {'Top Plot': pw1, 'Bottom Plot': pw2}
|
|
|
|
|
2012-04-05 01:03:31 +00:00
|
|
|
pw1Node = fc.createNode('PlotWidget', pos=(0, -150))
|
2013-12-28 02:07:03 +00:00
|
|
|
pw1Node.setPlotList(plotList)
|
2012-04-05 01:03:31 +00:00
|
|
|
pw1Node.setPlot(pw1)
|
2012-03-02 02:55:32 +00:00
|
|
|
|
2012-04-05 01:03:31 +00:00
|
|
|
pw2Node = fc.createNode('PlotWidget', pos=(150, -150))
|
|
|
|
pw2Node.setPlot(pw2)
|
2013-12-28 02:07:03 +00:00
|
|
|
pw2Node.setPlotList(plotList)
|
2012-04-05 01:03:31 +00:00
|
|
|
|
|
|
|
fNode = fc.createNode('GaussianFilter', pos=(0, 0))
|
2012-04-05 02:20:21 +00:00
|
|
|
fNode.ctrls['sigma'].setValue(5)
|
2013-01-04 17:05:36 +00:00
|
|
|
fc.connectTerminals(fc['dataIn'], fNode['In'])
|
|
|
|
fc.connectTerminals(fc['dataIn'], pw1Node['In'])
|
|
|
|
fc.connectTerminals(fNode['Out'], pw2Node['In'])
|
|
|
|
fc.connectTerminals(fNode['Out'], fc['dataOut'])
|
2012-03-02 02:55:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2012-04-05 01:03:31 +00:00
|
|
|
## Start Qt event loop unless running in interactive mode or using pyside.
|
2012-12-05 05:25:45 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys
|
|
|
|
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
|
|
|
|
QtGui.QApplication.instance().exec_()
|