From 3aa9eaf541538d90e37b2c7c271641a17e9111c0 Mon Sep 17 00:00:00 2001 From: Faraphel Date: Tue, 28 Feb 2023 18:27:53 +0100 Subject: [PATCH] fixed access to some style that would raise a attribute does not exist error --- source/gui/texture/abc/Style.py | 8 -------- source/gui/widget/Button.py | 8 ++++---- source/gui/widget/Checkbox.py | 2 +- source/gui/widget/GameGrid.py | 4 ++-- source/gui/widget/Input.py | 8 ++++---- source/gui/widget/Scroller.py | 4 ++-- 6 files changed, 13 insertions(+), 21 deletions(-) diff --git a/source/gui/texture/abc/Style.py b/source/gui/texture/abc/Style.py index 0c7442a..0e40acf 100644 --- a/source/gui/texture/abc/Style.py +++ b/source/gui/texture/abc/Style.py @@ -1,8 +1,4 @@ from abc import ABC -from pathlib import Path -from typing import Optional, Any - -import pyglet class Style(ABC): @@ -10,10 +6,6 @@ class Style(ABC): This class represent a style that can be attached to a widget. """ - @classmethod - def __getattr__(cls, item): - return None # by default, an object will be None if not found. - @classmethod def get(cls, item, default=None): return getattr(cls, item, default) diff --git a/source/gui/widget/Button.py b/source/gui/widget/Button.py index a419b37..4553574 100644 --- a/source/gui/widget/Button.py +++ b/source/gui/widget/Button.py @@ -33,7 +33,7 @@ class Button(BoxWidget): self.style = style self.background = Sprite( - img=self.style.normal, + img=self.style.get("normal"), **dict_filter_prefix("background_", kwargs) ) @@ -60,9 +60,9 @@ class Button(BoxWidget): """ return ( - texture if self.clicking and (texture := self.style.click) is not None else # NOQA - texture if self.hovering and (texture := self.style.hover) is not None else - self.style.normal + texture if self.clicking and (texture := self.style.get("click")) is not None else # NOQA + texture if self.hovering and (texture := self.style.get("hover")) is not None else + self.style.get("normal") ) # refresh diff --git a/source/gui/widget/Checkbox.py b/source/gui/widget/Checkbox.py index 7e0accc..38e14e3 100644 --- a/source/gui/widget/Checkbox.py +++ b/source/gui/widget/Checkbox.py @@ -31,7 +31,7 @@ class Checkbox(BoxWidget): self.style = style - self.tick = Sprite(img=self.style.disabled, **kwargs) + self.tick = Sprite(img=self.style.get("disabled"), **kwargs) self.state = state diff --git a/source/gui/widget/GameGrid.py b/source/gui/widget/GameGrid.py index cbc2d0c..befa02c 100644 --- a/source/gui/widget/GameGrid.py +++ b/source/gui/widget/GameGrid.py @@ -61,7 +61,7 @@ class GameGrid(BoxWidget): self.bomb_style = bomb_style self.background = Sprite( - img=grid_style.background, + img=grid_style.get("background"), **dict_filter_prefix("background_", kwargs) ) @@ -224,7 +224,7 @@ class GameGrid(BoxWidget): def place_bomb(self, cell: Point2D, touched: bool): self.cell_sprites[cell] = Sprite( - img=self.bomb_style.touched if touched else self.bomb_style.missed, + img=self.bomb_style.get("touched" if touched else "missed"), **self._bomb_kwargs ) diff --git a/source/gui/widget/Input.py b/source/gui/widget/Input.py index f6e8cd7..a9a808d 100644 --- a/source/gui/widget/Input.py +++ b/source/gui/widget/Input.py @@ -39,7 +39,7 @@ class Input(BoxWidget): self.regex = re.compile(regex) if isinstance(regex, str) else regex self.background = Sprite( - img=self.style.normal, + img=self.style.get("normal"), **dict_filter_prefix("background_", kwargs) ) @@ -65,9 +65,9 @@ class Input(BoxWidget): """ return ( - texture if self.activated and (texture := self.style.active) is not None else # NOQA - texture if self.invalid and (texture := self.style.signal) is not None else - self.style.normal + texture if self.activated and (texture := self.style.get("active")) is not None else # NOQA + texture if self.invalid and (texture := self.style.get("signal")) is not None else + self.style.get("normal") ) # refresh diff --git a/source/gui/widget/Scroller.py b/source/gui/widget/Scroller.py index e4d4299..eccbf95 100644 --- a/source/gui/widget/Scroller.py +++ b/source/gui/widget/Scroller.py @@ -43,12 +43,12 @@ class Scroller(BoxWidget): self.text_transform = text_transform self.background = Sprite( - img=self.style.background, + img=self.style.get("background"), **dict_filter_prefix("background_", kwargs) ) self.cursor = Sprite( - img=self.style.cursor, + img=self.style.get("cursor"), **dict_filter_prefix("cursor_", kwargs) )