From 6e6e42d54e34a1f4649c0eb6f3b4a19e92d6b0a7 Mon Sep 17 00:00:00 2001 From: Faraphel Date: Thu, 9 Mar 2023 09:40:12 +0100 Subject: [PATCH] renamed "invalid" to "valid" for the Input widget --- source/gui/scene/abc/Scene.py | 2 +- source/gui/widget/Input.py | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/source/gui/scene/abc/Scene.py b/source/gui/scene/abc/Scene.py index b505885..6bbab26 100644 --- a/source/gui/scene/abc/Scene.py +++ b/source/gui/scene/abc/Scene.py @@ -71,7 +71,7 @@ class Scene(ABC, EventPropagationMixin): """ 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 diff --git a/source/gui/widget/Input.py b/source/gui/widget/Input.py index 5af861f..81d1757 100644 --- a/source/gui/widget/Input.py +++ b/source/gui/widget/Input.py @@ -35,7 +35,7 @@ class Input(BoxWidget): 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.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.check() # actualise si le regex est valide ou non + self._refresh_size() # background @@ -69,7 +71,7 @@ class Input(BoxWidget): """ return ( 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") ) @@ -87,17 +89,17 @@ class Input(BoxWidget): 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 - self.invalid = self.check_regex.fullmatch(self.text) is None + self.valid = self.check_regex.fullmatch(self.text) is not None # property @property - def invalid(self): - return self._invalid + def valid(self): + return self._valid - @invalid.setter - def invalid(self, invalid: bool): - self._invalid = invalid + @valid.setter + def valid(self, valid: bool): + self._valid = valid self._refresh_background() @property @@ -134,7 +136,7 @@ class Input(BoxWidget): 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") def on_resize(self, width: int, height: int):