[gnome-music/wip/mschraal/coremodel-flatten-search-models: 5/6] coremodel: Add static type annotations




commit deb0df2535f4721e9cc14a35fdd7a845f61a03d9
Author: Marinus Schraal <mschraal gnome org>
Date:   Wed Nov 18 16:01:21 2020 +0100

    coremodel: Add static type annotations

 gnomemusic/corealbum.py  |  3 +-
 gnomemusic/coreartist.py |  2 +-
 gnomemusic/coremodel.py  | 78 ++++++++++++++++++++++++++++--------------------
 3 files changed, 49 insertions(+), 34 deletions(-)
---
diff --git a/gnomemusic/corealbum.py b/gnomemusic/corealbum.py
index 4ab1569cc..665e86606 100644
--- a/gnomemusic/corealbum.py
+++ b/gnomemusic/corealbum.py
@@ -86,7 +86,8 @@ class CoreAlbum(GObject.GObject):
         return disc_model_sort
 
     @GObject.Property(
-        type=Gio.ListModel, default=None, flags=GObject.ParamFlags.READABLE)
+        type=Gfm.SortListModel, default=None,
+        flags=GObject.ParamFlags.READABLE)
     def model(self):
         if self._model is None:
             self._model = self._get_album_model()
diff --git a/gnomemusic/coreartist.py b/gnomemusic/coreartist.py
index 1630d3fb6..6e44e94bf 100644
--- a/gnomemusic/coreartist.py
+++ b/gnomemusic/coreartist.py
@@ -76,7 +76,7 @@ class CoreArtist(GObject.GObject):
 
         return albums_model_sort
 
-    @GObject.Property(type=Gio.ListModel, default=None)
+    @GObject.Property(type=Gfm.SortListModel, default=None)
     def model(self):
         if self._model is None:
             self._model = self._get_artist_album_model()
diff --git a/gnomemusic/coremodel.py b/gnomemusic/coremodel.py
index b79d7bad9..1c109a50c 100644
--- a/gnomemusic/coremodel.py
+++ b/gnomemusic/coremodel.py
@@ -23,6 +23,7 @@
 # delete this exception statement from your version.
 
 from __future__ import annotations
+from typing import Optional, Union
 import math
 import typing
 
@@ -39,6 +40,7 @@ from gnomemusic.songliststore import SongListStore
 from gnomemusic.widgets.songwidget import SongWidget
 if typing.TYPE_CHECKING:
     from gnomemusic.application import Application
+    from gnomemusic.search import Search
 import gnomemusic.utils as utils
 
 
@@ -84,40 +86,52 @@ class CoreModel(GObject.GObject):
         """
         super().__init__()
 
-        self._flatten_model = None
+        self._flatten_model: Optional[Gfm.FlattenListModel] = None
         self._player_signal_id = 0
-        self._current_playlist_model = None
-        self._previous_playlist_model = None
-
-        self._songs_model_proxy = Gio.ListStore.new(Gio.ListModel)
-        self._songs_model = Gfm.FlattenListModel.new(
+        self._current_playlist_model: Optional[Union[
+            Gfm.FlattenListModel, Gfm.SortListModel, Gio.ListModel]] = None
+        self._previous_playlist_model: Optional[Union[
+            Gfm.FlattenListModel, Gfm.SortListModel, Gio.ListModel]] = None
+
+        self._songs_model_proxy: Gio.ListStore = Gio.ListStore.new(
+            Gio.ListModel)
+        self._songs_model: Gfm.FlattenListModel = Gfm.FlattenListModel.new(
             CoreSong, self._songs_model_proxy)
         self._songliststore = SongListStore(self._songs_model)
 
         self._application = application
 
-        self._albums_model_proxy = Gio.ListStore.new(Gio.ListModel)
-        self._albums_model = Gfm.FlattenListModel.new(
+        self._albums_model_proxy: Gio.ListStore = Gio.ListStore.new(
+            Gio.ListModel)
+        self._albums_model: Gfm.FlattenListModel = Gfm.FlattenListModel.new(
             CoreAlbum, self._albums_model_proxy)
-        self._albums_model_sort = Gfm.SortListModel.new(self._albums_model)
+        self._albums_model_sort: Gfm.SortListModel = Gfm.SortListModel.new(
+            self._albums_model)
         self._albums_model_sort.set_sort_func(
             utils.wrap_list_store_sort_func(self._albums_sort))
 
-        self._artists_model_proxy = Gio.ListStore.new(Gio.ListModel)
-        self._artists_model = Gfm.FlattenListModel.new(
+        self._artists_model_proxy: Gio.ListStore = Gio.ListStore.new(
+            Gio.ListModel)
+        self._artists_model: Gfm.FlattenListModel = Gfm.FlattenListModel.new(
             CoreArtist, self._artists_model_proxy)
-        self._artists_model_sort = Gfm.SortListModel.new(self._artists_model)
+        self._artists_model_sort: Gfm.SortListModel = Gfm.SortListModel.new(
+            self._artists_model)
         self._artists_model_sort.set_sort_func(
             utils.wrap_list_store_sort_func(self._artist_sort))
 
-        self._playlist_model = Gio.ListStore.new(CoreSong)
-        self._playlist_model_sort = Gfm.SortListModel.new(self._playlist_model)
-        self._playlist_model_recent = Gfm.SliceListModel.new(
-            self._playlist_model_sort, 0, self._recent_size)
-        self._active_core_object = None
+        self._playlist_model: Gio.ListStore = Gio.ListStore.new(CoreSong)
+        self._playlist_model_sort: Gfm.SortListModel = Gfm.SortListModel.new(
+            self._playlist_model)
+        self._playlist_model_recent: Gfm.SliceListModel = (
+            Gfm.SliceListModel.new(
+                self._playlist_model_sort, 0, self._recent_size))
+        self._active_core_object: Optional[Union[
+            CoreAlbum, CoreArtist, Playlist]] = None
 
-        self._songs_search_proxy = Gio.ListStore.new(Gfm.FilterListModel)
-        self._songs_search_flatten = Gfm.FlattenListModel.new(CoreSong)
+        self._songs_search_proxy: Gio.ListStore = Gio.ListStore.new(
+            Gfm.FilterListModel)
+        self._songs_search_flatten: Gfm.FlattenListModel = (
+            Gfm.FlattenListModel.new(CoreSong))
         self._songs_search_flatten.set_model(self._songs_search_proxy)
 
         self._albums_search_proxy: Gio.Liststore = Gio.ListStore.new(
@@ -126,8 +140,8 @@ class CoreModel(GObject.GObject):
             Gfm.FlattenListModel.new(CoreAlbum))
         self._albums_search_flatten.set_model(self._albums_search_proxy)
 
-        self._albums_search_filter = Gfm.FilterListModel.new(
-            self._albums_search_flatten)
+        self._albums_search_filter: Gfm.FilterListModel = (
+            Gfm.FilterListModel.new(self._albums_search_flatten))
 
         self._artists_search_proxy: Gio.Liststore = Gio.ListStore.new(
             Gfm.FilterListModel)
@@ -135,25 +149,25 @@ class CoreModel(GObject.GObject):
             Gfm.FlattenListModel.new(CoreArtist))
         self._artists_search_flatten.set_model(self._artists_search_proxy)
 
-        self._artists_search_filter = Gfm.FilterListModel.new(
-            self._artists_search_flatten)
+        self._artists_search_filter: Gfm.FilterListModel = (
+            Gfm.FilterListModel.new(self._artists_search_flatten))
 
-        self._playlists_model = Gio.ListStore.new(Playlist)
-        self._playlists_model_filter = Gfm.FilterListModel.new(
-            self._playlists_model)
-        self._playlists_model_sort = Gfm.SortListModel.new(
+        self._playlists_model: Gio.ListStore = Gio.ListStore.new(Playlist)
+        self._playlists_model_filter: Gfm.FilterListModel = (
+            Gfm.FilterListModel.new(self._playlists_model))
+        self._playlists_model_sort: Gfm.SortListModel = Gfm.SortListModel.new(
             self._playlists_model_filter)
         self._playlists_model_sort.set_sort_func(
             utils.wrap_list_store_sort_func(self._playlists_sort))
 
-        self._user_playlists_model_filter = Gfm.FilterListModel.new(
-            self._playlists_model)
-        self._user_playlists_model_sort = Gfm.SortListModel.new(
-            self._user_playlists_model_filter)
+        self._user_playlists_model_filter: Gfm.FilterListModel = (
+            Gfm.FilterListModel.new(self._playlists_model))
+        self._user_playlists_model_sort: Gfm.SortListModel = (
+            Gfm.SortListModel.new(self._user_playlists_model_filter))
         self._user_playlists_model_sort.set_sort_func(
             utils.wrap_list_store_sort_func(self._playlists_sort))
 
-        self._search = application.props.search
+        self._search: Search = application.props.search
 
         self._songs_model.connect(
             "items-changed", self._on_songs_items_changed)


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