[gnome-music/wip/mschraal/default-icon-cleanups: 6/25] artistalbumswidget: Use Gtk.Template




commit b181e22ceea253844546eb8d51407206c13bc271
Author: Marinus Schraal <mschraal gnome org>
Date:   Wed Aug 25 00:49:57 2021 +0200

    artistalbumswidget: Use Gtk.Template
    
    * Port to Gtk.Template
    * Add type hints

 data/org.gnome.Music.gresource.xml       |  1 +
 data/ui/ArtistAlbumsWidget.ui            | 10 ++++++++++
 gnomemusic/widgets/artistalbumswidget.py | 23 ++++++++++++++---------
 3 files changed, 25 insertions(+), 9 deletions(-)
---
diff --git a/data/org.gnome.Music.gresource.xml b/data/org.gnome.Music.gresource.xml
index 1c31a6ad9..5ea55cddb 100644
--- a/data/org.gnome.Music.gresource.xml
+++ b/data/org.gnome.Music.gresource.xml
@@ -9,6 +9,7 @@
     <file preprocess="xml-stripblanks">ui/AlbumCover.ui</file>
     <file preprocess="xml-stripblanks">ui/AlbumWidget.ui</file>
     <file preprocess="xml-stripblanks">ui/AlbumsView.ui</file>
+    <file preprocess="xml-stripblanks">ui/ArtistAlbumsWidget.ui</file>
     <file preprocess="xml-stripblanks">ui/ArtistSearchTile.ui</file>
     <file preprocess="xml-stripblanks">ui/AppMenu.ui</file>
     <file preprocess="xml-stripblanks">ui/ArtistsView.ui</file>
diff --git a/data/ui/ArtistAlbumsWidget.ui b/data/ui/ArtistAlbumsWidget.ui
new file mode 100644
index 000000000..77cf09926
--- /dev/null
+++ b/data/ui/ArtistAlbumsWidget.ui
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <requires lib="gtk+" version="3.18"/>
+  <template class="ArtistAlbumsWidget" parent="GtkListBox">
+    <property name="visible">True</property>
+    <style>
+      <class name="artist-album-widget"/>
+    </style>
+  </template>
+</interface>
diff --git a/gnomemusic/widgets/artistalbumswidget.py b/gnomemusic/widgets/artistalbumswidget.py
index c65dafa9e..eb6291a08 100644
--- a/gnomemusic/widgets/artistalbumswidget.py
+++ b/gnomemusic/widgets/artistalbumswidget.py
@@ -22,11 +22,18 @@
 # code, but you are not obligated to do so.  If you do not wish to do so,
 # delete this exception statement from your version.
 
+from __future__ import annotations
+import typing
+
 from gi.repository import GObject, Gtk
 
 from gnomemusic.widgets.albumwidget import AlbumWidget
+if typing.TYPE_CHECKING:
+    from gnomemusic.application import Application
+    from gnomemusic.coreartist import CoreArtist
 
 
+@Gtk.Template(resource_path="/org/gnome/Music/ui/ArtistAlbumsWidget.ui")
 class ArtistAlbumsWidget(Gtk.ListBox):
     """Widget containing all albums by an artist
 
@@ -39,7 +46,8 @@ class ArtistAlbumsWidget(Gtk.ListBox):
 
     selection_mode = GObject.Property(type=bool, default=False)
 
-    def __init__(self, coreartist, application):
+    def __init__(
+            self, coreartist: CoreArtist, application: Application) -> None:
         """Initialize the ArtistAlbumsWidget
 
         :param CoreArtist coreartist: The CoreArtist object
@@ -54,9 +62,6 @@ class ArtistAlbumsWidget(Gtk.ListBox):
 
         self.bind_model(self._model, self._add_album)
 
-        self.get_style_context().add_class("artist-albums-widget")
-        self.props.visible = True
-
     def _add_album(self, corealbum):
         row = Gtk.ListBoxRow()
         row.props.selectable = False
@@ -77,21 +82,21 @@ class ArtistAlbumsWidget(Gtk.ListBox):
 
         return row
 
-    def select_all(self):
+    def select_all(self) -> None:
         """Select all items"""
-        def toggle_selection(row):
+        def toggle_selection(row: Gtk.ListBoxRow) -> None:
             row.get_child().select_all()
 
         self.foreach(toggle_selection)
 
-    def deselect_all(self):
+    def deselect_all(self) -> None:
         """Deselect all items"""
-        def toggle_selection(row):
+        def toggle_selection(row: Gtk.ListBoxRow) -> None:
             row.get_child().deselect_all()
 
         self.foreach(toggle_selection)
 
     @GObject.Property(type=str, flags=GObject.ParamFlags.READABLE)
-    def artist(self):
+    def artist(self) -> str:
         """Artist name"""
         return self._artist.props.artist


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