View Single Post
Old 09-14-2023, 09:51 AM   #204
Nicolas F
Groupie
Nicolas F once ate a cherry pie in a record 7 seconds.Nicolas F once ate a cherry pie in a record 7 seconds.Nicolas F once ate a cherry pie in a record 7 seconds.Nicolas F once ate a cherry pie in a record 7 seconds.Nicolas F once ate a cherry pie in a record 7 seconds.Nicolas F once ate a cherry pie in a record 7 seconds.Nicolas F once ate a cherry pie in a record 7 seconds.Nicolas F once ate a cherry pie in a record 7 seconds.Nicolas F once ate a cherry pie in a record 7 seconds.Nicolas F once ate a cherry pie in a record 7 seconds.Nicolas F once ate a cherry pie in a record 7 seconds.
 
Posts: 161
Karma: 1842
Join Date: Jan 2016
Device: Kobo Glo HD
Quote:
Originally Posted by thiago.eec View Post
If I'm not mistaken, this is how calibre choose an icon:

1) Look for user overrides in '../resources/images/Plugin name'
2) Look for themed versions (for-dark-theme / for-light-theme)
3) Look in the theme package
4) Use the plugin zipped image

But, most of the plugins I checked, have their on implementation of a get_icon() function, created by @kiwidude. This was created back when calibre couldn't handle this.

The point is: calibre changed but many plugins still uses the old scheme. Some plugin developers updated their function, like you mentioned (@JimmXinu and @kiwidude, for example).

Also, I don't see anyone looking for themed icons (maybe I missed some). I implemented this for my plugins.

This is my calibre 6+ get_icon() function:
Spoiler:
Code:
def get_icon(icon_name):
    # Check to see whether the icon exists as a Calibre resource
    # This will enable skinning if the user stores icons within a folder like:
    # ...\AppData\Roaming\calibre\resources\images\Plugin Name\

    # General icons (..\resources\images\)
    general_icons = ['dialog_warning.png', 'marked.png']

    if icon_name not in general_icons:
        icon_name = 'images/' + icon_name

    # First, look for the themed icon (Qt resource files)
    tc = 'dark' if is_dark_theme() else 'light'
    sq, ext = os.path.splitext(icon_name)
    sq = f'{sq}-for-{tc}-theme{ext}'  # Yet to be implemented by theme creators, but...
    icon = QIcon.ic(PLUGIN_NAME + '/' + sq.replace('images/', ''))
    if icon.isNull():
        # Then, look for the regular icon (..\resources\images\Plugin Name\)
        sq, ext = os.path.splitext(icon_name)
        if 'help' not in icon_name:  # There is only one help icon
            sq = f'{sq}_{tc}{ext}'
        else:
            sq = icon_name
        icon = QIcon.ic(PLUGIN_NAME + '/' + sq.replace('images/', ''))
        if icon.isNull():
            # Then, look for it on general icons (Qt resource files)
            if not sq.startswith('images/'):  # Image does not come with the zip file
                return QIcon.ic(icon_name)
        else:
            return icon
    else:
        return icon

    # As we did not find an icon elsewhere, look within our zip resources
    return get_icons(sq)

This function also deals with themed icons inside the zip file. I always create two set of icons, to work with light and dark theme.

P.S.: 'Check books' and 'Reading goal' are examples of plugins that can handle themed versions.
Thank you for replying.

It works with your plugin with the for-dark-theme / for-light-theme like I was thinking.

I made the highlight theme a few years ago with icons for a majority of the plugins at the time and I wanted to update it to be compatible with light and dark themes
Nicolas F is offline   Reply With Quote