Closed claudio-rosati closed 6 years ago
Another comment from the integrator:
Actually what the operators really need is the number in exponential format. So it would be really useful to be able to specify the same format parameters as in the Format property of Text Update...
That would be a 4th option in my previous list.
If you want that type of fine control, why not format it the way you want in the script? The PVUtil contains the basic getDouble(), getString() that has been helpful for the last 10 years of BOY usage, but nothing keeps you from calling the FormatOptionHandler:
from org.csstudio.display.builder.runtime.script import PVUtil
from org.csstudio.display.builder.model.properties import FormatOption
from org.csstudio.display.builder.model.util import FormatOptionHandler
vtype = PVUtil.getVType(pvs[0])
# Exponential, 5 digits, with units
text = FormatOptionHandler.format(vtype, FormatOption.EXPONENTIAL, 5, true)
Or get the number and format it any way you want in your own code.
Still, if you want to show a number with exponential notation, why not simply use a TextUpdate widget, enter the PV name, select the format? If the precision is wrong, fix that on the IOC. If you can't, OK, then enter the precision on the widget.
Why use a script at all?
I think that your example should be ok. I supposed only PVUtil was available inside the script. Anyway I’ll report all above to the integrator. Thank you
I'm not sure if it is a bug or if an alternative way of solving the original problem exists.
See: CSSTUDIO-752.bob.zip
After few trial-and-errors, I suggested my integrator to use
PVUtil.getDouble()
instead. And this was the answer:Looking at the
PVUtil
, I'm thinking that maybe we could:getUnit()
method returning the engineering unit as a String object;getString()
accepting the theprecision
to be used when converting double numbers;getString()
passing -1 as precision toFormatOptionHandler.format()
, instead of 0.