home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / doc / python-notify / examples / test-replace-widget.py < prev    next >
Encoding:
Python Source  |  2006-04-26  |  1.2 KB  |  50 lines

  1. #!/usr/bin/env python
  2.  
  3. import pygtk
  4. pygtk.require('2.0')
  5. import gtk
  6. import pynotify
  7. import sys
  8.  
  9. exposed_signal_id = 0
  10. count = 0
  11.  
  12. def exposed_cb(button, event, n):
  13.     global exposed_signal_id
  14.     button.disconnect(exposed_signal_id)
  15.     if not n.show():
  16.         print "Failed to send notification"
  17.         gtk.main_quit()
  18.  
  19. def clicked_cb(button, n):
  20.     global count
  21.     count += 1
  22.     n.update("Widget Attachment Test",
  23.              "You clicked the button %s times" % count)
  24.     if not n.show():
  25.         print "Failed to send notification"
  26.         gtk.main_quit()
  27.  
  28.  
  29. if __name__ == '__main__':
  30.     if not pynotify.init("Replace Test"):
  31.         sys.exit(1)
  32.  
  33.     win = gtk.Window(gtk.WINDOW_TOPLEVEL)
  34.     win.show()
  35.     win.connect('delete_event', gtk.main_quit)
  36.  
  37.     button = gtk.Button("Click here to change notification")
  38.     button.show()
  39.     win.add(button)
  40.  
  41.     n = pynotify.Notification("Widget Attachment Test",
  42.                               "Button has not been clicked yet", None, button)
  43.     n.set_category("presence.online")
  44.     n.set_timeout(0)
  45.  
  46.     button.connect('clicked', clicked_cb, n)
  47.     exposed_signal_id = button.connect('expose_event', exposed_cb, n)
  48.  
  49.     gtk.main()
  50.