[gnome-music/wip/jfelder/songwidget-menu-v3: 4/4] discbox: Add support for SongWidgetMenu




commit 76c778438cbde1addccb12b0d61c00ec3b732bbc
Author: Jean Felder <jfelder src gnome org>
Date:   Sun May 9 16:08:42 2021 +0200

    discbox: Add support for SongWidgetMenu
    
    This allows to add a menu for each SongWidget of AlbumsView and
    ArtistsView.

 gnomemusic/widgets/albumwidget.py        |  2 +-
 gnomemusic/widgets/artistalbumswidget.py |  3 ++-
 gnomemusic/widgets/artistalbumwidget.py  |  9 +++++++--
 gnomemusic/widgets/disclistboxwidget.py  | 13 ++++++++++++-
 4 files changed, 22 insertions(+), 5 deletions(-)
---
diff --git a/gnomemusic/widgets/albumwidget.py b/gnomemusic/widgets/albumwidget.py
index 60e5ba15b..4e9db294a 100644
--- a/gnomemusic/widgets/albumwidget.py
+++ b/gnomemusic/widgets/albumwidget.py
@@ -116,7 +116,7 @@ class AlbumWidget(Gtk.Box):
         self._album_model.items_changed(0, 0, 0)
 
     def _create_widget(self, disc):
-        disc_box = DiscBox(disc)
+        disc_box = DiscBox(self._application, self._corealbum, disc)
         disc_box.connect('song-activated', self._song_activated)
 
         self._disc_list_box.bind_property(
diff --git a/gnomemusic/widgets/artistalbumswidget.py b/gnomemusic/widgets/artistalbumswidget.py
index 701ff9991..cd924b86e 100644
--- a/gnomemusic/widgets/artistalbumswidget.py
+++ b/gnomemusic/widgets/artistalbumswidget.py
@@ -81,7 +81,8 @@ class ArtistAlbumsWidget(Gtk.ListBox):
         row.props.activatable = False
 
         widget = ArtistAlbumWidget(
-            corealbum, self._songs_grid_size_group, self._cover_size_group)
+            self._application, corealbum, self._songs_grid_size_group,
+            self._cover_size_group)
 
         self.bind_property(
             'selection-mode', widget, 'selection-mode',
diff --git a/gnomemusic/widgets/artistalbumwidget.py b/gnomemusic/widgets/artistalbumwidget.py
index 63dbec2ad..29a45d529 100644
--- a/gnomemusic/widgets/artistalbumwidget.py
+++ b/gnomemusic/widgets/artistalbumwidget.py
@@ -32,6 +32,7 @@ from gnomemusic.utils import ArtSize
 from gnomemusic.widgets.disclistboxwidget import DiscBox
 from gnomemusic.widgets.songwidget import SongWidget
 if typing.TYPE_CHECKING:
+    from gnomemusic.application import Application
     from gnomemusic.corealbum import CoreAlbum
 
 
@@ -59,17 +60,21 @@ class ArtistAlbumWidget(Gtk.Box):
     }
 
     def __init__(
-            self, corealbum: CoreAlbum,
+            self, application: Application, corealbum: CoreAlbum,
             size_group: Optional[Gtk.SizeGroup] = None,
             cover_size_group: Optional[Gtk.SizeGroup] = None) -> None:
         """Initialize the ArtistAlbumWidget
 
+        :param Application application: The Application object
         :param CoreAlbum corealbum: The CoreAlbum object
         :param GtkSizeGroup size_group: SizeGroup for the discs
         :param GtkSizeGroup cover_size_group: SizeGroup for the cover
         """
         super().__init__(orientation=Gtk.Orientation.HORIZONTAL)
 
+        self._application = application
+        self._corealbum = corealbum
+
         self._size_group = size_group
         self._cover_size_group = cover_size_group
 
@@ -102,7 +107,7 @@ class ArtistAlbumWidget(Gtk.Box):
         corealbum.props.model.items_changed(0, 0, 0)
 
     def _create_widget(self, disc):
-        disc_box = DiscBox(disc)
+        disc_box = DiscBox(self._application, self._corealbum, disc)
         disc_box.connect('song-activated', self._song_activated)
 
         self._disc_list_box.bind_property(
diff --git a/gnomemusic/widgets/disclistboxwidget.py b/gnomemusic/widgets/disclistboxwidget.py
index 77ee0d871..09f490e29 100644
--- a/gnomemusic/widgets/disclistboxwidget.py
+++ b/gnomemusic/widgets/disclistboxwidget.py
@@ -29,7 +29,10 @@ import typing
 from gi.repository import Gdk, Gio, GObject, Gtk
 
 from gnomemusic.widgets.songwidget import SongWidget
+from gnomemusic.widgets.songwidgetmenu import SongWidgetMenu
 if typing.TYPE_CHECKING:
+    from gnomemusic.application import Application
+    from gnomemusic.corealbum import CoreAlbum
     from gnomemusic.coredisc import CoreDisc
 
 
@@ -52,13 +55,19 @@ class DiscBox(Gtk.ListBoxRow):
     selection_mode = GObject.Property(type=bool, default=False)
     show_disc_label = GObject.Property(type=bool, default=False)
 
-    def __init__(self, coredisc: CoreDisc) -> None:
+    def __init__(
+            self, application: Application, corealbum: CoreAlbum,
+            coredisc: CoreDisc) -> None:
         """Initialize
 
+        :param Application coredisc: The Application object
+        :param CoreAlbum corealbum: The corealbum of the coredisc
         :param CoreDisc coredisc: The CoreDisc object to use
         """
         super().__init__()
 
+        self._application = application
+        self._corealbum = corealbum
         self._model: Gio.ListModel = coredisc.props.model
 
         disc_nr: int = coredisc.props.disc_nr
@@ -86,6 +95,8 @@ class DiscBox(Gtk.ListBoxRow):
 
     def _create_widget(self, coresong):
         song_widget = SongWidget(coresong)
+        song_widget.props.menu = SongWidgetMenu(
+            self._application, song_widget, self._corealbum)
 
         self.bind_property(
             "selection-mode", song_widget, "selection-mode",


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