View Single Post
Old 09-14-2023, 09:54 AM   #203
thiago.eec
Wizard
thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.
 
Posts: 1,308
Karma: 1436993
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite, Kindle Oasis
Quote:
Originally Posted by Nicolas F View Post
Hi,

if I understand this correctly I should be able to create an icon theme with light and dark versions for plugin icons too?

I'm on windows 10,
I tried to create icons in the "resources\images\Name of the plugin" folder but it works when I use icon.png but if I use icon-for-dark-theme.png or icon-for-light-theme.png the icon doesn't show up in calibre.

Even with @JimmXinu plugin's like EpubMerge which specifies in the version note "Use Cal6 get_icons() so icon themes apply" I can't get it to work.

What should I do concretely with the light and dark icons ?
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.

Last edited by thiago.eec; 09-14-2023 at 10:08 AM. Reason: add examples
thiago.eec is offline   Reply With Quote