Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

Taurus eval using python variable defined in the current python module #745

Open
almarass opened this issue Apr 27, 2018 · 9 comments
Open
Labels

Comments

@almarass
Copy link

almarass commented Apr 27, 2018

Hi,
I tried to visualize in a TaurusLabel the content of a variable defined in the current python module, but without success.
The code is as follows:

import sys
from taurus.external.qt import Qt
from taurus.qt.qtgui.application import TaurusApplication

app = TaurusApplication(sys.argv)
panel = Qt.QWidget()
layout = Qt.QHBoxLayout()
panel.setLayout(layout)

s = 'MAINTENANCE'

from taurus.qt.qtgui.display import TaurusLabel
w = TaurusLabel()
layout.addWidget(w)

w.model = 'eval:a=s1'
#w.model = 'eval:a=@self.*/s1'

panel.show()
sys.exit(app.exec_())

The commented instruction was another attempt.
Is it somehow possible?

thanks

@teresanunez
Copy link

teresanunez commented Apr 27, 2018 via email

@almarass
Copy link
Author

almarass commented Apr 27, 2018 via email

@cmft
Copy link
Member

cmft commented Apr 27, 2018

Hi @almarass ,
Yes, It can be done. Be aware of the PyTango limitation

See the first example. If you need to do something more fancy, check the documentation

Some examples:

taurusform 'eval:foo="hello";foo'
taurusform 'eval:@random.*/foo=choice("abcd");foo'
taurusform 'eval:string="--> "+ {sys/tg_test/1/string_scalar};string'

@almarass
Copy link
Author

almarass commented Apr 27, 2018 via email

@cmft
Copy link
Member

cmft commented Apr 27, 2018

Hi @almarass,
I used taurusform to avoid writing extra code. In your example should be like this:

w.model = 'eval:a="{0}";a'.format(s)

@cpascual
Copy link
Member

cpascual commented Apr 30, 2018

I am not sure, but I think that the solution from #745 (comment) is not what @almarass is after, because it is static (the model is set to a string with the value of the variable at the moment of setting the model).
I understand that what @almarass wants is to be able to update the value of s and see the display updated.

If the module where the s variable is stored is called foo.py and it is in the python path, the following should work:

 w.model = 'eval:@foo.*/s'

BUT: when I tried I found that it does not work if used from the same module foo (it seems to get stuck). As a workaround, if you can use 2 modules:

  • main.py
import sys
from taurus.qt.qtgui.application import TaurusApplication
from taurus.qt.qtgui.display import TaurusLabel

app = TaurusApplication(sys.argv)

w = TaurusLabel()
w.model = 'eval:@foo.*/s'

w.show()
sys.exit(app.exec_())
  • foo.py (note that this file must be in the python path!!!)
s = "WHATEVER"

@almarass
Copy link
Author

almarass commented Apr 30, 2018 via email

@cpascual
Copy link
Member

It seems to work, but when the value of dishmode is changed, it does not show the new value.

This is because your code is essentially following the recipe from #745 (comment).

Have a look at the alternative that I propose in #745 (comment)

@almarass
Copy link
Author

almarass commented May 2, 2018

I followed the alternative proposed in #745 (comment), but it seems to behave in the same way (it does not update)

@cpascual cpascual added the bug label Jul 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants