[gnome-music/wip/mschraal/core: 80/86] artistsview: Make the model more prefab
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/mschraal/core: 80/86] artistsview: Make the model more prefab
- Date: Fri, 7 Jun 2019 15:33:54 +0000 (UTC)
commit ef9e3cb9a0e18152ac25e45b7b564a4c55a7faf5
Author: Marinus Schraal <mschraal gnome org>
Date: Wed Jun 5 15:46:46 2019 +0200
artistsview: Make the model more prefab
Should make it easier to create a playlist from it
gnomemusic/coremodel.py | 26 +++++++++++++++++++++++++-
gnomemusic/views/artistsview.py | 5 ++++-
gnomemusic/widgets/artistalbumswidget.py | 16 +++++++++-------
gnomemusic/widgets/artistalbumwidget.py | 4 ++--
gnomemusic/widgets/disclistboxwidget.py | 10 +++++-----
5 files changed, 45 insertions(+), 16 deletions(-)
---
diff --git a/gnomemusic/coremodel.py b/gnomemusic/coremodel.py
index ac51454b..5d04839c 100644
--- a/gnomemusic/coremodel.py
+++ b/gnomemusic/coremodel.py
@@ -1,6 +1,6 @@
import gi
gi.require_version('Dazzle', '1.0')
-from gi.repository import Dazzle, GObject, Gio, Gfm
+from gi.repository import Dazzle, GObject, Gio, Gfm, Grl
from gi._gi import pygobject_new_full
from gnomemusic import log
@@ -17,6 +17,12 @@ class CoreDisc(GObject.GObject):
model = None
+class CoreArtistAlbum(GObject.GObject):
+
+ media = GObject.Property(type=Grl.Media, default=None)
+ model = GObject.Property(type=Gio.ListModel, default=None)
+
+
class CoreModel(GObject.GObject):
__gsignals__ = {
@@ -92,6 +98,24 @@ class CoreModel(GObject.GObject):
return disc_model_sort
+ def get_artists_model_full(self, artist_media):
+ albums = self._grilo.get_artist_albums(artist_media)
+
+ albums_model = Gio.ListStore()
+ albums_model_sort = Gfm.SortListModel.new(albums_model)
+
+ for album in albums:
+ album_model = self.get_album_model(album)
+
+ artist_album = CoreArtistAlbum()
+ artist_album.props.model = album_model
+ artist_album.props.media = album
+
+ albums_model.append(artist_album)
+
+ return albums_model
+
+
def get_playlist_model(self):
return self._playlist_model_sort
diff --git a/gnomemusic/views/artistsview.py b/gnomemusic/views/artistsview.py
index 40631494..a82b2d8c 100644
--- a/gnomemusic/views/artistsview.py
+++ b/gnomemusic/views/artistsview.py
@@ -63,6 +63,7 @@ class ArtistsView(BaseView):
self.player = player
self._artists = {}
+ self._window = window
self._model = window._app._coremodel.get_artists_model()
self._sidebar.bind_model(self._model, self._create_widget)
@@ -121,13 +122,15 @@ class ArtistsView(BaseView):
artist = row.props.artist.props.artist
artist_media = row.props.artist.props.media
+ model = self._window._app._coremodel.get_artists_model_full(row.props.artist)
+
new_artist_albums_widget = Gtk.Frame(
shadow_type=Gtk.ShadowType.NONE, hexpand=True)
self._view.add(new_artist_albums_widget)
albums = self._window._app._coremodel.get_artist_albums(row.props.artist)
artist_albums = ArtistAlbumsWidget(
- artist, albums, self.player, self._window)
+ artist, albums, self.player, self._window, False, model)
# self._artists[artist.casefold()]['widget'] = artist_albums
new_artist_albums_widget.add(artist_albums)
new_artist_albums_widget.show()
diff --git a/gnomemusic/widgets/artistalbumswidget.py b/gnomemusic/widgets/artistalbumswidget.py
index 0c74e4a2..9cfe0873 100644
--- a/gnomemusic/widgets/artistalbumswidget.py
+++ b/gnomemusic/widgets/artistalbumswidget.py
@@ -56,8 +56,9 @@ class ArtistAlbumsWidget(Gtk.Box):
@log
def __init__(
self, artist, albums, player, window,
- selection_mode_allowed=False):
+ selection_mode_allowed=False, model=None):
super().__init__(orientation=Gtk.Orientation.VERTICAL)
+ self._model = model
self._player = player
self._artist = artist
self._window = window
@@ -67,9 +68,9 @@ class ArtistAlbumsWidget(Gtk.Box):
self._widgets = []
- self._create_model()
+ # self._create_model()
- self._model.connect('row-changed', self._model_row_changed)
+ # self._model.connect('row-changed', self._model_row_changed)
hbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
self._album_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL,
@@ -89,8 +90,8 @@ class ArtistAlbumsWidget(Gtk.Box):
self._window.notifications_popup.push_loading()
- self._albums_to_load = len(albums)
- for album in albums:
+ # self._albums_to_load = len(albums)
+ for album in self._model:
self._add_album(album)
self._player.connect('song-changed', self._update_model)
@@ -124,8 +125,9 @@ class ArtistAlbumsWidget(Gtk.Box):
@log
def _add_album(self, album):
widget = ArtistAlbumWidget(
- album, self._player, self._model, self._selection_mode_allowed,
- self._songs_grid_size_group, self._cover_size_group, self._window)
+ album.props.media, self._player, album.props.model,
+ self._selection_mode_allowed, self._songs_grid_size_group,
+ self._cover_size_group, self._window)
self.bind_property(
'selection-mode', widget, 'selection-mode',
diff --git a/gnomemusic/widgets/artistalbumwidget.py b/gnomemusic/widgets/artistalbumwidget.py
index 4ed09ccb..11ae0793 100644
--- a/gnomemusic/widgets/artistalbumwidget.py
+++ b/gnomemusic/widgets/artistalbumwidget.py
@@ -102,9 +102,9 @@ class ArtistAlbumWidget(Gtk.Box):
# self._disc_list_box.show()
# grilo.populate_album_songs(self._media, self._add_item)
- disc_model = window._app._coremodel.get_album_model(self._media)
+ # disc_model = window._app._coremodel.get_album_model(self._media)
- self._disc_list_box.bind_model(disc_model, self._create_widget)
+ self._disc_list_box.bind_model(self._model, self._create_widget)
def _create_widget(self, disc):
disc_box = self._create_disc_box(
diff --git a/gnomemusic/widgets/disclistboxwidget.py b/gnomemusic/widgets/disclistboxwidget.py
index 9ff2af38..c95c719a 100644
--- a/gnomemusic/widgets/disclistboxwidget.py
+++ b/gnomemusic/widgets/disclistboxwidget.py
@@ -123,11 +123,6 @@ class DiscBox(Gtk.Box):
if self._model is not None:
self._model.connect('row-changed', self._model_row_changed)
- if listmodel is not None:
- self._listmodel = listmodel
- self._list_box.bind_model(
- self._listmodel, self._create_widget)
-
# self.bind_property(
# 'columns', self._list_box, 'columns',
# GObject.BindingFlags.SYNC_CREATE)
@@ -139,6 +134,11 @@ class DiscBox(Gtk.Box):
self._selected_items = []
self._songs = []
+ if listmodel is not None:
+ self._listmodel = listmodel
+ self._list_box.bind_model(
+ self._listmodel, self._create_widget)
+
@log
def set_disc_number(self, disc_number):
"""Set the dics number to display
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]