|
1 | | -from typing import List |
| 1 | +from typing import Any, List |
2 | 2 | from pathlib import Path |
3 | 3 | import json |
4 | 4 |
|
@@ -146,20 +146,23 @@ def themes_list() -> List[str]: |
146 | 146 | return themes |
147 | 147 |
|
148 | 148 |
|
| 149 | +def replace_conf_color(conf: ConfigManager, theme_json: Any, dark_mode: bool) -> None: |
| 150 | + modeidx = 2 if dark_mode else 1 |
| 151 | + |
| 152 | + for color in theme_json["colors"]: |
| 153 | + conf[f"colors.{color}.{modeidx}"] = theme_json["colors"][color][modeidx] |
| 154 | + |
| 155 | + |
149 | 156 | def apply_theme(conf_window: ConfigWindow, theme: str) -> None: |
150 | 157 | theme_path = THEMES_DIR / f"{theme}.json" |
151 | 158 | theme_json = json.loads(theme_path.read_text()) |
152 | 159 |
|
153 | | - if theme.startswith("(dark)"): |
154 | | - modeidx = 2 |
155 | | - elif theme.startswith("(light)"): |
156 | | - modeidx = 1 |
157 | | - else: |
158 | | - tooltip("Invalid theme name<br />Theme name must start with (light) or (dark)") |
159 | | - return |
160 | | - |
161 | | - for color in theme_json["colors"]: |
162 | | - conf[f"colors.{color}.{modeidx}"] = theme_json["colors"][color][modeidx] |
| 160 | + # Dark mode or universal |
| 161 | + if not theme.startswith("(dark)"): |
| 162 | + replace_conf_color(conf, theme_json, False) |
| 163 | + # Light mode or universal |
| 164 | + if not theme.startswith("(light)"): |
| 165 | + replace_conf_color(conf, theme_json, True) |
163 | 166 |
|
164 | 167 | conf_window.update_widgets() |
165 | 168 | conf_window.main_tab.setCurrentIndex(0) |
|
0 commit comments