Skip to content

Add write and instantiation support to eval scheme

Carlos Pascual requested to merge github/fork/cpascual/evalwrite into develop

This PR extends the evaluation scheme with two related features (it is a continuation of PR #423 ):

  • support for creation of arbitrary instances by EvaluationDevices
  • support for writeable attributes

The first feature introduces the possibility of defining an Evaluation Device such as:

eval:@c=mymod.MyClass(1,"a",b=3)

This adds the c symbol to the context of the EvaluationAttributes of this device. In other words, any evaluation done by this Evaluation device is done in an environment that behaves as if one had done the following beforehand:

from mymod import MyClass
c = MyClass(1, "a", b=3)

The second feature (support of writeable attributes) can be accessed by instantiating a class that declares writeable properties. For example, assume that the mymod module defines the following class:

from taurus.external.pint import Quantity


class MyClass(object):
    def __init__(self, foomag=123):
        self._foo = Quantity(foomag, "m")

    def get_foo(self):
        return self._foo

    def set_foo(self, value):
        self._foo = value

    foo = property(get_foo, set_foo)

Then, the following code would give a taurus form allowing to read and write foo (of course, a more practical example could do other calls in get_foo and set_foo):

taurusform 'eval:@c=mymod.MyClass(99)/c.foo'

For more examples, see the docs in the evaluation module and in the evaluation test resource files

Other possible ideas for using this:

  • Getting images from a webcam without tango (with opencv)
  • Make a trend of a log file size (with os.path.getsize)
  • Read/write environment variables from a TaurusForm (with os.environ)
  • ...

Merge request reports