def _updateValidator(self, value): """This method sets a validator depending on the data type""" val = None if value is not None and isinstance(value.wvalue, Quantity): val = self.validator() if not isinstance(val, PintValidator): val = PintValidator(self) self.setValidator(val) attr = self.getModelObj() if attr is not None: bottom, top = attr.range if bottom != val.bottom: val.setBottom(bottom) if top != val.top: val.setTop(top) units = value.wvalue.units if units != val.units: val.setUnits(units) # @TODO Other validators can be configured for other types # (e.g. with string lengths, tango names,...) else: self.setValidator(None) self.debug("Validator disabled") return val
def _updateValidator(self, attr): '''This method sets a validator depending on the data type :param attr: TaurusAttribute ''' data_type = attr.getType() if data_type in [DataType.Integer, DataType.Float]: self._min_range, self._max_range = attr.range self._min_alarm, self._max_alarm = attr.alarms self._default_unit = attr.wvalue.units validator = PintValidator() validator.setBottom(self._min_range) validator.setTop(self._max_range) validator.setUnits(self._default_unit) self.setValidator(validator) else: self.setValidator(None)
def _updateValidator(self, value): '''This method sets a validator depending on the data type''' if isinstance(value.wvalue, Quantity): val = self.validator() if not isinstance(val, PintValidator): val = PintValidator(self) self.setValidator(val) attr = self.getModelObj() bottom, top = attr.range if bottom != val.bottom: val.setBottom(bottom) if top != val.top: val.setTop(top) units = value.wvalue.units if units != val.units: val.setUnits(units) # @TODO Other validators can be configured for other types (e.g. with string lengths, tango names,...) else: self.setValidator(None) self.debug("Validator disabled")