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



commit 5191196cfd01c26e1ee17007e89fe0d134314b4d
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 |  6 ++----
 gnomemusic/window.py                | 17 ++++++++---------
 2 files changed, 10 insertions(+), 13 deletions(-)
---
diff --git a/gnomemusic/widgets/playertoolbar.py b/gnomemusic/widgets/playertoolbar.py
index 78917de9..5508013e 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.player = self._player.get_gst_player()
 
@@ -132,8 +131,7 @@ class PlayerToolbar(Gtk.ActionBar):
 
     @log
     def _sync_playing(self, player):
-        if not self._main_window.props.selection_mode:
-            self.show()
+        self.show()
 
         if self._player.get_playback_status() == Playback.PLAYING:
             image = self._pause_image
diff --git a/gnomemusic/window.py b/gnomemusic/window.py
index f2993650..a9150e11 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()
@@ -256,6 +256,9 @@ class Window(Gtk.ApplicationWindow):
 
         self._stack.set_visible_child(self.views[View.ALBUM])
 
+        # 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:
@@ -468,10 +471,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]