[gnome-music/wip/jfelder/songwidget-listboxrow: 2/9] discbox: Use the row-activated signal to handle song clicks
- From: Jean Felder <jfelder src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/jfelder/songwidget-listboxrow: 2/9] discbox: Use the row-activated signal to handle song clicks
- Date: Sun, 9 May 2021 13:18:36 +0000 (UTC)
commit 4ed8570e1951bc659cd1817a7406f0b93cd1d0ee
Author: Jean Felder <jfelder src gnome org>
Date: Sat May 8 17:09:45 2021 +0200
discbox: Use the row-activated signal to handle song clicks
SongWidget inherits from GtkEventBox and is inserted into a
GtkListBoxRow in order to be used by a GtkListBox. The SongWidget
consumers use the "button-release-event" signal from the GtkEventBox
to handle clicks on songs.
This commit changes the signal logic to use the "row-activated" signal
from the GtkListBox instead. It will make it possible to have
SongWidget directly inheriting from a GtkListBoxRow once all the
"button-release-event" signal usages have been removed.
data/ui/DiscBox.ui | 1 +
gnomemusic/widgets/disclistboxwidget.py | 32 +++++++++++++++++---------------
2 files changed, 18 insertions(+), 15 deletions(-)
---
diff --git a/data/ui/DiscBox.ui b/data/ui/DiscBox.ui
index d75b72f92..6bcb7ea6a 100644
--- a/data/ui/DiscBox.ui
+++ b/data/ui/DiscBox.ui
@@ -30,6 +30,7 @@
<property name="can_focus">False</property>
<property name="valign">start</property>
<property name="selection_mode">none</property>
+ <signal name="row-activated" handler="_song_activated" swapped="no"/>
<style>
<class name="songs-list"/>
</style>
diff --git a/gnomemusic/widgets/disclistboxwidget.py b/gnomemusic/widgets/disclistboxwidget.py
index 83c47a111..2a7c31fdc 100644
--- a/gnomemusic/widgets/disclistboxwidget.py
+++ b/gnomemusic/widgets/disclistboxwidget.py
@@ -94,37 +94,39 @@ class DiscBox(Gtk.ListBoxRow):
GObject.BindingFlags.BIDIRECTIONAL
| GObject.BindingFlags.SYNC_CREATE)
- song_widget.connect('button-release-event', self._song_activated)
-
row = Gtk.ListBoxRow()
- row.props.activatable = False
row.props.selectable = False
row.add(song_widget)
return row
- def _song_activated(self, widget, event):
- if widget.props.select_click:
- widget.props.select_click = False
- return
+ @Gtk.Template.Callback()
+ def _song_activated(
+ self, list_box: Gtk.ListBox, row: Gtk.ListBoxRow) -> bool:
+ song_widget = row.get_child()
+ if song_widget.props.select_click:
+ song_widget.props.select_click = False
+ return True
+ event = Gtk.get_current_event()
+ (_, state) = event.get_state()
mod_mask = Gtk.accelerator_get_default_mod_mask()
- if ((event.get_state() & mod_mask) == Gdk.ModifierType.CONTROL_MASK
+ if ((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
+ song_widget.props.select_click = True
+ song_widget.props.coresong.props.selected = True
+ return True
(_, button) = event.get_button()
if (button == Gdk.BUTTON_PRIMARY
and not self.props.selection_mode):
- self.emit('song-activated', widget)
+ self.emit("song-activated", song_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
+ song_widget.props.select_click = True
+ selection_state = song_widget.props.coresong.props.selected
+ song_widget.props.coresong.props.selected = not selection_state
return True
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]