@@ -11,7 +11,10 @@ class ThemePatcher():
1111 # Add properties you want to scale (case-sensitive)
1212 SCALABLE_KEYS = {"grid1x4" ,"grid3x4" ,"FontSize" ,"gameSelectImgWidth" ,"gameSelectImgHeight" ,"gridGameSelectImgWidth" ,
1313 "gridGameSelectImgHeight" ,"listGameSelectImgWidth" ,"listGameSelectImgHeight" ,"gridMultiRowSelBgResizePadWidth" ,
14- "gridMultiRowSelBgResizePadHeight" ,"gridMultiRowExtraYPad" , "topBarInitialXOffset" }
14+ "gridMultiRowSelBgResizePadHeight" ,"gridMultiRowExtraYPad" , "topBarInitialXOffset" ,"gridMultiRowImageYOffset" ,
15+ "singleRowGridTextYOffset" ,"multiRowGridTextYOffset" ,"carouselSystemExternalXPad" ,"carouselSystemXPad" ,
16+ "gridSystemImageYOffset" ,"gridSystemSelectImgWidth" ,"listSystemSelectImgWidth" ,"carouselSystemSelectPrimaryImgWidth" ,
17+ "gridSystemSelectImgHeight" ,"listSystemSelectImgHeight" }
1518
1619 @classmethod
1720 def convert_to_qoi (cls , path ):
@@ -104,10 +107,11 @@ def scale_theme(cls, config_path, theme_width, theme_height, target_width, targe
104107 ])
105108 Display .present ()
106109
107- cls .patch_folder (os .path .join (config_path ,"icons" ),
108- os .path .join (config_path ,f"icons_{ target_width } x{ target_height } " ),
109- scale ,
110- theme_width , theme_height , target_width , target_height )
110+ if (os .path .exists (os .path .join (config_path ,"icons" ))):
111+ cls .patch_folder (os .path .join (config_path ,"icons" ),
112+ os .path .join (config_path ,f"icons_{ target_width } x{ target_height } " ),
113+ scale ,
114+ theme_width , theme_height , target_width , target_height )
111115
112116 cls .scale_config_json (os .path .join (config_path ,"config.json" ),
113117 os .path .join (config_path ,f"config_{ target_width } x{ target_height } .json" ),
@@ -140,35 +144,37 @@ def patch_folder(cls, input_folder, output_folder, scale, theme_width, theme_hei
140144
141145 @staticmethod
142146 def scale_image (input_file , output_file , scale , theme_width , theme_height , target_width , target_height ):
143-
144- image_utils = Device .get_image_utils ()
145- try :
146- img_width ,img_height = image_utils .get_image_dimensions (input_file )
147- new_width = int (img_width * scale )
148- new_height = int (img_height * scale )
149- preserve_aspect_ratio = True
150-
151- if (img_width == theme_width and img_height != theme_height ):
152- new_width = target_width
153- preserve_aspect_ratio = False
154-
155- if (img_height == theme_height and img_width != theme_width ):
156- new_height = target_height
157- preserve_aspect_ratio = False
158-
159- image_utils .resize_image (input_file , output_file , new_width , new_height ,preserve_aspect_ratio = preserve_aspect_ratio )
160-
161- if not os .path .exists (output_file ):
162- # Means non image -- should this be raised as an error as part of resize?
163- shutil .copyfile (input_file , output_file )
164-
165- except Exception as e :
166- # Copy the file instead of scaling if something fails
147+ if os .path .exists (output_file ):
148+ PyUiLogger ().get_logger ().info (f"Scaled version of { output_file } already exists, skipping scaling." )
149+ else :
150+ image_utils = Device .get_image_utils ()
167151 try :
168- shutil .copyfile (input_file , output_file )
169- PyUiLogger ().get_logger ().warning (f"Scaling failed for { input_file } , copied original instead: { e } " )
170- except Exception as copy_err :
171- PyUiLogger ().get_logger ().exception (f"Failed to copy { input_file } to { output_file } : { copy_err } " )
152+ img_width ,img_height = image_utils .get_image_dimensions (input_file )
153+ new_width = int (img_width * scale )
154+ new_height = int (img_height * scale )
155+ preserve_aspect_ratio = True
156+
157+ if (img_width == theme_width and img_height != theme_height ):
158+ new_width = target_width
159+ preserve_aspect_ratio = False
160+
161+ if (img_height == theme_height and img_width != theme_width ):
162+ new_height = target_height
163+ preserve_aspect_ratio = False
164+
165+ image_utils .resize_image (input_file , output_file , new_width , new_height ,preserve_aspect_ratio = preserve_aspect_ratio )
166+
167+ if not os .path .exists (output_file ):
168+ # Means non image -- should this be raised as an error as part of resize?
169+ shutil .copyfile (input_file , output_file )
170+
171+ except Exception as e :
172+ # Copy the file instead of scaling if something fails
173+ try :
174+ shutil .copyfile (input_file , output_file )
175+ PyUiLogger ().get_logger ().warning (f"Scaling failed for { input_file } , copied original instead: { e } " )
176+ except Exception as copy_err :
177+ PyUiLogger ().get_logger ().exception (f"Failed to copy { input_file } to { output_file } : { copy_err } " )
172178
173179 @classmethod
174180 def scale_config_json (cls , config_path , output_config_path , scale ):
0 commit comments