From 314ff7328003a5d0982283305a20c7d5122c7bfd Mon Sep 17 00:00:00 2001 From: Jim Miller Date: Wed, 20 Jul 2022 13:33:26 -0500 Subject: [PATCH] Use Cal6 get_icons() so icon themes apply--print_tracebacks_for_missing_resources=False cal 6.2+. --- calibre-plugin/common_utils.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/calibre-plugin/common_utils.py b/calibre-plugin/common_utils.py index 73da7481..f510a37c 100644 --- a/calibre-plugin/common_utils.py +++ b/calibre-plugin/common_utils.py @@ -41,16 +41,33 @@ def set_plugin_icon_resources(name, resources): plugin_name = name plugin_icon_resources = resources +# print_tracebacks_for_missing_resources first appears in cal 6.2.0 +if calibre_version >= (6,2,0): + def get_icons_nolog(icon_name,plugin_name): + return get_icons(icon_name, + plugin_name, + print_tracebacks_for_missing_resources=False) +else: + get_icons_nolog = get_icons def get_icon_6plus(icon_name): ''' - Retrieve a QIcon for the named image from the zip file if it exists, - or if not then from Calibre's image cache. + Retrieve a QIcon for the named image from + 1. Calibre's image cache + 2. resources/images + 3. the icon theme + 4. the plugin zip + Only plugin zip has images/ in the image name for backward + compatibility. ''' if icon_name: - ## look in theme 1st, plugin zip 2nd - ## both .ic and get_icons return an empty QIcon if not found. icon = QIcon.ic(icon_name) + ## both .ic and get_icons return an empty QIcon if not found. + if not icon or icon.isNull(): + # don't need a tracestack from get_icons just because + # there's no icon in the theme + icon = get_icons_nolog(icon_name.replace('images/',''), + plugin_name) if not icon or icon.isNull(): icon = get_icons(icon_name,plugin_name) return icon @@ -69,6 +86,7 @@ def get_icon_old(icon_name): return QIcon(pixmap) return QIcon() +# get_icons changed in Cal6. if calibre_version >= (6,0,0): get_icon = get_icon_6plus else: