[gnome-music/wip/mschraal/restore-loading-notifications-3-34: 1/2] Pass Application object to init
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/mschraal/restore-loading-notifications-3-34: 1/2] Pass Application object to init
- Date: Mon, 30 Sep 2019 19:33:48 +0000 (UTC)
commit df966709a4567efa567e9fadefb8a262ed757fda
Author: Marinus Schraal <mschraal gnome org>
Date: Mon Sep 16 16:32:49 2019 +0200
Pass Application object to init
Simplify a number of init calls by passing around the root Application
object instead of a several different objects created in Application.
gnomemusic/application.py | 2 +-
gnomemusic/coregrilo.py | 12 +++++++---
gnomemusic/coremodel.py | 10 ++++++---
gnomemusic/grilowrappers/grltrackerplaylists.py | 30 +++++++++++++++++--------
gnomemusic/grilowrappers/grltrackerwrapper.py | 9 ++++----
5 files changed, 42 insertions(+), 21 deletions(-)
---
diff --git a/gnomemusic/application.py b/gnomemusic/application.py
index dc6e4559..53f6fd4c 100644
--- a/gnomemusic/application.py
+++ b/gnomemusic/application.py
@@ -64,7 +64,7 @@ class Application(Gtk.Application):
self._window = None
self._coreselection = CoreSelection()
- self._coremodel = CoreModel(self._coreselection)
+ self._coremodel = CoreModel(self)
self._settings = Gio.Settings.new('org.gnome.Music')
self._player = Player(self)
diff --git a/gnomemusic/coregrilo.py b/gnomemusic/coregrilo.py
index 47b3151e..52c62003 100644
--- a/gnomemusic/coregrilo.py
+++ b/gnomemusic/coregrilo.py
@@ -51,11 +51,17 @@ class CoreGrilo(GObject.GObject):
def __repr__(self):
return "<CoreGrilo>"
- def __init__(self, coremodel, coreselection):
+ def __init__(self, coremodel, application):
+ """Initiate the CoreGrilo object
+
+ :param CoreModel coremodel: The CoreModel instance to use
+ :param Application application: The Application instance to use
+ """
super().__init__()
+ self._application = application
self._coremodel = coremodel
- self._coreselection = coreselection
+ self._coreselection = application.props.coreselection
self._search_wrappers = {}
self._thumbnail_sources = []
self._thumbnail_sources_timeout = None
@@ -122,7 +128,7 @@ class CoreGrilo(GObject.GObject):
and source.props.source_id not in self._wrappers.keys()
and new_state == TrackerState.AVAILABLE):
new_wrapper = GrlTrackerWrapper(
- source, self._coremodel, self._coreselection, self,
+ source, self._coremodel, self._application, self,
self._tracker_wrapper)
self._wrappers[source.props.source_id] = new_wrapper
# elif source.props.source_id[:10] == "grl-dleyna":
diff --git a/gnomemusic/coremodel.py b/gnomemusic/coremodel.py
index 46b69a0f..d9afb6fb 100644
--- a/gnomemusic/coremodel.py
+++ b/gnomemusic/coremodel.py
@@ -74,7 +74,11 @@ class CoreModel(GObject.GObject):
grilo = GObject.Property(type=CoreGrilo, default=None)
songs_available = GObject.Property(type=bool, default=False)
- def __init__(self, coreselection):
+ def __init__(self, application):
+ """Initiate the CoreModel object
+
+ :param Application application: The Application instance to use
+ """
super().__init__()
self._flatten_model = None
@@ -85,7 +89,7 @@ class CoreModel(GObject.GObject):
self._model = Gio.ListStore.new(CoreSong)
self._songliststore = SongListStore(self._model)
- self._coreselection = coreselection
+ self._coreselection = application.props.coreselection
self._album_model = Gio.ListStore()
self._album_model_sort = Gfm.SortListModel.new(self._album_model)
self._album_model_sort.set_sort_func(
@@ -132,7 +136,7 @@ class CoreModel(GObject.GObject):
self._user_playlists_model_sort.set_sort_func(
self._wrap_list_store_sort_func(self._playlists_sort))
- self.props.grilo = CoreGrilo(self, self._coreselection)
+ self.props.grilo = CoreGrilo(self, application)
# FIXME: Not all instances of internal _grilo use have been
# fixed.
self._grilo = self.props.grilo
diff --git a/gnomemusic/grilowrappers/grltrackerplaylists.py b/gnomemusic/grilowrappers/grltrackerplaylists.py
index 12db8b4e..fe96ef26 100644
--- a/gnomemusic/grilowrappers/grltrackerplaylists.py
+++ b/gnomemusic/grilowrappers/grltrackerplaylists.py
@@ -59,22 +59,22 @@ class GrlTrackerPlaylists(GObject.GObject):
return "<GrlTrackerPlaylists>"
def __init__(
- self, source, coremodel, coreselection, grilo, tracker_wrapper):
+ self, source, coremodel, application, grilo, tracker_wrapper):
"""Initialize GrlTrackerPlaylists.
:param Grl.TrackerSource source: The Tracker source to wrap
:param CoreModel coremodel: CoreModel instance to use models
from
- :param CoreSelection coreselection: CoreSelection instance to
- use
+ :param Application application: Application instance
:param CoreGrilo grilo: The CoreGrilo instance
:param TrackerWrapper tracker_wrapper: The TrackerWrapper
instance
"""
super().__init__()
+ self._application = application
self._coremodel = coremodel
- self._coreselection = coreselection
+ self._coreselection = application.props.coreselection
self._grilo = grilo
self._source = source
self._model = self._coremodel.props.playlists
@@ -94,7 +94,7 @@ class GrlTrackerPlaylists(GObject.GObject):
def _initial_playlists_fill(self):
args = {
"source": self._source,
- "coreselection": self._coreselection,
+ "application": self._application,
"grilo": self._grilo,
"tracker": self._tracker
}
@@ -147,7 +147,7 @@ class GrlTrackerPlaylists(GObject.GObject):
playlist = Playlist(
media=media, source=self._source, coremodel=self._coremodel,
- coreselection=self._coreselection, grilo=self._grilo,
+ application=self._application, grilo=self._grilo,
tracker=self._tracker)
self._model.append(playlist)
@@ -292,9 +292,21 @@ class Playlist(GObject.GObject):
def __init__(
self, media=None, query=None, tag_text=None, source=None,
- coremodel=None, coreselection=None, grilo=None, tracker=None):
- super().__init__()
+ coremodel=None, application=None, grilo=None, tracker=None):
+ super().__init__()
+ """Initialize a playlist
+
+ :param Grl.Media media: A media object
+ :param string query: Tracker query that returns the playlist
+ :param string tag_text: The non translatable unique identifier
+ of the playlist
+ :param Grl.Source source: The Grilo Tracker source object
+ :param CoreModel coremodel: The CoreModel instance
+ :param Application application: The Application instance
+ :param CoreGrilo grilo: The CoreGrilo instance
+ :param TrackerWrapper tracker: The TrackerWrapper instance
+ """
if media:
self.props.pl_id = media.get_id()
self.props.title = utils.get_media_title(media)
@@ -306,7 +318,7 @@ class Playlist(GObject.GObject):
self._model = None
self._source = source
self._coremodel = coremodel
- self._coreselection = coreselection
+ self._coreselection = application.props.coreselection
self._grilo = grilo
self._tracker = tracker
diff --git a/gnomemusic/grilowrappers/grltrackerwrapper.py b/gnomemusic/grilowrappers/grltrackerwrapper.py
index d6331938..f5a275dd 100644
--- a/gnomemusic/grilowrappers/grltrackerwrapper.py
+++ b/gnomemusic/grilowrappers/grltrackerwrapper.py
@@ -64,21 +64,20 @@ class GrlTrackerWrapper(GObject.GObject):
return "<GrlTrackerWrapper>"
def __init__(
- self, source, coremodel, coreselection, grilo, tracker_wrapper):
+ self, source, coremodel, application, grilo, tracker_wrapper):
"""Initialize the Tracker wrapper
:param Grl.TrackerSource source: The Tracker source to wrap
:param CoreModel coremodel: CoreModel instance to use models
from
- :param CoreSelection coreselection: CoreSelection instance to
- use
+ :param Application application: Application instance
:param CoreGrilo grilo: The CoreGrilo instance
:param TrackerWrapper tracker_wrapper: The TrackerWrapper instance
"""
super().__init__()
self._coremodel = coremodel
- self._coreselection = coreselection
+ self._coreselection = application.props.coreselection
self._grilo = grilo
self._source = source
self._model = self._coremodel.props.songs
@@ -106,7 +105,7 @@ class GrlTrackerWrapper(GObject.GObject):
self._initial_artists_fill(self._source)
self._tracker_playlists = GrlTrackerPlaylists(
- source, coremodel, coreselection, grilo, tracker_wrapper)
+ source, coremodel, application, grilo, tracker_wrapper)
self._source.notify_change_start()
self._source.connect("content-changed", self._batch_content_changed)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]