From: Carlos M. F. T. <cf...@ce...> - 2016-07-28 10:24:56
|
Hi Grzegorz, The actual TaurusLabelEditRW can not allow this "feature", the method setValidator is there because it comes from Qt widgets. TaurusLabelEditRW uses the TaurusLineEdit as writewidget and it overwrites the used validator in each event. TaurusLineEdit creates the validator each time attending the attribute range, that is the reason because your solution does not work. That I propose you is an ugly workaround : The workaround consists in create your own TaurusLineEdit widget and overwrite the "_updateValidator" method. Unfortunately these classes are not documented so I hope this example can help you. import sys from taurus.external.qt import QtGui from taurus.qt.qtgui.application import TaurusApplication from taurus.qt.qtgui.input import TaurusValueLineEdit from taurus.qt.qtgui.compact import TaurusLabelEditRW class MyTaurusValueLineEdit(TaurusValueLineEdit): # Reimplement _updateValidator method def _updateValidator(self, attrinfo): pass app = TaurusApplication() f = TaurusLabelEditRW(writeWClass=MyTaurusValueLineEdit) f.model = 'sys/tg_test/1/double_scalar_w' validator = QtGui.QDoubleValidator(10, 20, 5) f.writeWidget.setValidator(validator) f.show() sys.exit(app.exec_()) The other option is somehow in your widget update dynamically the range of your attribute. Could you create a ticket in taurus [1] to discuss a proper solution for taurus? [1] https://sourceforge.net/p/tauruslib/tickets/ Best, Carlos On 07/27/2016 07:36 PM, Grzegorz Kowalski wrote: > Hello, > I have a problem with TaurusLabelEditRW, I need to validate its input to > only set values inside certain range, but I don't know how to stop it > from setting an attribute value when it's invalid. > > My first try was to use QDoubleValidator with TaurusValueLineEdit that > is a part of RW widget, but it seems to ignore validator despite it's > based on QLineEdit. > > code: > rw = TaurusLabelEditRW() > validator = QDoubleValidator(100, 300, 5) > for c in rw.children(): > if c.__class__.__name__ == "TaurusValueLineEdit": > c.setValidator(self.validator) > > Second try was to connect to returnPressed signal of the line edit, and > check the value, but I have no idea on how to prevent setting invalid > value to the attribute. > > The range can't be just Tango attribute's max and min values because it > is dependent on other parameters. > I'm using Taurus 3.7.0. > > Thank you for any help! |