[gnome-music/wip/jfelder/new-artist-design: 4/6] albumwidget: Add an active_core_object parameter




commit 637bc1afc5631239f49444ca82984ed021d78e5c
Author: Jean Felder <jfelder src gnome org>
Date:   Fri Jul 30 19:14:53 2021 +0200

    albumwidget: Add an active_core_object parameter
    
    The active_core_object parameter is used to set the player playlist
    when a song is activated. By default, the current album is used.
    This will be used by ArtistAlbumsWidget to play the songs of an
    artist.

 gnomemusic/widgets/albumwidget.py | 35 ++++++++++++++++++++++++++++-------
 1 file changed, 28 insertions(+), 7 deletions(-)
---
diff --git a/gnomemusic/widgets/albumwidget.py b/gnomemusic/widgets/albumwidget.py
index 5794b36e0..399c703af 100644
--- a/gnomemusic/widgets/albumwidget.py
+++ b/gnomemusic/widgets/albumwidget.py
@@ -23,7 +23,7 @@
 # delete this exception statement from your version.
 
 from __future__ import annotations
-from typing import Any, Optional
+from typing import Any, Optional, Union
 import typing
 
 from gi.repository import Gfm, Gio, GLib, GObject, Gtk
@@ -35,10 +35,13 @@ from gnomemusic.widgets.disclistboxwidget import DiscListBox  # noqa: F401
 from gnomemusic.widgets.playlistdialog import PlaylistDialog
 if typing.TYPE_CHECKING:
     from gnomemusic.application import Application
+    from gnomemusic.coreartist import CoreArtist
     from gnomemusic.coredisc import CoreDisc
     from gnomemusic.coresong import CoreSong
     from gnomemusic.widgets.songwidget import SongWidget
 
+    ActiveObjectType = Union[CoreAlbum, CoreArtist]
+
 
 @Gtk.Template(resource_path='/org/gnome/Music/ui/AlbumWidget.ui')
 class AlbumWidget(Gtk.Box):
@@ -76,6 +79,7 @@ class AlbumWidget(Gtk.Box):
 
         self._application = application
         self._corealbum: Any = None
+        self._active_core_objet: Optional[ActiveObjectType] = None
         self._coremodel = self._application.props.coremodel
         self._model_signal_id = 0
 
@@ -115,14 +119,27 @@ class AlbumWidget(Gtk.Box):
         if self._cover_size_group:
             self._cover_size_group.add_widget(self._art_stack)
 
-    def update(self, corealbum: CoreAlbum) -> None:
+    def update(
+            self, corealbum: CoreAlbum,
+            active_core_object: Optional[ActiveObjectType] = None) -> None:
         """Update the album widget.
 
+        The active_core_object parameter is used to set the player
+        playlist when a song is activated. This in only useful to
+        play an artist. By default, the current album is used.
+
         :param CoreAlbum album: The CoreAlbum object
+        :param Union[CoreAlbum, CoreArtist] active_core_object:
+            The active object
         """
         if self._corealbum:
             self._corealbum.props.model.disconnect(self._model_signal_id)
 
+        if active_core_object:
+            self._active_core_objet = active_core_object
+        else:
+            self._active_core_objet = corealbum
+
         self._corealbum = corealbum
 
         self._art_stack.props.coreobject = self._corealbum
@@ -188,7 +205,9 @@ class AlbumWidget(Gtk.Box):
         self._composer_label.props.visible = show
         self._composer_label.props.visible = show
 
-    def _play(self, coresong: Optional[CoreSong] = None) -> None:
+    def _play(
+            self, active_object: ActiveObjectType,
+            coresong: Optional[CoreSong] = None) -> None:
         signal_id = 0
 
         def _on_playlist_loaded(klass, playlist_type):
@@ -197,7 +216,7 @@ class AlbumWidget(Gtk.Box):
 
         signal_id = self._coremodel.connect(
             "playlist-loaded", _on_playlist_loaded)
-        self._coremodel.props.active_core_object = self._corealbum
+        self._coremodel.props.active_core_object = active_object
 
     def _song_activated(
             self, widget: Gtk.Widget, song_widget: SongWidget) -> int:
@@ -205,7 +224,9 @@ class AlbumWidget(Gtk.Box):
             song_widget.props.selected = not song_widget.props.selected
             return GLib.SOURCE_CONTINUE
 
-        self._play(song_widget.props.coresong)
+        if self._active_core_objet:
+            self._play(self._active_core_objet, song_widget.props.coresong)
+
         return GLib.SOURCE_CONTINUE
 
     def select_all(self) -> None:
@@ -257,8 +278,8 @@ class AlbumWidget(Gtk.Box):
     def _on_play_action(
             self, action: Gio.SimpleAction,
             data: Optional[GLib.Variant]) -> None:
-        self._play()
+        self._play(self._corealbum)
 
     @Gtk.Template.Callback()
     def _on_play_button_clicked(self, button: Gtk.Button) -> None:
-        self._play()
+        self._play(self._corealbum)


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