[gnome-music/wip/mschraal/async-queue: 12/18] artstack: Rework ArtCache use




commit 5a7e17fbf8b76cefb96b31e4e0d61559bc7f207a
Author: Marinus Schraal <mschraal gnome org>
Date:   Mon Aug 9 15:48:34 2021 +0200

    artstack: Rework ArtCache use
    
    Make ArtCache ripe for AsyncQueue.

 gnomemusic/artcache.py         | 12 ++++++++----
 gnomemusic/widgets/artstack.py | 12 +++++-------
 2 files changed, 13 insertions(+), 11 deletions(-)
---
diff --git a/gnomemusic/artcache.py b/gnomemusic/artcache.py
index 70f17c52b..96d266ef9 100644
--- a/gnomemusic/artcache.py
+++ b/gnomemusic/artcache.py
@@ -159,21 +159,25 @@ class ArtCache(GObject.GObject):
 
     _log = MusicLogger()
 
-    def __init__(self, size, scale):
+    def __init__(self):
         super().__init__()
 
-        self._size = size
-        self._scale = scale
+        self._size = ArtSize.SMALL
+        self._scale = 1
 
         self._coreobject = None
         self._default_icon = None
 
-    def query(self, coreobject):
+    def query(self, coreobject, size, scale):
         """Start the cache query
 
         :param coreobject: The object to search art for
+        :param ArtSize size: The desired size
+        :param int scale: The scaling factor
         """
         self._coreobject = coreobject
+        self._scale = scale
+        self._size = size
 
         if isinstance(coreobject, CoreArtist):
             self._default_icon = DefaultIcon().get(
diff --git a/gnomemusic/widgets/artstack.py b/gnomemusic/widgets/artstack.py
index 772e359db..9a6a87c46 100644
--- a/gnomemusic/widgets/artstack.py
+++ b/gnomemusic/widgets/artstack.py
@@ -45,8 +45,8 @@ class ArtStack(Gtk.Stack):
         """
         super().__init__()
 
-        self._cache = None
-        self._handler_id = None
+        self._cache = ArtCache()
+        self._handler_id = 0
         self._size = size
         self._thumbnail_id = 0
 
@@ -102,10 +102,9 @@ class ArtStack(Gtk.Stack):
     def _on_thumbnail_changed(self, coreobject, uri):
         self._disconnect_cache()
 
-        self._cache = ArtCache(self.props.size, self.props.scale_factor)
         self._handler_id = self._cache.connect("result", self._on_cache_result)
 
-        self._cache.query(coreobject)
+        self._cache.query(coreobject, self._size, self.props.scale_factor)
 
     def _on_cache_result(self, cache, surface):
         if self.props.visible_child_name == "B":
@@ -122,7 +121,6 @@ class ArtStack(Gtk.Stack):
         self._disconnect_cache()
 
     def _disconnect_cache(self):
-        if (self._cache is not None
-                and self._handler_id is not None):
+        if self._handler_id != 0:
             self._cache.disconnect(self._handler_id)
-            self._handler_id = None
+            self._handler_id = 0


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