[gnome-music/wip/jfelder/albumwidget-add-contextmenu] discbox: Add support for a context menu
- From: Jean Felder <jfelder src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/jfelder/albumwidget-add-contextmenu] discbox: Add support for a context menu
- Date: Fri, 6 Aug 2021 20:29:55 +0000 (UTC)
commit a50bebdf865852bade5228d70d246a66b78c0292
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 | 20 ++++++++++++++++++++
2 files changed, 26 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..11f5fa8e7 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,25 @@ 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.props.position = Gtk.PositionType.BOTTOM
+ 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]