Wednesday, May 28, 2008

Adding python event notifications to the Desktop

Figured out how to get a Python script pop up a notification bubble on the desktop:

It uses the pynotify frontend to libnotify. It's not part of the python 2.5 base, but is included with the Ubuntu default install. Here's a test script for my Ubuntu system. It pops up a little bubble from the system tray

import pygtk
import pynotify

pynotify.init( "Some Application or Title" )
n = pynotify.Notification("Title", "body", "dialog-warning")
n.set_urgency(pynotify.URGENCY_NORMAL)
n.show()

Tip: The .init() call is neccessary, or you'll get a lot of ugly DBUS and GTK errors.

Changing Stuff: Simply replace the elements("Title", "body", "dialog-warning") with your desired title, body, and image path. The image display will take .jpg, .png, .svg, and likely others. For example...


n = pynotify.Notification("Milwaukee Without A Car", "The Python script MWC_Webcrawler has completed a scheduled run. The logfile has been added to your desktop", "/usr/share/icons/Rodent/48x48/apps/gnome-info.png")

No comments:

Post a Comment