renamed "invalid" to "valid" for the Input widget

This commit is contained in:
Faraphel 2023-03-09 09:40:12 +01:00
parent 9388c0eedb
commit 6e6e42d54e
2 changed files with 12 additions and 10 deletions

View file

@ -71,7 +71,7 @@ class Scene(ABC, EventPropagationMixin):
""" """
for widget in self._widgets: for widget in self._widgets:
if isinstance(widget, Input) and widget.invalid: return False if isinstance(widget, Input) and not widget.valid: return False
return True return True

View file

@ -35,7 +35,7 @@ class Input(BoxWidget):
self.style = style self.style = style
self._invalid = False self._valid = True
self.type_regex = re.compile(type_regex) if type_regex is not None else None self.type_regex = re.compile(type_regex) if type_regex is not None else None
self.check_regex = re.compile(check_regex) if check_regex is not None else None self.check_regex = re.compile(check_regex) if check_regex is not None else None
@ -55,6 +55,8 @@ class Input(BoxWidget):
self.add_listener("on_activate_change", lambda *_: self._refresh_background()) self.add_listener("on_activate_change", lambda *_: self._refresh_background())
self.check() # actualise si le regex est valide ou non
self._refresh_size() self._refresh_size()
# background # background
@ -69,7 +71,7 @@ class Input(BoxWidget):
""" """
return ( return (
texture if self.activated and (texture := self.style.get("active")) is not None else # NOQA texture if self.activated and (texture := self.style.get("active")) is not None else # NOQA
texture if self.invalid and (texture := self.style.get("error")) is not None else texture if not self.valid and (texture := self.style.get("error")) is not None else
self.style.get("normal") self.style.get("normal")
) )
@ -87,17 +89,17 @@ class Input(BoxWidget):
def check(self): def check(self):
if self.check_regex is not None: # si il y a un regex de validation, applique le pour vérifier le texte if self.check_regex is not None: # si il y a un regex de validation, applique le pour vérifier le texte
self.invalid = self.check_regex.fullmatch(self.text) is None self.valid = self.check_regex.fullmatch(self.text) is not None
# property # property
@property @property
def invalid(self): def valid(self):
return self._invalid return self._valid
@invalid.setter @valid.setter
def invalid(self, invalid: bool): def valid(self, valid: bool):
self._invalid = invalid self._valid = valid
self._refresh_background() self._refresh_background()
@property @property
@ -134,7 +136,7 @@ class Input(BoxWidget):
self.check() # rafraichi le fait que le texte est considéré comme valide ou non self.check() # rafraichi le fait que le texte est considéré comme valide ou non
if not self.invalid: if self.valid:
self.trigger_event("on_valid_text") self.trigger_event("on_valid_text")
def on_resize(self, width: int, height: int): def on_resize(self, width: int, height: int):