diff --git a/configure.py b/configure.py index c7822a03..2b5825ef 100755 --- a/configure.py +++ b/configure.py @@ -63,9 +63,10 @@ hw_lib_map = {"AUTO": "Automatic", "LHM": "LibreHardwareMonitor (admin.)", "PYTHON": "Python libraries", "STUB": "Fake random data", "STATIC": "Fake static data"} reverse_map = {False: "classic", True: "reverse"} +revision_size = {'A': '3.5"', 'B': '3.5"', 'C': '5"', 'SIMU': '3.5"', 'SIMU5': '5"'} -def get_themes(is5inch: bool = False): +def get_themes(revision: str): themes = [] directory = 'res/themes/' for filename in os.listdir('res/themes'): @@ -78,9 +79,7 @@ def get_themes(is5inch: bool = False): # Get display size from theme.yaml with open(theme, "rt", encoding='utf8') as stream: theme_data, ind, bsi = ruamel.yaml.util.load_yaml_guess_indent(stream) - if theme_data['display'].get("DISPLAY_SIZE", '3.5"') == '5"' and is5inch: - themes.append(filename) - elif theme_data['display'].get("DISPLAY_SIZE", '3.5"') == '3.5"' and not is5inch: + if theme_data['display'].get("DISPLAY_SIZE", '3.5"') == revision_size[revision]: themes.append(filename) return sorted(themes, key=str.casefold) @@ -307,8 +306,8 @@ def on_brightness_change(self, e=None): def on_model_change(self, e=None): self.show_hide_brightness_warning() - model_code = [k for k, v in revision_map.items() if v == self.model_cb.get()][0] - if model_code == "SIMU" or model_code == "SIMU5": + revision = [k for k, v in revision_map.items() if v == self.model_cb.get()][0] + if revision == "SIMU" or revision == "SIMU5": self.com_cb.configure(state="disabled", foreground="#C0C0C0") self.orient_cb.configure(state="disabled", foreground="#C0C0C0") self.brightness_slider.configure(state="disabled") @@ -319,11 +318,7 @@ def on_model_change(self, e=None): self.brightness_slider.configure(state="normal") self.brightness_val_label.configure(foreground="#000") - if model_code == "C" or model_code == "SIMU5": - themes = get_themes(is5inch=True) - else: - themes = get_themes(is5inch=False) - + themes = get_themes(revision) self.theme_cb.config(values=themes) if not self.theme_cb.get() in themes: diff --git a/library/config.py b/library/config.py index 758584ce..6e5ed400 100644 --- a/library/config.py +++ b/library/config.py @@ -38,6 +38,9 @@ def load_yaml(configfile): THEME_DEFAULT = load_yaml("res/themes/default.yaml") THEME_DATA = None +# Matching between hardware revision and display size in inches +revision_size = {'A': '3.5"', 'B': '3.5"', 'C': '5"', 'SIMU': '3.5"', 'SIMU5': '5"'} + def copy_default(default, theme): """recursively supply default values into a dict of dicts of dicts ....""" @@ -62,6 +65,15 @@ def load_theme(): except: os._exit(0) + # Check if theme is compatible with hardware revision + if revision_size[CONFIG_DATA["display"]["REVISION"]] != THEME_DATA['display'].get("DISPLAY_SIZE", '3.5"'): + logger.error("The selected theme " + CONFIG_DATA['config'][ + 'THEME'] + " is not compatible with your display revision " + CONFIG_DATA["display"]["REVISION"]) + try: + sys.exit(0) + except: + os._exit(0) + copy_default(THEME_DEFAULT, THEME_DATA)