Closed marouanebj closed 3 years ago
(Sorry for the late reply. I missed this question entirely)
TaurusValueLineEdit
already sets its own validator for numerical values, in order to enforce range limits and handling units (keep in mind that in taurus, the values of an attribute are not "doubles" or "ints" but "Quantities"). It actually checks if the validator is appropriate for the value type each time the value is updated, and as such, it overwrites the one you are setting.
I do not see a straight-forward way to customize this without modifying the class itself (the code of TaurusValueLineEdit
expects the API from the PintValidator
when dealing with numerical values).
You may try to make your validator inherit from PintValidator
. This way TaurusValueLineEdit
may respect it (but I am not sure it would work) .
Thanks,
I will try inherit PintValidator
.
Hi @marouanebj , did it work for you? If so, please let us know, so that we can close this issue
Thanks!
class PintCLocaleQDoubleValidator(PintValidator):
"""
A PintValidator using C locale
"""
def __init__(self, *var):
PintValidator.__init__(self, *var)
self._localeHolder = Qt.QLocale.c()
self._localeHolder.setNumberOptions(Qt.QLocale.RejectGroupSeparator)
self.setLocale(self._localeHolder)
I just tried this but I still have the same behavior.
Running the following snippet seems to indicate that my proposed approach should work...
from taurus.qt.qtgui.application import TaurusApplication
from taurus.qt.qtgui.input import TaurusValueLineEdit
from taurus.qt.qtgui.util import PintValidator
class MyValidator(PintValidator):
def __init__(self, *a):
PintValidator.__init__(self, *a)
print("MyValidator")
def validate(self, input, pos):
r = PintValidator.validate(self, input, pos)
print(r, input, pos)
return r
if __name__ == "__main__":
import sys
app = TaurusApplication(cmd_line_parser=None)
w = TaurusValueLineEdit()
w.setModel("sys/tg_test/1/double_scalar")
v = MyValidator(w)
w.setValidator(v)
w.show()
sys.exit(app.exec_())
Please note that PintValidator
(and therefore MyValidator
too) does not inherit from QDoubleValidator
, but from QValidator
, and therefore you may need to do some extra implementation yourself in the validate
method to accomplish your goal.
OK I got it, Thanks
Hi, The Validator seems not to be taken into account for TaurusValueLineEdit !
Here my Validator
Here my TaurusValueLineEdit code:
Here my QLineEdit code:
When I use the TaurusValueLineEdit and I type in "10,2.3" it is translated to 102.3 When I use the QEdit and I cannot type in "10,2.3" the comma ',' can note be used (That's normal according to my CLocaleQDoubleValidator)
Is this a Bug ? I'm I misusing it ? Is the Validator ignored in the TaurusValueLineEdit ? maybe because of the model that already have a format !
Regards, Marouane