[gnome-music/wip/jfelder/new-album-design-v3: 2/9] albumwidget: Add static type annotations




commit 5ab0be1d4aa5079783655159cc843563d0022ce8
Author: Jean Felder <jfelder src gnome org>
Date:   Fri Jul 30 15:44:48 2021 +0200

    albumwidget: Add static type annotations

 gnomemusic/widgets/albumwidget.py | 39 +++++++++++++++++++++++++--------------
 1 file changed, 25 insertions(+), 14 deletions(-)
---
diff --git a/gnomemusic/widgets/albumwidget.py b/gnomemusic/widgets/albumwidget.py
index 2671e4567..65f982eba 100644
--- a/gnomemusic/widgets/albumwidget.py
+++ b/gnomemusic/widgets/albumwidget.py
@@ -22,14 +22,21 @@
 # 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
 from gettext import ngettext
+from typing import Any, Optional
+import typing
 
-from gi.repository import GLib, GObject, Gtk
+from gi.repository import Gfm, GLib, GObject, Gtk
 
 from gnomemusic.corealbum import CoreAlbum
 from gnomemusic.utils import ArtSize
 from gnomemusic.widgets.disclistboxwidget import DiscBox
 from gnomemusic.widgets.disclistboxwidget import DiscListBox  # noqa: F401
+if typing.TYPE_CHECKING:
+    from gnomemusic.application import Application
+    from gnomemusic.coredisc import CoreDisc
+    from gnomemusic.widgets.songwidget import SongWidget
 
 
 @Gtk.Template(resource_path='/org/gnome/Music/ui/AlbumWidget.ui')
@@ -55,7 +62,7 @@ class AlbumWidget(Gtk.Box):
 
     _duration = 0
 
-    def __init__(self, application):
+    def __init__(self, application: Application) -> None:
         """Initialize the AlbumWidget.
 
         :param GtkApplication application: The application object
@@ -63,7 +70,7 @@ class AlbumWidget(Gtk.Box):
         super().__init__()
 
         self._application = application
-        self._corealbum = None
+        self._corealbum: Any = None
         self._coremodel = self._application.props.coremodel
         self._duration_signal_id = 0
         self._model_signal_id = 0
@@ -78,7 +85,7 @@ class AlbumWidget(Gtk.Box):
 
         self.connect("notify::selection-mode", self._on_selection_mode_changed)
 
-    def update(self, corealbum):
+    def update(self, corealbum: CoreAlbum) -> None:
         """Update the album widget.
 
         :param CoreAlbum album: The CoreAlbum object
@@ -115,7 +122,7 @@ class AlbumWidget(Gtk.Box):
 
         self._album_model.items_changed(0, 0, 0)
 
-    def _create_widget(self, disc):
+    def _create_widget(self, disc: CoreDisc) -> DiscBox:
         disc_box = DiscBox(disc)
         disc_box.connect('song-activated', self._song_activated)
 
@@ -126,8 +133,10 @@ class AlbumWidget(Gtk.Box):
 
         return disc_box
 
-    def _on_model_items_changed(self, model, position, removed, added):
-        n_items = model.get_n_items()
+    def _on_model_items_changed(
+            self, model: Gfm.SortListModel, position: int, removed: int,
+            added: int) -> None:
+        n_items: int = model.get_n_items()
         if n_items == 1:
             discbox = self._disc_list_box.get_row_at_index(0)
             discbox.props.show_disc_label = False
@@ -136,7 +145,7 @@ class AlbumWidget(Gtk.Box):
                 discbox = self._disc_list_box.get_row_at_index(i)
                 discbox.props.show_disc_label = True
 
-    def _set_composer_label(self, corealbum):
+    def _set_composer_label(self, corealbum: CoreAlbum) -> None:
         composer = corealbum.props.composer
         show = False
 
@@ -149,12 +158,13 @@ class AlbumWidget(Gtk.Box):
         self._composer_label.props.visible = show
         self._composer_info_label.props.visible = show
 
-    def _on_duration_changed(self, coredisc, duration):
+    def _on_duration_changed(self, coredisc: CoreDisc, duration: int) -> None:
         mins = (coredisc.props.duration // 60) + 1
         self._running_info_label.props.label = ngettext(
             "{} minute", "{} minutes", mins).format(mins)
 
-    def _song_activated(self, widget, song_widget):
+    def _song_activated(
+            self, widget: Gtk.Widget, song_widget: SongWidget) -> int:
         if self.props.selection_mode:
             song_widget.props.selected = not song_widget.props.selected
             return GLib.SOURCE_CONTINUE
@@ -171,19 +181,20 @@ class AlbumWidget(Gtk.Box):
 
         return GLib.SOURCE_CONTINUE
 
-    def select_all(self):
+    def select_all(self) -> None:
         self._disc_list_box.select_all()
 
-    def deselect_all(self):
+    def deselect_all(self) -> None:
         self._disc_list_box.deselect_all()
 
-    def _on_selection_mode_changed(self, widget, value):
+    def _on_selection_mode_changed(
+            self, widget: Gtk.Widget, value: GObject.ParamSpecBoolean) -> None:
         if not self.props.selection_mode:
             self.deselect_all()
 
     @GObject.Property(
         type=CoreAlbum, default=None, flags=GObject.ParamFlags.READABLE)
-    def album(self):
+    def album(self) -> Optional[CoreAlbum]:
         """Get the current album.
 
         :returns: the current album


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