[gnome-music/wip/cdavis/dark-style-opt-in: 3/5] artstack: Reload default icon when dark style pref changes




commit a9538b539a0ff4429b753b4d32a37703b60d20ef
Author: Christopher Davis <christopherdavis gnome org>
Date:   Sat Nov 27 18:50:13 2021 -0800

    artstack: Reload default icon when dark style pref changes

 gnomemusic/defaulticon.py      | 24 +++++++++++++++---------
 gnomemusic/widgets/artstack.py | 14 +++++++++++++-
 2 files changed, 28 insertions(+), 10 deletions(-)
---
diff --git a/gnomemusic/defaulticon.py b/gnomemusic/defaulticon.py
index 95def3e62..6e4d04a25 100644
--- a/gnomemusic/defaulticon.py
+++ b/gnomemusic/defaulticon.py
@@ -34,7 +34,7 @@ from gnomemusic.utils import ArtSize
 
 def make_icon_frame(
         icon_surface, art_size=None, scale=1, default_icon=False,
-        round_shape=False):
+        round_shape=False, dark=False):
     """Create an Art frame, square or round.
 
     :param cairo.Surface icon_surface: The surface to use
@@ -78,7 +78,7 @@ def make_icon_frame(
 
     fill_color = Gdk.RGBA(1.0, 1.0, 1.0, 1.0)
     icon_color = Gdk.RGBA(0.0, 0.0, 0.0, 0.3)
-    if Handy.StyleManager.get_default().props.dark:
+    if dark:
         fill_color = Gdk.RGBA(66.0 / 255, 66.0 / 255, 66.0 / 255, 1.0)
         icon_color = Gdk.RGBA(1.0, 1.0, 1.0, 1.0)
 
@@ -105,20 +105,22 @@ class DefaultIcon(GObject.GObject):
         ARTIST = "avatar-default-symbolic"
 
     _cache: Dict[
-        Tuple["DefaultIcon.Type", ArtSize, int, bool], cairo.Surface] = {}
+        Tuple[
+            "DefaultIcon.Type", ArtSize, int, bool, bool], cairo.Surface] = {}
 
     _default_theme = Gtk.IconTheme.get_default()
 
     def __init__(self):
         super().__init__()
 
-    def _make_default_icon(self, icon_type, art_size, scale, round_shape):
+    def _make_default_icon(
+            self, icon_type, art_size, scale, round_shape, dark):
         icon_info = self._default_theme.lookup_icon_for_scale(
             icon_type.value, art_size.width / 3, scale, 0)
         icon = icon_info.load_surface()
 
         icon_surface = make_icon_frame(
-            icon, art_size, scale, True, round_shape=round_shape)
+            icon, art_size, scale, True, round_shape=round_shape, dark=dark)
 
         return icon_surface
 
@@ -140,9 +142,13 @@ class DefaultIcon(GObject.GObject):
         else:
             round_shape = True
 
-        if (icon_type, art_size, scale, round_shape) not in self._cache.keys():
+        dark = Handy.StyleManager.get_default().props.dark
+
+        if (icon_type, art_size,
+                scale, round_shape, dark) not in self._cache.keys():
             new_icon = self._make_default_icon(
-                icon_type, art_size, scale, round_shape)
-            self._cache[(icon_type, art_size, scale, round_shape)] = new_icon
+                icon_type, art_size, scale, round_shape, dark)
+            self._cache[
+                (icon_type, art_size, scale, round_shape, dark)] = new_icon
 
-        return self._cache[(icon_type, art_size, scale, round_shape)]
+        return self._cache[(icon_type, art_size, scale, round_shape, dark)]
diff --git a/gnomemusic/widgets/artstack.py b/gnomemusic/widgets/artstack.py
index d0a72e504..6d1e69ee6 100644
--- a/gnomemusic/widgets/artstack.py
+++ b/gnomemusic/widgets/artstack.py
@@ -22,7 +22,7 @@
 # code, but you are not obligated to do so.  If you do not wish to do so,
 # delete this exception statement from your version.
 
-from gi.repository import GObject, Gtk
+from gi.repository import GObject, Gtk, Handy
 
 from gnomemusic.asyncqueue import AsyncQueue
 from gnomemusic.artcache import ArtCache
@@ -69,6 +69,8 @@ class ArtStack(Gtk.Stack):
         self.props.visible_child_name = "A"
 
         self.connect("destroy", self._on_destroy)
+        Handy.StyleManager.get_default().connect(
+            "notify::dark", self._on_dark_changed, self)
 
     @GObject.Property(type=object, flags=GObject.ParamFlags.READWRITE)
     def size(self):
@@ -128,6 +130,16 @@ class ArtStack(Gtk.Stack):
         if self._coreobject.props.thumbnail is not None:
             self._on_thumbnail_changed(self._coreobject, None)
 
+    def _on_dark_changed(style_manager, pspec, data, self):
+        default_icon = DefaultIcon().get(
+            self._art_type, self._size, self.props.scale_factor)
+
+        if self.coreobject:
+            if self.coreobject.props.thumbnail == "generic":
+                self._on_cache_result(self, default_icon)
+        else:
+            self._on_cache_result(self, default_icon)
+
     def _on_thumbnail_changed(self, coreobject, uri):
         self._disconnect_cache()
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]