[gnome-music/wip/mschraal/gtk4-toasts: 1/2] Use a progressbar as loading indicator
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/mschraal/gtk4-toasts: 1/2] Use a progressbar as loading indicator
- Date: Tue, 15 Feb 2022 16:14:21 +0000 (UTC)
commit 3e9c799dd87025173c2c529cca0ae631f8712250
Author: Marinus Schraal <mschraal gnome org>
Date: Tue Feb 15 12:39:37 2022 +0100
Use a progressbar as loading indicator
data/org.gnome.Music.gresource.xml | 1 -
data/ui/LoadingNotification.ui | 18 -------
data/ui/Window.ui | 9 ++++
gnomemusic/grilowrappers/grltrackerwrapper.py | 2 -
gnomemusic/notificationmanager.py | 34 ++++++-------
gnomemusic/widgets/notificationspopup.py | 72 +--------------------------
gnomemusic/window.py | 18 +++++++
po/POTFILES.in | 1 -
8 files changed, 44 insertions(+), 111 deletions(-)
---
diff --git a/data/org.gnome.Music.gresource.xml b/data/org.gnome.Music.gresource.xml
index d7f26d177..af573f539 100644
--- a/data/org.gnome.Music.gresource.xml
+++ b/data/org.gnome.Music.gresource.xml
@@ -18,7 +18,6 @@
<file preprocess="xml-stripblanks">ui/EmptyView.ui</file>
<file preprocess="xml-stripblanks">ui/HeaderBar.ui</file>
<file preprocess="xml-stripblanks">ui/LastfmDialog.ui</file>
- <file preprocess="xml-stripblanks">ui/LoadingNotification.ui</file>
<file preprocess="xml-stripblanks">ui/NotificationsPopup.ui</file>
<file preprocess="xml-stripblanks">ui/PlayerToolbar.ui</file>
<file preprocess="xml-stripblanks">ui/PlaylistControls.ui</file>
diff --git a/data/ui/Window.ui b/data/ui/Window.ui
index 92052f1bd..e767ae0cd 100644
--- a/data/ui/Window.ui
+++ b/data/ui/Window.ui
@@ -27,6 +27,15 @@
<property name="vhomogeneous">False</property>
</object>
</child>
+ <child type="overlay">
+ <object class="GtkProgressBar" id="_loading_progress">
+ <property name="valign">start</property>
+ <property name="visible">False</property>
+ <style>
+ <class name="osd"/>
+ </style>
+ </object>
+ </child>
<child type="overlay">
<object class="NotificationsPopup" id="notifications_popup">
<property name="halign">center</property>
diff --git a/gnomemusic/grilowrappers/grltrackerwrapper.py b/gnomemusic/grilowrappers/grltrackerwrapper.py
index a72963a3f..154cc35be 100644
--- a/gnomemusic/grilowrappers/grltrackerwrapper.py
+++ b/gnomemusic/grilowrappers/grltrackerwrapper.py
@@ -123,8 +123,6 @@ class GrlTrackerWrapper(GObject.GObject):
self._content_changed_timeout: int = 0
self._tracker_playlists: Optional[GrlTrackerPlaylists] = None
self._tracker_wrapper: TrackerWrapper = tracker_wrapper
- self._notificationmanager: NotificationManager = (
- application.props.notificationmanager)
self._songs_search: Gtk.FilterListModel = Gtk.FilterListModel.new(
self._songs_model)
diff --git a/gnomemusic/notificationmanager.py b/gnomemusic/notificationmanager.py
index 6ffee620c..1ed75ba8d 100644
--- a/gnomemusic/notificationmanager.py
+++ b/gnomemusic/notificationmanager.py
@@ -22,13 +22,16 @@
# 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 GObject
+from gi.repository import GLib, GObject
class NotificationManager(GObject.Object):
"""Managing wrapper around the notification widgets
"""
+ _pulse_id = 0
+ _loading_counter = 0
+
def __init__(self, application):
"""Initialize the notification manager
@@ -36,26 +39,21 @@ class NotificationManager(GObject.Object):
"""
super().__init__()
- self._application = application
- self._pushed = False
self._window = application.props.window
- if self._window is None:
- application.connect(
- "notify::window", self._on_window_changed)
-
- def _on_window_changed(self, klass, value):
- self._window = self._application.props.window
-
def push_loading(self):
"""Push a loading notifcation."""
- if self._window:
- # This makes sure push/pop are in sync when starting.
- self._pushed = True
- self._window.notifications_popup.push_loading()
+ self._loading_counter += 1
+
+ if self._pulse_id == 0:
+ self._window.loading_visible(True)
+ self._pulse_id = GLib.timeout_add(100, self._window.loading_pulse)
def pop_loading(self):
- """Pop a loading notification."""
- if (self._window
- and self._pushed):
- self._window.notifications_popup.pop_loading()
+ self._loading_counter -= 1
+
+ if (self._loading_counter == 0
+ and self._pulse_id != 0):
+ GLib.Source.remove(self._pulse_id)
+ self._pulse_id = 0
+ self._window.loading_visible(False)
diff --git a/gnomemusic/widgets/notificationspopup.py b/gnomemusic/widgets/notificationspopup.py
index f18e48b66..1068f50fc 100644
--- a/gnomemusic/widgets/notificationspopup.py
+++ b/gnomemusic/widgets/notificationspopup.py
@@ -44,15 +44,9 @@ class NotificationsPopup(Gtk.Revealer):
def __init__(self):
super().__init__()
- self._loading_notification = LoadingNotification()
- self._loading_notification.connect('visible', self._set_visibility)
- self._loading_notification.connect('invisible', self._set_visibility)
- self._box.append(self._loading_notification)
-
def _hide_notifications(self, notification, remove):
if remove:
self._box.remove(notification)
- self._loading_notification.hide()
self.hide()
def _set_visibility(self, notification, remove=False):
@@ -61,12 +55,8 @@ class NotificationsPopup(Gtk.Revealer):
Popup is displayed if a loading is active or if a playlist
deletion is in progress.
"""
- loading_finished = self._loading_notification._counter == 0
box_children = [child for child in self._box]
- no_other_notif = (len(box_children) == 1
- or (len(box_children) == 2
- and notification != self._loading_notification))
- invisible = loading_finished and no_other_notif
+ invisible = (len(box_children) == 1 or (len(box_children) == 2))
if not invisible:
if remove:
@@ -80,20 +70,6 @@ class NotificationsPopup(Gtk.Revealer):
duration + 100, self._hide_notifications, notification, remove)
self.set_reveal_child(not invisible)
- def pop_loading(self):
- """Decrease loading notification counter.
-
- If it reaches zero, the notification is withdrawn.
- """
- self._loading_notification.pop()
-
- def push_loading(self):
- """Increase loading notification counter.
-
- If no notification is visible, start loading notification.
- """
- self._loading_notification.push()
-
def add_notification(self, notification):
"""Display a new notification
@@ -118,52 +94,6 @@ class NotificationsPopup(Gtk.Revealer):
notification._finish_deletion()
-@Gtk.Template(resource_path="/org/gnome/Music/ui/LoadingNotification.ui")
-class LoadingNotification(Gtk.Grid):
- """LoadingNotification displays a loading notification message
-
- It can be triggered by different all main views. Message is
- displayed as long as at least one loading operation is in progress.
- """
-
- __gsignals__ = {
- 'visible': (GObject.SignalFlags.RUN_FIRST, None, ()),
- 'invisible': (GObject.SignalFlags.RUN_FIRST, None, ())
- }
-
- __gtype_name__ = "LoadingNotification"
-
- def __init__(self):
- super().__init__()
- self._counter = 0
- self._timeout_id = 0
-
- def pop(self):
- """Decrease the counter. Hide notification if it reaches 0."""
- self._counter = self._counter - 1
-
- if self._counter == 0:
- # Stop the timeout if necessary
- if self._timeout_id > 0:
- if not self.is_visible():
- GLib.source_remove(self._timeout_id)
- self._timeout_id = 0
- self.emit('invisible')
-
- def push(self):
- """Increase the counter. Start notification if necessary."""
- def callback():
- self.props.visible = True
- self.emit('visible')
-
- if self._counter == 0:
- # Only show the notification after a small delay, thus
- # add a timeout. 500ms feels good enough.
- self._timeout_id = GLib.timeout_add(500, callback)
-
- self._counter = self._counter + 1
-
-
@Gtk.Template(resource_path="/org/gnome/Music/ui/PlaylistNotification.ui")
class PlaylistNotification(Gtk.Grid):
"""Show a notification on playlist or song deletion.
diff --git a/gnomemusic/window.py b/gnomemusic/window.py
index a79753817..fedbd9203 100644
--- a/gnomemusic/window.py
+++ b/gnomemusic/window.py
@@ -58,6 +58,7 @@ class Window(Adw.ApplicationWindow):
notifications_popup = Gtk.Template.Child()
_headerbar_stack = Gtk.Template.Child()
+ _loading_progress = Gtk.Template.Child()
_overlay = Gtk.Template.Child()
_player_toolbar = Gtk.Template.Child()
_selection_toolbar = Gtk.Template.Child()
@@ -477,3 +478,20 @@ class Window(Adw.ApplicationWindow):
:param bool visible: actionbar visibility
"""
self._player_toolbar.props.revealed = visible
+
+ def loading_pulse(self) -> bool:
+ """Pulse the loading progress bar
+
+ :returns: GLib.SOURCE_CONTINUE
+ :rtype: bool
+ """
+ self._loading_progress.pulse()
+
+ return GLib.SOURCE_CONTINUE
+
+ def loading_visible(self, show: bool) -> None:
+ """Sets visibility of the loading progressbar
+
+ :param bool show: Wheter to show the loading bar
+ """
+ self._loading_progress.props.visible = show
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 302fb4376..f5b2bf5d0 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -10,7 +10,6 @@ data/ui/EmptyView.ui
data/ui/HeaderBar.ui
data/ui/help-overlay.ui
data/ui/LastfmDialog.ui
-data/ui/LoadingNotification.ui
data/ui/PlayerToolbar.ui
data/ui/PlaylistControls.ui
data/ui/PlaylistDialog.ui
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]