[gnome-music/wip/jfelder/albumsview-selection-mode-launch: 4/5] artistsview: Correctly select the first artist on launch
- From: Jean Felder <jfelder src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/jfelder/albumsview-selection-mode-launch: 4/5] artistsview: Correctly select the first artist on launch
- Date: Tue, 24 Mar 2020 20:34:40 +0000 (UTC)
commit 5804f9b5fdfb85dba3c50dbe1e04164b0b4fbd55
Author: Jean Felder <jfelder src gnome org>
Date: Tue Mar 24 16:32:11 2020 +0100
artistsview: Correctly select the first artist on launch
On some setups (mostly flatpak), the first artist from the
ArtistsView's sidebar may not be selected on launch.
Indeed, it relies on listening to the artists-loaded signal from the
CoreModel to select the first artist once the artists model is
loaded. However, this signal may already have been emitted when the
ArtistView is built. In that case, the first artist will never be
selected.
Now, ArtistsView instead directly listens to the artists model for
changes and uses an initial state variable (untouched_list) to check
if it is needed to activate a row.
The artists-loaded signal from CoreModel is now unused. It can be
removed.
gnomemusic/coremodel.py | 1 -
gnomemusic/grilowrappers/grltrackerwrapper.py | 1 -
gnomemusic/views/artistsview.py | 40 +++++++++++++++++----------
3 files changed, 25 insertions(+), 17 deletions(-)
---
diff --git a/gnomemusic/coremodel.py b/gnomemusic/coremodel.py
index e5372662..185413df 100644
--- a/gnomemusic/coremodel.py
+++ b/gnomemusic/coremodel.py
@@ -65,7 +65,6 @@ class CoreModel(GObject.GObject):
"""
__gsignals__ = {
- "artists-loaded": (GObject.SignalFlags.RUN_FIRST, None, ()),
"playlist-loaded": (GObject.SignalFlags.RUN_FIRST, None, (int,)),
"smart-playlist-change": (GObject.SignalFlags.RUN_FIRST, None, ())
}
diff --git a/gnomemusic/grilowrappers/grltrackerwrapper.py b/gnomemusic/grilowrappers/grltrackerwrapper.py
index 22e7796f..64616412 100644
--- a/gnomemusic/grilowrappers/grltrackerwrapper.py
+++ b/gnomemusic/grilowrappers/grltrackerwrapper.py
@@ -499,7 +499,6 @@ class GrlTrackerWrapper(GObject.GObject):
if not media:
self._artists_model.splice(
self._artists_model.get_n_items(), 0, artists_added)
- self._coremodel.emit("artists-loaded")
self._window.notifications_popup.pop_loading()
return
diff --git a/gnomemusic/views/artistsview.py b/gnomemusic/views/artistsview.py
index a5454ae5..1affa140 100644
--- a/gnomemusic/views/artistsview.py
+++ b/gnomemusic/views/artistsview.py
@@ -53,16 +53,21 @@ class ArtistsView(BaseView):
self._artists = {}
self._selected_artist = None
+ self._loaded_artists = []
+
+ # This indicates if the current list has been empty and has
+ # had no user interaction since.
+ self._untouched_list = True
self._window = application.props.window
self._coremodel = application.props.coremodel
self._model = self._coremodel.props.artists_sort
+ self._sidebar.bind_model(self._model, self._create_widget)
+
self._model.connect_after(
"items-changed", self._on_model_items_changed)
- self._sidebar.bind_model(self._model, self._create_widget)
- self._loaded_id = self._coremodel.connect(
- "artists-loaded", self._on_artists_loaded)
+ self._on_model_items_changed(self._model, 0, 0, 0)
sidebar_container.props.width_request = 220
sidebar_container.get_style_context().add_class('sidebar')
@@ -74,7 +79,6 @@ class ArtistsView(BaseView):
self._ctrl.props.button = Gdk.BUTTON_PRIMARY
self._ctrl.connect("released", self._on_sidebar_clicked)
- self._loaded_artists = []
self._loading_id = 0
self.show_all()
@@ -88,6 +92,18 @@ class ArtistsView(BaseView):
return row
def _on_model_items_changed(self, model, position, removed, added):
+ if model.get_n_items() == 0:
+ self._untouched_list = True
+ return
+ elif self._untouched_list is True:
+ first_row = self._sidebar.get_row_at_index(0)
+ if first_row is None:
+ return
+
+ self._sidebar.select_row(first_row)
+ self._on_artist_activated(self._sidebar, first_row, True)
+ return
+
if removed == 0:
return
@@ -107,20 +123,11 @@ class ArtistsView(BaseView):
or self._sidebar.get_row_at_index(position - 1))
if row_next:
self._sidebar.select_row(row_next)
- self._on_artist_activated(self._sidebar, row_next)
+ self._on_artist_activated(self._sidebar, row_next, True)
removed_frame = self._view.get_child_by_name(removed_artist)
self._view.remove(removed_frame)
- def _on_artists_loaded(self, klass):
- self._coremodel.disconnect(self._loaded_id)
- first_row = self._sidebar.get_row_at_index(0)
- if first_row is None:
- return
-
- self._sidebar.select_row(first_row)
- self._on_artist_activated(self._sidebar, first_row)
-
def _setup_view(self):
self._view_container = Gtk.ScrolledWindow(hexpand=True, vexpand=True)
self._box.pack_start(self._view_container, True, True, 0)
@@ -130,7 +137,7 @@ class ArtistsView(BaseView):
vhomogeneous=False)
self._view_container.add(self._view)
- def _on_artist_activated(self, sidebar, row, data=None):
+ def _on_artist_activated(self, sidebar, row, data=None, untouched=False):
"""Initializes new artist album widgets"""
# On application start the first row of ArtistView is activated
# to show an intial artist. When this happens while any of the
@@ -143,6 +150,9 @@ class ArtistsView(BaseView):
row.props.selected = not row.props.selected
return
+ if untouched is False:
+ self._untouched_list = False
+
selected_row = self._sidebar.get_selected_row()
self._selected_artist = selected_row.props.coreartist
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]