[gnome-music/wip/mschraal/playlistcontrols-disable-play-on-empty-3-34] playlistcontrols: Disable play item on empty list



commit 71a39070ce246819cbf2c3d4df057ccf01d60d8b
Author: Marinus Schraal <mschraal gnome org>
Date:   Fri Jan 3 21:30:53 2020 +0100

    playlistcontrols: Disable play item on empty list
    
    The popup "Play" item should be disabled on an empty list.
    
    Closes: #354

 gnomemusic/views/playlistsview.py      |  6 ++----
 gnomemusic/widgets/playlistcontrols.py | 11 ++++++++++-
 2 files changed, 12 insertions(+), 5 deletions(-)
---
diff --git a/gnomemusic/views/playlistsview.py b/gnomemusic/views/playlistsview.py
index 02d2e66b..bc133426 100644
--- a/gnomemusic/views/playlistsview.py
+++ b/gnomemusic/views/playlistsview.py
@@ -62,8 +62,6 @@ class PlaylistsView(BaseView):
         self._window = application.props.window
         self._player = player
 
-        self._pl_ctrls = PlaylistControls()
-
         self._song_popover = PlaylistContextMenu(self._view)
 
         play_song = Gio.SimpleAction.new('play_song', None)
@@ -81,8 +79,7 @@ class PlaylistsView(BaseView):
         self._window.add_action(self._remove_song_action)
 
         playlist_play_action = Gio.SimpleAction.new('playlist_play', None)
-        playlist_play_action.connect(
-            'activate', self._on_play_playlist)
+        playlist_play_action.connect("activate", self._on_play_playlist)
         self._window.add_action(playlist_play_action)
 
         self._playlist_delete_action = Gio.SimpleAction.new(
@@ -97,6 +94,7 @@ class PlaylistsView(BaseView):
             'activate', self._stage_playlist_for_renaming)
         self._window.add_action(self._playlist_rename_action)
 
+        self._pl_ctrls = PlaylistControls(application)
         self._grid.insert_row(0)
         self._grid.attach(self._pl_ctrls, 1, 0, 1, 1)
 
diff --git a/gnomemusic/widgets/playlistcontrols.py b/gnomemusic/widgets/playlistcontrols.py
index 9a08a397..9104f760 100644
--- a/gnomemusic/widgets/playlistcontrols.py
+++ b/gnomemusic/widgets/playlistcontrols.py
@@ -46,12 +46,19 @@ class PlaylistControls(Gtk.Grid):
     def __repr__(self):
         return '<PlaylistControls>'
 
-    def __init__(self):
+    def __init__(self, application):
+        """Initialize
+
+        :param GtkApplication application: The application object
+        """
         super().__init__()
 
         self._playlist = None
         self._count_id = 0
         self._binding_count = None
+        self._window = application.props.window
+
+        self._play_action = self._window.lookup_action("playlist_play")
 
     @Gtk.Template.Callback()
     @log
@@ -83,6 +90,8 @@ class PlaylistControls(Gtk.Grid):
             "{} Song", "{} Songs", self.props.playlist.count).format(
                 self.props.playlist.count)
 
+        self._play_action.props.enabled = self.props.playlist.props.count > 0
+
     @log
     def enable_rename_playlist(self, pl_torename):
         """Enables rename button and entry


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