taurus-org / taurus

Moved to https://gitlab.com/taurus-org/taurus
http://taurus-scada.org
43 stars 46 forks source link

Fix TaurusValueComboBox does not show set value #1032

Closed cmft closed 4 years ago

cmft commented 4 years ago

When a TaurusValueComboBox widget is initialized it does not show the set value.

The setValue method does not find the given value since it saves internally as string. Fix it doing a cast.

Update by @cpascual : It is more likely related to this

cpascual commented 4 years ago

This fixed it for me in py3, but not in py2.(UPDATE:id does fix it) I will try to write a unit test to make sure that we fix it properly.

Also, we should check if this approach is ok for comboboxes whose values are of different types (quantities, strings, states,...)

cpascual commented 4 years ago

Just for future reference: a script to reproduce the problem is:

from taurus.qt.qtgui.application import TaurusApplication
from taurus.qt.qtgui.input import TaurusValueComboBox
import taurus
import sys
app = TaurusApplication(cmd_line_parser=None)
w = TaurusValueComboBox()
model = 'sys/tg_test/1/short_scalar_w'
a = taurus.Attribute(model)
a.write(2)
names = [('name0', 0), ('name1', 1), ('name2', 2), ('name3', 3)]
w.addValueNames(names)
w.setModel(model)
w.show()
sys.exit(app.exec_())
cpascual commented 4 years ago

I added a unit test that tests some cases more complex than those in the snippet above, and it shows that just casting to a str is not enough. In 6736f01 I propose a different approach that should pass the test. @cmft , can you please review it?

cmft commented 4 years ago

I agree with the changes and seems that everything work. I will merge it