[gnome-music/wip/jfelder/songsview-songwidget-menu: 1/2] songwidgetmenu: Allow to change the coreobject




commit 06a12a7853005c0279644719e5811b0f3ddf6178
Author: Jean Felder <jfelder src gnome org>
Date:   Sun Feb 20 17:54:19 2022 +0100

    songwidgetmenu: Allow to change the coreobject

 gnomemusic/widgets/songwidgetmenu.py | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)
---
diff --git a/gnomemusic/widgets/songwidgetmenu.py b/gnomemusic/widgets/songwidgetmenu.py
index 86a3b1529..e3c602859 100644
--- a/gnomemusic/widgets/songwidgetmenu.py
+++ b/gnomemusic/widgets/songwidgetmenu.py
@@ -26,7 +26,7 @@ from __future__ import annotations
 from typing import Any, Optional, Union
 import typing
 
-from gi.repository import Gio, Gtk
+from gi.repository import Gio, GObject, Gtk
 
 from gnomemusic.grilowrappers.grltrackerplaylists import Playlist
 from gnomemusic.songtoast import SongToast
@@ -36,6 +36,7 @@ if typing.TYPE_CHECKING:
     from gnomemusic.application import Application
     from gnomemusic.corealbum import CoreAlbum
     from gnomemusic.coresong import CoreSong
+    CoreObject = Union[CoreAlbum, CoreSong, Playlist]
 
 
 @Gtk.Template(resource_path="/org/gnome/Music/ui/SongWidgetMenu.ui")
@@ -46,7 +47,7 @@ class SongWidgetMenu(Gtk.PopoverMenu):
     def __init__(
             self, application: Application,
             song_widget: Union[SongWidget, Gtk.ListItem],
-            coreobject: Union[CoreAlbum, CoreSong, Playlist]) -> None:
+            coreobject: Optional[CoreObject]) -> None:
         """Menu to interact with the song of a SongWidget.
 
         :param Application application: The application object
@@ -62,12 +63,9 @@ class SongWidgetMenu(Gtk.PopoverMenu):
         self._window = application.props.window
 
         self._coreobject = coreobject
+        self._coresong: CoreSong
         self._song_widget = song_widget
-
-        if isinstance(song_widget, SongWidget):
-            self._coresong = song_widget.props.coresong
-        else:
-            self._coresong = coreobject
+        self.props.coreobject = coreobject
 
         self._playlist_dialog: Optional[PlaylistDialog] = None
 
@@ -122,7 +120,21 @@ class SongWidgetMenu(Gtk.PopoverMenu):
         self._playlist_dialog.present()
 
     def _remove_from_playlist(self, action: Gio.Simple, param: Any) -> None:
+        assert isinstance(self._coreobject, Playlist)
         self.popdown()
         position = self._song_widget.get_index()
         SongToast(
             self._application, self._coreobject, position, self._coresong)
+
+    @GObject.Property(type=GObject.GObject)
+    def coreobject(self) -> CoreObject:
+        return self._coreobject
+
+    @coreobject.setter  # type: ignore
+    def coreobject(self, coreobject: CoreObject) -> None:
+        self._coreobject = coreobject
+
+        if isinstance(self._song_widget, SongWidget):
+            self._coresong = self._song_widget.props.coresong
+        else:
+            self._coresong = coreobject


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