[gnome-music/wip/mschraal/window-template: 2/5] playertoolbar: Shift visibility logic around



commit 59e7cdf36843c133005564643f680c8c83167e92
Author: Marinus Schraal <mschraal gnome org>
Date:   Sat Sep 8 14:41:18 2018 +0200

    playertoolbar: Shift visibility logic around
    
    Move most of the PlayerToolbar visibility logic to Window. This also
    removes one init argument from PlayerToolbar.

 gnomemusic/widgets/playertoolbar.py |  8 +++-----
 gnomemusic/window.py                | 13 ++++++-------
 2 files changed, 9 insertions(+), 12 deletions(-)
---
diff --git a/gnomemusic/widgets/playertoolbar.py b/gnomemusic/widgets/playertoolbar.py
index 3c38f051..c0ee9f83 100644
--- a/gnomemusic/widgets/playertoolbar.py
+++ b/gnomemusic/widgets/playertoolbar.py
@@ -66,10 +66,9 @@ class PlayerToolbar(Gtk.ActionBar):
         return '<PlayerToolbar>'
 
     @log
-    def __init__(self, player, main_window):
+    def __init__(self, player):
         super().__init__()
 
-        self._main_window = main_window
         self._player = player
         self._progress_scale.props.player = self._player
 
@@ -131,9 +130,8 @@ class PlayerToolbar(Gtk.ActionBar):
         self._repeat_image.set_from_icon_name(icon, Gtk.IconSize.MENU)
 
     @log
-    def _sync_playing(self, klass, args):
-        if not self._main_window.props.selection_mode:
-            self.show()
+    def _sync_playing(self, player, state):
+        self.show()
 
         if self._player.props.state == Playback.PLAYING:
             image = self._pause_image
diff --git a/gnomemusic/window.py b/gnomemusic/window.py
index 0af9f176..135733de 100644
--- a/gnomemusic/window.py
+++ b/gnomemusic/window.py
@@ -27,6 +27,7 @@ from gettext import gettext as _
 
 from gnomemusic import log
 from gnomemusic.grilo import grilo
+from gnomemusic.gstplayer import Playback
 from gnomemusic.mediakeys import MediaKeys
 from gnomemusic.player import RepeatMode
 from gnomemusic.playlists import Playlists
@@ -141,13 +142,13 @@ class Window(Gtk.ApplicationWindow):
             "state", self._searchbar, "search-state",
             GObject.BindingFlags.SYNC_CREATE)
 
-        self._player_toolbar = PlayerToolbar(self._player, self)
+        self._player_toolbar = PlayerToolbar(self._player)
+
         self.views = [None] * len(View)
 
         self._headerbar.connect(
             'back-button-clicked', self._switch_back_from_childview)
 
-        self.connect('notify::selection-mode', self._on_selection_mode_changed)
         self.bind_property(
             'selected-items-count', self._headerbar, 'selected-items-count')
         self.bind_property(
@@ -162,6 +163,7 @@ class Window(Gtk.ApplicationWindow):
             GObject.BindingFlags.INVERT_BOOLEAN)
         self.bind_property(
             'selection-mode', self._selection_toolbar, 'visible')
+        self.connect('notify::selection-mode', self._on_selection_mode_changed)
 
         # Create only the empty view at startup
         # if no music, switch to empty view and hide stack
@@ -190,8 +192,6 @@ class Window(Gtk.ApplicationWindow):
         self._headerbar.props.state = HeaderBar.State.MAIN
         self._headerbar.show()
 
-        self._player_toolbar.show_all()
-
         def songs_available_cb(available):
             if available:
                 self._switch_to_player_view()
@@ -480,10 +480,9 @@ class Window(Gtk.ApplicationWindow):
 
     @log
     def _on_selection_mode_changed(self, widget, data=None):
-        if self.props.selection_mode:
+        if (not self.props.selection_mode
+                and self._player.state == Playback.STOPPED):
             self._player_toolbar.hide()
-        elif self._player.props.playing:
-            self._player_toolbar.show()
         if not self.props.selection_mode:
             self._on_changes_pending()
 


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