File: test-replace-widget.py

package info (click to toggle)
notify-python 0.1.1-4
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch
  • size: 1,516 kB
  • ctags: 90
  • sloc: sh: 8,496; ansic: 622; python: 255; makefile: 111
file content (49 lines) | stat: -rwxr-xr-x 1,189 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python

import pygtk
pygtk.require('2.0')
import gtk
import pynotify
import sys

exposed_signal_id = 0
count = 0

def exposed_cb(button, event, n):
    global exposed_signal_id
    button.disconnect(exposed_signal_id)
    if not n.show():
        print "Failed to send notification"
        gtk.main_quit()

def clicked_cb(button, n):
    global count
    count += 1
    n.update("Widget Attachment Test",
             "You clicked the button %s times" % count)
    if not n.show():
        print "Failed to send notification"
        gtk.main_quit()


if __name__ == '__main__':
    if not pynotify.init("Replace Test"):
        sys.exit(1)

    win = gtk.Window(gtk.WINDOW_TOPLEVEL)
    win.show()
    win.connect('delete_event', gtk.main_quit)

    button = gtk.Button("Click here to change notification")
    button.show()
    win.add(button)

    n = pynotify.Notification("Widget Attachment Test",
                              "Button has not been clicked yet", None, button)
    n.set_category("presence.online")
    n.set_timeout(0)

    button.connect('clicked', clicked_cb, n)
    exposed_signal_id = button.connect('expose_event', exposed_cb, n)

    gtk.main()