[gnome-music/wip/jfelder/albumwidget-add-contextmenu: 7/8] discbox: Add support for a context menu
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/jfelder/albumwidget-add-contextmenu: 7/8] discbox: Add support for a context menu
- Date: Fri, 13 Aug 2021 20:49:48 +0000 (UTC)
commit 8ca252225364bd6cbe5ce74ef9f58be2b134dd8d
Author: Jean Felder <jfelder src gnome org>
Date: Fri Aug 6 22:26:38 2021 +0200
discbox: Add support for a context menu
right clicking on a SongWidget displays a SongWidgetMenu.
data/ui/DiscBox.ui | 6 ++++++
gnomemusic/widgets/disclistboxwidget.py | 19 +++++++++++++++++++
2 files changed, 25 insertions(+)
---
diff --git a/data/ui/DiscBox.ui b/data/ui/DiscBox.ui
index 164d8dcbe..57df9e70e 100644
--- a/data/ui/DiscBox.ui
+++ b/data/ui/DiscBox.ui
@@ -39,4 +39,10 @@
</object>
</child>
</template>
+ <object class="GtkGestureMultiPress" id="_list_box_ctrlr">
+ <property name="widget">_list_box</property>
+ <property name="propagation-phase">capture</property>
+ <property name="button">3</property>
+ <signal name="pressed" handler="_list_box_right_click" swapped="no"/>
+ </object>
</interface>
diff --git a/gnomemusic/widgets/disclistboxwidget.py b/gnomemusic/widgets/disclistboxwidget.py
index 09f490e29..c7c3f1775 100644
--- a/gnomemusic/widgets/disclistboxwidget.py
+++ b/gnomemusic/widgets/disclistboxwidget.py
@@ -47,6 +47,7 @@ class DiscBox(Gtk.ListBoxRow):
_disc_label = Gtk.Template.Child()
_list_box = Gtk.Template.Child()
+ _list_box_ctrlr = Gtk.Template.Child()
__gsignals__ = {
'song-activated': (GObject.SignalFlags.RUN_FIRST, None, (Gtk.Widget,))
@@ -134,6 +135,24 @@ class DiscBox(Gtk.ListBoxRow):
return True
+ @Gtk.Template.Callback()
+ def _list_box_right_click(
+ self, gesture: Gtk.GestureMultiPress, n_press: int, x: int,
+ y: int) -> None:
+ song_widget = self._list_box.get_row_at_y(y)
+
+ _, y0 = song_widget.translate_coordinates(self._list_box, 0, 0)
+ row_height = song_widget.get_allocated_height()
+ rect = Gdk.Rectangle()
+ rect.x = x
+ rect.y = y0 + 0.5 * row_height
+
+ song_context_menu = SongWidgetMenu(
+ self._application, song_widget, self._corealbum)
+ song_context_menu.props.relative_to = self._list_box
+ song_context_menu.props.pointing_to = rect
+ song_context_menu.popup()
+
class DiscListBox(Gtk.ListBox):
"""A ListBox widget containing all discs of a particular
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]