fixed access to some style that would raise a attribute does not exist error
This commit is contained in:
parent
b7d147fc3c
commit
3aa9eaf541
6 changed files with 13 additions and 21 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in a new issue