Skip to content

Commit

Permalink
Check if theme is compatible with display model
Browse files Browse the repository at this point in the history
  • Loading branch information
mathoudebine committed Jun 5, 2023
1 parent a120cc8 commit e71307c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
17 changes: 6 additions & 11 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'):
Expand All @@ -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)

Expand Down Expand Up @@ -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")
Expand All @@ -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:
Expand Down
12 changes: 12 additions & 0 deletions library/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ...."""
Expand All @@ -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)


Expand Down

0 comments on commit e71307c

Please sign in to comment.