[gnome-music] artistalbumswidget: Use Gtk.Template



commit 24443f4d743708016eccaa4799927f6ca035d132
Author: Apostol Bakalov <apogza gmail com>
Date:   Fri Jun 15 18:49:34 2018 +0300

    artistalbumswidget: Use Gtk.Template

 data/ArtistAlbumsWidget.ui               |  6 +++---
 gnomemusic/widgets/artistalbumswidget.py | 10 ++++++----
 2 files changed, 9 insertions(+), 7 deletions(-)
---
diff --git a/data/ArtistAlbumsWidget.ui b/data/ArtistAlbumsWidget.ui
index 445615c0..7add0951 100644
--- a/data/ArtistAlbumsWidget.ui
+++ b/data/ArtistAlbumsWidget.ui
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <!-- interface-requires gtk+ 3.12 -->
-  <object class="GtkBox" id="ArtistAlbumsWidget">
+  <template class="ArtistAlbumsWidget" parent="GtkBox">
     <property name="name">ArtistAlbumsWidget</property>
     <property name="visible">True</property>
     <property name="can_focus">False</property>
@@ -9,7 +9,7 @@
     <property name="margin_top">18</property>
     <property name="orientation">vertical</property>
     <child>
-      <object class="GtkLabel" id="artist">
+      <object class="GtkLabel" id="_artist">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
         <property name="xalign">0</property>
@@ -37,5 +37,5 @@
         <property name="position">1</property>
       </packing>
     </child>
-  </object>
+  </template>
 </interface>
diff --git a/gnomemusic/widgets/artistalbumswidget.py b/gnomemusic/widgets/artistalbumswidget.py
index e0c4c99a..5590262c 100644
--- a/gnomemusic/widgets/artistalbumswidget.py
+++ b/gnomemusic/widgets/artistalbumswidget.py
@@ -33,6 +33,7 @@ from gnomemusic.widgets.songwidget import SongWidget
 logger = logging.getLogger(__name__)
 
 
+@Gtk.Template(resource_path='/org/gnome/Music/ArtistAlbumsWidget.ui')
 class ArtistAlbumsWidget(Gtk.Box):
     """Widget containing all albums by an artist
 
@@ -41,6 +42,10 @@ class ArtistAlbumsWidget(Gtk.Box):
     the album(s).
     """
 
+    __gtype_name__ = 'ArtistAlbumsWidget'
+
+    _artist = Gtk.Template.Child()
+
     def __repr__(self):
         return '<ArtistAlbumsWidget>'
 
@@ -57,9 +62,7 @@ class ArtistAlbumsWidget(Gtk.Box):
         self._selection_toolbar = selection_toolbar
         self._header_bar = header_bar
 
-        ui = Gtk.Builder()
-        ui.add_from_resource('/org/gnome/Music/ArtistAlbumsWidget.ui')
-        ui.get_object('artist').set_label(self.artist)
+        self._artist.props.label = self.artist
 
         self._widgets = []
 
@@ -68,7 +71,6 @@ class ArtistAlbumsWidget(Gtk.Box):
         self._row_changed_source_id = None
 
         hbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
-        hbox.pack_start(ui.get_object('ArtistAlbumsWidget'), False, False, 0)
         self._album_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL,
                                   spacing=48)
         hbox.pack_start(self._album_box, False, False, 16)


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