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




commit 2f186b3ad11254974181a87d485046fe8d2f60b7
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 | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)
---
diff --git a/gnomemusic/widgets/songwidgetmenu.py b/gnomemusic/widgets/songwidgetmenu.py
index 86a3b1529..fc27239d5 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
 
@@ -126,3 +124,16 @@ class SongWidgetMenu(Gtk.PopoverMenu):
         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]