]>
Commit | Line | Data |
---|---|---|
f853d479 BB |
1 | # -*- coding: utf-8 -*- |
2 | # | |
3 | # Copyright (c) 2009 by xt <xt@bash.no> | |
4 | # | |
5 | # This program is free software; you can redistribute it and/or modify | |
6 | # it under the terms of the GNU General Public License as published by | |
7 | # the Free Software Foundation; either version 3 of the License, or | |
8 | # (at your option) any later version. | |
9 | # | |
10 | # This program is distributed in the hope that it will be useful, | |
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | # GNU General Public License for more details. | |
14 | # | |
15 | # You should have received a copy of the GNU General Public License | |
16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | # | |
18 | # | |
19 | # | |
20 | # USAGE: Bind a key to command /flip . Then write some text at input line | |
21 | # press your key to transform it to upside down. | |
22 | ||
23 | # | |
24 | # (this script requires WeeChat 0.3.0 or newer) | |
25 | # | |
26 | # History: | |
27 | # 2010-01-14, xt | |
28 | # version 0.3: steal more chars from m4v | |
29 | # 2010-01-06, xt <xt@bash.no> | |
30 | # version 0.2: fix idiotic programming | |
31 | # 2009-11-12, xt <xt@bash.no> | |
32 | # version 0.1: initial release | |
33 | ||
34 | import weechat as w | |
35 | import re | |
36 | ||
37 | SCRIPT_NAME = "upside_down" | |
38 | SCRIPT_AUTHOR = "xt <xt@bash.no>" | |
39 | SCRIPT_VERSION = "0.3" | |
40 | SCRIPT_LICENSE = "GPL3" | |
41 | SCRIPT_DESC = "Replaces text you write with upside down text" | |
42 | ||
43 | settings = {} | |
44 | ||
45 | replacements = { | |
46 | # Upper case | |
47 | u'A' : u'\N{FOR ALL}', | |
48 | u'B' : u'\N{GREEK SMALL LETTER XI}', | |
49 | u'C' : u'\N{ROMAN NUMERAL REVERSED ONE HUNDRED}', | |
50 | u'D' : u'\N{LEFT HALF BLACK CIRCLE}', | |
51 | u'E' : u'\N{LATIN CAPITAL LETTER REVERSED E}', | |
52 | u'F' : u'\N{TURNED CAPITAL F}', | |
53 | u'G' : u'\N{TURNED SANS-SERIF CAPITAL G}', | |
54 | u'J' : u'\N{LATIN SMALL LETTER LONG S}', | |
55 | u'K' : u'\N{RIGHT NORMAL FACTOR SEMIDIRECT PRODUCT}', | |
56 | u'L' : u'\ua780', | |
57 | u'M' : u'W', | |
58 | u'N' : u'\N{LATIN LETTER SMALL CAPITAL REVERSED N}', | |
59 | u'P' : u'\N{CYRILLIC CAPITAL LETTER KOMI DE}', | |
60 | u'Q' : u'\N{GREEK CAPITAL LETTER OMICRON WITH TONOS}', | |
61 | u'R' : u'\N{LATIN LETTER SMALL CAPITAL TURNED R}', | |
62 | u'T' : u'\N{UP TACK}', | |
63 | u'U' : u'\N{INTERSECTION}', | |
64 | u'V' : u'\u0245', | |
65 | u'Y' : u'\N{TURNED SANS-SERIF CAPITAL Y}', | |
66 | 'a' : u"\u0250", | |
67 | 'b' : u'q', | |
68 | 'c' : u"\u0254", | |
69 | 'd' : u'p', | |
70 | 'e' : u"\u01DD", | |
71 | 'f' : u"\u025F", | |
72 | 'g' : u"\u0183", | |
73 | 'h' : u'\u0265', | |
74 | 'i' : u'\u0131', | |
75 | 'j' : u'\u027E', | |
76 | 'k' : u'\u029E', | |
77 | 'm' : u'\u026F', | |
78 | 'n' : u'u', | |
79 | 'r' : u'\u0279', | |
80 | 't' : u'\u0287', | |
81 | 'p' : u'd', | |
82 | 'u' : u'n', | |
83 | 'q' : u'b', | |
84 | 'v' : u'\u028C', | |
85 | 'w' : u'\u028D', | |
86 | 'y' : u'\u028E', | |
87 | '.' : u'\u02D9', | |
88 | '[' : u']', | |
89 | '(' : u')', | |
90 | '{' : u'}', | |
91 | '?' : u'\u00BF', | |
92 | '!' : u'\u00A1', | |
93 | "\'" :u',', | |
94 | '>' : u'<', | |
95 | '<' : u'>', | |
96 | '_' : u'\u203E', | |
97 | ';' : u'\u061B', | |
98 | '\u203F' : u'\u2040', | |
99 | '\u2045' : u'\u2046', | |
100 | '\u2234' : u'\u2235', | |
101 | } | |
102 | ||
103 | ||
104 | ||
105 | if w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, | |
106 | SCRIPT_DESC, "", ""): | |
107 | for option, default_value in settings.iteritems(): | |
108 | if not w.config_is_set_plugin(option): | |
109 | w.config_set_plugin(option, default_value) | |
110 | w.hook_command("flip", | |
111 | SCRIPT_DESC, | |
112 | "[text]", | |
113 | "text: text to be flipped\n" | |
114 | "", | |
115 | "", "flip_cmd_cb", "") | |
116 | ||
117 | ||
118 | def flip_cmd_cb(data, buffer, args): | |
119 | ''' Command /flip ''' | |
120 | translate_input = args | |
121 | if not translate_input: | |
122 | translate_input = w.buffer_get_string(w.current_buffer(), "input") | |
123 | outstring = '' | |
124 | for char in translate_input: | |
125 | if char in replacements: | |
126 | char = replacements[char] | |
127 | outstring += char | |
128 | outstring = outstring.encode('UTF-8') | |
129 | w.buffer_set(w.current_buffer(), 'input', outstring) | |
130 | return w.WEECHAT_RC_OK |