[gnome-music/wip/mschraal/async-queue: 20/25] artcache: Use AsyncQueue for cache retrieval
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/mschraal/async-queue: 20/25] artcache: Use AsyncQueue for cache retrieval
- Date: Sat, 14 Aug 2021 23:20:22 +0000 (UTC)
commit 6addf2a15d48b436fef172ce446394f86183137a
Author: Marinus Schraal <mschraal gnome org>
Date: Tue Aug 10 15:15:55 2021 +0200
artcache: Use AsyncQueue for cache retrieval
gnomemusic/artcache.py | 16 ++++++++--------
gnomemusic/asyncqueue.py | 4 ++--
gnomemusic/widgets/artstack.py | 9 +++++++--
3 files changed, 17 insertions(+), 12 deletions(-)
---
diff --git a/gnomemusic/artcache.py b/gnomemusic/artcache.py
index 96d266ef9..0e1959ca9 100644
--- a/gnomemusic/artcache.py
+++ b/gnomemusic/artcache.py
@@ -24,7 +24,7 @@
from enum import Enum
from math import pi
-from typing import Dict, Tuple
+from typing import Dict, Tuple, Union
import cairo
from gi.repository import Gdk, GdkPixbuf, Gio, Gtk, GLib, GObject
@@ -154,7 +154,7 @@ class ArtCache(GObject.GObject):
__gtype_name__ = "ArtCache"
__gsignals__ = {
- "result": (GObject.SignalFlags.RUN_FIRST, None, (object, ))
+ "finished": (GObject.SignalFlags.RUN_FIRST, None, (object, ))
}
_log = MusicLogger()
@@ -168,7 +168,7 @@ class ArtCache(GObject.GObject):
self._coreobject = None
self._default_icon = None
- def query(self, coreobject, size, scale):
+ def start(self, coreobject, size, scale):
"""Start the cache query
:param coreobject: The object to search art for
@@ -189,7 +189,7 @@ class ArtCache(GObject.GObject):
thumbnail_uri = coreobject.props.thumbnail
if thumbnail_uri == "generic":
- self.emit("result", self._default_icon)
+ self.emit("finished", self._default_icon)
return
thumb_file = Gio.File.new_for_uri(thumbnail_uri)
@@ -198,7 +198,7 @@ class ArtCache(GObject.GObject):
GLib.PRIORITY_LOW, None, self._open_stream, None)
return
- self.emit("result", self._default_icon)
+ self.emit("finished", self._default_icon)
def _open_stream(self, thumb_file, result, arguments):
try:
@@ -206,7 +206,7 @@ class ArtCache(GObject.GObject):
except GLib.Error as error:
self._log.warning(
"Error: {}, {}".format(error.domain, error.message))
- self.emit("result", self._default_icon)
+ self.emit("finished", self._default_icon)
return
GdkPixbuf.Pixbuf.new_from_stream_async(
@@ -218,7 +218,7 @@ class ArtCache(GObject.GObject):
except GLib.Error as error:
self._log.warning(
"Error: {}, {}".format(error.domain, error.message))
- self.emit("result", self._default_icon)
+ self.emit("finished", self._default_icon)
return
stream.close_async(GLib.PRIORITY_LOW, None, self._close_stream, None)
@@ -232,7 +232,7 @@ class ArtCache(GObject.GObject):
or isinstance(self._coreobject, CoreSong)):
surface = _make_icon_frame(surface, self._size, self._scale)
- self.emit("result", surface)
+ self.emit("finished", surface)
def _close_stream(self, stream, result, data):
try:
diff --git a/gnomemusic/asyncqueue.py b/gnomemusic/asyncqueue.py
index 5a3459307..53357274a 100644
--- a/gnomemusic/asyncqueue.py
+++ b/gnomemusic/asyncqueue.py
@@ -22,7 +22,7 @@
# code, but you are not obligated to do so. If you do not wish to do so,
# delete this exception statement from your version.
-from typing import Dict, Tuple
+from typing import Any, Dict, Tuple
from gi.repository import GObject
@@ -52,7 +52,7 @@ class AsyncQueue(GObject.GObject):
self._async_active_pool: Dict[int, Tuple] = {}
self._max_async = 4
- def queue(self, *args) -> None:
+ def queue(self, *args: Any) -> None:
"""Queue an async call
:param *args: The first item should be an async class, the
diff --git a/gnomemusic/widgets/artstack.py b/gnomemusic/widgets/artstack.py
index 5e7014d3f..a75cad9b3 100644
--- a/gnomemusic/widgets/artstack.py
+++ b/gnomemusic/widgets/artstack.py
@@ -24,6 +24,7 @@
from gi.repository import GObject, Gtk
+from gnomemusic.asyncqueue import AsyncQueue
from gnomemusic.artcache import ArtCache
from gnomemusic.utils import ArtSize
@@ -38,6 +39,8 @@ class ArtStack(Gtk.Stack):
__gtype_name__ = "ArtStack"
+ _async_queue = AsyncQueue()
+
def __init__(self, size=ArtSize.MEDIUM):
"""Initialize the ArtStack
@@ -103,9 +106,11 @@ class ArtStack(Gtk.Stack):
def _on_thumbnail_changed(self, coreobject, uri):
self._disconnect_cache()
- self._handler_id = self._cache.connect("result", self._on_cache_result)
+ self._handler_id = self._cache.connect(
+ "finished", self._on_cache_result)
- self._cache.query(coreobject, self._size, self.props.scale_factor)
+ self._async_queue.queue(
+ self._cache, coreobject, self._size, self.props.scale_factor)
def _on_cache_result(self, cache, surface):
if self.props.visible_child_name == "B":
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]