diff --git a/calibre-plugin/common_utils.py b/calibre-plugin/common_utils.py index f235f4a9..73da7481 100644 --- a/calibre-plugin/common_utils.py +++ b/calibre-plugin/common_utils.py @@ -15,6 +15,7 @@ from PyQt5.Qt import (QApplication, Qt, QIcon, QPixmap, QLabel, QDialog, QHBoxLa QVBoxLayout, QDialogButtonBox, QStyledItemDelegate, QDateTime, QTextEdit, QListWidget, QAbstractItemView, QCursor) +from calibre.constants import numeric_version as calibre_version from calibre.constants import iswindows, DEBUG from calibre.gui2 import UNDEFINED_QDATETIME, gprefs, info_dialog from calibre.gui2.actions import menu_action_unique_name @@ -41,7 +42,20 @@ def set_plugin_icon_resources(name, resources): plugin_icon_resources = resources -def get_icon(icon_name): +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. + ''' + 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) + if not icon or icon.isNull(): + icon = get_icons(icon_name,plugin_name) + return icon + +def get_icon_old(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. @@ -55,6 +69,10 @@ def get_icon(icon_name): return QIcon(pixmap) return QIcon() +if calibre_version >= (6,0,0): + get_icon = get_icon_6plus +else: + get_icon = get_icon_old def get_pixmap(icon_name): ''' diff --git a/calibre-plugin/fff_plugin.py b/calibre-plugin/fff_plugin.py index f013c7c5..83b8291d 100644 --- a/calibre-plugin/fff_plugin.py +++ b/calibre-plugin/fff_plugin.py @@ -164,16 +164,14 @@ class FanFicFarePlugin(InterfaceAction): base = self.interface_action_base_plugin self.version = base.name+" v%d.%d.%d"%base.version - # Set the icon for this interface action - # The get_icons function is a builtin function defined for all your - # plugin code. It loads icons from the plugin zip file. It returns - # QIcon objects, if you want the actual data, use the analogous - # get_resources builtin function. - - # Note that if you are loading more than one icon, for performance, you - # should pass a list of names to get_icons. In this case, get_icons - # will return a dictionary mapping names to QIcons. Names that - # are not found in the zip file will result in null QIcons. + # Set the icon for this interface action. + # We use our own get_icon, originally inherited from kiwidude, + # later extended to allow new cal6 theming of plugins. + # For theme creators, use: + # FanFicFare/images/icon.png + # (optionally) + # FanFicFare/images/icon-for-dark-theme.png + # FanFicFare/images/icon-for-light-theme.png icon = get_icon('images/icon.png') self.qaction.setText(_('FanFicFare'))