From 59ee20efe50bc525918998ebdfd68b3e0233f0b6 Mon Sep 17 00:00:00 2001 From: Faraphel Date: Mon, 13 Feb 2023 14:31:25 +0100 Subject: [PATCH] fixed bbox property not returning the correct x2 and y2 --- main.pyw | 4 ++-- source/gui/scene/abc/Scene.py | 11 +++++------ source/gui/widget/abc/BoxWidget.py | 2 +- source/gui/window/Window.py | 6 ++++-- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/main.pyw b/main.pyw index 4c0eea0..facc814 100644 --- a/main.pyw +++ b/main.pyw @@ -14,8 +14,8 @@ class TestScene(Scene): self.add_widget(FPSDisplay) label = self.add_widget(Text, text="Hello World !", x=0.5, y=0.5, width=0.5, height=0.5, anchor_x="center", anchor_y="center") - label.on_pressed = lambda self, button, modifiers: print("pressed", self, button, modifiers) - label.on_release = lambda self, button, modifiers: print("release", self, button, modifiers) + label.on_pressed = lambda button, modifiers: print("pressed", label, button, modifiers) + label.on_release = lambda button, modifiers: print("release", label, button, modifiers) # Create a new window diff --git a/source/gui/scene/abc/Scene.py b/source/gui/scene/abc/Scene.py index a1b663b..95f1f3b 100644 --- a/source/gui/scene/abc/Scene.py +++ b/source/gui/scene/abc/Scene.py @@ -59,14 +59,13 @@ class Scene(ABC): :return: une fonction appelant l'événement original ainsi que ceux des scènes. """ - # Récupère la fonction originale. S'il n'y en a pas, renvoie une fonction sans effet. - try: - func = super().__getattribute__(item) - except AttributeError: - func = lambda *_, **__: "pass" # NOQA E731 + # Récupère la fonction originale. S'il n'y en a pas, renvoie une fonction sans effet.* + func = None + try: func = super().__getattribute__(item) + except AttributeError: pass def _func(*args, **kwargs) -> None: - func(*args, **kwargs) + if func is not None: func(*args, **kwargs) for widget in self._widgets: getattr(widget, item, lambda *_, **__: "pass")(*args, **kwargs) diff --git a/source/gui/widget/abc/BoxWidget.py b/source/gui/widget/abc/BoxWidget.py index 6707d06..106b66e 100644 --- a/source/gui/widget/abc/BoxWidget.py +++ b/source/gui/widget/abc/BoxWidget.py @@ -72,7 +72,7 @@ class BoxWidget(Widget, ABC): @property def bbox(self) -> tuple[int, int, int, int]: - return self.x, self.y, self.width, self.height + return self.x, self.y, self.x + self.width, self.y + self.height # event diff --git a/source/gui/window/Window.py b/source/gui/window/Window.py index ac7ebf9..2d63f7f 100644 --- a/source/gui/window/Window.py +++ b/source/gui/window/Window.py @@ -76,10 +76,12 @@ class Window(pyglet.window.Window): # NOQA :return: une fonction appelant l'événement original ainsi que ceux des scènes. """ - func = super().__getattribute__(item) + func = None + try: func = super().__getattribute__(item) + except AttributeError: pass def _func(*args, **kwargs) -> None: - func(*args, **kwargs) + if func is not None: func(*args, **kwargs) for scene in self._scenes: getattr(scene, item)(*args, **kwargs)