[gnome-music/wip/mschraal/core] artistview: Make selection mode work
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/mschraal/core] artistview: Make selection mode work
- Date: Thu, 27 Jun 2019 09:09:17 +0000 (UTC)
commit e41dea4459de78502e8b836f229d846248f921d2
Author: Marinus Schraal <mschraal gnome org>
Date: Wed Jun 26 16:35:04 2019 +0200
artistview: Make selection mode work
gnomemusic/coreartist.py | 25 ++++++++++++++++-
gnomemusic/views/artistsview.py | 58 +++++-----------------------------------
gnomemusic/widgets/sidebarrow.py | 9 +++++--
3 files changed, 38 insertions(+), 54 deletions(-)
---
diff --git a/gnomemusic/coreartist.py b/gnomemusic/coreartist.py
index 673702ae..79722cda 100644
--- a/gnomemusic/coreartist.py
+++ b/gnomemusic/coreartist.py
@@ -12,7 +12,6 @@ class CoreArtist(GObject.GObject):
artist = GObject.Property(type=str)
media = GObject.Property(type=Grl.Media)
- selected = GObject.Property(type=bool, default=False)
@log
def __init__(self, media, coremodel):
@@ -20,6 +19,7 @@ class CoreArtist(GObject.GObject):
self._coremodel = coremodel
self._model = None
+ self._selected = False
self.update(media)
@@ -33,5 +33,28 @@ class CoreArtist(GObject.GObject):
if self._model is None:
self._model = self._coremodel.get_artists_model_full(
self.props.media)
+ self._model.connect("items-changed", self._on_items_changed)
+
+ self._on_items_changed(self._model, None, None, None)
return self._model
+
+ def _on_items_changed(self, model, pos, removed, added):
+ with self.freeze_notify():
+ for corealbum in self._model:
+ corealbum.props.selected = self.props.selected
+
+ @GObject.Property(type=bool, default=False)
+ def selected(self):
+ return self._selected
+
+ @selected.setter
+ def selected(self, value):
+ self._selected = value
+
+ # The model is loaded on-demand, so the first time the model is
+ # returned it can still be empty. This is problem for returning
+ # a selection. Trigger loading of the model here if a selection
+ # is requested, it will trigger the filled model update as
+ # well.
+ self.props.model
diff --git a/gnomemusic/views/artistsview.py b/gnomemusic/views/artistsview.py
index 607237f4..f086c882 100644
--- a/gnomemusic/views/artistsview.py
+++ b/gnomemusic/views/artistsview.py
@@ -77,10 +77,11 @@ class ArtistsView(BaseView):
self.show_all()
- def _create_widget(self, artist):
- row = SidebarRow()
- row.props.artist = artist
- row.props.text = artist.props.artist
+ def _create_widget(self, coreartist):
+ row = SidebarRow(coreartist)
+ row.props.text = coreartist.props.artist
+
+ self.bind_property("selection-mode", row, "selection-mode")
return row
@@ -115,7 +116,7 @@ class ArtistsView(BaseView):
return
# Prepare a new artist_albums_widget here
- coreartist = row.props.artist
+ coreartist = row.props.coreartist
new_artist_albums_widget = Gtk.Frame(
shadow_type=Gtk.ShadowType.NONE, hexpand=True)
@@ -147,12 +148,7 @@ class ArtistsView(BaseView):
@log
def _on_selection_changed(self, widget, value, data=None):
- selected_artists = 0
- for row in self._sidebar:
- if row.props.selected:
- selected_artists += 1
-
- self.props.selected_items_count = selected_artists
+ return
@log
def _on_selection_mode_changed(self, widget, data=None):
@@ -164,10 +160,6 @@ class ArtistsView(BaseView):
else:
self._sidebar.props.selection_mode = Gtk.SelectionMode.SINGLE
- if (not self.props.selection_mode
- and grilo.changes_pending['Artists']):
- self._on_changes_pending()
-
@log
def _toggle_all_selection(self, selected):
for row in self._sidebar:
@@ -180,39 +172,3 @@ class ArtistsView(BaseView):
@log
def unselect_all(self):
self._toggle_all_selection(False)
-
- @log
- def get_selected_songs(self, callback):
- """Returns a list of songs selected
-
- In this view this will be all albums of the selected artists.
- :returns: All selected songs
- :rtype: A list of songs
- """
- selected_albums = []
- for row in self._sidebar:
- if row.props.selected:
- artist = row.props.text
- albums = self._artists[artist.casefold()]['albums']
- selected_albums.extend(albums)
-
- if len(selected_albums) > 0:
- self._get_selected_albums_songs(selected_albums, callback)
-
- @log
- def _get_selected_albums_songs(self, albums, callback):
- selected_songs = []
- self._album_index = 0
-
- def add_songs(source, param, item, remaining, data=None):
- if item:
- selected_songs.append(item)
- if remaining == 0:
- self._album_index += 1
- if self._album_index < len(albums):
- grilo.populate_album_songs(
- albums[self._album_index], add_songs)
- else:
- callback(selected_songs)
-
- grilo.populate_album_songs(albums[self._album_index], add_songs)
diff --git a/gnomemusic/widgets/sidebarrow.py b/gnomemusic/widgets/sidebarrow.py
index c72007e5..09c3020f 100644
--- a/gnomemusic/widgets/sidebarrow.py
+++ b/gnomemusic/widgets/sidebarrow.py
@@ -41,7 +41,7 @@ class SidebarRow(Gtk.ListBoxRow):
_label = Gtk.Template.Child()
_revealer = Gtk.Template.Child()
- artist = GObject.Property(type=CoreArtist, default=None)
+ coreartist = GObject.Property(type=CoreArtist, default=None)
selected = GObject.Property(type=bool, default=False)
selection_mode = GObject.Property(type=bool, default=False)
text = GObject.Property(type=str, default='')
@@ -50,12 +50,17 @@ class SidebarRow(Gtk.ListBoxRow):
return '<SidebarRow>'
@log
- def __init__(self):
+ def __init__(self, coreartist):
super().__init__()
+ self.props.coreartist = coreartist
+
self.bind_property(
'selected', self._check, 'active',
GObject.BindingFlags.BIDIRECTIONAL)
+ self.bind_property(
+ "selected", coreartist, "selected",
+ GObject.BindingFlags.BIDIRECTIONAL)
self.bind_property('selection-mode', self._revealer, 'reveal-child')
self.bind_property('text', self._label, 'label')
self.bind_property('text', self._label, 'tooltip-text')
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]