[gnome-music/wip/mschraal/async-queue: 8/8] artstack: Load default icon faster




commit eab7ae681754bd89606ec43d96c075578cced9d3
Author: Marinus Schraal <mschraal gnome org>
Date:   Wed Aug 11 11:51:15 2021 +0200

    artstack: Load default icon faster
    
    Icon retrieval works by asynchronous lookup, the downside is that this
    process is too unreliable for default icons to show up in time in the
    views.
    
    Work around this by setting a default icon for the AlbumCover right
    away. For this add an art_type property and set it in AlbumCover, this
    is needed to differentiate between the different default icons for
    albums and artists.
    
    Related: #423

 gnomemusic/widgets/albumcover.py |  2 ++
 gnomemusic/widgets/artstack.py   | 30 ++++++++++++++++++++++++++++--
 2 files changed, 30 insertions(+), 2 deletions(-)
---
diff --git a/gnomemusic/widgets/albumcover.py b/gnomemusic/widgets/albumcover.py
index 59878ca2e..7afe00fa8 100644
--- a/gnomemusic/widgets/albumcover.py
+++ b/gnomemusic/widgets/albumcover.py
@@ -26,6 +26,7 @@ import gi
 gi.require_version('Grl', '0.3')
 from gi.repository import GObject, Gtk
 
+from gnomemusic.defaulticon import DefaultIcon
 from gnomemusic.corealbum import CoreAlbum
 from gnomemusic.utils import ArtSize
 from gnomemusic.widgets.twolinetip import TwoLineTip
@@ -82,6 +83,7 @@ class AlbumCover(Gtk.FlowBoxChild):
         self.connect('query-tooltip', self._on_tooltip_query)
 
         self._art_stack.props.size = ArtSize.MEDIUM
+        self._art_stack.props.arttype = DefaultIcon.Type.ALBUM
 
         self.show()
 
diff --git a/gnomemusic/widgets/artstack.py b/gnomemusic/widgets/artstack.py
index 5d0dda198..bce8294be 100644
--- a/gnomemusic/widgets/artstack.py
+++ b/gnomemusic/widgets/artstack.py
@@ -26,9 +26,9 @@ from gi.repository import GObject, Gtk
 
 from gnomemusic.asyncqueue import AsyncQueue
 from gnomemusic.artcache import ArtCache
+from gnomemusic.defaulticon import DefaultIcon
 from gnomemusic.utils import ArtSize
 
-
 class ArtStack(Gtk.Stack):
     """Provides a smooth transition between image states
 
@@ -41,13 +41,14 @@ class ArtStack(Gtk.Stack):
 
     _async_queue = AsyncQueue()
 
-    def __init__(self, size=ArtSize.MEDIUM):
+    def __init__(self, size: ArtSize = ArtSize.MEDIUM) -> None:
         """Initialize the ArtStack
 
         :param ArtSize size: The size of the art used for the cover
         """
         super().__init__()
 
+        self._art_type = DefaultIcon.Type.ALBUM
         self._cache = ArtCache()
         self._handler_id = 0
         self._size = size
@@ -85,6 +86,31 @@ class ArtStack(Gtk.Stack):
         self.set_size_request(value.width, value.height)
         self._size = value
 
+    @GObject.Property(
+        type=DefaultIcon.Type, flags=GObject.ParamFlags.READWRITE,
+        default=DefaultIcon.Type.ALBUM)
+    def art_type(self) -> DefaultIcon.Type:
+        """Type of the stack cover
+
+        :returns: The type of the default icon
+        :rtype: DefaultIcon.Type
+        """
+        return self._type
+
+    @arttype.setter  # type: ignore
+    def art_type(self, value: DefaultIcon.Type) -> None:
+        """Set the stack cover type
+
+        :param DefaultIcon.Type value: The default icon type for the
+            stack
+        """
+        self._type = value
+
+        default_icon = DefaultIcon().get(
+            self._type, self._size, self.props.scale_factor)
+
+        self._on_cache_result(None, default_icon)
+
     @GObject.Property(type=object, default=None)
     def coreobject(self):
         return self._coreobject


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