[gnome-music/wip/jfelder/core-playlists-view] artistsview: Display the albums after the whole is loaded



commit 4c832d0dd2e7f7ba394163d6b3ae8a0bc1bce912
Author: Jean Felder <jfelder src gnome org>
Date:   Thu Jul 11 00:29:19 2019 +0200

    artistsview: Display the albums after the whole is loaded

 gnomemusic/views/artistsview.py          | 13 +++++++++++--
 gnomemusic/widgets/artistalbumswidget.py | 13 +++++++++++++
 gnomemusic/widgets/artistalbumwidget.py  | 15 +++++++++++++--
 gnomemusic/widgets/disclistboxwidget.py  |  6 ++++++
 4 files changed, 43 insertions(+), 4 deletions(-)
---
diff --git a/gnomemusic/views/artistsview.py b/gnomemusic/views/artistsview.py
index 3f59debd..eede7035 100644
--- a/gnomemusic/views/artistsview.py
+++ b/gnomemusic/views/artistsview.py
@@ -106,6 +106,10 @@ class ArtistsView(BaseView):
             vhomogeneous=False)
         self._view_container.add(self._view)
 
+        empty_frame = Gtk.Frame(shadow_type=Gtk.ShadowType.NONE, hexpand=True)
+        empty_frame.show()
+        self._view.add_named(empty_frame, "empty-frame")
+
     @log
     def _on_changes_pending(self, data=None):
         if (self._init
@@ -133,11 +137,16 @@ class ArtistsView(BaseView):
 
         artist_albums = ArtistAlbumsWidget(
             coreartist, self.player, self._window, False)
+        artist_albums.connect(
+            "ready", self._on_artist_albums_ready, coreartist)
+        self._view.set_visible_child_name("empty-frame")
+        return
+
+    def _on_artist_albums_ready(self, klass, coreartist):
         new_artist_albums_widget = Gtk.Frame(
             shadow_type=Gtk.ShadowType.NONE, hexpand=True)
-        new_artist_albums_widget.add(artist_albums)
+        new_artist_albums_widget.add(klass)
         new_artist_albums_widget.show()
-
         self._view.add_named(new_artist_albums_widget, coreartist.props.artist)
         scroll_vadjustment = self._view_container.props.vadjustment
         scroll_vadjustment.props.value = 0.
diff --git a/gnomemusic/widgets/artistalbumswidget.py b/gnomemusic/widgets/artistalbumswidget.py
index 6d59f603..8a2aa703 100644
--- a/gnomemusic/widgets/artistalbumswidget.py
+++ b/gnomemusic/widgets/artistalbumswidget.py
@@ -46,6 +46,10 @@ class ArtistAlbumsWidget(Gtk.ListBox):
     selected_items_count = GObject.Property(type=int, default=0, minimum=0)
     selection_mode = GObject.Property(type=bool, default=False)
 
+    __gsignals__ = {
+        "ready": (GObject.SignalFlags.RUN_FIRST, None, ()),
+    }
+
     def __repr__(self):
         return '<ArtistAlbumsWidget>'
 
@@ -66,6 +70,7 @@ class ArtistAlbumsWidget(Gtk.ListBox):
         self._songs_grid_size_group = Gtk.SizeGroup.new(
             Gtk.SizeGroupMode.HORIZONTAL)
 
+        self._nb_albums_loaded = 0
         self._model.props.model.connect_after(
             "items-changed", self. _on_model_items_changed)
         self.bind_model(self._model, self._add_album)
@@ -98,10 +103,18 @@ class ArtistAlbumsWidget(Gtk.ListBox):
             | GObject.BindingFlags.SYNC_CREATE)
 
         self._widgets.append(widget)
+        widget.connect("ready", self._on_discbox_ready)
         widget.connect("song-activated", self._song_activated)
 
         return widget
 
+    def _on_discbox_ready(self, klass):
+        self._nb_albums_loaded += 1
+        if self._nb_albums_loaded == self._model.get_n_items():
+            klass.disconnect_by_func(self._on_discbox_ready)
+            self._nb_albums_loaded = 0
+            self.emit("ready")
+
     def _on_model_items_changed(self, model, position, removed, added):
         for i in range(model.get_n_items()):
             row = self.get_row_at_index(i)
diff --git a/gnomemusic/widgets/artistalbumwidget.py b/gnomemusic/widgets/artistalbumwidget.py
index dd3749f3..11aed656 100644
--- a/gnomemusic/widgets/artistalbumwidget.py
+++ b/gnomemusic/widgets/artistalbumwidget.py
@@ -44,6 +44,7 @@ class ArtistAlbumWidget(Gtk.Box):
     selection_mode = GObject.Property(type=bool, default=False)
 
     __gsignals__ = {
+        "ready": (GObject.SignalFlags.RUN_FIRST, None, ()),
         "song-activated": (
             GObject.SignalFlags.RUN_FIRST, None, (SongWidget, )
         ),
@@ -85,10 +86,12 @@ class ArtistAlbumWidget(Gtk.Box):
         if self._cover_size_group:
             self._cover_size_group.add_widget(self._cover_stack)
 
-        corealbum.props.model.connect_after(
+        self._nb_disc_box_loaded = 0
+        self._model = corealbum.props.model
+        self._model.props.model.connect_after(
             "items-changed", self._on_model_items_changed)
         self._disc_list_box.bind_model(
-            corealbum.props.model, self._create_widget)
+            self._model, self._create_widget)
 
     def _create_widget(self, disc):
         disc_box = self._create_disc_box(disc.props.disc_nr, disc.model)
@@ -101,10 +104,18 @@ class ArtistAlbumWidget(Gtk.Box):
         disc_box.props.show_durations = False
         disc_box.props.show_favorites = False
         disc_box.props.show_song_numbers = True
+        disc_box.connect("ready", self._on_discbox_ready)
         disc_box.connect('song-activated', self._song_activated)
 
         return disc_box
 
+    def _on_discbox_ready(self, klass):
+        self._nb_disc_box_loaded += 1
+        if self._nb_disc_box_loaded == self._model.get_n_items():
+            klass.disconnect_by_func(self._on_discbox_ready)
+            self._nb_disc_box_loaded = 0
+            self.emit("ready")
+
     def _on_model_items_changed(self, model, position, removed, added):
         n_items = model.get_n_items()
         if n_items == 1:
diff --git a/gnomemusic/widgets/disclistboxwidget.py b/gnomemusic/widgets/disclistboxwidget.py
index 10c5bf3c..957538d8 100644
--- a/gnomemusic/widgets/disclistboxwidget.py
+++ b/gnomemusic/widgets/disclistboxwidget.py
@@ -61,6 +61,7 @@ class DiscBox(Gtk.Box):
     _list_box = Gtk.Template.Child()
 
     __gsignals__ = {
+        "ready": (GObject.SignalFlags.RUN_FIRST, None, ()),
         'selection-changed': (GObject.SignalFlags.RUN_FIRST, None, ()),
         'song-activated': (GObject.SignalFlags.RUN_FIRST, None, (Gtk.Widget,))
     }
@@ -93,6 +94,8 @@ class DiscBox(Gtk.Box):
         self._selected_items = []
         self._songs = []
 
+        self._model.connect_after(
+            "items-changed", self._on_model_items_changed)
         self._list_box.bind_model(self._model, self._create_widget)
 
     @log
@@ -141,6 +144,9 @@ class DiscBox(Gtk.Box):
 
         return song_widget
 
+    def _on_model_items_changed(self, model, position, removed, added):
+        self.emit("ready")
+
     @log
     def _on_selection_changed(self, widget):
         self.emit('selection-changed')


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