NotificationDevelopmentGuidelines

Attachment 'summary-only.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 summary-only.py
  13 ##    ./summary-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 		'private-synchronous': False,
  48 		'append':              False,
  49 		'private-icon-only':   False}
  50 
  51 def initCaps ():
  52 	caps = pynotify.get_server_caps ()
  53 	if caps is None:
  54 	        print "Failed to receive server caps."
  55 		sys.exit (1)
  56 
  57 	for cap in caps:
  58 		capabilities[cap] = True
  59 
  60 def printCaps ():
  61 	info = pynotify.get_server_info ()
  62 	print "Name:          " + info["name"]
  63 	print "Vendor:        " + info["vendor"]
  64 	print "Version:       " + info["version"]
  65 	print "Spec. Version: " + info["spec-version"]
  66 
  67 	caps = pynotify.get_server_caps ()
  68 	if caps is None:
  69 	        print "Failed to receive server caps."
  70 		sys.exit (1)
  71 
  72 	print "Supported capabilities/hints:"
  73 	if capabilities['actions']:
  74 		print "\tactions"
  75 	if capabilities['body']:
  76 		print "\tbody"
  77 	if capabilities['body-hyperlinks']:
  78 		print "\tbody-hyperlinks"
  79 	if capabilities['body-images']:
  80 		print "\tbody-images"
  81 	if capabilities['body-markup']:
  82 		print "\tbody-markup"
  83 	if capabilities['icon-multi']:
  84 		print "\ticon-multi"
  85 	if capabilities['icon-static']:
  86 		print "\ticon-static"
  87 	if capabilities['sound']:
  88 		print "\tsound"
  89 	if capabilities['image/svg+xml']:
  90 		print "\timage/svg+xml"
  91 	if capabilities['private-synchronous']:
  92 		print "\tprivate-synchronous"
  93 	if capabilities['append']:
  94 		print "\tappend"
  95 	if capabilities['private-icon-only']:
  96 		print "\tprivate-icon-only"
  97 
  98 	print "Notes:"
  99 	if info["name"] == "notify-osd":
 100 		print "\tx- and y-coordinates hints are ignored"
 101 		print "\texpire-timeout is ignored"
 102 		print "\tbody-markup is accepted but filtered"
 103 	else:
 104 		print "\tnone"
 105 
 106 if __name__ == '__main__':
 107 	if not pynotify.init ("summary-only"):
 108 		sys.exit (1)
 109 
 110 	# call this so we can savely use capabilities dictionary later
 111 	initCaps ()
 112 
 113 	# show what's supported
 114 	printCaps ()
 115 
 116 	# try the summary-only case
 117 	n = pynotify.Notification ("Summary-only",
 118 				   "")
 119 	n.show ()

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.
  • [get | view] (2009-02-25 22:40:59, 8.2 KB) [[attachment:append-hint-example.c]]
  • [get | view] (2009-02-25 22:41:05, 6.3 KB) [[attachment:append-hint-example.cs]]
  • [get | view] (2009-02-25 15:44:14, 931.0 KB) [[attachment:append-hint-example.ogg]]
  • [get | view] (2009-02-25 22:41:10, 4.1 KB) [[attachment:append-hint-example.py]]
  • [get | view] (2009-02-25 22:41:58, 6.8 KB) [[attachment:icon-summary-body.c]]
  • [get | view] (2009-02-25 22:42:06, 5.8 KB) [[attachment:icon-summary-body.cs]]
  • [get | view] (2009-02-25 23:32:31, 25.9 KB) [[attachment:icon-summary-body.png]]
  • [get | view] (2010-01-13 10:26:42, 3.6 KB) [[attachment:icon-summary-body.py]]
  • [get | view] (2009-02-25 22:41:37, 6.7 KB) [[attachment:icon-summary.c]]
  • [get | view] (2009-02-25 22:41:42, 5.7 KB) [[attachment:icon-summary.cs]]
  • [get | view] (2009-02-25 23:32:25, 21.8 KB) [[attachment:icon-summary.png]]
  • [get | view] (2009-02-25 22:41:48, 3.5 KB) [[attachment:icon-summary.py]]
  • [get | view] (2009-02-25 17:28:21, 39.8 KB) [[attachment:small_append-hint-example_ogg.png]]
  • [get | view] (2009-03-02 00:26:37, 31.5 KB) [[attachment:small_update-notifications_ogg.png]]
  • [get | view] (2009-02-25 22:42:54, 6.7 KB) [[attachment:summary-body.c]]
  • [get | view] (2009-02-25 22:43:06, 5.7 KB) [[attachment:summary-body.cs]]
  • [get | view] (2009-02-25 23:32:55, 22.4 KB) [[attachment:summary-body.png]]
  • [get | view] (2009-02-25 22:43:22, 3.5 KB) [[attachment:summary-body.py]]
  • [get | view] (2009-02-25 22:43:29, 6.7 KB) [[attachment:summary-only.c]]
  • [get | view] (2009-02-25 22:43:35, 5.6 KB) [[attachment:summary-only.cs]]
  • [get | view] (2009-02-25 23:33:04, 20.3 KB) [[attachment:summary-only.png]]
  • [get | view] (2009-02-25 22:43:42, 3.5 KB) [[attachment:summary-only.py]]
  • [get | view] (2009-03-01 07:01:45, 8.5 KB) [[attachment:update-notifications.c]]
  • [get | view] (2009-03-01 07:01:53, 6.6 KB) [[attachment:update-notifications.cs]]
  • [get | view] (2009-03-01 07:02:38, 1226.6 KB) [[attachment:update-notifications.ogg]]
  • [get | view] (2009-03-01 07:01:59, 4.3 KB) [[attachment:update-notifications.py]]
 All files | Selected Files: delete move to page

You are not allowed to attach a file to this page.