[gnome-music/wip/jfelder/gtk4-v3: 30/110] headerbar: Restore headerbar title and subtitle




commit 4aec8e5f86d38cca18de8067f82f11f894e171b6
Author: Jean Felder <jfelder src gnome org>
Date:   Mon Jan 10 18:38:02 2022 +0100

    headerbar: Restore headerbar title and subtitle

 data/ui/HeaderBar.ui            | 27 +++++++++++++++++++++++++++
 gnomemusic/views/albumsview.py  |  6 +++---
 gnomemusic/views/searchview.py  | 13 +++++--------
 gnomemusic/widgets/headerbar.py | 15 +++++++++++++++
 4 files changed, 50 insertions(+), 11 deletions(-)
---
diff --git a/data/ui/HeaderBar.ui b/data/ui/HeaderBar.ui
index 87de27138..ebecae2be 100644
--- a/data/ui/HeaderBar.ui
+++ b/data/ui/HeaderBar.ui
@@ -107,6 +107,33 @@
       </object>
     </child>
   </template>
+  <object class="GtkBox" id="_label_title_box">
+    <property name="orientation">vertical</property>
+    <child>
+      <object class="GtkLabel" id="_label_title">
+        <property name="single-line-mode">True</property>
+        <property name="ellipsize">end</property>
+        <property name="width-chars">5</property>
+        <property name="vexpand">True</property>
+        <property name="yalign">1.0</property>
+        <style>
+          <class name="title"/>
+        </style>
+      </object>
+    </child>
+    <child>
+      <object class="GtkLabel" id="_label_subtitle">
+        <property name="single-line-mode">True</property>
+        <property name="ellipsize">end</property>
+        <property name="width-chars">5</property>
+        <property name="vexpand">True</property>
+        <property name="yalign">0.0</property>
+        <style>
+          <class name="subtitle"/>
+        </style>
+      </object>
+    </child>
+  </object>
   <object class="GtkSizeGroup" id="size1">
     <property name="mode">vertical</property>
     <widgets>
diff --git a/gnomemusic/views/albumsview.py b/gnomemusic/views/albumsview.py
index 4ccca9eef..f86900eae 100644
--- a/gnomemusic/views/albumsview.py
+++ b/gnomemusic/views/albumsview.py
@@ -229,10 +229,10 @@ class AlbumsView(Gtk.Stack):
         self._set_album_headerbar(corealbum)
         self.set_visible_child_name("widget")
 
-    def _set_album_headerbar(self, corealbum):
+    def _set_album_headerbar(self, corealbum: CoreAlbum) -> None:
         self._headerbar.props.state = HeaderBar.State.CHILD
-        # self._headerbar.props.title = corealbum.props.title
-        # self._headerbar.props.subtitle = corealbum.props.artist
+        self._headerbar.set_label_title(
+            corealbum.props.title, corealbum.props.artist)
 
     # @Gtk.Template.Callback()
     # def _on_flowbox_press_begin(self, gesture, sequence):
diff --git a/gnomemusic/views/searchview.py b/gnomemusic/views/searchview.py
index cc36dd381..4283da91f 100644
--- a/gnomemusic/views/searchview.py
+++ b/gnomemusic/views/searchview.py
@@ -360,8 +360,8 @@ class SearchView(Gtk.Stack):
 
         self.props.state = SearchView.State.ALBUM
         self._headerbar.props.state = HeaderBar.State.SEARCH
-        self._headerbar.props.title = corealbum.props.title
-        self._headerbar.props.subtitle = corealbum.props.artist
+        self._headerbar.set_label_title(
+            corealbum.props.title, corealbum.props.artist)
 
         self.set_visible_child(self._scrolled_album_widget)
         self.props.search_mode_active = False
@@ -389,8 +389,7 @@ class SearchView(Gtk.Stack):
 
         self.props.state = SearchView.State.ARTIST
         self._headerbar.props.state = HeaderBar.State.SEARCH
-        self._headerbar.props.title = coreartist.props.artist
-        self._headerbar.props.subtitle = None
+        self._headerbar.props.set_label_title(coreartist.props.artist, "")
 
         self.set_visible_child(self._scrolled_artist_window)
         self.props.search_mode_active = False
@@ -399,8 +398,7 @@ class SearchView(Gtk.Stack):
     def _on_all_artists_clicked(self, widget, event, user_data=None):
         self.props.state = SearchView.State.ALL_ARTISTS
         self._headerbar.props.state = HeaderBar.State.SEARCH
-        self._headerbar.props.title = _("Artists Results")
-        self._headerbar.props.subtitle = None
+        self._headerbar.props.set_label_title(_("Artists Results"), "")
 
         self._artist_all_flowbox.props.visible = True
         self._album_all_flowbox.props.visible = False
@@ -414,8 +412,7 @@ class SearchView(Gtk.Stack):
     def _on_all_albums_clicked(self, widget, event, user_data=None):
         self.props.state = SearchView.State.ALL_ALBUMS
         self._headerbar.props.state = HeaderBar.State.SEARCH
-        self._headerbar.props.title = _("Albums Results")
-        self._headerbar.props.subtitle = None
+        self._headerbar.props.set_label_title(_("Albums Results"), "")
 
         self._artist_all_flowbox.props.visible = False
         self._album_all_flowbox.props.visible = True
diff --git a/gnomemusic/widgets/headerbar.py b/gnomemusic/widgets/headerbar.py
index 6872a46cb..8fb912938 100644
--- a/gnomemusic/widgets/headerbar.py
+++ b/gnomemusic/widgets/headerbar.py
@@ -93,6 +93,9 @@ class HeaderBar(Adw.Bin):
     _cancel_button = Gtk.Template.Child()
     _back_button = Gtk.Template.Child()
     _headerbar = Gtk.Template.Child()
+    _label_title_box = Gtk.Template.Child()
+    _label_title = Gtk.Template.Child()
+    _label_subtitle = Gtk.Template.Child()
     _menu_button = Gtk.Template.Child()
 
     search_mode_active = GObject.Property(type=bool, default=False)
@@ -205,6 +208,18 @@ class HeaderBar(Adw.Bin):
             self._select_button.props.sensitive = True
             self._stack_switcher.show()
 
+    def set_label_title(self, title: str, subtitle: str) -> None:
+        """Set the headerbar title-widget as two labels:
+        a title and a subtitle
+
+        :param str title: headerbar title
+        :param str subtitle: headerbar subtitle
+        :returns:
+        """
+        self._headerbar.props.title_widget = self._label_title_box
+        self._label_title.props.label = title
+        self._label_subtitle.props.label = subtitle
+
     @Gtk.Template.Callback()
     def _on_back_button_clicked(self, widget=None):
         self.emit('back-button-clicked')


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