Skip to content

Commit e71307c

Browse files
committed
Check if theme is compatible with display model
1 parent a120cc8 commit e71307c

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

configure.py

+6-11
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@
6363
hw_lib_map = {"AUTO": "Automatic", "LHM": "LibreHardwareMonitor (admin.)", "PYTHON": "Python libraries",
6464
"STUB": "Fake random data", "STATIC": "Fake static data"}
6565
reverse_map = {False: "classic", True: "reverse"}
66+
revision_size = {'A': '3.5"', 'B': '3.5"', 'C': '5"', 'SIMU': '3.5"', 'SIMU5': '5"'}
6667

6768

68-
def get_themes(is5inch: bool = False):
69+
def get_themes(revision: str):
6970
themes = []
7071
directory = 'res/themes/'
7172
for filename in os.listdir('res/themes'):
@@ -78,9 +79,7 @@ def get_themes(is5inch: bool = False):
7879
# Get display size from theme.yaml
7980
with open(theme, "rt", encoding='utf8') as stream:
8081
theme_data, ind, bsi = ruamel.yaml.util.load_yaml_guess_indent(stream)
81-
if theme_data['display'].get("DISPLAY_SIZE", '3.5"') == '5"' and is5inch:
82-
themes.append(filename)
83-
elif theme_data['display'].get("DISPLAY_SIZE", '3.5"') == '3.5"' and not is5inch:
82+
if theme_data['display'].get("DISPLAY_SIZE", '3.5"') == revision_size[revision]:
8483
themes.append(filename)
8584
return sorted(themes, key=str.casefold)
8685

@@ -307,8 +306,8 @@ def on_brightness_change(self, e=None):
307306

308307
def on_model_change(self, e=None):
309308
self.show_hide_brightness_warning()
310-
model_code = [k for k, v in revision_map.items() if v == self.model_cb.get()][0]
311-
if model_code == "SIMU" or model_code == "SIMU5":
309+
revision = [k for k, v in revision_map.items() if v == self.model_cb.get()][0]
310+
if revision == "SIMU" or revision == "SIMU5":
312311
self.com_cb.configure(state="disabled", foreground="#C0C0C0")
313312
self.orient_cb.configure(state="disabled", foreground="#C0C0C0")
314313
self.brightness_slider.configure(state="disabled")
@@ -319,11 +318,7 @@ def on_model_change(self, e=None):
319318
self.brightness_slider.configure(state="normal")
320319
self.brightness_val_label.configure(foreground="#000")
321320

322-
if model_code == "C" or model_code == "SIMU5":
323-
themes = get_themes(is5inch=True)
324-
else:
325-
themes = get_themes(is5inch=False)
326-
321+
themes = get_themes(revision)
327322
self.theme_cb.config(values=themes)
328323

329324
if not self.theme_cb.get() in themes:

library/config.py

+12
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ def load_yaml(configfile):
3838
THEME_DEFAULT = load_yaml("res/themes/default.yaml")
3939
THEME_DATA = None
4040

41+
# Matching between hardware revision and display size in inches
42+
revision_size = {'A': '3.5"', 'B': '3.5"', 'C': '5"', 'SIMU': '3.5"', 'SIMU5': '5"'}
43+
4144

4245
def copy_default(default, theme):
4346
"""recursively supply default values into a dict of dicts of dicts ...."""
@@ -62,6 +65,15 @@ def load_theme():
6265
except:
6366
os._exit(0)
6467

68+
# Check if theme is compatible with hardware revision
69+
if revision_size[CONFIG_DATA["display"]["REVISION"]] != THEME_DATA['display'].get("DISPLAY_SIZE", '3.5"'):
70+
logger.error("The selected theme " + CONFIG_DATA['config'][
71+
'THEME'] + " is not compatible with your display revision " + CONFIG_DATA["display"]["REVISION"])
72+
try:
73+
sys.exit(0)
74+
except:
75+
os._exit(0)
76+
6577
copy_default(THEME_DEFAULT, THEME_DATA)
6678

6779

0 commit comments

Comments
 (0)