|
8 | 8 |
|
9 | 9 |
|
10 | 10 | class ThemeColors: |
11 | | - def __init__(self, name: BSW5_THEME_NAME) -> None: |
12 | | - self._name = name |
13 | | - self._colors: dict[str, str] = bsw5_theme_colors[name] |
14 | | - |
15 | | - def __getattr__(self, key: str) -> str: |
16 | | - return self._colors[key] |
| 11 | + # Leave type definitions for pyright type stubs; Do not set values here |
| 12 | + # Leave type definintions here for completions w/ static type checker |
| 13 | + primary: str |
| 14 | + secondary: str |
| 15 | + success: str |
| 16 | + danger: str |
| 17 | + warning: str |
| 18 | + info: str |
| 19 | + light: str |
| 20 | + dark: str |
| 21 | + body_color: str |
| 22 | + body_bg: str |
17 | 23 |
|
18 | | - def __getitem__(self, key: str) -> str: |
19 | | - return self._colors[key] |
| 24 | + def __init__(self, name: BSW5_THEME_NAME) -> None: |
| 25 | + colors = bsw5_theme_colors[name] |
| 26 | + _color_names: list[str] = list(colors.keys()) |
| 27 | + _color_name_len = max(len(x) for x in _color_names) |
20 | 28 |
|
21 | | - def __dir__(self) -> list[str]: |
22 | | - return list(self._colors.keys()) |
| 29 | + self._name = name |
| 30 | + self._color_names = _color_names |
| 31 | + self._color_name_len = _color_name_len |
| 32 | + for k, v in colors.items(): |
| 33 | + setattr(self, k, v) |
23 | 34 |
|
24 | 35 | def __repr__(self) -> str: |
25 | | - colors = [f"{k:11}: {v}" for k, v in self._colors.items()] |
| 36 | + colors = [ |
| 37 | + f"{k:{self._color_name_len + 1}}: {getattr(self, k)}" |
| 38 | + for k in self._color_names |
| 39 | + ] |
26 | 40 | colors = "\n ".join(colors) |
27 | 41 | ret = [f"<ThemeColors({self._name!r}):", " " + colors, ">"] |
28 | 42 | return "\n".join(ret) |
29 | 43 |
|
30 | 44 |
|
31 | 45 | class ShinyswatchTheme(Tagifiable): |
| 46 | + # Leave type definitions for pyright type stubs; Do not set values here |
| 47 | + name: BSW5_THEME_NAME |
| 48 | + colors: ThemeColors |
| 49 | + |
32 | 50 | def __init__(self, name: BSW5_THEME_NAME) -> None: |
33 | 51 | assert_theme(name=name) |
34 | 52 | self.name: BSW5_THEME_NAME = name |
|
0 commit comments