From 598ffbd3407551d2df87bd780344e2a3ddb07cd8 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 31 Jan 2020 13:30:12 +1000 Subject: [PATCH] maintain separate icon cache for light and dark themes --- qt/aqt/theme.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/qt/aqt/theme.py b/qt/aqt/theme.py index 279ae8529..15fbf0cc4 100644 --- a/qt/aqt/theme.py +++ b/qt/aqt/theme.py @@ -15,7 +15,8 @@ from aqt.qt import QColor, QIcon, QPalette, QPixmap, QStyleFactory, Qt class ThemeManager: _night_mode_preference = False - _icon_cache: Dict[str, QIcon] = {} + _icon_cache_light: Dict[str, QIcon] = {} + _icon_cache_dark: Dict[str, QIcon] = {} _icon_size = 128 def macos_dark_mode(self) -> bool: @@ -31,7 +32,11 @@ class ThemeManager: def icon_from_resources(self, path: str) -> QIcon: "Fetch icon from Qt resources, and invert if in night mode." - icon = self._icon_cache.get(path) + if self.night_mode: + cache = self._icon_cache_light + else: + cache = self._icon_cache_dark + icon = cache.get(path) if icon: return icon @@ -42,7 +47,7 @@ class ThemeManager: img.invertPixels() icon = QIcon(QPixmap(img)) - return self._icon_cache.setdefault(path, icon) + return cache.setdefault(path, icon) def body_class(self) -> str: "Returns space-separated class list for platform/theme."