Skip to content

Commit ec0defe

Browse files
committed
Fallback to default themes icons for pyui icons if current theme is missing
1 parent 5902a26 commit ec0defe

File tree

2 files changed

+38
-7
lines changed

2 files changed

+38
-7
lines changed

main-ui/menus/app/app_menu.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,16 @@ def append_pyui_apps(self, app_list):
6464
boxart_scraper_config = PyUiAppConfig("Boxart Scraper")
6565
hidden = AppsManager.is_hidden(boxart_scraper_config) and not self.show_all_apps
6666
if(not hidden):
67+
icon = self.get_icon(None,"scraper.png")
68+
if(icon is None):
69+
icon = Theme.get_cfw_default_icon("scraper.png")
6770
app_list.append(
6871
GridOrListEntry(
6972
primary_text=boxart_scraper_config.get_label() + "(Hidden)" if AppsManager.is_hidden(boxart_scraper_config) else boxart_scraper_config.get_label(),
7073
image_path=None,
7174
image_path_selected=None,
7275
description="Scrape game boxart",
73-
icon=self.get_icon(None,"scraper.png"),
76+
icon=icon,
7477
extra_data=boxart_scraper_config,
7578
value=BoxArtScraper().scrape_boxart
7679
)

main-ui/themes/theme.py

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ def set_theme_path(cls,path, width = 0, height = 0):
4949
cls._load_from_file(os.path.join(path, config_path))
5050

5151
cls._path = path
52-
cls._skin_folder = cls._get_asset_folder("skin", width, height)
53-
cls._icon_folder = cls._get_asset_folder("icons", width, height)
52+
cls._skin_folder = cls._get_asset_folder(cls._path, "skin", width, height)
53+
cls._icon_folder = cls._get_asset_folder(cls._path, "icons", width, height)
5454
daijisho_theme_index_file = os.path.join(cls._path, cls._icon_folder,"index.json")
5555
if os.path.exists(daijisho_theme_index_file):
5656
try:
@@ -132,17 +132,17 @@ def load_defaults_so_user_can_see_at_least(cls, path):
132132
cls._load_from_file(os.path.join(path, "config.json"))
133133

134134
cls._path = path
135-
cls._skin_folder = cls._get_asset_folder("skin", -1, -1)
136-
cls._icon_folder = cls._get_asset_folder("icons", -1, -1)
135+
cls._skin_folder = cls._get_asset_folder(cls._path,"skin", -1, -1)
136+
cls._icon_folder = cls._get_asset_folder(cls._path,"icons", -1, -1)
137137

138138
@classmethod
139139
def get_theme_path(cls):
140140
return cls._path
141141

142142
@classmethod
143-
def _get_asset_folder(cls, base_folder, width, height):
143+
def _get_asset_folder(cls, path, base_folder, width, height):
144144
folder = f"{base_folder}_{width}x{height}"
145-
full_path = os.path.join(cls._path, folder)
145+
full_path = os.path.join(path, folder)
146146
if os.path.isdir(full_path):
147147
#PyUiLogger.get_logger().info(f"Resolution specific assets found, using {folder}")
148148
return folder
@@ -1508,3 +1508,31 @@ def check_and_create_ra_assets(cls):
15081508
1.00)
15091509

15101510

1511+
1512+
@classmethod
1513+
def get_cfw_default_icon(cls, icon_name):
1514+
cfw_theme = PyUiConfig.get("theme")
1515+
PyUiLogger.get_logger().debug(f"Getting CFW default icon '{icon_name}' for theme '{cfw_theme}'")
1516+
if(cfw_theme is None):
1517+
PyUiLogger.get_logger().debug(f"CFW theme is None, cannot get icon")
1518+
return None
1519+
else:
1520+
cfw_theme_path = os.path.join(PyUiConfig.get("themeDir"),cfw_theme)
1521+
PyUiLogger.get_logger().debug(f"cfw_theme_path is '{cfw_theme_path}'")
1522+
path = os.path.join(cfw_theme_path,
1523+
cls._get_asset_folder(cfw_theme_path, "icons",
1524+
Device.screen_width(),
1525+
Device.screen_height()),
1526+
"app",icon_name)
1527+
1528+
PyUiLogger.get_logger().debug(f"icon path resolved to '{path}'")
1529+
if os.path.exists(path):
1530+
return path
1531+
1532+
# Fallback only makes sense for .qoi assets/icons
1533+
if path.endswith(".qoi"):
1534+
png_path = path[:-4] + ".png"
1535+
if os.path.exists(png_path):
1536+
return png_path
1537+
1538+
return None

0 commit comments

Comments
 (0)