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.
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:
You can easily configure it from Jive by going to Edit->Create server and type the above parameters in the dialog that pops up.
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.
Displaying a tango attribute value in a GUI is easy with tau and TauValueLabel

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!
Let’s spice it up a bit: add the tango label for the position attribute so it looks something like this:

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!
And little bit more... add the units. Lets also put a container and see how simple setting the model becomes.

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?
Humm... Now supose the user wants to change this value. TauValueLineEdit does this job well (and so does TauValueSpinBox and TauWheelEdit :-)
With TauValueLineEdit
With TauValueSpinBox
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?
Getting tired of writing all that code just to represent one attribute? Tau provides a better option: The TauValue.

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 ;-)
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.

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!
TauForm is highly customizable. This example shows how you can change the default widget for some attributes according to the user needs.

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!
@TODO: put a jdraw synoptics here
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) .

code:
panel = tau.widget.qwt.TauPlot()
model = ['sys/tautest/1/abscissas', 'sys/tautest/1/curve']
panel.setModel(model)
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.

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.
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:

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!
Many times we are interested in showing how an scalar attribute evolves with time. A close-cousin of the TauPlot called qwt.TauTrend is here to help you:

code:
panel = tau.widget.qwt.TauTrend()
model = ['sys/tautest/1/position']
panel.setXIsTime(True) #to show the x values as time
panel.setModel(model)
Note: if you pass a model that is a Tango SPECTRUM attribute (instead of a scalar), TauTrend will interpret it as a collection of scalar values and will plot a separate trend line for each.