From c6db98a56a90a0b2e68efc236c8d80b6ca2feb39 Mon Sep 17 00:00:00 2001 From: Jean Felder Date: Fri, 9 Mar 2018 16:02:34 +0100 Subject: [PATCH 1/2] albumwidget: Do not recreate model every time One only need to create it at launch time and clear it if necessary. Its structure does not change. --- gnomemusic/widgets/albumwidget.py | 36 ++++++++++++++----------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/gnomemusic/widgets/albumwidget.py b/gnomemusic/widgets/albumwidget.py index fe9f5aedc..d0ebf8e47 100644 --- a/gnomemusic/widgets/albumwidget.py +++ b/gnomemusic/widgets/albumwidget.py @@ -53,6 +53,21 @@ class AlbumWidget(Gtk.EventBox): """ super().__init__() + self._model = Gtk.ListStore( + GObject.TYPE_STRING, # title + GObject.TYPE_STRING, + GObject.TYPE_STRING, + GObject.TYPE_STRING, + GdkPixbuf.Pixbuf, # icon + GObject.TYPE_OBJECT, # song object + GObject.TYPE_BOOLEAN, # item selected + GObject.TYPE_STRING, + GObject.TYPE_BOOLEAN, + GObject.TYPE_INT, # icon shown + GObject.TYPE_BOOLEAN, + GObject.TYPE_INT + ) + self._songs = [] self._player = player @@ -62,7 +77,6 @@ class AlbumWidget(Gtk.EventBox): self._builder = Gtk.Builder() self._builder.add_from_resource('/org/gnome/Music/AlbumWidget.ui') - self._create_model() self._album = None self._header_bar = None self._selection_mode_allowed = True @@ -100,24 +114,6 @@ class AlbumWidget(Gtk.EventBox): """Selection mode toggled.""" self._header_bar._select_button.clicked() - @log - def _create_model(self): - """Create the ListStore model for this widget.""" - self._model = Gtk.ListStore( - GObject.TYPE_STRING, # title - GObject.TYPE_STRING, - GObject.TYPE_STRING, - GObject.TYPE_STRING, - GdkPixbuf.Pixbuf, # icon - GObject.TYPE_OBJECT, # song object - GObject.TYPE_BOOLEAN, # item selected - GObject.TYPE_STRING, - GObject.TYPE_BOOLEAN, - GObject.TYPE_INT, # icon shown - GObject.TYPE_BOOLEAN, - GObject.TYPE_INT - ) - @log def update(self, artist, album, item, header_bar, selection_toolbar): """Update the album widget. @@ -130,7 +126,7 @@ class AlbumWidget(Gtk.EventBox): """ # reset view self._songs = [] - self._create_model() + self._model.clear() for widget in self._disc_listbox.get_children(): self._disc_listbox.remove(widget) -- GitLab From b5d9f1bf2f9b29bf6941e6aef250a203a3199340 Mon Sep 17 00:00:00 2001 From: Jean Felder Date: Fri, 9 Mar 2018 16:04:50 +0100 Subject: [PATCH 2/2] albumwidget: Restore currently played album Closes: #111 --- gnomemusic/widgets/albumwidget.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/gnomemusic/widgets/albumwidget.py b/gnomemusic/widgets/albumwidget.py index d0ebf8e47..e0b324fdf 100644 --- a/gnomemusic/widgets/albumwidget.py +++ b/gnomemusic/widgets/albumwidget.py @@ -243,6 +243,12 @@ class AlbumWidget(Gtk.EventBox): self._player.set_playing(True) return True + @log + def _set_duration_label(self): + duration = self._duration // 60 + 1 + self._builder.get_object('running_length_label_info').set_text( + _("%d min") % duration) + @log def add_item(self, source, prefs, song, remaining, data=None): """Add a song to the item to album list. @@ -273,9 +279,13 @@ class AlbumWidget(Gtk.EventBox): disc.show_disc_label(False) if remaining == 0: - self._builder.get_object('running_length_label_info').set_text( - _("%d min") % (int(self._duration / 60) + 1)) - + if self._player.running_playlist('Album', self._album): + current_path = self._player.currentTrack.get_path() + current_track = self._player.playlist.get_iter(current_path) + self._update_model( + self._player, self._player.playlist, current_track) + else: + self._set_duration_label() self.show_all() @log @@ -294,16 +304,15 @@ class AlbumWidget(Gtk.EventBox): self._duration = 0 song_passed = False - _iter = playlist.get_iter_first() + _iter = self._model.get_iter_first() while _iter: - song = playlist[_iter][player.Field.SONG] + song = self._model[_iter][5] song_widget = song.song_widget self._duration += song.get_duration() escaped_title = GLib.markup_escape_text( utils.get_media_title(song)) - - if (song == current_song): + if song.get_id() == current_song.get_id(): song_widget.now_playing_sign.show() song_widget.title.set_markup("{}".format(escaped_title)) song_passed = True @@ -316,10 +325,9 @@ class AlbumWidget(Gtk.EventBox): song_widget.title.set_markup( "{}".format(escaped_title)) - _iter = playlist.iter_next(_iter) + _iter = self._model.iter_next(_iter) - self._builder.get_object('running_length_label_info').set_text( - _("%d min") % (int(self._duration / 60) + 1)) + self._set_duration_label() return True -- GitLab