Attachment 'Skype.py'
Download 1 # -*- coding: iso-8859-1 -*-
2 """
3 MoinMoin - Skype button and link macro
4
5 @copyright: 2006 Andreas Schreiber <AndreasSchreiber@dlr.de>
6 @license: GNU GPL, see COPYING for details.
7
8 """
9
10 __version__ = '$Revision: $'[11:-2]
11
12 IMAGE_URL = 'http://goodies.skype.com/graphics/skypeme_btn%s_%s.gif'
13
14 COLORS = ['green',
15 'black',
16 'blue',
17 'brownish',
18 'darkgrey',
19 'lightgrey',
20 'orange',
21 'pink',
22 'purple',
23 'red',
24 'white',
25 'yellow']
26
27
28 class Skype:
29 """ This implements the MantisIssue macro for the MoinMoin Wiki."""
30
31 def __init__(self, macro, args):
32 self.macro = macro
33 self.formatter = macro.request.formatter
34
35 # default values
36 self.username = None
37 self.color = COLORS[0]
38 self.size = "small"
39
40 self.parseArgs(args)
41
42
43 def execute(self):
44 if (self.username == None):
45 return self.errorMessage("No username specified!")
46
47 if self.color not in COLORS:
48 return self.errorMessage("Color '%s' unknown! Use one of %s." % (self.color, str(COLORS)))
49
50 if self.size == "small":
51 imageUrl = IMAGE_URL % ("_small", self.color)
52 else:
53 imageUrl = IMAGE_URL % ("", self.color)
54 return '<a href="callto://%s"><img src="%s" alt="Skype me!" title="Call %s with Skype" border=0></a>' % (self.username, imageUrl, self.username)
55
56 def parseArgs(self, args):
57 """Parse arguments."""
58 if args:
59 # Arguments are comma delimited
60 sargs = args.split(',')
61
62 # The first argument should be the username
63 if len(sargs[0].split('=')) == 1:
64 self.username = sargs[0]
65
66 # Optional arguments are key:value pairs
67 for item in sargs:
68 sitem = item.strip().split('=')
69
70 if len(sitem) == 2:
71 if sitem[0] == "color":
72 self.color = sitem[1]
73 if sitem[0] == "size":
74 self.size = sitem[1]
75 return
76
77 def errorMessage(self, message):
78 _ = self.macro.request.getText
79 formatter = self.macro.formatter
80 return (formatter.sysmsg(1) +
81 formatter.smiley("{X}") +
82 _(" ") +
83 formatter.highlight(1) +
84 _(message) +
85 formatter.highlight(0) +
86 formatter.sysmsg(0))
87
88
89 def execute(macro, args):
90 return Skype(macro, args).execute()
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.