[gnome-music/wip/jfelder/gtk4-v3: 24/174] Adapt PlayerToolbar to GTK4 changes




commit b21e94020ffb7bc529f0d9a259f5a4bd65224520
Author: Marinus Schraal <mschraal gnome org>
Date:   Sun Apr 11 21:10:39 2021 +0200

    Adapt PlayerToolbar to GTK4 changes

 data/org.gnome.Music.css            |  2 --
 data/ui/PlayerToolbar.ui            | 49 +++++++++----------------------------
 gnomemusic/widgets/playertoolbar.py | 26 +++++++-------------
 gnomemusic/window.py                |  4 +--
 4 files changed, 22 insertions(+), 59 deletions(-)
---
diff --git a/data/org.gnome.Music.css b/data/org.gnome.Music.css
index 9e2cea716..640a52583 100644
--- a/data/org.gnome.Music.css
+++ b/data/org.gnome.Music.css
@@ -31,7 +31,6 @@
 
 .semi-circular {
     border-radius: 20px;
-    -gtk-outline-radius: 20px;
 }
 
 .semi-circular:hover {
@@ -43,7 +42,6 @@
 
 .pill {
     border-radius: 9999px;
-    -gtk-outline-radius: 9999px;
 }
 
 .smooth-scale {
diff --git a/data/ui/PlayerToolbar.ui b/data/ui/PlayerToolbar.ui
index f67fbae81..995ec1d20 100644
--- a/data/ui/PlayerToolbar.ui
+++ b/data/ui/PlayerToolbar.ui
@@ -1,36 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <requires lib="gtk+" version="3.12"/>
-  <object class="GtkImage" id="next_image">
-    <property name="visible">True</property>
-    <property name="can_focus">False</property>
-    <property name="icon_name">media-skip-forward-symbolic</property>
-    <property name="icon_size">1</property>
-  </object>
-  <object class="GtkImage" id="_pause_image">
-    <property name="visible">True</property>
-    <property name="can_focus">False</property>
-    <property name="icon_name">media-playback-pause-symbolic</property>
-    <property name="icon_size">3</property>
-    <property name="margin-bottom">4</property>
-    <property name="margin-top">4</property>
-  </object>
-  <object class="GtkImage" id="_play_image">
-    <property name="visible">True</property>
-    <property name="can_focus">False</property>
-    <property name="icon_name">media-playback-start-symbolic</property>
-    <property name="icon_size">3</property>
-    <property name="margin-bottom">4</property>
-    <property name="margin-top">4</property>
-  </object>
-  <object class="GtkImage" id="previous_image">
-    <property name="visible">True</property>
-    <property name="can_focus">False</property>
-    <property name="icon_name">media-skip-backward-symbolic</property>
-    <property name="icon_size">1</property>
-  </object>
   <template class="PlayerToolbar" parent="GtkActionBar">
     <property name="can_focus">False</property>
+    <property name="revealed">False</property>
     <child>
       <object class="GtkBox" id="_song_info_box">
         <property name="visible">True</property>
@@ -86,6 +59,7 @@
     </child>
     <child type="center">
       <object class="GtkBox" id="_buttons_and_scale">
+        <property name="hexpand">True</property>
         <property name="orientation">vertical</property>
         <property name="visible">True</property>
         <property name="can_focus">False</property>
@@ -106,8 +80,7 @@
                 <property name="sensitive">False</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">True</property>
-                <property name="image">previous_image</property>
-                <property name="always_show_image">True</property>
+                <property name="icon_name">media-skip-backward-symbolic</property>
                 <property name="tooltip_text" translatable="yes">Previous</property>
                 <signal name="clicked" handler="_on_prev_button_clicked" swapped="no"/>
                 <style>
@@ -123,14 +96,18 @@
                 <property name="sensitive">False</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">True</property>
-                <property name="image">_play_image</property>
-                <property name="always_show_image">True</property>
                 <property name="tooltip_text" translatable="yes">Play</property>
                 <signal name="clicked" handler="_on_play_button_clicked" swapped="no"/>
                 <style>
                   <class name="border-solid"/>
                   <class name="pill"/>
                 </style>
+                <child>
+                  <object class="GtkImage" id="_play_pause_image">
+                    <property name="icon_name">media-playback-start-symbolic</property>
+                    <property name="icon_size">2</property>
+                  </object>
+                </child>
               </object>
             </child>
             <child>
@@ -140,8 +117,7 @@
                 <property name="sensitive">False</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">True</property>
-                <property name="image">next_image</property>
-                <property name="always_show_image">True</property>
+                <property name="icon_name">media-skip-forward-symbolic</property>
                 <property name="tooltip_text" translatable="yes">Next</property>
                 <signal name="clicked" handler="_on_next_button_clicked" swapped="no"/>
                 <style>
@@ -208,7 +184,7 @@
         </child>
       </object>
     </child>
-    <child>
+    <child type="end">
       <object class="GtkBox" id="menuBox">
         <property name="height_request">34</property>
         <property name="visible">True</property>
@@ -251,9 +227,6 @@
           </object>
         </child>
       </object>
-      <packing>
-        <property name="pack-type">end</property>
-      </packing>
     </child>
   </template>
 </interface>
diff --git a/gnomemusic/widgets/playertoolbar.py b/gnomemusic/widgets/playertoolbar.py
index f148bd228..b609b4e98 100644
--- a/gnomemusic/widgets/playertoolbar.py
+++ b/gnomemusic/widgets/playertoolbar.py
@@ -28,6 +28,7 @@ from gi.repository import Gio, GLib, GObject, Gtk
 from gnomemusic.gstplayer import Playback
 from gnomemusic.utils import ArtSize, DefaultIconType
 from gnomemusic.player import Player, RepeatMode
+from gnomemusic.widgets.artstack import ArtStack  # noqa: F401
 from gnomemusic.widgets.smoothscale import SmoothScale  # noqa: F401
 from gnomemusic.widgets.twolinetip import TwoLineTip
 import gnomemusic.utils as utils
@@ -44,12 +45,10 @@ class PlayerToolbar(Gtk.ActionBar):
 
     _artist_label = Gtk.Template.Child()
     _art_stack = Gtk.Template.Child()
-    _buttons_and_scale = Gtk.Template.Child()
     _duration_label = Gtk.Template.Child()
     _next_button = Gtk.Template.Child()
-    _pause_image = Gtk.Template.Child()
     _play_button = Gtk.Template.Child()
-    _play_image = Gtk.Template.Child()
+    _play_pause_image = Gtk.Template.Child()
     _prev_button = Gtk.Template.Child()
     _progress_scale = Gtk.Template.Child()
     _progress_time_label = Gtk.Template.Child()
@@ -68,13 +67,6 @@ class PlayerToolbar(Gtk.ActionBar):
 
         self._tooltip = TwoLineTip()
 
-        # A centered widget has an expand child property set to False
-        # by default. It needs to be True to have a progress scale
-        # at the correct size.
-        main_container = self._buttons_and_scale.get_parent()
-        main_container.child_set_property(
-            self._buttons_and_scale, "expand", True)
-
         repeat_menu = Gio.Menu.new()
         for mode in RepeatMode:
             item = Gio.MenuItem.new()
@@ -158,26 +150,26 @@ class PlayerToolbar(Gtk.ActionBar):
 
     def _sync_repeat_image(self) -> None:
         self._repeat_image.set_from_icon_name(
-            self._player.props.repeat_mode.icon, Gtk.IconSize.MENU)
+            self._player.props.repeat_mode.icon)
 
     def _sync_playing(self, player, state):
         if (self._player.props.state == Playback.STOPPED
                 and not self._player.props.has_next
                 and not self._player.props.has_previous):
-            self.hide()
+            self.props.revealed = False
             return
 
-        self.show()
+        self.props.revealed = True
 
         if self._player.props.state == Playback.PLAYING:
-            image = self._pause_image
+            icon_name = "media-playback-pause-symbolic"
             tooltip = _("Pause")
         else:
-            image = self._play_image
+            icon_name = "media-playback-start-symbolic"
             tooltip = _("Play")
 
-        if self._play_button.get_image() != image:
-            self._play_button.set_image(image)
+        if self._play_pause_image.props.icon_name != icon_name:
+            self._play_pause_image.props.icon_name = icon_name
 
         self._play_button.set_tooltip_text(tooltip)
 
diff --git a/gnomemusic/window.py b/gnomemusic/window.py
index 9ec551cb9..c3719987f 100644
--- a/gnomemusic/window.py
+++ b/gnomemusic/window.py
@@ -444,7 +444,7 @@ class Window(Adw.ApplicationWindow):
     def _on_selection_mode_changed(self, widget, data=None):
         if (not self.props.selection_mode
                 and self._player.state == Playback.STOPPED):
-            self._player_toolbar.hide()
+            self._player_toolbar.props.revealed = False
 
     def _on_add_to_playlist(self, widget: SelectionToolbar) -> None:
 
@@ -478,4 +478,4 @@ class Window(Adw.ApplicationWindow):
 
         :param bool visible: actionbar visibility
         """
-        self._player_toolbar.set_visible(visible)
+        self._player_toolbar.props.revealed = visible


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