~macslow/notify-osd/ubutu

« back to all changes in this revision

Viewing changes to examples/low-urgency.py

  • Committer: seb128
  • Date: 2009-06-03 14:24:53 UTC
  • mfrom: (24.15.93 notify-osd)
  • Revision ID: seb128@seb128-laptop-20090603142453-kfmqu0pp3nb8e1jo
Tags: 0.9.13-0ubuntu1
releasing version 0.9.13-0ubuntu1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 low-urgency.py
 
13
##    ./low-urgency.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 ("low-urgency"):
 
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-summary-body case
 
120
        n = pynotify.Notification ("Gerhard Gepard",
 
121
                                   "No, I'd rather see paint dry, pal *yawn*",
 
122
                                   "notification-message-im")
 
123
        n.set_urgency (pynotify.URGENCY_LOW)
 
124
 
 
125
        n.show ()
 
126