303
by Mirco Müller
added examples form development-guidelines |
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 icon-only.py
|
|
13 |
## ./icon-only.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 pynotify |
|
36 |
||
37 |
# even in Python this is globally nasty :), do something nicer in your own code
|
|
38 |
capabilities = {'actions': False, |
|
39 |
'body': False, |
|
40 |
'body-hyperlinks': False, |
|
41 |
'body-images': False, |
|
42 |
'body-markup': False, |
|
43 |
'icon-multi': False, |
|
44 |
'icon-static': False, |
|
45 |
'sound': False, |
|
46 |
'image/svg+xml': False, |
|
47 |
'x-canonical-private-synchronous': False, |
|
48 |
'x-canonical-append': False, |
|
49 |
'x-canonical-private-icon-only': False, |
|
50 |
'x-canonical-truncation': 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['x-canonical-private-synchronous']: |
|
93 |
print "\tx-canonical-private-synchronous" |
|
94 |
if capabilities['x-canonical-append']: |
|
95 |
print "\tx-canonical-append" |
|
96 |
if capabilities['x-canonical-private-icon-only']: |
|
97 |
print "\tx-canonical-private-icon-only" |
|
98 |
if capabilities['x-canonical-truncation']: |
|
99 |
print "\tx-canonical-truncation" |
|
100 |
||
101 |
print "Notes:" |
|
102 |
if info["name"] == "notify-osd": |
|
103 |
print "\tx- and y-coordinates hints are ignored" |
|
104 |
print "\texpire-timeout is ignored" |
|
105 |
print "\tbody-markup is accepted but filtered" |
|
106 |
else: |
|
107 |
print "\tnone" |
|
108 |
||
109 |
if __name__ == '__main__': |
|
110 |
if not pynotify.init ("icon-only"): |
|
111 |
sys.exit (1) |
|
112 |
||
113 |
# call this so we can savely use capabilities dictionary later
|
|
114 |
initCaps () |
|
115 |
||
116 |
# show what's supported
|
|
117 |
printCaps () |
|
118 |
||
119 |
# try the icon-only case
|
|
120 |
if capabilities['x-canonical-private-icon-only']: |
|
439
by Mirco Müller
updated C- and Python-examples, updated NEWS |
121 |
n = pynotify.Notification ("", # for a11y-reasons put something meaningfull here |
122 |
"", # for a11y-reasons put something meaningfull here |
|
303
by Mirco Müller
added examples form development-guidelines |
123 |
"notification-device-eject") |
439
by Mirco Müller
updated C- and Python-examples, updated NEWS |
124 |
n.set_hint_string ("x-canonical-private-icon-only", "true"); |
303
by Mirco Müller
added examples form development-guidelines |
125 |
n.show () |
126 |
else: |
|
127 |
print "The daemon does not support the x-canonical-private-icon-only hint!" |
|
128 |