[gnome-music/wip/mschraal/gtk4-v2: 60/60] albumwidget: Enable song activation




commit e9c08114cd59732e5d3a701c922ea41b8ab89313
Author: Marinus Schraal <mschraal gnome org>
Date:   Sun Apr 25 17:11:29 2021 +0200

    albumwidget: Enable song activation

 gnomemusic/widgets/albumwidget.py       |  4 +--
 gnomemusic/widgets/disclistboxwidget.py | 54 ++++++++++++++++++---------------
 2 files changed, 31 insertions(+), 27 deletions(-)
---
diff --git a/gnomemusic/widgets/albumwidget.py b/gnomemusic/widgets/albumwidget.py
index 81bf52957..6f57b707e 100644
--- a/gnomemusic/widgets/albumwidget.py
+++ b/gnomemusic/widgets/albumwidget.py
@@ -153,7 +153,7 @@ class AlbumWidget(Gtk.Box):
         self._running_info_label.props.label = ngettext(
             "{} minute", "{} minutes", mins).format(mins)
 
-    def _song_activated(self, widget, song_widget):
+    def _song_activated(self, widget, coresong):
         if self.props.selection_mode:
             song_widget.props.selected = not song_widget.props.selected
             return
@@ -161,7 +161,7 @@ class AlbumWidget(Gtk.Box):
         signal_id = None
 
         def _on_playlist_loaded(klass, playlist_type):
-            self._player.play(song_widget.props.coresong)
+            self._player.play(coresong)
             self._coremodel.disconnect(signal_id)
 
         signal_id = self._coremodel.connect(
diff --git a/gnomemusic/widgets/disclistboxwidget.py b/gnomemusic/widgets/disclistboxwidget.py
index 65d905543..9170211d8 100644
--- a/gnomemusic/widgets/disclistboxwidget.py
+++ b/gnomemusic/widgets/disclistboxwidget.py
@@ -25,6 +25,7 @@
 from gettext import gettext as _
 from gi.repository import Gdk, GObject, Gtk
 
+from gnomemusic.coresong import CoreSong
 from gnomemusic.widgets.songwidget import SongWidget
 
 
@@ -41,7 +42,7 @@ class DiscBox(Gtk.ListBoxRow):
     _list_view = Gtk.Template.Child()
 
     __gsignals__ = {
-        'song-activated': (GObject.SignalFlags.RUN_FIRST, None, (Gtk.Widget,))
+        'song-activated': (GObject.SignalFlags.RUN_FIRST, None, (CoreSong,))
     }
 
     selection_mode = GObject.Property(type=bool, default=False)
@@ -70,6 +71,8 @@ class DiscBox(Gtk.ListBoxRow):
             resource="/org/gnome/Music/ui/SongListItem.ui")
         self._list_view.props.factory = list_item_factory
 
+        self._list_view.connect("activate", self._song_activated)
+
     def select_all(self):
         """Select all songs"""
         def child_select_all(child):
@@ -103,30 +106,31 @@ class DiscBox(Gtk.ListBoxRow):
 
         return row
 
-    def _song_activated(self, widget, event):
-        if widget.props.select_click:
-            widget.props.select_click = False
-            return
-
-        mod_mask = Gtk.accelerator_get_default_mod_mask()
-        if ((event.get_state() & mod_mask) == Gdk.ModifierType.CONTROL_MASK
-                and not self.props.selection_mode):
-            self.props.selection_mode = True
-            widget.props.select_click = True
-            widget.props.coresong.props.selected = True
-            return
-
-        (_, button) = event.get_button()
-        if (button == Gdk.BUTTON_PRIMARY
-                and not self.props.selection_mode):
-            self.emit('song-activated', widget)
-
-        if self.props.selection_mode:
-            widget.props.select_click = True
-            selection_state = widget.props.coresong.props.selected
-            widget.props.coresong.props.selected = not selection_state
-
-        return True
+    def _song_activated(self, widget, position):
+        self.emit("song-activated", self._model[position])
+        # if widget.props.select_click:
+        #     widget.props.select_click = False
+        #     return
+
+        # mod_mask = Gtk.accelerator_get_default_mod_mask()
+        # if ((event.get_state() & mod_mask) == Gdk.ModifierType.CONTROL_MASK
+        #         and not self.props.selection_mode):
+        #     self.props.selection_mode = True
+        #     widget.props.select_click = True
+        #     widget.props.coresong.props.selected = True
+        #     return
+
+        # (_, button) = event.get_button()
+        # if (button == Gdk.BUTTON_PRIMARY
+        #         and not self.props.selection_mode):
+        #     self.emit('song-activated', widget)
+
+        # if self.props.selection_mode:
+        #     widget.props.select_click = True
+        #     selection_state = widget.props.coresong.props.selected
+        #     widget.props.coresong.props.selected = not selection_state
+
+        # return True
 
 
 class DiscListBox(Gtk.ListBox):


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