2525import tkinter .ttk as ttk
2626from tkinter import *
2727
28- import sv_ttk
2928import psutil
3029import ruamel .yaml
30+ import sv_ttk
3131from PIL import Image , ImageTk
3232from serial .tools .list_ports import comports
3333
3434# Maps between config.yaml values and GUI description
3535revision_map = {'A' : "Turing / rev. A" , 'B' : "XuanFang / rev. B / flagship" , 'SIMU' : "Simulated screen" }
36- hw_lib_map = {"AUTO" : "Automatic" , "LHM" : "LibreHardwareMonitor (Win .)" , "PYTHON" : "Python libraries (all OS) " ,
36+ hw_lib_map = {"AUTO" : "Automatic" , "LHM" : "LibreHardwareMonitor (admin .)" , "PYTHON" : "Python libraries" ,
3737 "STUB" : "Fake random data" , "STATIC" : "Fake static data" }
3838reverse_map = {False : "classic" , True : "reverse" }
3939
@@ -92,6 +92,8 @@ def __init__(self):
9292
9393 self .hwlib_label = ttk .Label (self .window , text = 'Hardware monitoring' )
9494 self .hwlib_label .place (x = 320 , y = 75 )
95+ if sys .platform != "win32" :
96+ del hw_lib_map ["LHM" ] # LHM is for Windows platforms only
9597 self .hwlib_cb = ttk .Combobox (self .window , values = list (hw_lib_map .values ()), state = 'readonly' )
9698 self .hwlib_cb .place (x = 500 , y = 70 , width = 210 )
9799 self .hwlib_cb .bind ('<<ComboboxSelected>>' , self .on_hwlib_change )
@@ -106,7 +108,9 @@ def __init__(self):
106108 self .wl_cb = ttk .Combobox (self .window , values = get_net_if (), state = 'readonly' )
107109 self .wl_cb .place (x = 500 , y = 150 , width = 210 )
108110
109- self .lhm_admin_warning = ttk .Label (self .window , text = "Admin rights needed, or select another Hardware monitoring" , foreground = '#00f' )
111+ self .lhm_admin_warning = ttk .Label (self .window ,
112+ text = "Admin rights needed, or select another Hardware monitoring" ,
113+ foreground = '#00f' )
110114 self .lhm_admin_warning .place (x = 320 , y = 190 )
111115
112116 sysmon_label = ttk .Label (self .window , text = 'Display configuration' , font = 'bold' )
@@ -136,7 +140,9 @@ def __init__(self):
136140 self .brightness_slider .place (x = 550 , y = 380 , width = 160 )
137141 self .brightness_val_label = ttk .Label (self .window , textvariable = self .brightness_string )
138142 self .brightness_val_label .place (x = 500 , y = 385 )
139- self .brightness_warning_label = ttk .Label (self .window , text = "⚠ Turing / rev. A displays can get hot at high brightness!" , foreground = '#f00' )
143+ self .brightness_warning_label = ttk .Label (self .window ,
144+ text = "⚠ Turing / rev. A displays can get hot at high brightness!" ,
145+ foreground = '#f00' )
140146 self .brightness_warning_label .place (x = 320 , y = 420 )
141147
142148 self .edit_theme_btn = ttk .Button (self .window , text = "Edit theme" , command = lambda : self .on_theme_editor_click ())
@@ -171,24 +177,55 @@ def load_config_values(self):
171177 with open ("config.yaml" , "rt" , encoding = 'utf8' ) as stream :
172178 self .config , ind , bsi = ruamel .yaml .util .load_yaml_guess_indent (stream )
173179
174- self .theme_cb .set (self .config ['config' ]['THEME' ])
180+ try :
181+ self .theme_cb .set (self .config ['config' ]['THEME' ])
182+ except :
183+ self .theme_cb .current (0 )
175184 self .load_theme_preview ()
176- self .hwlib_cb .set (hw_lib_map [self .config ['config' ]['HW_SENSORS' ]])
177- if self .config ['config' ]['ETH' ] == "" :
185+
186+ try :
187+ self .hwlib_cb .set (hw_lib_map [self .config ['config' ]['HW_SENSORS' ]])
188+ except :
189+ self .hwlib_cb .current (0 )
190+
191+ try :
192+ if self .config ['config' ]['ETH' ] == "" :
193+ self .eth_cb .current (0 )
194+ else :
195+ self .eth_cb .set (self .config ['config' ]['ETH' ])
196+ except :
178197 self .eth_cb .current (0 )
179- else :
180- self .eth_cb .set (self .config ['config' ]['ETH' ])
181- if self .config ['config' ]['WLO' ] == "" :
198+
199+ try :
200+ if self .config ['config' ]['WLO' ] == "" :
201+ self .wl_cb .current (0 )
202+ else :
203+ self .wl_cb .set (self .config ['config' ]['WLO' ])
204+ except :
182205 self .wl_cb .current (0 )
183- else :
184- self .wl_cb .set (self .config ['config' ]['WLO' ])
185- if self .config ['config' ]['COM_PORT' ] == "AUTO" :
206+
207+ try :
208+ if self .config ['config' ]['COM_PORT' ] == "AUTO" :
209+ self .com_cb .current (0 )
210+ else :
211+ self .com_cb .set (self .config ['config' ]['COM_PORT' ])
212+ except :
186213 self .com_cb .current (0 )
187- else :
188- self .com_cb .set (self .config ['config' ]['COM_PORT' ])
189- self .model_cb .set (revision_map [self .config ['display' ]['REVISION' ]])
190- self .orient_cb .set (reverse_map [self .config ['display' ]['DISPLAY_REVERSE' ]])
191- self .brightness_slider .set (int (self .config ['display' ]['BRIGHTNESS' ]))
214+
215+ try :
216+ self .model_cb .set (revision_map [self .config ['display' ]['REVISION' ]])
217+ except :
218+ self .model_cb .current (0 )
219+
220+ try :
221+ self .orient_cb .set (reverse_map [self .config ['display' ]['DISPLAY_REVERSE' ]])
222+ except :
223+ self .orient_cb .current (0 )
224+
225+ try :
226+ self .brightness_slider .set (int (self .config ['display' ]['BRIGHTNESS' ]))
227+ except :
228+ self .brightness_slider .set (50 )
192229
193230 # Reload content on screen
194231 self .on_model_change ()
@@ -266,7 +303,8 @@ def on_hwlib_change(self, e=None):
266303 self .lhm_admin_warning .place_forget ()
267304
268305 def show_hide_brightness_warning (self , e = None ):
269- if int (self .brightness_slider .get ()) > 50 and [k for k , v in revision_map .items () if v == self .model_cb .get ()][0 ] == "A" :
306+ if int (self .brightness_slider .get ()) > 50 and [k for k , v in revision_map .items () if v == self .model_cb .get ()][
307+ 0 ] == "A" :
270308 # Show warning for Turing Smart screen with high brightness
271309 self .brightness_warning_label .place (x = 320 , y = 420 )
272310 else :
0 commit comments