Skip to content

Commit 2b204d3

Browse files
Merge remote-tracking branch 'upstream/main'
2 parents 903b946 + c56020e commit 2b204d3

File tree

2 files changed

+46
-36
lines changed

2 files changed

+46
-36
lines changed

main-ui/themes/theme.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import sys
44
import traceback
5+
from turtle import color
56

67
from devices.charge.charge_status import ChargeStatus
78
from devices.device import Device
@@ -680,8 +681,11 @@ def text_color_selected(cls, font_purpose : FontPurpose):
680681
return cls.hex_to_color(cls._data["grid"]["selectedcolor"])
681682
case FontPurpose.LIST | FontPurpose.DESCRIPTIVE_LIST_TITLE | FontPurpose.DESCRIPTIVE_LIST_DESCRIPTION:
682683
if(cls._data.get("list") and cls._data.get("list").get("selectedcolor")):
683-
return cls.hex_to_color(cls._data.get("list").get("selectedcolor"))
684+
color = cls.hex_to_color(cls._data.get("list").get("selectedcolor"))
685+
#PyUiLogger.get_logger().error(f"list selected color is {color}")
686+
return color
684687
else:
688+
#PyUiLogger.get_logger().error(f"list selectedcolor not found, using grid")
685689
return cls.hex_to_color(cls._data["grid"]["selectedcolor"])
686690
case FontPurpose.MESSAGE:
687691
return cls.hex_to_color(cls._data["grid"]["selectedcolor"])
@@ -702,7 +706,7 @@ def text_color_selected(cls, font_purpose : FontPurpose):
702706
case _:
703707
return cls.hex_to_color(cls._data["grid"]["selectedcolor"])
704708
except Exception as e:
705-
#PyUiLogger.get_logger().error(f"text_color error occurred: {e}")
709+
PyUiLogger.get_logger().error(f"text_color error occurred: {e}")
706710
return cls.text_color(font_purpose)
707711

708712
@classmethod
@@ -995,7 +999,7 @@ def set_game_selection_view_type(cls, view_type):
995999

9961000
@classmethod
9971001
def get_main_menu_column_count(cls):
998-
return cls._data.get("mainMenuColCount", 4)
1002+
return cls._data.get("mainMenuColCount", int(4 * cls.width_multiplier))
9991003

10001004
@classmethod
10011005
def set_main_menu_column_count(cls, count):

main-ui/themes/theme_patcher.py

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)