|
Update to include light/dark theme custom icons
Hi DiapDealer,
Thanks for the considered response — your concern about backwards compatibility is completely valid, and I want to address it directly.
I've put together a patch that adds light/dark theme-aware icon support while maintaining compatibility with Qt4, Qt5, and Qt6. The changes are confined to two files: utilities.py and action.py, both attached.
Here's what was changed and why it's safe:
utilities.py
- QApplication and QPalette are added to the existing import block, which already has PyQt4 → PyQt5 → qt.core fallbacks, so no minimum version change is introduced
- A new is_dark_theme() function detects the current theme using QPalette. It tries the Qt6 enum style (QPalette.ColorRole.Window) first, and falls back to the Qt5/Qt4 style (QPalette.Window) via AttributeError. If detection fails for any reason it silently returns False — no crash, no breakage
- get_pixmap() is updated to look for -for-light-theme and -for-dark-theme filename variants first, before falling back to the plain filename. This means the change is entirely opt-in — users without themed icons see zero behaviour change
action.py
- QApplication is added to the existing import block (same PyQt4 → PyQt5 → qt.core fallback chain)
- A paletteChanged signal connection is added so the toolbar icon updates live when the user switches themes. The connection is wrapped in try/except so if paletteChanged doesn't exist on an older Qt version it silently skips — the icon just won't update live, which is the same behaviour as today
The net result: on any calibre version that currently works, behaviour is identical unless the user explicitly places themed icon files in their resources/images/KindleUnpack - The Plugin/ folder. There is no minimum calibre version change.
I've tested this on calibre 9.8 on macOS, confirmed working for both light and dark mode on startup and live theme switching.
note - the folder for the custom icons is actually
'resources/images/KindleUnpack - The Plugin' and not just 'resources/images/KindleUnpack'
If you want to publish the patch so others can use it that would be great. Thank you for maintaining this plugin.
|