[gnome-music/wip/mschraal/insanely-slow-startup-fix: 1/3] Introduce CoreObjectType enum
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/mschraal/insanely-slow-startup-fix: 1/3] Introduce CoreObjectType enum
- Date: Thu, 17 Feb 2022 07:53:28 +0000 (UTC)
commit 1c518f53680da96e81868aef91327609ddf3fa77
Author: Marinus Schraal <mschraal gnome org>
Date: Tue Feb 15 09:35:02 2022 +0100
Introduce CoreObjectType enum
Instead of using isinstance to figure out the coreobject type, use an
enum. This resolves circular imports that would otherwise arise in
following commits.
gnomemusic/grilowrappers/grltrackerwrapper.py | 10 +++++++---
gnomemusic/storeart.py | 12 +++++-------
gnomemusic/utils.py | 7 +++++++
3 files changed, 19 insertions(+), 10 deletions(-)
---
diff --git a/gnomemusic/grilowrappers/grltrackerwrapper.py b/gnomemusic/grilowrappers/grltrackerwrapper.py
index 8fe8f5dd2..fefcb00b9 100644
--- a/gnomemusic/grilowrappers/grltrackerwrapper.py
+++ b/gnomemusic/grilowrappers/grltrackerwrapper.py
@@ -39,6 +39,7 @@ from gnomemusic.grilowrappers.grltrackerplaylists import (
GrlTrackerPlaylists, Playlist)
from gnomemusic.storeart import StoreArt
from gnomemusic.trackerwrapper import TrackerWrapper
+from gnomemusic.utils import CoreObjectType
if typing.TYPE_CHECKING:
from gnomemusic.application import Application
from gnomemusic.coremodel import CoreModel
@@ -1210,7 +1211,8 @@ class GrlTrackerWrapper(GObject.GObject):
return
self._async_queue.queue(
- StoreArt(), coresong, queried_media.get_thumbnail())
+ StoreArt(), coresong, queried_media.get_thumbnail(),
+ CoreObjectType.SONG)
song_id: str = media.get_id()
query: str = self._get_album_for_media_id_query(song_id)
@@ -1238,7 +1240,8 @@ class GrlTrackerWrapper(GObject.GObject):
return
self._async_queue.queue(
- StoreArt(), corealbum, queried_media.get_thumbnail())
+ StoreArt(), corealbum, queried_media.get_thumbnail(),
+ CoreObjectType.ALBUM)
album_id: str = media.get_id()
query: str = self._get_album_for_media_id_query(album_id, False)
@@ -1268,7 +1271,8 @@ class GrlTrackerWrapper(GObject.GObject):
return
self._async_queue.queue(
- StoreArt(), coreartist, resolved_media.get_thumbnail())
+ StoreArt(), coreartist, resolved_media.get_thumbnail(),
+ CoreObjectType.ARTIST)
self.props.source.resolve(
media, [Grl.METADATA_KEY_THUMBNAIL], self._full_options_lprio,
diff --git a/gnomemusic/storeart.py b/gnomemusic/storeart.py
index 7cbec9dad..60d91809e 100644
--- a/gnomemusic/storeart.py
+++ b/gnomemusic/storeart.py
@@ -27,9 +27,7 @@ gi.require_versions({"MediaArt": "2.0", "Soup": "2.4"})
from gi.repository import Gio, GLib, GObject, MediaArt, Soup, GdkPixbuf
from gnomemusic.musiclogger import MusicLogger
-from gnomemusic.coreartist import CoreArtist
-from gnomemusic.corealbum import CoreAlbum
-from gnomemusic.coresong import CoreSong
+from gnomemusic.utils import CoreObjectType
class StoreArt(GObject.Object):
@@ -54,7 +52,7 @@ class StoreArt(GObject.Object):
self._log = MusicLogger()
self._soup_session = Soup.Session.new()
- def start(self, coreobject, uri):
+ def start(self, coreobject, uri, coreobjecttype):
self._coreobject = coreobject
if (uri is None
@@ -62,14 +60,14 @@ class StoreArt(GObject.Object):
self.emit("finished")
return
- if isinstance(self._coreobject, CoreArtist):
+ if coreobjecttype == CoreObjectType.ARTIST:
success, self._file = MediaArt.get_file(
self._coreobject.props.artist, None, "artist")
- elif isinstance(self._coreobject, CoreAlbum):
+ elif coreobjecttype == CoreObjectType.ALBUM:
success, self._file = MediaArt.get_file(
self._coreobject.props.artist, self._coreobject.props.title,
"album")
- elif isinstance(self._coreobject, CoreSong):
+ elif coreobjecttype == CoreObjectType.SONG:
success, self._file = MediaArt.get_file(
self._coreobject.props.artist, self._coreobject.props.album,
"album")
diff --git a/gnomemusic/utils.py b/gnomemusic/utils.py
index c2762cf06..7a87bb1ff 100644
--- a/gnomemusic/utils.py
+++ b/gnomemusic/utils.py
@@ -46,6 +46,13 @@ class ArtSize(Enum):
self.height = height
+class CoreObjectType(Enum):
+ """Indicates the type of the CoreObject passed"""
+ ALBUM = 0
+ ARTIST = 1
+ SONG = 2
+
+
class DefaultIconType(Enum):
ALBUM = "folder-music-symbolic"
ARTIST = "avatar-default-symbolic"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]