[gnome-music/wip/mschraal/albumsview-selection-rework: 4/7] albumwidget: Do selection via coreobjects
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/mschraal/albumsview-selection-rework: 4/7] albumwidget: Do selection via coreobjects
- Date: Fri, 10 Sep 2021 22:51:51 +0000 (UTC)
commit b7e9980e8b7b53c709ac20d6876438012c9431b2
Author: Marinus Schraal <mschraal gnome org>
Date: Fri Sep 10 23:45:09 2021 +0200
albumwidget: Do selection via coreobjects
Selection changes were triggered through the widgets. However,
this is rather the long way around if you want to actually select
the coreobjects. In GTK4 it is no longer possible to cycle through the
widgets, so it is no longer sustainable.
Trigger selection changes directly through the coreobjects.
gnomemusic/widgets/albumwidget.py | 9 +++++++--
gnomemusic/widgets/disclistboxwidget.py | 15 +++++++--------
2 files changed, 14 insertions(+), 10 deletions(-)
---
diff --git a/gnomemusic/widgets/albumwidget.py b/gnomemusic/widgets/albumwidget.py
index df02cf52d..0852083e0 100644
--- a/gnomemusic/widgets/albumwidget.py
+++ b/gnomemusic/widgets/albumwidget.py
@@ -193,6 +193,8 @@ class AlbumWidget(Handy.Clamp):
disc_box = DiscBox(self._application, self._corealbum, disc)
disc_box.connect('song-activated', self._song_activated)
+ self._corealbum.bind_property(
+ "selected", disc, "selected", GObject.BindingFlags.SYNC_CREATE)
self._disc_list_box.bind_property(
"selection-mode", disc_box, "selection-mode",
GObject.BindingFlags.BIDIRECTIONAL
@@ -265,10 +267,13 @@ class AlbumWidget(Handy.Clamp):
self._play(song_widget.props.coresong)
def select_all(self) -> None:
- self._disc_list_box.select_all()
+ for coredisc in self._album_model:
+ coredisc.props.selected = True
def deselect_all(self) -> None:
- self._disc_list_box.deselect_all()
+ if self._album_model:
+ for coredisc in self._album_model:
+ coredisc.props.selected = False
def _on_selection_mode_changed(
self, widget: Gtk.Widget, value: GObject.ParamSpecBoolean) -> None:
diff --git a/gnomemusic/widgets/disclistboxwidget.py b/gnomemusic/widgets/disclistboxwidget.py
index 251c2c1cd..495f0ce7c 100644
--- a/gnomemusic/widgets/disclistboxwidget.py
+++ b/gnomemusic/widgets/disclistboxwidget.py
@@ -69,6 +69,7 @@ class DiscBox(Gtk.ListBoxRow):
self._application = application
self._corealbum = corealbum
+ self._coredisc = coredisc
self._model: Gio.ListModel = coredisc.props.model
disc_nr: int = coredisc.props.disc_nr
@@ -82,23 +83,21 @@ class DiscBox(Gtk.ListBoxRow):
def select_all(self):
"""Select all songs"""
- def child_select_all(child):
- child.props.coresong.props.selected = True
-
- self._list_box.foreach(child_select_all)
+ for coresong in self._model:
+ coresong.props.selected = True
def deselect_all(self):
"""Deselect all songs"""
- def child_deselect_all(child):
- child.props.coresong.props.selected = False
-
- self._list_box.foreach(child_deselect_all)
+ for coresong in self._model:
+ coresong.props.selected = False
def _create_widget(self, coresong):
song_widget = SongWidget(coresong)
song_widget.props.menu = SongWidgetMenu(
self._application, song_widget, self._corealbum)
+ self._coredisc.bind_property(
+ "selected", coresong, "selected", GObject.BindingFlags.SYNC_CREATE)
self.bind_property(
"selection-mode", song_widget, "selection-mode",
GObject.BindingFlags.BIDIRECTIONAL
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]