From 7b76aaeb6ee506793d205814796e54ff44c8be84 Mon Sep 17 00:00:00 2001 From: un-pogaz <46523284+un-pogaz@users.noreply.github.com> Date: Sun, 18 Jan 2026 16:05:26 +0100 Subject: [PATCH] Bookshelf: allow override colors theme --- src/calibre/gui2/__init__.py | 1 + src/calibre/gui2/library/bookshelf_view.py | 11 +++++++++- .../look_feel_tabs/bookshelf_view.py | 6 ++++++ .../look_feel_tabs/bookshelf_view.ui | 21 +++++++++++++++++-- 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index 070cb6a821..64a4f7faef 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -506,6 +506,7 @@ def create_defs(): defs['bookshelf_divider_text_right'] = False defs['bookshelf_start_with_divider'] = False defs['bookshelf_divider_style'] = 'text' + defs['bookshelf_theme_override'] = 'none' # Migrate beta bookshelf_thumbnail if isinstance(btv := gprefs.get('bookshelf_thumbnail'), bool): diff --git a/src/calibre/gui2/library/bookshelf_view.py b/src/calibre/gui2/library/bookshelf_view.py index 8f9335c996..ef4829b3ca 100644 --- a/src/calibre/gui2/library/bookshelf_view.py +++ b/src/calibre/gui2/library/bookshelf_view.py @@ -68,7 +68,7 @@ from xxhash import xxh3_64_intdigest from calibre import fit_image from calibre.db.cache import Cache from calibre.ebooks.metadata import authors_to_string, rating_to_stars -from calibre.gui2 import config, gprefs, is_dark_theme +from calibre.gui2 import config, gprefs from calibre.gui2.library.alternate_views import ( ClickStartData, double_click_action, @@ -230,6 +230,13 @@ class WoodTheme(NamedTuple): ) +def is_dark_theme(): + from calibre.gui2 import is_dark_theme + if gprefs['bookshelf_theme_override'] == 'none': + return is_dark_theme() + return gprefs['bookshelf_theme_override'] == 'dark' + + def color_with_alpha(c: QColor, a: int) -> QColor: ans = QColor(c) ans.setAlpha(a) @@ -1517,6 +1524,7 @@ class BookshelfView(MomentumScrollMixin, QAbstractScrollArea): '''Refresh the gui and render settings.''' self.template_inited = False self.calculate_shelf_geometry() + self.palette_changed() if hasattr(self, 'cover_cache'): self.cover_cache.set_thumbnail_size(*self.thumbnail_size()) self.cover_cache.set_disk_cache_max_size(gprefs['bookshelf_disk_cache_size']) @@ -1526,6 +1534,7 @@ class BookshelfView(MomentumScrollMixin, QAbstractScrollArea): def palette_changed(self): self.text_color_for_dark_background = dark_palette().color(QPalette.ColorRole.WindowText) self.text_color_for_light_background = light_palette().color(QPalette.ColorRole.WindowText) + self.setPalette(dark_palette() if is_dark_theme() else light_palette()) def view_is_visible(self) -> bool: '''Return if the bookshelf view is visible.''' diff --git a/src/calibre/gui2/preferences/look_feel_tabs/bookshelf_view.py b/src/calibre/gui2/preferences/look_feel_tabs/bookshelf_view.py index 4f2850c604..23067816c7 100644 --- a/src/calibre/gui2/preferences/look_feel_tabs/bookshelf_view.py +++ b/src/calibre/gui2/preferences/look_feel_tabs/bookshelf_view.py @@ -112,6 +112,12 @@ class BookshelfTab(QTabWidget, LazyConfigWidgetBase, Ui_Form): r('bookshelf_author_template', db.prefs) r('bookshelf_spine_size_template', db.prefs) + r('bookshelf_theme_override', gprefs, choices=[ + (_('Global setting'), 'none'), + (_('Light'), 'light'), + (_('Dark'), 'dark'), + ]) + self.config_cache.link( self.gui.bookshelf_view.cover_cache, 'bookshelf_disk_cache_size', 'bookshelf_cache_size_multiple', diff --git a/src/calibre/gui2/preferences/look_feel_tabs/bookshelf_view.ui b/src/calibre/gui2/preferences/look_feel_tabs/bookshelf_view.ui index 0a89a9e890..6f79452716 100644 --- a/src/calibre/gui2/preferences/look_feel_tabs/bookshelf_view.ui +++ b/src/calibre/gui2/preferences/look_feel_tabs/bookshelf_view.ui @@ -322,7 +322,24 @@ - + + + + Colors &theme: + + + opt_bookshelf_theme_override + + + + + + + Control which colors theme to use for the bookshelf view + + + + @@ -356,7 +373,7 @@ - + Qt::Vertical