[gnome-music/wip/jfelder/songwidget-menu-v3: 6/10] songwidget: Introduce an optional menu button




commit b41d069c6d459ae7b76b9b664b022103b22ed752
Author: Jean Felder <jfelder src gnome org>
Date:   Wed Nov 11 21:22:18 2020 +0100

    songwidget: Introduce an optional menu button
    
    This button is only visible when an associated menu is set. This menu
    will be introduced in the next commit.

 data/ui/SongWidget.ui            | 16 ++++++++++++++++
 gnomemusic/widgets/songwidget.py | 22 ++++++++++++++++++++++
 2 files changed, 38 insertions(+)
---
diff --git a/data/ui/SongWidget.ui b/data/ui/SongWidget.ui
index 6c936b381..cfa6782f4 100644
--- a/data/ui/SongWidget.ui
+++ b/data/ui/SongWidget.ui
@@ -180,6 +180,22 @@
             </child>
           </object>
         </child>
+       <child>
+          <object class="GtkMenuButton" id="_menu_button">
+            <property name="visible">False</property>
+            <property name="can-focus">True</property>
+            <style>
+              <class name="flat"/>
+            </style>
+            <child>
+              <object class="GtkImage">
+                <property name="visible">True</property>
+                <property name="can-focus">False</property>
+                <property name="icon-name">view-more-symbolic</property>
+              </object>
+            </child>
+          </object>
+        </child>
       </object>
     </child>
   </template>
diff --git a/gnomemusic/widgets/songwidget.py b/gnomemusic/widgets/songwidget.py
index 31e67849a..3649a12db 100644
--- a/gnomemusic/widgets/songwidget.py
+++ b/gnomemusic/widgets/songwidget.py
@@ -23,6 +23,7 @@
 # delete this exception statement from your version.
 
 from enum import IntEnum
+from typing import Optional
 
 import gi
 gi.require_version('Dazzle', '1.0')
@@ -65,6 +66,7 @@ class SongWidget(Gtk.ListBoxRow):
     _artist_label = Gtk.Template.Child()
     _controller_motion = Gtk.Template.Child()
     _dnd_eventbox = Gtk.Template.Child()
+    _menu_button = Gtk.Template.Child()
     _select_button = Gtk.Template.Child()
     _number_label = Gtk.Template.Child()
     _title_label = Gtk.Template.Child()
@@ -317,3 +319,23 @@ class SongWidget(Gtk.ListBoxRow):
             new_nr = ""
 
         self._number_label.props.label = str(new_nr)
+
+    @GObject.Property(type=Gtk.Popover, default=None)
+    def menu(self) -> Optional[Gtk.Popover]:
+        """Get the song menu.
+
+        If no menu is set, the menu button is not displayed.
+
+        :returns: song menu
+        :rtype: Gtk.PopoverMenu
+        """
+        return self._menu_button.props.popover
+
+    @menu.setter  # type: ignore
+    def menu(self, menu: Optional[Gtk.PopoverMenu]) -> None:
+        """Set song menu.
+
+        :param Gtk.PopoverMenu menu: new song menu
+        """
+        self._menu_button.props.popover = menu
+        self._menu_button.props.visible = (menu is not None)


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