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



commit 1fd6559551e25c3fbedc64766b2867a77cfa26b7
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, however on
    startup the toolbar is not shown. For that special case there is some
    additional logic in Window and PlayerToolbar itself.
    This also removes one init argument from PlayerToolbar.

 gnomemusic/widgets/playertoolbar.py |  8 +++-----
 gnomemusic/window.py                | 17 ++++++++---------
 2 files changed, 11 insertions(+), 14 deletions(-)
---
diff --git a/gnomemusic/widgets/playertoolbar.py b/gnomemusic/widgets/playertoolbar.py
index 7c0b69ca..14c8d484 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
 
@@ -127,9 +126,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 3b0d6848..35de6e57 100644
--- a/gnomemusic/window.py
+++ b/gnomemusic/window.py
@@ -130,7 +130,7 @@ class Window(Gtk.ApplicationWindow):
     def _setup_view(self):
         self._headerbar = HeaderBar()
 
-        self._player_toolbar = PlayerToolbar(self._player, self)
+        self._player_toolbar = PlayerToolbar(self._player)
         self.views = [None] * len(View)
 
         self._headerbar.bind_property(
@@ -152,8 +152,10 @@ class Window(Gtk.ApplicationWindow):
             GObject.BindingFlags.BIDIRECTIONAL |
             GObject.BindingFlags.SYNC_CREATE)
         self.bind_property(
-            'selection-mode', self._selection_toolbar, 'visible',
-            GObject.BindingFlags.SYNC_CREATE)
+            'selection-mode', self._player_toolbar, 'visible',
+            GObject.BindingFlags.INVERT_BOOLEAN)
+        self.bind_property(
+            'selection-mode', self._selection_toolbar, 'visible')
         # Create only the empty view at startup
         # if no music, switch to empty view and hide stack
         # if some music is available, populate stack with mainviews,
@@ -180,8 +182,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()
@@ -267,6 +267,9 @@ class Window(Gtk.ApplicationWindow):
         self.views[View.SEARCH].bind_property(
             'search-state', self._searchbar, 'search-state')
 
+        # Hide the player toolbar on startup.
+        self._player_toolbar.hide()
+
     @log
     def _select_all(self, action=None, param=None):
         if not self.props.selection_mode:
@@ -471,10 +474,6 @@ class Window(Gtk.ApplicationWindow):
 
     @log
     def _on_selection_mode_changed(self, widget, data=None):
-        if self.props.selection_mode:
-            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]