2222# This file is the system monitor configuration GUI
2323
2424from library .pythoncheck import check_python_version
25+
2526check_python_version ()
2627
2728import glob
126127
127128circular_mask = Image .open (MAIN_DIRECTORY + "res/backgrounds/circular-mask.png" )
128129
130+
129131def get_theme_data (name : str ):
130132 folder = os .path .join (THEMES_DIR , name )
131133 # checking if it is a directory
@@ -187,7 +189,7 @@ def __init__(self):
187189 self .geometry ("820x580" )
188190 self .iconphoto (True , PhotoImage (file = MAIN_DIRECTORY + "res/icons/monitor-icon-17865/64.png" ))
189191 # When window gets focus again, reload theme preview in case it has been updated by theme editor
190- self .bind ("<FocusIn>" , lambda * _ :self .on_theme_change ())
192+ self .bind ("<FocusIn>" , lambda * _ : self .load_theme_preview ())
191193 self .after (0 , self .on_fan_speed_update )
192194
193195 # Subwindow for weather/ping config.
@@ -209,13 +211,13 @@ def __init__(self):
209211 self .model_label .place (x = 370 , y = 35 )
210212 self .model_cb = ttk .Combobox (self , values = list (dict .fromkeys ((revision_and_size_to_model_map .values ()))),
211213 state = 'readonly' )
212- self .model_cb .bind ('<<ComboboxSelected>>' , self .on_model_change )
214+ self .model_cb .bind ('<<ComboboxSelected>>' , lambda * _ : self .on_model_change () )
213215 self .model_cb .place (x = 550 , y = 30 , width = 250 )
214216
215217 self .size_label = ttk .Label (self , text = 'Smart screen size' )
216218 self .size_label .place (x = 370 , y = 75 )
217219 self .size_cb = ttk .Combobox (self , values = size_list , state = 'readonly' )
218- self .size_cb .bind ('<<ComboboxSelected>>' , lambda * _ :self .on_size_change ())
220+ self .size_cb .bind ('<<ComboboxSelected>>' , lambda * _ : self .on_size_change ())
219221 self .size_cb .place (x = 550 , y = 70 , width = 250 )
220222
221223 self .com_label = ttk .Label (self , text = 'COM port' )
@@ -232,7 +234,7 @@ def __init__(self):
232234 self .brightness_label = ttk .Label (self , text = 'Brightness' )
233235 self .brightness_label .place (x = 370 , y = 195 )
234236 self .brightness_slider = ttk .Scale (self , from_ = 0 , to = 100 , orient = HORIZONTAL ,
235- command = lambda * _ :self .on_brightness_change ())
237+ command = lambda * _ : self .on_brightness_change ())
236238 self .brightness_slider .place (x = 600 , y = 195 , width = 180 )
237239 self .brightness_val_label = ttk .Label (self , textvariable = self .brightness_string )
238240 self .brightness_val_label .place (x = 550 , y = 195 )
@@ -247,15 +249,15 @@ def __init__(self):
247249 self .theme_label .place (x = 370 , y = 300 )
248250 self .theme_cb = ttk .Combobox (self , state = 'readonly' )
249251 self .theme_cb .place (x = 550 , y = 295 , width = 250 )
250- self .theme_cb .bind ('<<ComboboxSelected>>' , lambda * _ :self .on_theme_change ())
252+ self .theme_cb .bind ('<<ComboboxSelected>>' , lambda * _ : self .load_theme_preview ())
251253
252254 self .hwlib_label = ttk .Label (self , text = 'Hardware monitoring' )
253255 self .hwlib_label .place (x = 370 , y = 340 )
254256 if sys .platform != "win32" :
255257 del hw_lib_map ["LHM" ] # LHM is for Windows platforms only
256258 self .hwlib_cb = ttk .Combobox (self , values = list (hw_lib_map .values ()), state = 'readonly' )
257259 self .hwlib_cb .place (x = 550 , y = 335 , width = 250 )
258- self .hwlib_cb .bind ('<<ComboboxSelected>>' , lambda * _ :self .on_hwlib_change ())
260+ self .hwlib_cb .bind ('<<ComboboxSelected>>' , lambda * _ : self .on_hwlib_change ())
259261
260262 self .eth_label = ttk .Label (self , text = 'Ethernet interface' )
261263 self .eth_label .place (x = 370 , y = 380 )
@@ -283,18 +285,17 @@ def __init__(self):
283285 "and run 'sudo sensors-detect' command, then reboot." )
284286
285287 self .weather_ping_btn = ttk .Button (self , text = "Weather & ping" ,
286- command = lambda : self .on_weatherping_click ())
288+ command = lambda : self .more_config_window . deiconify ())
287289 self .weather_ping_btn .place (x = 80 , y = 520 , height = 50 , width = 130 )
288290
289-
290291 self .open_theme_folder_btn = ttk .Button (self , text = "Open themes\n folder" ,
291- command = lambda : self .on_open_theme_folder_click ())
292+ command = lambda : self .on_open_theme_folder_click ())
292293 self .open_theme_folder_btn .place (x = 220 , y = 520 , height = 50 , width = 130 )
293294
294295 self .edit_theme_btn = ttk .Button (self , text = "Edit theme" , command = lambda : self .on_theme_editor_click ())
295296 self .edit_theme_btn .place (x = 360 , y = 520 , height = 50 , width = 130 )
296297
297- self .save_btn = ttk .Button (self , text = "Save settings" , command = lambda : self .on_save_click ())
298+ self .save_btn = ttk .Button (self , text = "Save settings" , command = lambda : self .save_config_values ())
298299 self .save_btn .place (x = 500 , y = 520 , height = 50 , width = 130 )
299300
300301 self .save_run_btn = ttk .Button (self , text = "Save and run" , command = lambda : self .on_saverun_click ())
@@ -380,7 +381,7 @@ def load_config_values(self):
380381
381382 # Guess display size from theme in the configuration
382383 size = get_theme_size (self .config ['config' ]['THEME' ])
383- 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"
384+ 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"
384385 try :
385386 self .size_cb .set (size )
386387 except :
@@ -414,7 +415,7 @@ def load_config_values(self):
414415 # Reload content on screen
415416 self .on_model_change ()
416417 self .on_size_change ()
417- self .on_theme_change ()
418+ self .load_theme_preview ()
418419 self .on_brightness_change ()
419420 self .on_hwlib_change ()
420421
@@ -458,12 +459,6 @@ def save_additional_config(self, ping: str, api_key: str, lat: str, long: str, u
458459 with open (MAIN_DIRECTORY + "config.yaml" , "w" , encoding = 'utf-8' ) as file :
459460 ruamel .yaml .YAML ().dump (self .config , file )
460461
461- def on_theme_change (self ):
462- self .load_theme_preview ()
463-
464- def on_weatherping_click (self ):
465- self .more_config_window .show ()
466-
467462 def on_open_theme_folder_click (self ):
468463 path = f'"{ MAIN_DIRECTORY } res/themes"'
469464 if platform .system () == "Windows" :
@@ -478,9 +473,6 @@ def on_theme_editor_click(self):
478473 f'"{ MAIN_DIRECTORY } { glob .glob ("theme-editor.*" , root_dir = MAIN_DIRECTORY )[0 ]} " "{ self .theme_cb .get ()} "' ,
479474 shell = True )
480475
481- def on_save_click (self ):
482- self .save_config_values ()
483-
484476 def on_saverun_click (self ):
485477 self .save_config_values ()
486478 subprocess .Popen (f'"{ MAIN_DIRECTORY } { glob .glob ("main.*" , root_dir = MAIN_DIRECTORY )[0 ]} "' , shell = True )
@@ -506,7 +498,8 @@ def on_model_change(self):
506498
507499 def on_size_change (self ):
508500 size = self .size_cb .get ()
509- 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
501+ size = size .replace (SIZE_2_x_INCH ,
502+ SIZE_2_1_INCH ) # For '2.1" / 2.8"' size, keep '2.1"' as size to get themes for
510503 themes = get_themes (size )
511504 self .theme_cb .config (values = themes )
512505
@@ -518,7 +511,7 @@ def on_size_change(self):
518511
519512 def on_hwlib_change (self ):
520513 hwlib = [k for k , v in hw_lib_map .items () if v == self .hwlib_cb .get ()][0 ]
521- if hwlib == "STUB" or hwlib == "STATIC" :
514+ if hwlib in [ "STUB" , "STATIC" ] :
522515 self .eth_cb .configure (state = "disabled" , foreground = "#C0C0C0" )
523516 self .wl_cb .configure (state = "disabled" , foreground = "#C0C0C0" )
524517 else :
@@ -626,9 +619,10 @@ def __init__(self, main_window: TuringConfigWindow):
626619 self .citysearch1_label = ttk .Label (self , text = 'Location search' , font = 'bold' )
627620 self .citysearch1_label .place (x = 80 , y = 370 )
628621
629- self .citysearch2_label = ttk .Label (self , text = "Enter location to automatically get coordinates (latitude/longitude).\n "
630- "For example \" Berlin\" \" London, GB\" , \" London, Quebec\" .\n "
631- "Remember to set valid API key and pick language first!" )
622+ self .citysearch2_label = ttk .Label (self ,
623+ text = "Enter location to automatically get coordinates (latitude/longitude).\n "
624+ "For example \" Berlin\" \" London, GB\" , \" London, Quebec\" .\n "
625+ "Remember to set valid API key and pick language first!" )
632626 self .citysearch2_label .place (x = 10 , y = 396 )
633627
634628 self .citysearch3_label = ttk .Label (self , text = "Enter location" )
@@ -652,7 +646,7 @@ def __init__(self, main_window: TuringConfigWindow):
652646 self .save_btn = ttk .Button (self , text = "Save settings" , command = lambda : self .on_save_click ())
653647 self .save_btn .place (x = 590 , y = 620 , height = 50 , width = 130 )
654648
655- self .protocol ("WM_DELETE_WINDOW" , self .on_closing )
649+ self .protocol ("WM_DELETE_WINDOW" , self .withdraw )
656650
657651 self ._city_entries = []
658652
@@ -665,12 +659,6 @@ def validateCoord(self, coord: str):
665659 return False
666660 return True
667661
668- def show (self ):
669- self .deiconify ()
670-
671- def on_closing (self ):
672- self .withdraw ()
673-
674662 def load_config_values (self , config ):
675663 self .config = config
676664
@@ -703,10 +691,10 @@ def load_config_values(self, config):
703691 self .lang_cb .set (weather_lang_map [self .config ['config' ]['WEATHER_LANGUAGE' ]])
704692 except :
705693 self .lang_cb .set (weather_lang_map ["en" ])
706-
694+
707695 def citysearch_show_warning (self , warning ):
708696 self .citysearch_warn_label .config (text = warning )
709-
697+
710698 def on_search_click (self ):
711699 OPENWEATHER_GEOAPI_URL = "http://api.openweathermap.org/geo/1.0/direct"
712700 api_key = self .api_entry .get ()
@@ -718,8 +706,8 @@ def on_search_click(self):
718706 return
719707
720708 try :
721- request = requests .get (OPENWEATHER_GEOAPI_URL , timeout = 5 , params = {"appid" : api_key , "lang" : lang ,
722- "q" : city , "limit" : 10 })
709+ request = requests .get (OPENWEATHER_GEOAPI_URL , timeout = 5 , params = {"appid" : api_key , "lang" : lang ,
710+ "q" : city , "limit" : 10 })
723711 except :
724712 self .citysearch_show_warning ("Error fetching OpenWeatherMap Geo API" )
725713 return
@@ -730,7 +718,7 @@ def on_search_click(self):
730718 elif request .status_code != 200 :
731719 self .citysearch_show_warning (f"Error #{ request .status_code } fetching OpenWeatherMap Geo API." )
732720 return
733-
721+
734722 self ._city_entries = []
735723 cb_entries = []
736724 for entry in request .json ():
@@ -747,7 +735,7 @@ def on_search_click(self):
747735 self ._city_entries .append ({"full_name" : full_name , "lat" : str (lat ), "long" : str (long )})
748736 cb_entries .append (full_name )
749737
750- self .citysearch_cb .config (values = cb_entries )
738+ self .citysearch_cb .config (values = cb_entries )
751739 if len (cb_entries ) == 0 :
752740 self .citysearch_show_warning ("No given city found." )
753741 else :
@@ -767,7 +755,7 @@ def on_filllatlong_click(self):
767755
768756 def on_save_click (self ):
769757 self .save_config_values ()
770- self .on_closing ()
758+ self .withdraw ()
771759
772760 def save_config_values (self ):
773761 ping = self .ping_entry .get ()
0 commit comments