#!/usr/bin/env python2.7 # -*- coding: utf-8 -*- """ A simple Python test of the pynotify module to use notifylib on Linux (Ubuntu). .. warning:: Copyleft 2013 - Lilian Besson. .. warning:: `License GPLv3 `_ """ try: import pynotify # WARNING this is required! pynotify.init("My application") except ImportError: print "pynotify is not available!" exit(1) def notify(msg, title="Default title for the notify function"): """ Notify the user with the message `msg`.""" n = pynotify.Notification(title, msg) n.set_urgency(pynotify.URGENCY_NORMAL) n.set_timeout(20) n.show() return n def callback_function(notification=None, action=None, data=None): """ Test of a callback function for :fun:`pynotify.Notification.add_action`.""" # print notification, action, data return notify(notification.get_properties("summary")[0], "The notification has been closed.") def main(): """ main() -> None Test several notifications.""" # notify("Test of the short function notify.") n = pynotify.Notification("Title of the notification", "Body of the notification !\nTango markup tags are available !") # Urgency (Low, critical or normal) n.set_urgency(pynotify.URGENCY_CRITICAL) # Timeout # n.set_timeout(pynotify.EXPIRES_NEVER) n.set_timeout(40) # We can add some button on the notification n.add_action("clicked", "OK?", callback_function, None) # n.add_action("clicked", "...", callback_function, None) n.add_action("clicked", "Bug!", callback_function, None) # set_property(property_name, property_value) can be used n.set_property("app-name", "App name") # n.set_property("summary", "Title") # n.set_property("body", "Body") # icon-name with a theme-compliant name n.set_property("icon-name", "sound") # icon-name with a filename n.set_property("icon-name", "/home/lilian/lbesson_link.png") print n.get_properties("summary")[0] n.show() return 0 if __name__ == "__main__": from doctest import testmod testmod(verbose=False) main()