[gnome-music/wip/cdavis/dark-style-opt-in: 20/20] artstack: Don't animate transition for dark mode




commit 3288ca39a5a051ff66073d49c5ccbf0c43c3c9ee
Author: Christopher Davis <christopherdavis gnome org>
Date:   Thu Dec 9 11:19:51 2021 -0800

    artstack: Don't animate transition for dark mode
    
    Special thanks to Alexander Mikhaylenko for figuring
    this bit out.

 gnomemusic/widgets/artstack.py | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)
---
diff --git a/gnomemusic/widgets/artstack.py b/gnomemusic/widgets/artstack.py
index 4c67612fa..7c21c4f97 100644
--- a/gnomemusic/widgets/artstack.py
+++ b/gnomemusic/widgets/artstack.py
@@ -80,8 +80,6 @@ class ArtStack(Gtk.Stack):
         self.add_named(self._cover_b, "B")
 
         self.props.size = size
-        self.props.transition_type = Gtk.StackTransitionType.CROSSFADE
-        self.props.visible_child_name = "A"
 
         self.connect("destroy", self._on_destroy)
         Handy.StyleManager.get_default().connect(
@@ -126,7 +124,7 @@ class ArtStack(Gtk.Stack):
         default_icon = DefaultIcon().get(
             self._art_type, self._size, self.props.scale_factor)
 
-        self._on_cache_result(None, default_icon)
+        self._swap_thumbnails(default_icon, False)
 
     @GObject.Property(type=object, default=None)
     def coreobject(self) -> Optional[CoreObject]:
@@ -153,9 +151,9 @@ class ArtStack(Gtk.Stack):
 
         if self.coreobject:
             if self.coreobject.props.thumbnail == "generic":
-                self._on_cache_result(self, default_icon)
+                self._swap_thumbnails(default_icon, False)
         else:
-            self._on_cache_result(self, default_icon)
+            self._swap_thumbnails(default_icon, False)
 
     def _on_thumbnail_changed(
             self, coreobject: CoreObject,
@@ -168,13 +166,24 @@ class ArtStack(Gtk.Stack):
         self._async_queue.queue(
             self._cache, coreobject, self._size, self.props.scale_factor)
 
-    def _on_cache_result(self, cache: ArtCache, surface: ImageSurface) -> None:
+    def _swap_thumbnails(self, surface: ImageSurface, animate: bool):
         if self.props.visible_child_name == "B":
             self._cover_a.props.surface = surface
-            self.props.visible_child_name = "A"
+            if animate:
+                self.set_visible_child_full("A",
+                                            Gtk.StackTransitionType.CROSSFADE)
+            else:
+                self.props.visible_child_name = "A"
         else:
             self._cover_b.props.surface = surface
-            self.props.visible_child_name = "B"
+            if animate:
+                self.set_visible_child_full("B",
+                                            Gtk.StackTransitionType.CROSSFADE)
+            else:
+                self.props.visible_child_name = "B"
+
+    def _on_cache_result(self, cache: ArtCache, surface: ImageSurface) -> None:
+        self._swap_thumbnails(surface, True)
 
     def _on_destroy(self, widget: ArtStack) -> None:
         # If the stack is destroyed while the art is updated, an error


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