[gnome-music/wip/jfelder/empty-playlist-v2: 2/2] playlistswidget: Display a special view for an empty playlist
- From: Jean Felder <jfelder src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/jfelder/empty-playlist-v2: 2/2] playlistswidget: Display a special view for an empty playlist
- Date: Wed, 27 Jan 2021 15:13:36 +0000 (UTC)
commit 267ed391e56ab203b2f78eef155b28f1f75b9fd3
Author: Jean Felder <jfelder src gnome org>
Date: Wed Nov 11 21:18:50 2020 +0100
playlistswidget: Display a special view for an empty playlist
When a playlist does not contain any song, the view seems broken: the
big empty space makes the feature appear ambiguous and the line at the
top also looks out of place (see #424).
This issue is fixed by replacing the default state by a new empty view
when a playlist is empty. This view contains the icon introduced in
the previous commit.
closes: #424
data/ui/PlaylistsWidget.ui | 27 +++++++++++++++-
gnomemusic/widgets/playlistswidget.py | 60 ++++++++++++++++++++++++++++++++++-
po/POTFILES.in | 1 +
3 files changed, 86 insertions(+), 2 deletions(-)
---
diff --git a/data/ui/PlaylistsWidget.ui b/data/ui/PlaylistsWidget.ui
index fbc7882b4..74f72e401 100644
--- a/data/ui/PlaylistsWidget.ui
+++ b/data/ui/PlaylistsWidget.ui
@@ -9,7 +9,7 @@
</object>
</child>
<child>
- <object class="GtkScrolledWindow" id="playlist-container">
+ <object class="GtkScrolledWindow" id="_playlist_container">
<property name="vexpand">True</property>
<property name="visible">True</property>
<child>
@@ -27,6 +27,31 @@
</child>
</object>
</child>
+ <child>
+ <object class="GtkBox" id="_empty_playlist">
+ <property name="hexpand">True</property>
+ <property name="orientation">vertical</property>
+ <property name="valign">center</property>
+ <property name="vexpand">True</property>
+ <property name="visible">False</property>
+ <child>
+ <object class="GtkImage" id="_empty_playlist_icon">
+ <property name="visible">True</property>
+ <property name="icon_size">0</property>
+ <property name="pixel_size">128</property>
+ <property name="margin_bottom">18</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel" id="_empty_playlist_label">
+ <property name="visible">True</property>
+ <style>
+ <class name="no-music-found-label"/>
+ </style>
+ </object>
+ </child>
+ </object>
+ </child>
</template>
<object class="GtkGestureMultiPress" id="_songs_list_ctrlr">
<property name="widget">_songs_list</property>
diff --git a/gnomemusic/widgets/playlistswidget.py b/gnomemusic/widgets/playlistswidget.py
index 00f9fbcd2..a12f36abf 100644
--- a/gnomemusic/widgets/playlistswidget.py
+++ b/gnomemusic/widgets/playlistswidget.py
@@ -22,13 +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 gi.repository import Gdk, GObject, Gtk
+from __future__ import annotations
+
+from gettext import gettext as _
+from typing import Optional
+import typing
+
+from gi.repository import Gdk, GLib, GObject, Gtk
from gnomemusic.widgets.notificationspopup import PlaylistNotification
from gnomemusic.widgets.playlistcontextmenu import PlaylistContextMenu
from gnomemusic.widgets.playlistcontrols import PlaylistControls # noqa: F401
from gnomemusic.widgets.playlistdialog import PlaylistDialog
from gnomemusic.widgets.songwidget import SongWidget
+if typing.TYPE_CHECKING:
+ from gnomemusic.grilowrappers.grltrackerplaylists import Playlist
@Gtk.Template(resource_path="/org/gnome/Music/ui/PlaylistsWidget.ui")
@@ -37,7 +45,11 @@ class PlaylistsWidget(Gtk.Box):
__gtype_name__ = "PlaylistsWidget"
+ _empty_playlist = Gtk.Template.Child()
+ _empty_playlist_icon = Gtk.Template.Child()
+ _empty_playlist_label = Gtk.Template.Child()
_pl_ctrls = Gtk.Template.Child()
+ _playlist_container = Gtk.Template.Child()
_songs_list = Gtk.Template.Child()
_songs_list_ctrlr = Gtk.Template.Child()
@@ -60,6 +72,10 @@ class PlaylistsWidget(Gtk.Box):
self._pl_ctrls.props.application = application
+ self._previous_playlist: Optional[Playlist] = None
+ self._count_id = 0
+ self._count_timeout = 0
+
self._song_popover = PlaylistContextMenu(application, self._songs_list)
play_song = self._window.lookup_action("play_song")
@@ -84,6 +100,22 @@ class PlaylistsWidget(Gtk.Box):
self._songs_list.bind_model(
playlist.props.model, self._create_song_widget, playlist)
+
+ if self._count_id > 0:
+ self._previous_playlist.disconnect(self._count_id)
+ self._count_id = 0
+
+ self._previous_playlist = playlist
+ self._count_id = playlist.connect(
+ "notify::count", self._on_count_changed)
+ if playlist.props.count == 0:
+ self._pl_ctrls.props.visible = False
+ self._playlist_container.props.visible = False
+ self._count_timeout = GLib.timeout_add(
+ 500, self._on_count_changed, playlist)
+ else:
+ self._on_count_changed(playlist)
+
if playlist.props.is_smart:
playlist.update()
@@ -91,6 +123,32 @@ class PlaylistsWidget(Gtk.Box):
self._remove_song_action.set_enabled(not playlist.props.is_smart)
+ def _on_count_changed(
+ self, playlist: Playlist,
+ value: GObject.GParamSpec = None) -> None:
+ if self._count_timeout > 0:
+ GLib.source_remove(self._count_timeout)
+ self._count_timeout = 0
+
+ if playlist.props.count == 0:
+ self._pl_ctrls.props.visible = False
+ self._playlist_container.props.visible = False
+ self._empty_playlist.props.visible = True
+ pl_icon = playlist.props.icon_name
+ self._empty_playlist_icon.props.icon_name = pl_icon
+
+ if playlist.props.is_smart:
+ label_suffix = _("Will Appear Here")
+ else:
+ label_suffix = _("Is Empty")
+
+ empty_label = "{} {}".format(playlist.props.title, label_suffix)
+ self._empty_playlist_label.props.label = empty_label
+ else:
+ self._empty_playlist.props.visible = False
+ self._pl_ctrls.props.visible = True
+ self._playlist_container.props.visible = True
+
def _create_song_widget(self, coresong, playlist):
can_dnd = not playlist.props.is_smart
song_widget = SongWidget(coresong, can_dnd, True)
diff --git a/po/POTFILES.in b/po/POTFILES.in
index c88c5b2cc..e947a235a 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -40,6 +40,7 @@ gnomemusic/widgets/lastfmdialog.py
gnomemusic/widgets/notificationspopup.py
gnomemusic/widgets/playertoolbar.py
gnomemusic/widgets/playlistcontrols.py
+gnomemusic/widgets/playlistswidget.py
gnomemusic/widgets/playlistdialog.py
gnomemusic/widgets/starhandlerwidget.py
gnomemusic/window.py
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]