I am using PyGObject with Python 3 and I want to display a notification using a Notify.Notification
which has a progress bar in it. The progress bar doesn't need to update on its own/asynchronously or anything - it can (and should) be static, updating only when I manually set a new value then tell the notification to show. I'm after something like a volume notification showing the new volume as you change it.
I have been unable to find any way to do this searching documentation such as this, is this possible using PyGObject? Alternatively is there another Python 3 library which would allow this behaviour?
I'm currently showing notifications with text-based progress similar to this:
import gi
gi.require_version('Notify', '0.7')
from gi.repository import Notify
def __init___(self):
...
Notify.init("Progress")
self.notification = Notify.Notification(summary='Progress', body='0%')
self.notification.set_image_from_pixbuf(notification_image)
...
def on_progress_update(self, progress):
...
self.notification.update('Progress', str(progress) + '%', None)
self.notification.show()
...
So after much more searching I found this thread on the xfce forums discussing the use of send-notify to get xfce4-notifyd "gauges", and was able to figure out how to use Notify.Notification.set_hint()
. So, if you want your notification to show a progress bar/status bar/gauge, you can use the following:
import gi
gi.require_version('Notify', '0.7')
from gi.repository import GLib, Notify
Notify.init("Name")
notification = Notify.Notification()
notification.set_hint('value', GLib.Variant.new_int32(volume))
Points of note:
notification.set_image_from_pixbuf()
int32
, int64
, double
, and possibly others of numeric type larger than int32
, but NOT byte
or int16
, any uint
type such as uint32
, or (I would assume) any non-numeric type. Just use int32
as fas I can tell.Name
for other steps, the value for set_hint
MUST be 'value'
with a lower case v.Also worth noting I'm not sure if this is a unniversal method or if it only works for xfce4-notifyd, I only use xfce4-notifyd so for now I'm not concerned, but if I look into this I will try to remember to update my answer. Alternatively if anyone else knows the answer to this please let me know.