Skip to content

Commit b0a7132

Browse files
committed
Harmonize themes and display sizes: common for all 2.x" and 8.8"/9.2"
1 parent 65652cf commit b0a7132

1 file changed

Lines changed: 42 additions & 28 deletions

File tree

configure.py

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
# This file is the system monitor configuration GUI
2323

2424
from library.pythoncheck import check_python_version
25+
2526
check_python_version()
2627

27-
import glob
2828
import os
2929
import platform
3030
import subprocess
@@ -63,8 +63,10 @@
6363
WEACT_MODEL = "WeAct Studio Display FS V1"
6464
SIMULATED_MODEL = "Simulated screen"
6565

66+
_SIZE_2_1_INCH = "2.1\"" # Only for retro compatibility
67+
_SIZE_2_8_INCH = "2.8\"" # Only for retro compatibility
68+
_SIZE_9_2_INCH = "9.2\"" # Only for retro compatibility
6669
SIZE_0_96_INCH = "0.96\""
67-
SIZE_2_1_INCH = "2.1\"" # Only for retro compatibility
6870
SIZE_2_x_INCH = "2.1\" / 2.8\""
6971
SIZE_3_5_INCH = "3.5\""
7072
SIZE_4_6_INCH = "4.6\""
@@ -158,9 +160,9 @@
158160
MAIN_DIRECTORY = Path(__file__).resolve().parent
159161
THEMES_DIR = MAIN_DIRECTORY / "res/themes"
160162

161-
162163
circular_mask = Image.open(MAIN_DIRECTORY / "res/backgrounds/circular-mask.png")
163164

165+
164166
def get_theme_data(name: str):
165167
dir = THEMES_DIR / name
166168

@@ -220,7 +222,8 @@ def __init__(self):
220222
self.window = Tk()
221223
self.window.title('Turing System Monitor configuration')
222224
self.window.geometry("820x580")
223-
self.window.iconphoto(True,PhotoImage(file=str(MAIN_DIRECTORY / "res/icons/monitor-icon-17865/64.png"))) # When window gets focus again, reload theme preview in case it has been updated by theme editor
225+
self.window.iconphoto(True, PhotoImage(file=str(
226+
MAIN_DIRECTORY / "res/icons/monitor-icon-17865/64.png"))) # When window gets focus again, reload theme preview in case it has been updated by theme editor
224227
self.window.bind("<FocusIn>", self.on_theme_change)
225228
self.window.after(0, self.on_fan_speed_update)
226229

@@ -320,9 +323,8 @@ def __init__(self):
320323
command=lambda: self.on_weatherping_click())
321324
self.weather_ping_btn.place(x=80, y=520, height=50, width=130)
322325

323-
324326
self.open_theme_folder_btn = ttk.Button(self.window, text="Open themes\nfolder",
325-
command=lambda: self.on_open_theme_folder_click())
327+
command=lambda: self.on_open_theme_folder_click())
326328
self.open_theme_folder_btn.place(x=220, y=520, height=50, width=130)
327329

328330
self.edit_theme_btn = ttk.Button(self.window, text="Edit theme", command=lambda: self.on_theme_editor_click())
@@ -346,7 +348,7 @@ def load_theme_preview(self):
346348
try:
347349
theme_preview = Image.open(MAIN_DIRECTORY / "res" / "themes" / self.theme_cb.get() / "preview.png")
348350

349-
if theme_data and theme_data['display'].get("DISPLAY_SIZE", '3.5"') == SIZE_2_1_INCH:
351+
if theme_data and theme_data['display'].get("DISPLAY_SIZE", '3.5"') == _SIZE_2_1_INCH:
350352
# This is a circular screen: apply a circle mask over the preview
351353
theme_preview.paste(circular_mask, mask=circular_mask)
352354
except:
@@ -414,7 +416,10 @@ def load_config_values(self):
414416

415417
# Guess display size from theme in the configuration
416418
size = get_theme_size(self.config['config']['THEME'])
417-
size = size.replace(SIZE_2_1_INCH, SIZE_2_x_INCH) # If a theme is for 2.1" then it also is for 2.8"
419+
size = size.replace(_SIZE_2_1_INCH, SIZE_2_x_INCH) # If a theme is for 2.1" then it is for all 2.x"
420+
size = size.replace(_SIZE_2_8_INCH, SIZE_2_x_INCH) # If a theme is for 2.8" then it is for all 2.x"
421+
size = size.replace(_SIZE_9_2_INCH,
422+
SIZE_8_8_INCH_NEWREV) # If a theme is for 9.2" then it is for 8.8"/9.2" (new rev)
418423
try:
419424
if size == SIZE_8_8_INCH and self.config['display']['REVISION'] == 'TUR_USB':
420425
size = SIZE_8_8_INCH_NEWREV
@@ -501,12 +506,12 @@ def on_weatherping_click(self):
501506
self.more_config_window.show()
502507

503508
def on_open_theme_folder_click(self):
504-
#path = f'"{MAIN_DIRECTORY}res/themes"'
505-
#if platform.system() == "Windows":
509+
# path = f'"{MAIN_DIRECTORY}res/themes"'
510+
# if platform.system() == "Windows":
506511
# os.startfile(path)
507-
#elif platform.system() == "Darwin":
512+
# elif platform.system() == "Darwin":
508513
# subprocess.Popen(["open", path])
509-
#else:
514+
# else:
510515
# subprocess.Popen(["xdg-open", path])
511516
path = MAIN_DIRECTORY / "res/themes"
512517

@@ -517,7 +522,6 @@ def on_open_theme_folder_click(self):
517522
else:
518523
subprocess.Popen(["xdg-open", str(path)])
519524

520-
521525
def on_theme_editor_click(self):
522526
theme_editor = next(MAIN_DIRECTORY.glob("theme-editor.*"))
523527

@@ -526,7 +530,6 @@ def on_theme_editor_click(self):
526530
else:
527531
subprocess.Popen([str(theme_editor), self.theme_cb.get()])
528532

529-
530533
def on_save_click(self):
531534
self.save_config_values()
532535

@@ -538,7 +541,7 @@ def on_saverun_click(self):
538541
subprocess.Popen([str(main_file)], shell=True)
539542
else:
540543
subprocess.Popen([str(main_file)])
541-
544+
542545
self.window.destroy()
543546

544547
def on_brightness_change(self, e=None):
@@ -561,9 +564,18 @@ def on_model_change(self, e=None):
561564

562565
def on_size_change(self, e=None):
563566
size = self.size_cb.get()
564-
size = size.replace(SIZE_2_x_INCH, SIZE_2_1_INCH) # For '2.1" / 2.8"' size, keep '2.1"' as size to get themes for
565-
size = size.replace(SIZE_8_8_INCH_NEWREV, SIZE_8_8_INCH)
566-
themes = get_themes(size)
567+
568+
# For '2.1" / 2.8"' size, search for themes of both sizes
569+
if size == SIZE_2_x_INCH:
570+
themes = get_themes(_SIZE_2_1_INCH)
571+
themes += get_themes(_SIZE_2_8_INCH)
572+
# For 8.8" & 9.2" sizes, search for themes of both sizes
573+
elif size == SIZE_8_8_INCH_NEWREV or size == SIZE_8_8_INCH:
574+
themes = get_themes(SIZE_8_8_INCH)
575+
themes += get_themes(_SIZE_9_2_INCH)
576+
else:
577+
themes = get_themes(size)
578+
567579
self.theme_cb.config(values=themes)
568580

569581
if not self.theme_cb.get() in themes:
@@ -682,9 +694,10 @@ def __init__(self, main_window: TuringConfigWindow):
682694
self.citysearch1_label = ttk.Label(self.window, text='Location search', font='bold')
683695
self.citysearch1_label.place(x=80, y=370)
684696

685-
self.citysearch2_label = ttk.Label(self.window, text="Enter location to automatically get coordinates (latitude/longitude).\n"
686-
"For example \"Berlin\" \"London, GB\", \"London, Quebec\".\n"
687-
"Remember to set valid API key and pick language first!")
697+
self.citysearch2_label = ttk.Label(self.window,
698+
text="Enter location to automatically get coordinates (latitude/longitude).\n"
699+
"For example \"Berlin\" \"London, GB\", \"London, Quebec\".\n"
700+
"Remember to set valid API key and pick language first!")
688701
self.citysearch2_label.place(x=10, y=396)
689702

690703
self.citysearch3_label = ttk.Label(self.window, text="Enter location")
@@ -698,7 +711,8 @@ def __init__(self, main_window: TuringConfigWindow):
698711
self.citysearch4_label.place(x=10, y=540)
699712
self.citysearch_cb = ttk.Combobox(self.window, values=[], state='readonly')
700713
self.citysearch_cb.place(x=140, y=544, width=360)
701-
self.citysearch_btn2 = ttk.Button(self.window, text="Fill in lat/long", command=lambda: self.on_filllatlong_click())
714+
self.citysearch_btn2 = ttk.Button(self.window, text="Fill in lat/long",
715+
command=lambda: self.on_filllatlong_click())
702716
self.citysearch_btn2.place(x=520, y=540, height=40, width=130)
703717

704718
self.citysearch_warn_label = ttk.Label(self.window, text="")
@@ -759,10 +773,10 @@ def load_config_values(self, config):
759773
self.lang_cb.set(weather_lang_map[self.config['config']['WEATHER_LANGUAGE']])
760774
except:
761775
self.lang_cb.set(weather_lang_map["en"])
762-
776+
763777
def citysearch_show_warning(self, warning):
764778
self.citysearch_warn_label.config(text=warning)
765-
779+
766780
def on_search_click(self):
767781
OPENWEATHER_GEOAPI_URL = "http://api.openweathermap.org/geo/1.0/direct"
768782
api_key = self.api_entry.get()
@@ -774,8 +788,8 @@ def on_search_click(self):
774788
return
775789

776790
try:
777-
request = requests.get(OPENWEATHER_GEOAPI_URL, timeout=5, params={"appid": api_key, "lang": lang,
778-
"q": city, "limit": 10})
791+
request = requests.get(OPENWEATHER_GEOAPI_URL, timeout=5, params={"appid": api_key, "lang": lang,
792+
"q": city, "limit": 10})
779793
except:
780794
self.citysearch_show_warning("Error fetching OpenWeatherMap Geo API")
781795
return
@@ -786,7 +800,7 @@ def on_search_click(self):
786800
elif request.status_code != 200:
787801
self.citysearch_show_warning(f"Error #{request.status_code} fetching OpenWeatherMap Geo API.")
788802
return
789-
803+
790804
self._city_entries = []
791805
cb_entries = []
792806
for entry in request.json():
@@ -803,7 +817,7 @@ def on_search_click(self):
803817
self._city_entries.append({"full_name": full_name, "lat": str(lat), "long": str(long)})
804818
cb_entries.append(full_name)
805819

806-
self.citysearch_cb.config(values = cb_entries)
820+
self.citysearch_cb.config(values=cb_entries)
807821
if len(cb_entries) == 0:
808822
self.citysearch_show_warning("No given city found.")
809823
else:

0 commit comments

Comments
 (0)