[gnome-music/wip/mschraal/pass-around-application: 2/4] baseview: Pass around application instead of window



commit ad71f14c96bd0c05f6dff8f0854e90bbadc97bd5
Author: Marinus Schraal <mschraal gnome org>
Date:   Wed Jul 17 23:22:17 2019 +0200

    baseview: Pass around application instead of window
    
    Application has access to more core elements of Music.

 gnomemusic/application.py         |  9 +++++++++
 gnomemusic/views/albumsview.py    |  6 +++---
 gnomemusic/views/artistsview.py   | 11 ++++++-----
 gnomemusic/views/baseview.py      |  9 ++++-----
 gnomemusic/views/playlistsview.py | 10 +++++-----
 gnomemusic/views/searchview.py    |  6 +++---
 gnomemusic/views/songsview.py     | 11 +++++------
 gnomemusic/window.py              | 10 +++++-----
 8 files changed, 40 insertions(+), 32 deletions(-)
---
diff --git a/gnomemusic/application.py b/gnomemusic/application.py
index 605362e6..dc6e4559 100644
--- a/gnomemusic/application.py
+++ b/gnomemusic/application.py
@@ -120,6 +120,15 @@ class Application(Gtk.Application):
         """
         return self._coreselection
 
+    @GObject.Property(type=Window, flags=GObject.ParamFlags.READABLE)
+    def window(self):
+        """Get main window.
+
+        :returns: Main window.
+        :rtype: Window
+        """
+        return self._window
+
     @log
     def _build_app_menu(self):
         action_entries = [
diff --git a/gnomemusic/views/albumsview.py b/gnomemusic/views/albumsview.py
index e07b95ff..72aa1238 100644
--- a/gnomemusic/views/albumsview.py
+++ b/gnomemusic/views/albumsview.py
@@ -40,9 +40,9 @@ class AlbumsView(BaseView):
         return '<AlbumsView>'
 
     @log
-    def __init__(self, window, player):
-        self._window = window
-        super().__init__('albums', _("Albums"), window)
+    def __init__(self, application, player):
+        self._window = application.props.window
+        super().__init__('albums', _("Albums"), application)
 
         self.player = player
         self._album_widget = AlbumWidget(player, self)
diff --git a/gnomemusic/views/artistsview.py b/gnomemusic/views/artistsview.py
index fcb3849a..1df3028c 100644
--- a/gnomemusic/views/artistsview.py
+++ b/gnomemusic/views/artistsview.py
@@ -45,23 +45,24 @@ class ArtistsView(BaseView):
         return '<ArtistsView>'
 
     @log
-    def __init__(self, window, player):
+    def __init__(self, application, player):
         """Initialize
 
-        :param GtkWidget window: The main window
+        :param GtkApplication application: The application object
         :param player: The main player object
         """
         self._sidebar = Gtk.ListBox()
         sidebar_container = Gtk.ScrolledWindow()
         sidebar_container.add(self._sidebar)
 
-        super().__init__('artists', _("Artists"), window, sidebar_container)
+        super().__init__(
+            'artists', _("Artists"), application, sidebar_container)
 
         self.player = player
         self._artists = {}
 
-        self._window = window
-        self._coremodel = window._app.props.coremodel
+        self._window = application.props.window
+        self._coremodel = application.props.coremodel
         self._model = self._coremodel.props.artists_sort
 
         self._model.connect_after(
diff --git a/gnomemusic/views/baseview.py b/gnomemusic/views/baseview.py
index b3be52d4..f8d62e05 100644
--- a/gnomemusic/views/baseview.py
+++ b/gnomemusic/views/baseview.py
@@ -37,14 +37,13 @@ class BaseView(Gtk.Stack):
         return '<BaseView>'
 
     @log
-    def __init__(self, name, title, window, sidebar=None):
+    def __init__(self, name, title, application, sidebar=None):
         """Initialize
         :param name: The view name
         :param title: The view title
-        :param GtkWidget window: The main window
+        :param GtkApplication application: The application object
         :param sidebar: The sidebar object (Default: Gtk.Box)
         """
-
         super().__init__(transition_type=Gtk.StackTransitionType.CROSSFADE)
 
         self._grid = Gtk.Grid(orientation=Gtk.Orientation.HORIZONTAL)
@@ -58,8 +57,8 @@ class BaseView(Gtk.Stack):
 
         self._grid.add(self._box)
 
-        self._window = window
-        self._headerbar = window._headerbar
+        self._window = application.props.window
+        self._headerbar = self._window._headerbar
 
         self.name = name
         self.title = title
diff --git a/gnomemusic/views/playlistsview.py b/gnomemusic/views/playlistsview.py
index 63bef109..1b2cdc2e 100644
--- a/gnomemusic/views/playlistsview.py
+++ b/gnomemusic/views/playlistsview.py
@@ -44,10 +44,10 @@ class PlaylistsView(BaseView):
         return '<PlaylistsView>'
 
     @log
-    def __init__(self, window, player):
+    def __init__(self, application, player):
         """Initialize
 
-        :param GtkWidget window: The main window
+        :param GtkApplication window: The application object
         :param player: The main player object
         """
         self._sidebar = Gtk.ListBox()
@@ -55,11 +55,11 @@ class PlaylistsView(BaseView):
         sidebar_container.add(self._sidebar)
 
         super().__init__(
-            'playlists', _("Playlists"), window, sidebar_container)
+            'playlists', _("Playlists"), application, sidebar_container)
 
-        self._coremodel = window._app.props.coremodel
+        self._coremodel = application.props.coremodel
         self._model = self._coremodel.props.playlists_sort
-        self._window = window
+        self._window = application.props.window
         self.player = player
 
         self._pl_ctrls = PlaylistControls()
diff --git a/gnomemusic/views/searchview.py b/gnomemusic/views/searchview.py
index e794de48..cfe196c0 100644
--- a/gnomemusic/views/searchview.py
+++ b/gnomemusic/views/searchview.py
@@ -45,12 +45,12 @@ class SearchView(BaseView):
         return '<SearchView>'
 
     @log
-    def __init__(self, window, player):
-        self._coremodel = window._app.props.coremodel
+    def __init__(self, application, player):
+        self._coremodel = application.props.coremodel
         self._model = self._coremodel.props.songs_search
         self._album_model = self._coremodel.props.albums_search
         self._artist_model = self._coremodel.props.artists_search
-        super().__init__('search', None, window)
+        super().__init__('search', None, application)
 
         self.player = player
 
diff --git a/gnomemusic/views/songsview.py b/gnomemusic/views/songsview.py
index e3290ea5..767d74bf 100644
--- a/gnomemusic/views/songsview.py
+++ b/gnomemusic/views/songsview.py
@@ -47,15 +47,14 @@ class SongsView(BaseView):
         return '<SongsView>'
 
     @log
-    def __init__(self, window, player):
+    def __init__(self, application, player):
         """Initialize
 
-        :param GtkWidget window: The main window
+        :param GtkApplication window: The application object
         :param player: The main player object
         """
-        self._window = window
-        self._coremodel = self._window._app.props.coremodel
-        super().__init__('songs', _("Songs"), window)
+        self._coremodel = application.props.coremodel
+        super().__init__('songs', _("Songs"), application)
 
         self._iter_to_clean = None
 
@@ -181,7 +180,7 @@ class SongsView(BaseView):
 
         itr = self._view.props.model.get_iter(path)
         coresong = self._view.props.model[itr][7]
-        self._window._app._coremodel.set_player_model(
+        self._coremodel.set_player_model(
             PlayerPlaylist.Type.SONGS, self._view.props.model)
 
         self.player.play(coresong)
diff --git a/gnomemusic/window.py b/gnomemusic/window.py
index 81eb97d4..2b51cdee 100644
--- a/gnomemusic/window.py
+++ b/gnomemusic/window.py
@@ -230,11 +230,11 @@ class Window(Gtk.ApplicationWindow):
         self._headerbar.props.stack = self._stack
         self._searchbar.show()
 
-        self.views[View.ALBUM] = AlbumsView(self, self._player)
-        self.views[View.ARTIST] = ArtistsView(self, self._player)
-        self.views[View.SONG] = SongsView(self, self._player)
-        self.views[View.PLAYLIST] = PlaylistsView(self, self._player)
-        self.views[View.SEARCH] = SearchView(self, self._player)
+        self.views[View.ALBUM] = AlbumsView(self._app, self._player)
+        self.views[View.ARTIST] = ArtistsView(self._app, self._player)
+        self.views[View.SONG] = SongsView(self._app, self._player)
+        self.views[View.PLAYLIST] = PlaylistsView(self._app, self._player)
+        self.views[View.SEARCH] = SearchView(self._app, self._player)
 
         selectable_views = [View.ALBUM, View.ARTIST, View.SONG, View.SEARCH]
         for view in selectable_views:


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