def test_regexpvalidator(): val = gui.RegExpValidator() val.set_regex("[0-9]") with open("data.pkl", "wb") as jar: pickle.dump(val, jar) with open("data.pkl", "rb") as jar: val = pickle.load(jar) assert val.get_regex() == "[0-9]" assert val.is_valid_value("0")
def __init__(self, label, value=None, notempty=False, regex=None): super().__init__(label, value=value) self.widget = widgets.LineEdit() if notempty: val = custom_validators.NotEmptyValidator() self.widget.set_validator(val) if regex is not None: val = gui.RegExpValidator() val.set_regex(regex) self.widget.set_validator(val) if value is not None: self.widget.set_value(value)
def set_regex_validator(self, regex: str) -> gui.RegExpValidator: validator = gui.RegExpValidator(self) validator.set_regex(regex) self.setValidator(validator) self.set_validation_color() return validator