[gnome-music/wip/jfelder/songwidget-listboxrow: 5/9] searchview: 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: 5/9] searchview: Use the row-activated signal to handle song clicks
- Date: Sat, 8 May 2021 23:24:22 +0000 (UTC)
commit 93c780d2c1b43243f17fce8e598d5944f895b0ad
Author: Jean Felder <jfelder src gnome org>
Date: Sat May 8 17:26:58 2021 +0200
searchview: 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/SearchView.ui | 1 +
gnomemusic/views/searchview.py | 35 +++++++++++++++++++++--------------
2 files changed, 22 insertions(+), 14 deletions(-)
---
diff --git a/data/ui/SearchView.ui b/data/ui/SearchView.ui
index 035b7aed5..d9aa4a097 100644
--- a/data/ui/SearchView.ui
+++ b/data/ui/SearchView.ui
@@ -159,6 +159,7 @@
<object class="GtkListBox" id="_songs_listbox">
<property name="margin-top">20</property>
<property name="visible">True</property>
+ <signal name="row-activated" handler="_song_activated" swapped="no"/>
<style>
<class name="songs-list"/>
</style>
diff --git a/gnomemusic/views/searchview.py b/gnomemusic/views/searchview.py
index d251caf54..918ae05b9 100644
--- a/gnomemusic/views/searchview.py
+++ b/gnomemusic/views/searchview.py
@@ -244,30 +244,37 @@ class SearchView(Gtk.Stack):
else:
self.props.search_state = Search.State.NO_RESULT
- 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
if self.props.selection_mode:
- widget.props.select_click = True
- widget.props.selected = not widget.props.selected
- widget.props.coresong.props.selected = widget.props.selected
- return
+ song_widget.props.select_click = True
+ selection_state = song_widget.props.selected
+ song_widget.props.selected = not selection_state
+ song_widget.props.coresong.props.selected = not selection_state
+ return True
(_, button) = event.get_button()
if (button == Gdk.BUTTON_PRIMARY
and not self.props.selection_mode):
- self._coremodel.props.active_core_object = widget.props.coresong
- self._player.play(widget.props.coresong)
+ coresong = song_widget.props.coresong
+ self._coremodel.props.active_core_object = coresong
+ self._player.play(coresong)
return True
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]