tau tau

Table Of Contents

Previous topic

Tau color guide

Next topic

The tau API

This Page

Examples

Here you will find a host of example figures with the code that generated them.

In order for the examples to work on your computer, you need to have a Tango device server running. The following section explains how to do this.

Setup

The device server used for the examples can be obtained here.

In order for the examples to work as they are provided a TauTest device must be created and running with the following configuration:

Server (ServerName/Instance):
TauTest/tautest
Class:
TauTest
Devices:
sys/tautest/1

You can easily configure it from Jive by going to Edit->Create server and type the above parameters in the dialog that pops up.

Common

For the sake of simplicity the code presented below (except for the first example) does not include the following header and footer code lines:

header:

import sys
from PyQt4 import Qt
import tau.widget

app = Qt.QApplication(sys.argv)

footer:

panel.setVisible(True)
sys.exit(app.exec_())

You must prepend and postpend the above code in order for the examples to work properly.

Display attribute value

Displaying a tango attribute value in a GUI is easy with tau and TauValueLabel

../_images/label01.png

code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
import sys
from PyQt4 import Qt
import tau.widget

app = Qt.QApplication(sys.argv)

w = tau.widget.TauValueLabel()
w.setModel('sys/tautest/1/position')

w.setVisible(True)
sys.exit(app.exec_())

not much code to write, but... boring!

Display attribute value with label

Let’s spice it up a bit: add the tango label for the position attribute so it looks something like this:

../_images/label02.png

code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
panel = Qt.QWidget()
layout = Qt.QHBoxLayout()
panel.setLayout(layout)

w1 = tau.widget.TauConfigLabel()
w2 = tau.widget.TauValueLabel()
w1.setModel('sys/tautest/1/position?configuration=label')
w2.setModel('sys/tautest/1/position')
layout.addWidget(w1)
layout.addWidget(w2)

Much better indeed!

Display attribute value with label and units

And little bit more... add the units. Lets also put a container and see how simple setting the model becomes.

../_images/label03.png

code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
panel = tau.widget.TauWidget()
layout = Qt.QHBoxLayout()
panel.setLayout(layout)

w1 = tau.widget.TauConfigLabel()
w2 = tau.widget.TauValueLabel()
w3 = tau.widget.TauConfigLabel()
layout.addWidget(w1)
layout.addWidget(w2)
layout.addWidget(w3)
w1.setUseParentModel(True)
w2.setUseParentModel(True)
w3.setUseParentModel(True)
panel.setModel('sys/tautest/1')
w1.setModel('/position?configuration=label')
w2.setModel('/position')
w3.setModel('/position?configuration=unit')

Noticed that we only had to write the device name once? Nice isn’t it?

Interactively display attribute

Humm... Now supose the user wants to change this value. TauValueLineEdit does this job well (and so does TauValueSpinBox and TauWheelEdit :-)

../_images/edit01.png

With TauValueLineEdit

../_images/edit02.png

With TauValueSpinBox

../_images/edit03.png

With TauWheelEdit

code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
panel = tau.widget.TauWidget()
layout = Qt.QHBoxLayout()
panel.setLayout(layout)

w1 = tau.widget.TauConfigLabel()
w2 = tau.widget.TauValueLabel()
w3 = tau.widget.TauValueLineEdit() # or TauValueSpinBox or TauWheelEdit
w4 = tau.widget.TauConfigLabel()
layout.addWidget(w1)
layout.addWidget(w2)
layout.addWidget(w3)
layout.addWidget(w4)
w1.setUseParentModel(True)
w2.setUseParentModel(True)
w3.setUseParentModel(True)
w4.setUseParentModel(True)
panel.setModel('sys/tautest/1')
w1.setModel('/position?configuration=label')
w2.setModel('/position')
w3.setModel('/position')
w4.setModel('/position?configuration=unit')

Now it seems a little bit more useful, doesn’t it?

The standard attribute display widget

Getting tired of writing all that code just to represent one attribute? Tau provides a better option: The TauValue.

../_images/tauvalue01.png

code:

1
2
3
4
5
6
7
panel = tau.widget.TauWidget()
layout = Qt.QGridLayout()
panel.setLayout(layout)

w1 = tau.widget.TauValue(panel)
layout.addWidget(w1)
w1.setModel('sys/tautest/1/position')

...and don’t worry: TauValue manages all attribute flavors: all tango data types (float, string, bool, ...), data formats (scalar, spectrum, image) and permissions (R, RW)

I should increase the gap because it’s getting close to the limit ;-)

Using forms

Now let’s say you want not only one but a dozen attributes! lines 5, 6 and 7 of the previous example would have to be replicated for all twelve attributes. Tau provides a better way: the TauForm.

../_images/forms01.png

code:

panel = tau.widget.TauForm()
props = [ 'state', 'status', 'position', 'velocity', 'acceleration' ]
model = [ 'sys/tautest/1/%s' % p for p in props ]
panel.setModel(model)

...and don’t worry: TauForm properly aligns the labels, manages the apply buttons and because it uses TauValue behind it also manages all attribute flavors.

I specially enjoyed this one... let’s see what’s next!

Customizing forms

TauForm is highly customizable. This example shows how you can change the default widget for some attributes according to the user needs.

../_images/forms02.png

code:

1
2
3
4
5
6
panel = tau.widget.TauForm()
props = [ 'state', 'status', 'position', 'velocity', 'acceleration' ]
model = [ 'sys/tautest/1/%s' % p for p in props ]
panel.setModel(model)
panel.getItemByIndex(0).setReadWidgetClass(tau.widget.TauValueLabel)
panel.getItemByIndex(2).setWriteWidgetClass(tau.widget.TauWheelEdit)

A little configuration goes a long way!

Synoptics one-o-one

@TODO: put a jdraw synoptics here

Let’s go graphical

Simple plotting of various spectrum attributes

Say you want to plot two SPECTRUM atributes and watch them changing on-line? Tau provides a very complete widget: qwt.TauPlot (which makes use of the PyQwt library) .

../_images/tauplot01.png

code:

panel = tau.widget.qwt.TauPlot()
model = ['sys/tautest/1/abscissas', 'sys/tautest/1/curve']
panel.setModel(model)

Scatter plots (Y vs X plots)

In the former example each element of the spectrum attributes, was assigned its position index as the x-value (i.e., the “abscissas” attribute was plotted as a spectrum). But, what if you want to create a scatter plot where you want to read the x values from one attribute and the y-values from another?

Solution: you use xValuesAttrName|yValuesAttrName as a member of the models list.

../_images/tauplot02.png

code:

panel = tau.widget.qwt.TauPlot()
model = ['sys/tautest/1/abscissas|sys/tautest/1/curve']
panel.setModel(model)

Note that now the sys/tautest/1/abscissas attribute is being used as x-values instead of being considered as another spectrum to plot like before.

Plotting data that is not an attribute

You are not limited to plotting data from Tango attributes. With TauPlot you can also include arbitrary points (or even functions) in the plot.

Oh, and you can can change the display properties of any curve:

../_images/tauplot03.png

code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import numpy
from PyQt4 import Qwt5

panel = tau.widget.qwt.TauPlot()

rawdata1 = {"y":5*numpy.random.random(10), "name":"Random"}
rawdata2 = {"x":[1, 2, 5, 7], "y":[2, 3, 1, 4], "name":"Hand-written"}
rawdata3 = {"x":numpy.arange(0,10,0.1), "f(x)":"sqrt(x)"}

p1 = tau.widget.qwt.CurveAppearanceProperties(sStyle=Qwt5.QwtSymbol.Rect,
                                                 sSize=5,
                                                 sColor="green",
                                                 sFill=False,
                                                 lStyle=Qt.Qt.NoPen)

p2 = tau.widget.qwt.CurveAppearanceProperties(sStyle=Qwt5.QwtSymbol.Triangle,
                                                 sSize=8,
                                                 sColor="red",
                                                 sFill=True,
                                                 lColor="red",
                                                 lStyle=Qt.Qt.DashLine)

panel.attachRawData(rawdata1, properties=p1)
panel.attachRawData(rawdata2, properties=p2)
panel.attachRawData(rawdata3)

...note the third curve: its definition is just a string defining a mathematical formula!

TauPlot knows maths!