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.
  • [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.