124124 "sk" : "Slovak" , "sl" : "Slovenian" , "sp" : "Spanish" , "sv" : "Swedish" , "th" : "Thai" , "tr" : "Turkish" ,
125125 "ua" : "Ukrainian" , "vi" : "Vietnamese" , "zu" : "Zulu" }
126126
127- MAIN_DIRECTORY = str ( Path (__file__ ).parent . resolve ()) + "/"
128- THEMES_DIR = MAIN_DIRECTORY + ' res/themes'
127+ MAIN_DIRECTORY = Path (__file__ ).resolve (). parent
128+ THEMES_DIR = MAIN_DIRECTORY / " res/themes"
129129
130- circular_mask = Image .open (MAIN_DIRECTORY + "res/backgrounds/circular-mask.png" )
130+
131+ circular_mask = Image .open (MAIN_DIRECTORY / "res/backgrounds/circular-mask.png" )
131132
132133def get_theme_data (name : str ):
133- dir = os .path .join (THEMES_DIR , name )
134+ dir = THEMES_DIR / name
135+
134136 # checking if it is a directory
135- if os .path .isdir (dir ):
136- # Check if a theme.yaml file exists
137- theme = os .path .join (dir , 'theme.yaml' )
138- if os .path .isfile (theme ):
139- # Get display size from theme.yaml
140- with open (theme , "rt" , encoding = 'utf8' ) as stream :
137+ if dir .is_dir ():
138+ theme = dir / "theme.yaml"
139+ if theme .is_file ():
140+ with open (theme , "rt" , encoding = "utf8" ) as stream :
141141 theme_data , ind , bsi = ruamel .yaml .util .load_yaml_guess_indent (stream )
142142 return theme_data
143143 return None
@@ -189,8 +189,7 @@ def __init__(self):
189189 self .window = Tk ()
190190 self .window .title ('Turing System Monitor configuration' )
191191 self .window .geometry ("820x580" )
192- self .window .iconphoto (True , PhotoImage (file = MAIN_DIRECTORY + "res/icons/monitor-icon-17865/64.png" ))
193- # When window gets focus again, reload theme preview in case it has been updated by theme editor
192+ 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
194193 self .window .bind ("<FocusIn>" , self .on_theme_change )
195194 self .window .after (0 , self .on_fan_speed_update )
196195
@@ -313,14 +312,17 @@ def run(self):
313312 def load_theme_preview (self ):
314313 theme_data = get_theme_data (self .theme_cb .get ())
315314
315+ if theme_data and theme_data ['display' ].get ("DISPLAY_SIZE" , '3.5"' ) == SIZE_2_1_INCH :
316+ theme_preview .paste (circular_mask , mask = circular_mask )
317+
316318 try :
317- theme_preview = Image .open (MAIN_DIRECTORY + "res/ themes/" + self .theme_cb .get () + "/ preview.png" )
319+ theme_preview = Image .open (MAIN_DIRECTORY / "res" / " themes" / self .theme_cb .get () / " preview.png" )
318320
319321 if theme_data ['display' ].get ("DISPLAY_SIZE" , '3.5"' ) == SIZE_2_1_INCH :
320322 # This is a circular screen: apply a circle mask over the preview
321323 theme_preview .paste (circular_mask , mask = circular_mask )
322324 except :
323- theme_preview = Image .open (MAIN_DIRECTORY + "res/docs/no-preview.png" )
325+ theme_preview = Image .open (MAIN_DIRECTORY / "res/docs/no-preview.png" )
324326 finally :
325327 theme_preview .thumbnail ((320 , 480 ), Image .Resampling .LANCZOS )
326328 self .theme_preview_img = ImageTk .PhotoImage (theme_preview )
@@ -338,7 +340,7 @@ def load_theme_preview(self):
338340 self .theme_author .place (x = 10 , y = self .theme_preview_img .height () + 15 )
339341
340342 def load_config_values (self ):
341- with open (MAIN_DIRECTORY + "config.yaml" , "rt" , encoding = 'utf8' ) as stream :
343+ with open (MAIN_DIRECTORY / "config.yaml" , "rt" , encoding = 'utf8' ) as stream :
342344 self .config , ind , bsi = ruamel .yaml .util .load_yaml_guess_indent (stream )
343345
344346 # Check if theme is valid
@@ -450,7 +452,7 @@ def save_config_values(self):
450452 self .config ['display' ]['DISPLAY_REVERSE' ] = [k for k , v in reverse_map .items () if v == self .orient_cb .get ()][0 ]
451453 self .config ['display' ]['BRIGHTNESS' ] = int (self .brightness_slider .get ())
452454
453- with open (MAIN_DIRECTORY + "config.yaml" , "w" , encoding = 'utf-8' ) as file :
455+ with open (MAIN_DIRECTORY / "config.yaml" , "w" , encoding = 'utf-8' ) as file :
454456 ruamel .yaml .YAML ().dump (self .config , file )
455457
456458 def save_additional_config (self , ping : str , api_key : str , lat : str , long : str , unit : str , lang : str ):
@@ -461,7 +463,7 @@ def save_additional_config(self, ping: str, api_key: str, lat: str, long: str, u
461463 self .config ['config' ]['WEATHER_UNITS' ] = unit
462464 self .config ['config' ]['WEATHER_LANGUAGE' ] = lang
463465
464- with open (MAIN_DIRECTORY + "config.yaml" , "w" , encoding = 'utf-8' ) as file :
466+ with open (MAIN_DIRECTORY / "config.yaml" , "w" , encoding = 'utf-8' ) as file :
465467 ruamel .yaml .YAML ().dump (self .config , file )
466468
467469 def on_theme_change (self , e = None ):
@@ -471,25 +473,44 @@ def on_weatherping_click(self):
471473 self .more_config_window .show ()
472474
473475 def on_open_theme_folder_click (self ):
474- path = f'"{ MAIN_DIRECTORY } res/themes"'
476+ #path = f'"{MAIN_DIRECTORY}res/themes"'
477+ #if platform.system() == "Windows":
478+ # os.startfile(path)
479+ #elif platform.system() == "Darwin":
480+ # subprocess.Popen(["open", path])
481+ #else:
482+ # subprocess.Popen(["xdg-open", path])
483+ path = MAIN_DIRECTORY / "res/themes"
484+
475485 if platform .system () == "Windows" :
476486 os .startfile (path )
477487 elif platform .system () == "Darwin" :
478- subprocess .Popen (["open" , path ])
488+ subprocess .Popen (["open" , str ( path ) ])
479489 else :
480- subprocess .Popen (["xdg-open" , path ])
490+ subprocess .Popen (["xdg-open" , str (path )])
491+
481492
482493 def on_theme_editor_click (self ):
483- subprocess .Popen (
484- f'"{ MAIN_DIRECTORY } { glob .glob ("theme-editor.*" , root_dir = MAIN_DIRECTORY )[0 ]} " "{ self .theme_cb .get ()} "' ,
485- shell = True )
494+ theme_editor = next (MAIN_DIRECTORY .glob ("theme-editor.*" ))
495+
496+ if platform .system () == "Windows" :
497+ subprocess .Popen ([str (theme_editor ), self .theme_cb .get ()], shell = True )
498+ else :
499+ subprocess .Popen ([str (theme_editor ), self .theme_cb .get ()])
500+
486501
487502 def on_save_click (self ):
488503 self .save_config_values ()
489504
490505 def on_saverun_click (self ):
491506 self .save_config_values ()
492- subprocess .Popen (f'"{ MAIN_DIRECTORY } { glob .glob ("main.*" , root_dir = MAIN_DIRECTORY )[0 ]} "' , shell = True )
507+ main_file = next (MAIN_DIRECTORY .glob ("main.*" ))
508+
509+ if platform .system () == "Windows" :
510+ subprocess .Popen ([str (main_file )], shell = True )
511+ else :
512+ subprocess .Popen ([str (main_file )])
513+
493514 self .window .destroy ()
494515
495516 def on_brightness_change (self , e = None ):
0 commit comments