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




commit cf414f43177b512915f5dcebe41a609b4d5a44c5
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   | 29 ++++++++++++++++++++++++++++-
 2 files changed, 30 insertions(+), 1 deletion(-)
---
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..6ceeaf8c6 100644
--- a/gnomemusic/widgets/artstack.py
+++ b/gnomemusic/widgets/artstack.py
@@ -26,6 +26,7 @@ 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
 
 
@@ -41,13 +42,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 +87,31 @@ class ArtStack(Gtk.Stack):
         self.set_size_request(value.width, value.height)
         self._size = value
 
+    @GObject.Property(
+        type=object, 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
+
+    @art_type.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]