Sending notifications with GObjects
Asked Answered
C

1

6

There seems to be a distinct lack of documentation of the GObjects module for python at the moment, so maybe somebody can help me.

I am making an application which occasionally will have to notify the user that an event has occurred. I have found about using from gi.repository import Notify and the relating classes from using a short snippet for skype notifications and the C documentation, but it seems to not close when I call Notify.uninit. The program closes, but the little notification window thing stays put and has to be closed by right clicking on it and selecting "Remove". So, I am wondering if there is perhaps another way like if there was something similar to how in Mac OS the application icon shakes/bounces when something happens or in Windows the application icon glowing a different color?

I like the Gnome 3 notification system with the message stack and such, but since I can't seem to get it to disappear when my application exits I don't really want to use it (unless someone knows how to properly do this...it may be that I forgot to set a timeout, but that still doesn't make sense as to why I can't just make the notification spot disappear).

Coventry answered 1/7, 2012 at 22:3 Comment(0)
K
6

Calling Notify.uninit is not supposed to make the notifications disappear, it only tells libnotify that it will no longer be needed for your application. To make notifications disappear, you have to close them explicitly like in the following example:

import time
from gi.repository import Notify

Notify.init('myapp')

# optionally set an icon as the last argument
n = Notify.Notification.new('summary text', 'body text', "dialog-information")
n.show()

# do whatever your application is doing
time.sleep(10)

n.close()
Notify.uninit()
Kindness answered 3/7, 2012 at 11:33 Comment(1)
+1 because the documentation of PyGobject is missing from the internets somehow.Executor

© 2022 - 2024 — McMap. All rights reserved.