[gnome-music/wip/mschraal/core: 12/20] pass coremodel around and use it in albumwidget2



commit 420301741bcda679c3e1adbca058797c64d89285
Author: Marinus Schraal <mschraal gnome org>
Date:   Wed May 8 20:49:19 2019 +0200

    pass coremodel around and use it in albumwidget2

 gnomemusic/application.py          | 2 +-
 gnomemusic/coremodel.py            | 4 ++++
 gnomemusic/widgets/albumwidget2.py | 9 +++++++++
 gnomemusic/window.py               | 3 +++
 4 files changed, 17 insertions(+), 1 deletion(-)
---
diff --git a/gnomemusic/application.py b/gnomemusic/application.py
index af6ec260..2d44e44f 100644
--- a/gnomemusic/application.py
+++ b/gnomemusic/application.py
@@ -63,7 +63,7 @@ class Application(Gtk.Application):
         self._init_style()
         self._window = None
 
-        coremodel = CoreModel()
+        self._coremodel = CoreModel()
 
         self._settings = Gio.Settings.new('org.gnome.Music')
         self._player = Player(self)
diff --git a/gnomemusic/coremodel.py b/gnomemusic/coremodel.py
index 95c46a00..75345b81 100644
--- a/gnomemusic/coremodel.py
+++ b/gnomemusic/coremodel.py
@@ -14,3 +14,7 @@ class CoreModel(GObject.GObject):
         self._hash = {}
 
         self._grilo = CoreGrilo(self._model, self._hash)
+
+    @log
+    def get_model(self):
+        return self._model
diff --git a/gnomemusic/widgets/albumwidget2.py b/gnomemusic/widgets/albumwidget2.py
index d68a1e06..a1fe3d18 100644
--- a/gnomemusic/widgets/albumwidget2.py
+++ b/gnomemusic/widgets/albumwidget2.py
@@ -125,6 +125,15 @@ class AlbumWidget2(Gtk.EventBox):
         # self._player.connect('song-changed', self._update_model)
 
         # grilo.populate_album_songs(album, self.add_item)
+        self._listbox.bind_model(
+            self._parent_view._window._app._coremodel.get_model(),
+            self._create_widget)
+
+    @log
+    def _create_widget(self, song):
+        song_widget = SongWidget(song._media)
+
+        return song_widget
 
     @log
     def _set_composer_label(self, album):
diff --git a/gnomemusic/window.py b/gnomemusic/window.py
index 6af945ee..24ea32f5 100644
--- a/gnomemusic/window.py
+++ b/gnomemusic/window.py
@@ -76,6 +76,9 @@ class Window(Gtk.ApplicationWindow):
         """
         super().__init__(application=app, title=_("Music"))
 
+        # Hack
+        self._app = app
+
         self._settings = app.props.settings
         self.add_action(self._settings.create_action('repeat'))
         select_all = Gio.SimpleAction.new('select_all', None)


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