[gnome-music/wip/mschraal/gtk4: 75/90] Port listmodels to sorters and filters
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/mschraal/gtk4: 75/90] Port listmodels to sorters and filters
- Date: Sat, 27 Jun 2020 11:58:55 +0000 (UTC)
commit b121264d10c1de77a6b65a1512bb34aafab22562
Author: Marinus Schraal <mschraal gnome org>
Date: Wed May 6 00:12:41 2020 +0200
Port listmodels to sorters and filters
Basic port, filters and sorters allow for more control.
gnomemusic/corealbum.py | 4 +++-
gnomemusic/coreartist.py | 6 ++++--
gnomemusic/coredisc.py | 11 ++++++++---
gnomemusic/coremodel.py | 20 ++++++++++++++------
gnomemusic/grilowrappers/grlsearchwrapper.py | 2 +-
gnomemusic/grilowrappers/grltrackerplaylists.py | 24 +++++++++++++++++-------
gnomemusic/grilowrappers/grltrackerwrapper.py | 18 +++++++++++++-----
gnomemusic/player.py | 8 +++++---
gnomemusic/songliststore.py | 4 +++-
gnomemusic/views/searchview.py | 8 ++++----
10 files changed, 72 insertions(+), 33 deletions(-)
---
diff --git a/gnomemusic/corealbum.py b/gnomemusic/corealbum.py
index f2303c32..4ddb7ec3 100644
--- a/gnomemusic/corealbum.py
+++ b/gnomemusic/corealbum.py
@@ -73,8 +73,10 @@ class CoreAlbum(GObject.GObject):
def _disc_order_sort(disc_a, disc_b):
return disc_a.props.disc_nr - disc_b.props.disc_nr
- disc_model_sort.set_sort_func(
+ disc_sorter = Gtk.CustomSorter()
+ disc_sorter.set_sort_func(
utils.wrap_list_store_sort_func(_disc_order_sort))
+ disc_model_sort.set_sorter(disc_sorter)
self._coregrilo.get_album_discs(
self.props.media, disc_model)
diff --git a/gnomemusic/coreartist.py b/gnomemusic/coreartist.py
index e89bae19..51f94dc2 100644
--- a/gnomemusic/coreartist.py
+++ b/gnomemusic/coreartist.py
@@ -62,7 +62,7 @@ class CoreArtist(GObject.GObject):
def _get_artist_album_model(self):
albums_model_filter = Gtk.FilterListModel.new(
self._coremodel.props.albums)
- albums_model_filter.set_filter_func(lambda a: False)
+ albums_model_filter.set_filter(Gtk.AnyFilter())
albums_model_sort = Gtk.SortListModel.new(albums_model_filter)
@@ -72,8 +72,10 @@ class CoreArtist(GObject.GObject):
def _album_sort(album_a, album_b):
return album_a.props.year > album_b.props.year
- albums_model_sort.set_sort_func(
+ albums_sorter = Gtk.CustomSorter()
+ albums_sorter.set_sort_func(
utils.wrap_list_store_sort_func(_album_sort))
+ albums_model_sort.set_sorter(albums_sorter)
return albums_model_sort
diff --git a/gnomemusic/coredisc.py b/gnomemusic/coredisc.py
index 14edc8fc..9b5839b2 100644
--- a/gnomemusic/coredisc.py
+++ b/gnomemusic/coredisc.py
@@ -64,10 +64,13 @@ class CoreDisc(GObject.GObject):
if self._model is None:
self._filter_model = Gtk.FilterListModel.new(
self._coremodel.props.songs)
- self._filter_model.set_filter_func(lambda a: False)
+ self._filter_model.set_filter(Gtk.AnyFilter())
+
self._model = Gtk.SortListModel.new(self._filter_model)
- self._model.set_sort_func(
+ disc_sorter = Gtk.CustomSorter()
+ disc_sorter.set_sort_func(
utils.wrap_list_store_sort_func(_disc_sort))
+ self._model.set_sorter(disc_sorter)
self._model.connect("items-changed", self._on_disc_changed)
@@ -100,7 +103,9 @@ class CoreDisc(GObject.GObject):
if media is None:
if sorted(album_ids) == sorted(self._old_album_ids):
return
- model_filter.set_filter_func(_filter_func)
+ album_disc_filter = Gtk.CustomFilter()
+ album_disc_filter.set_filter_func(_filter_func)
+ model_filter.set_filter(album_disc_filter)
self._old_album_ids = album_ids
return
diff --git a/gnomemusic/coremodel.py b/gnomemusic/coremodel.py
index 98c17314..10b5d90e 100644
--- a/gnomemusic/coremodel.py
+++ b/gnomemusic/coremodel.py
@@ -88,13 +88,17 @@ class CoreModel(GObject.GObject):
self._albums_model = Gio.ListStore()
self._albums_model_sort = Gtk.SortListModel.new(self._albums_model)
- self._albums_model_sort.set_sort_func(
+ albums_sorter = Gtk.CustomSorter()
+ albums_sorter.set_sort_func(
utils.wrap_list_store_sort_func(self._albums_sort))
+ self._albums_model_sort.set_sorter(albums_sorter)
self._artists_model = Gio.ListStore.new(CoreArtist)
self._artists_model_sort = Gtk.SortListModel.new(self._artists_model)
- self._artists_model_sort.set_sort_func(
+ artists_sorter = Gtk.CustomSorter()
+ artists_sorter.set_sort_func(
utils.wrap_list_store_sort_func(self._artist_sort))
+ self._artists_model_sort.set_sorter(artists_sorter)
self._playlist_model = Gio.ListStore.new(CoreSong)
self._playlist_model_sort = Gtk.SortListModel.new(self._playlist_model)
@@ -105,14 +109,14 @@ class CoreModel(GObject.GObject):
self._albums_search_model = Gtk.FilterListModel.new(
self._albums_model)
- self._albums_search_model.set_filter_func(lambda a: False)
+ self._albums_search_model.set_filter(Gtk.AnyFilter())
self._albums_search_filter = Gtk.FilterListModel.new(
self._albums_search_model)
self._artists_search_model = Gtk.FilterListModel.new(
self._artists_model)
- self._artists_search_model.set_filter_func(lambda a: False)
+ self._artists_search_model.set_filter(Gtk.AnyFilter())
self._artists_search_filter = Gtk.FilterListModel.new(
self._artists_search_model)
@@ -122,15 +126,19 @@ class CoreModel(GObject.GObject):
self._playlists_model)
self._playlists_model_sort = Gtk.SortListModel.new(
self._playlists_model_filter)
- self._playlists_model_sort.set_sort_func(
+ playlists_sorter = Gtk.CustomSorter()
+ playlists_sorter.set_sort_func(
utils.wrap_list_store_sort_func(self._playlists_sort))
+ self._playlists_model_sort.set_sorter(playlists_sorter)
self._user_playlists_model_filter = Gtk.FilterListModel.new(
self._playlists_model)
self._user_playlists_model_sort = Gtk.SortListModel.new(
self._user_playlists_model_filter)
- self._user_playlists_model_sort.set_sort_func(
+ user_playlists_sorter = Gtk.CustomSorter()
+ user_playlists_sorter.set_sort_func(
utils.wrap_list_store_sort_func(self._playlists_sort))
+ self._user_playlists_model_sort.set_sorter(user_playlists_sorter)
self._songs_model.connect(
"items-changed", self._on_songs_items_changed)
diff --git a/gnomemusic/grilowrappers/grlsearchwrapper.py b/gnomemusic/grilowrappers/grlsearchwrapper.py
index 7f7df774..739af349 100644
--- a/gnomemusic/grilowrappers/grlsearchwrapper.py
+++ b/gnomemusic/grilowrappers/grlsearchwrapper.py
@@ -77,7 +77,7 @@ class GrlSearchWrapper(GObject.GObject):
# list model.
self._song_search_model = Gtk.FilterListModel.new(
self._song_search_store)
- self._song_search_model.set_filter_func(lambda a: True)
+ self._song_search_model.set_filter(Gtk.AnyFilter())
self._song_search_proxy.append(self._song_search_model)
self._fast_options = Grl.OperationOptions()
diff --git a/gnomemusic/grilowrappers/grltrackerplaylists.py b/gnomemusic/grilowrappers/grltrackerplaylists.py
index b59eefae..a55d3031 100644
--- a/gnomemusic/grilowrappers/grltrackerplaylists.py
+++ b/gnomemusic/grilowrappers/grltrackerplaylists.py
@@ -28,7 +28,7 @@ from gettext import gettext as _
import gi
gi.require_versions({"Grl": "0.3"})
-from gi.repository import Gio, Grl, GLib, GObject
+from gi.repository import Gio, Grl, Gtk, GLib, GObject
from gnomemusic.coresong import CoreSong
import gnomemusic.utils as utils
@@ -78,7 +78,9 @@ class GrlTrackerPlaylists(GObject.GObject):
self._tracker_wrapper = tracker_wrapper
self._window = application.props.window
- self._user_model_filter.set_filter_func(self._user_playlists_filter)
+ user_playlists_filter = Gtk.CustomFilter()
+ user_playlists_filter.set_filter_func(self._user_playlists_filter)
+ self._user_model_filter.set_filter(user_playlists_filter)
self._fast_options = Grl.OperationOptions()
self._fast_options.set_resolution_flags(
@@ -163,7 +165,9 @@ class GrlTrackerPlaylists(GObject.GObject):
:param Playlist playlist: playlist
"""
self._pls_todelete.append(playlist)
- self._model_filter.set_filter_func(self._playlists_filter)
+ playlists_filter = Gtk.CustomFilter()
+ playlists_filter.set_filter_func(self._playlists_filter)
+ self._model_filter.set_filter(self._playlists_filter)
def finish_playlist_deletion(self, playlist, deleted):
"""Removes playlist from the list of playlists to delete
@@ -171,11 +175,15 @@ class GrlTrackerPlaylists(GObject.GObject):
:param Playlist playlist: playlist
:param bool deleted: indicates if the playlist has been deleted
"""
+ playlists_filter = Gtk.CustomFilter()
+ playlists_filter.set_filter_func(self._playlists_filter)
+ user_playlists_filter = Gtk.CustomFilter()
+ user_playlists_filter.set_filter_func(self._playlists_filter)
+
self._pls_todelete.remove(playlist)
if deleted is False:
- self._model_filter.set_filter_func(self._playlists_filter)
- self._user_model_filter.set_filter_func(
- self._user_playlists_filter)
+ self._model_filter.set_filter(playlists_filter)
+ self._user_model_filter.set_filter(user_playlists_filter)
return
def _delete_cb(conn, res, data):
@@ -190,7 +198,9 @@ class GrlTrackerPlaylists(GObject.GObject):
self._model.remove(idx)
break
- self._model_filter.set_filter_func(self._playlists_filter)
+ playlists_filter = Gtk.CustomFilter()
+ playlists_filter.set_filter_func(self._playlists_filter)
+ self._model_filter.set_filter(playlists_filter)
self._window.notifications_popup.pop_loading()
self._window.notifications_popup.push_loading()
diff --git a/gnomemusic/grilowrappers/grltrackerwrapper.py b/gnomemusic/grilowrappers/grltrackerwrapper.py
index 31a61368..b924c688 100644
--- a/gnomemusic/grilowrappers/grltrackerwrapper.py
+++ b/gnomemusic/grilowrappers/grltrackerwrapper.py
@@ -90,7 +90,7 @@ class GrlTrackerWrapper(GObject.GObject):
self._window = application.props.window
self._song_search_tracker = Gtk.FilterListModel.new(self._songs_model)
- self._song_search_tracker.set_filter_func(lambda a: False)
+ self._song_search_tracker.set_filter(Gtk.AnyFilter())
self._song_search_proxy.append(self._song_search_tracker)
self._fast_options = Grl.OperationOptions()
@@ -580,7 +580,9 @@ class GrlTrackerWrapper(GObject.GObject):
return
if not media:
- model.set_filter_func(albums_filter, albums)
+ custom_filter = Gtk.CustomFilter()
+ custom_filter.set_filter_func(albums_filter, albums)
+ model.set_filter(custom_filter)
self._window.notifications_popup.pop_loading()
return
@@ -750,7 +752,9 @@ class GrlTrackerWrapper(GObject.GObject):
return
if not media:
- self._artist_search_model.set_filter_func(artist_filter)
+ custom_filter = Gtk.CustomFilter()
+ custom_filter.set_filter(artist_filter)
+ self._artist_search_model.set_filter(custom_filter)
self._window.notifications_popup.pop_loading()
return
@@ -805,7 +809,9 @@ class GrlTrackerWrapper(GObject.GObject):
return
if not media:
- self._album_search_model.set_filter_func(album_filter)
+ custom_filter = Gtk.CustomFilter()
+ custom_filter.set_filter_func(album_filter)
+ self._album_search_model.set_filter(custom_filter)
self._window.notifications_popup.pop_loading()
return
@@ -866,7 +872,9 @@ class GrlTrackerWrapper(GObject.GObject):
return
if not media:
- self._song_search_tracker.set_filter_func(songs_filter)
+ custom_filter = Gtk.CustomFilter()
+ custom_filter.set_filter_func(songs_filter)
+ self._song_search_tracker.set_filter(custom_filter)
self._window.notifications_popup.pop_loading()
return
diff --git a/gnomemusic/player.py b/gnomemusic/player.py
index a550b56b..508e2876 100644
--- a/gnomemusic/player.py
+++ b/gnomemusic/player.py
@@ -28,7 +28,7 @@ import time
import gi
gi.require_version('GstPbutils', '1.0')
-from gi.repository import GObject, GstPbutils
+from gi.repository import GObject, GstPbutils, Gtk
from gnomemusic.coresong import CoreSong
from gnomemusic.gstplayer import GstPlayer, Playback
@@ -252,10 +252,12 @@ class PlayerPlaylist(GObject.GObject):
return randint(-1, 1)
if self.props.repeat_mode == RepeatMode.SHUFFLE:
- self._model.set_sort_func(
+ shuffle_sort = Gtk.CustomSorter()
+ shuffle_sort.set_sort_func(
utils.wrap_list_store_sort_func(_shuffle_sort))
+ self._mode.set_sorter(shuffle_sort)
elif self.props.repeat_mode in [RepeatMode.NONE, RepeatMode.ALL]:
- self._model.set_sort_func(None)
+ self._model.set_sorter(None)
def _validate_song(self, coresong):
# Song is being processed or has already been processed.
diff --git a/gnomemusic/songliststore.py b/gnomemusic/songliststore.py
index abbb78df..5d9c8f1d 100644
--- a/gnomemusic/songliststore.py
+++ b/gnomemusic/songliststore.py
@@ -37,8 +37,10 @@ class SongListStore(Gtk.ListStore):
super().__init__()
self._model = Gtk.SortListModel.new(model)
- self._model.set_sort_func(
+ sorter = Gtk.CustomSorter()
+ sorter.set_sort_func(
utils.wrap_list_store_sort_func(self._songs_sort))
+ self._model.set_sorter(sorter)
self.set_column_types([
GObject.TYPE_STRING, # play or invalid icon
diff --git a/gnomemusic/views/searchview.py b/gnomemusic/views/searchview.py
index 3bbe325a..af12028b 100644
--- a/gnomemusic/views/searchview.py
+++ b/gnomemusic/views/searchview.py
@@ -87,13 +87,13 @@ class SearchView(Gtk.Stack):
self._model = self._coremodel.props.songs_search
self._album_model = self._coremodel.props.albums_search
self._album_filter = self._coremodel.props.albums_search_filter
- self._album_filter.set_filter_func(
- self._core_filter, self._album_model, 12)
+ # self._album_filter.set_filter_func(
+ # self._core_filter, self._album_model, 12)
self._artist_model = self._coremodel.props.artists_search
self._artist_filter = self._coremodel.props.artists_search_filter
- self._artist_filter.set_filter_func(
- self._core_filter, self._artist_model, 6)
+ # self._artist_filter.set_filter_func(
+ # self._core_filter, self._artist_model, 6)
self._model.connect_after(
"items-changed", self._on_model_items_changed)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]