[gnome-music/wip/mschraal/albumsview-selection-rework: 2/8] artistalbumswidget: Route selections via coreobjects




commit c2b7c9a8aed5a20bdcc50feb21c6a9859b3a4819
Author: Marinus Schraal <mschraal gnome org>
Date:   Sat Sep 11 02:23:57 2021 +0200

    artistalbumswidget: Route selections 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 frowned upon cycling through widgets to
    obtain their properties, so it is no longer sustainable.
    
    Trigger selection changes directly through the coreobjects.

 gnomemusic/widgets/artistalbumswidget.py | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
---
diff --git a/gnomemusic/widgets/artistalbumswidget.py b/gnomemusic/widgets/artistalbumswidget.py
index 4f213157a..1f494ae06 100644
--- a/gnomemusic/widgets/artistalbumswidget.py
+++ b/gnomemusic/widgets/artistalbumswidget.py
@@ -75,6 +75,9 @@ class ArtistAlbumsWidget(Handy.Clamp):
         widget.props.active_coreobject = self._artist
         widget.props.show_artist_label = False
 
+        self._artist.bind_property(
+            "selected", corealbum, "selected",
+            GObject.BindingFlags.SYNC_CREATE)
         self.bind_property(
             'selection-mode', widget, 'selection-mode',
             GObject.BindingFlags.BIDIRECTIONAL
@@ -86,17 +89,13 @@ class ArtistAlbumsWidget(Handy.Clamp):
 
     def select_all(self) -> None:
         """Select all items"""
-        def toggle_selection(row: Gtk.ListBoxRow) -> None:
-            row.get_child().select_all()
-
-        self._listbox.foreach(toggle_selection)
+        for corealbum in self._model:
+            corealbum.props.selected = True
 
     def deselect_all(self) -> None:
         """Deselect all items"""
-        def toggle_selection(row: Gtk.ListBoxRow) -> None:
-            row.get_child().deselect_all()
-
-        self._listbox.foreach(toggle_selection)
+        for corealbum in self._model:
+            corealbum.props.selected = False
 
     @GObject.Property(type=str, flags=GObject.ParamFlags.READABLE)
     def artist(self) -> str:


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