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




commit 0ffe3fc0fb26e4b22346b1fa36f02f87a4dc1b16
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 ArtStack in widgets right
    away. For this add an art_type property, the property is needed to
    differentiate between the different default icons for albums and
    artists.
    
    Related: #423

 gnomemusic/widgets/albumcover.py       |  2 ++
 gnomemusic/widgets/albumwidget.py      |  2 ++
 gnomemusic/widgets/artistsearchtile.py |  2 ++
 gnomemusic/widgets/artstack.py         | 27 ++++++++++++++++++++++++++-
 gnomemusic/widgets/playertoolbar.py    |  2 ++
 5 files changed, 34 insertions(+), 1 deletion(-)
---
diff --git a/gnomemusic/widgets/albumcover.py b/gnomemusic/widgets/albumcover.py
index 59878ca2e..ec51de65b 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.art_type = DefaultIcon.Type.ALBUM
 
         self.show()
 
diff --git a/gnomemusic/widgets/albumwidget.py b/gnomemusic/widgets/albumwidget.py
index f3933a740..1e657e884 100644
--- a/gnomemusic/widgets/albumwidget.py
+++ b/gnomemusic/widgets/albumwidget.py
@@ -30,6 +30,7 @@ import typing
 from gi.repository import Gfm, Gio, GLib, GObject, Gtk
 
 from gnomemusic.corealbum import CoreAlbum
+from gnomemusic.defaulticon import DefaultIcon
 from gnomemusic.utils import ArtSize
 from gnomemusic.widgets.disclistboxwidget import DiscBox
 from gnomemusic.widgets.disclistboxwidget import DiscListBox  # noqa: F401
@@ -80,6 +81,7 @@ class AlbumWidget(Gtk.Box):
         self._model_signal_id = 0
 
         self._art_stack.props.size = ArtSize.LARGE
+        self._art_stack.props.art_type = DefaultIcon.Type.ALBUM
         self._player = self._application.props.player
 
         self.bind_property(
diff --git a/gnomemusic/widgets/artistsearchtile.py b/gnomemusic/widgets/artistsearchtile.py
index 177ab948c..2eaad9725 100644
--- a/gnomemusic/widgets/artistsearchtile.py
+++ b/gnomemusic/widgets/artistsearchtile.py
@@ -25,6 +25,7 @@
 from gi.repository import Gdk, GObject, Gtk
 
 from gnomemusic.coreartist import CoreArtist
+from gnomemusic.defaulticon import DefaultIcon
 from gnomemusic.utils import ArtSize
 from gnomemusic.widgets.artstack import ArtStack  # noqa: F401
 from gnomemusic.widgets.twolinetip import TwoLineTip
@@ -61,6 +62,7 @@ class ArtistSearchTile(Gtk.FlowBoxChild):
         self.props.coreartist = coreartist
 
         self._art_stack.props.size = ArtSize.MEDIUM
+        self._art_stack.props.art_type = DefaultIcon.Type.ARTIST
         self._art_stack.props.coreobject = self.props.coreartist
 
         self._tooltip = TwoLineTip()
diff --git a/gnomemusic/widgets/artstack.py b/gnomemusic/widgets/artstack.py
index a75cad9b3..bba487901 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._coreobject = None
         self._handler_id = 0
@@ -86,6 +88,29 @@ class ArtStack(Gtk.Stack):
         self.set_size_request(value.width, value.height)
         self._size = value
 
+    @GObject.Property(type=object, flags=GObject.ParamFlags.READWRITE)
+    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
diff --git a/gnomemusic/widgets/playertoolbar.py b/gnomemusic/widgets/playertoolbar.py
index 94f61895a..5b98d0e5c 100644
--- a/gnomemusic/widgets/playertoolbar.py
+++ b/gnomemusic/widgets/playertoolbar.py
@@ -25,6 +25,7 @@
 from gettext import gettext as _
 from gi.repository import Gio, GLib, GObject, Gtk
 
+from gnomemusic.defaulticon import DefaultIcon
 from gnomemusic.gstplayer import Playback
 from gnomemusic.utils import ArtSize
 from gnomemusic.player import Player, RepeatMode
@@ -64,6 +65,7 @@ class PlayerToolbar(Gtk.ActionBar):
         self._player = None
 
         self._art_stack.props.size = ArtSize.SMALL
+        self._art_stack.props.art_type = DefaultIcon.Type.ALBUM
 
         self._tooltip = TwoLineTip()
 


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