Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending notifications with GObjects

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).

like image 710
Los Frijoles Avatar asked Jul 01 '12 22:07

Los Frijoles


1 Answers

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()
like image 167
Marcel Stimberg Avatar answered Sep 22 '22 08:09

Marcel Stimberg