notify-osd
Attachment 'append-hint-example.py'
Download 1 #!/usr/bin/python
2
3 ################################################################################
4 ##3456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
5 ## 10 20 30 40 50 60 70 80
6 ##
7 ## Info:
8 ## Example of how to use libnotify correctly and at the same time comply to
9 ## the new jaunty notification spec (read: visual guidelines)
10 ##
11 ## Run:
12 ## chmod +x append-hint-example.py
13 ## ./append-hint-example.py
14 ##
15 ## Copyright 2009 Canonical Ltd.
16 ##
17 ## Author:
18 ## Mirco "MacSlow" Mueller <mirco.mueller@canonical.com>
19 ##
20 ## This program is free software: you can redistribute it and/or modify it
21 ## under the terms of the GNU General Public License version 3, as published
22 ## by the Free Software Foundation.
23 ##
24 ## This program is distributed in the hope that it will be useful, but
25 ## WITHOUT ANY WARRANTY; without even the implied warranties of
26 ## MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
27 ## PURPOSE. See the GNU General Public License for more details.
28 ##
29 ## You should have received a copy of the GNU General Public License along
30 ## with this program. If not, see <http://www.gnu.org/licenses/>.
31 ##
32 ################################################################################
33
34 import sys
35 import time
36 import pynotify
37
38 # even in Python this is globally nasty :), do something nicer in your own code
39 capabilities = {'actions': False,
40 'body': False,
41 'body-hyperlinks': False,
42 'body-images': False,
43 'body-markup': False,
44 'icon-multi': False,
45 'icon-static': False,
46 'sound': False,
47 'image/svg+xml': False,
48 'private-synchronous': False,
49 'append': False,
50 'private-icon-only': False}
51
52 def initCaps ():
53 caps = pynotify.get_server_caps ()
54 if caps is None:
55 print "Failed to receive server caps."
56 sys.exit (1)
57
58 for cap in caps:
59 capabilities[cap] = True
60
61 def printCaps ():
62 info = pynotify.get_server_info ()
63 print "Name: " + info["name"]
64 print "Vendor: " + info["vendor"]
65 print "Version: " + info["version"]
66 print "Spec. Version: " + info["spec-version"]
67
68 caps = pynotify.get_server_caps ()
69 if caps is None:
70 print "Failed to receive server caps."
71 sys.exit (1)
72
73 print "Supported capabilities/hints:"
74 if capabilities['actions']:
75 print "\tactions"
76 if capabilities['body']:
77 print "\tbody"
78 if capabilities['body-hyperlinks']:
79 print "\tbody-hyperlinks"
80 if capabilities['body-images']:
81 print "\tbody-images"
82 if capabilities['body-markup']:
83 print "\tbody-markup"
84 if capabilities['icon-multi']:
85 print "\ticon-multi"
86 if capabilities['icon-static']:
87 print "\ticon-static"
88 if capabilities['sound']:
89 print "\tsound"
90 if capabilities['image/svg+xml']:
91 print "\timage/svg+xml"
92 if capabilities['private-synchronous']:
93 print "\tprivate-synchronous"
94 if capabilities['append']:
95 print "\tappend"
96 if capabilities['private-icon-only']:
97 print "\tprivate-icon-only"
98
99 print "Notes:"
100 if info["name"] == "notify-osd":
101 print "\tx- and y-coordinates hints are ignored"
102 print "\texpire-timeout is ignored"
103 print "\tbody-markup is accepted but filtered"
104 else:
105 print "\tnone"
106
107 if __name__ == '__main__':
108 if not pynotify.init ("append-hint-example"):
109 sys.exit (1)
110
111 # call this so we can savely use capabilities dictionary later
112 initCaps ()
113
114 # show what's supported
115 printCaps ()
116
117 # try the append-hint
118 if capabilities['append']:
119 n = pynotify.Notification ("Cole Raby",
120 "Hey Bro Coly!",
121 "notification-message-IM")
122 n.set_hint_string ("append", "allowed");
123 n.show ()
124 time.sleep (2) # simulate a user typing
125 n.update ("Cole Raby",
126 "What's up dude?",
127 "notification-message-IM")
128 n.show ()
129 time.sleep (2) # simulate a user typing
130 n.update ("Cole Raby",
131 "Did you watch the air-race in Oshkosh last week?",
132 "notification-message-IM")
133 n.show ()
134 time.sleep (2) # simulate a user typing
135 n.update ("Cole Raby",
136 "Phil owned the place like no one before him!",
137 "notification-message-IM")
138 n.show ()
139 else:
140 print "The daemon does not support the append-hint!"
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.