Mercurial > traipse
comparison plugins/xxquotebox.py @ 0:4385a7d0efd1 grumpy-goblin
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
author | sirebral |
---|---|
date | Tue, 14 Jul 2009 16:41:58 -0500 |
parents | |
children | 97265586402b |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4385a7d0efd1 |
---|---|
1 import os | |
2 import orpg.dirpath | |
3 import orpg.plugindb | |
4 import orpg.pluginhandler | |
5 from orpg.tools.rgbhex import RGBHex | |
6 import wx | |
7 | |
8 __version__ = "2.0" # updated for OpenRPG+ 1.7.0 | |
9 | |
10 class Plugin(orpg.pluginhandler.PluginHandler): | |
11 # Initialization subroutine. | |
12 # | |
13 # !self : instance of self | |
14 # !openrpg : instance of the the base openrpg control | |
15 def __init__(self, plugindb, parent): | |
16 orpg.pluginhandler.PluginHandler.__init__(self, plugindb, parent) | |
17 | |
18 # The Following code should be edited to contain the proper information | |
19 self.name = "Quote Box" | |
20 self.author = "frobnic8 (erskin@eldritch.org), mDuo13, Veggiesama" | |
21 self.help = """This plugin allows you to put your text in a special box. Again, while | |
22 it could (except for the color selection) be easily done with a text node, | |
23 this plugin makes it faster, presents a consistant appearance, and saves | |
24 you from silly HTML errors. Just type "/box" and some text to get started. | |
25 | |
26 Type /quotebox to load a help node into your game tree. | |
27 | |
28 Advanced commands: | |
29 '/box': Displays the current settings. | |
30 '/box *text*': Displays *text* in the box. | |
31 '/box_size *size*': Lets you set the size of the text | |
32 \tin the box, where *size* is a number from 1 to 7. The default is 3. | |
33 '/box_bgcol': Brings up a color selection dialog for picking the background | |
34 \tcolor of the box. The default is pale grey. | |
35 '/box_fontcol': Brings up a color selection dialog for picking the color of | |
36 \tthe font in the box. The default is black. | |
37 '/box_border': Toggles a small black border around the box. | |
38 '/box_italics': Toggles whether the text in the box should be italicized or not. | |
39 '/box_bold': Toggles whether the text in the box should be bolded or not. | |
40 '/box_type': Toggles between the old and new versions of the box. Defaults to new. | |
41 '/box_default': Sets plugin to default settings. | |
42 | |
43 Credits go out to Travis for the original HTML code and Sunless DM for | |
44 bringing it to mDuo13's attention.""" | |
45 | |
46 self.version = __version__ | |
47 self.orpg_min_version="1.7.0" | |
48 | |
49 self.fontcolor = "#000000" | |
50 self.bgcolor="#aaaaaa" | |
51 self.size = 3 | |
52 self.border = 0 | |
53 self.italics = 0 | |
54 self.bold = 1 | |
55 self.boxtype = 1 | |
56 self.r_h = RGBHex() | |
57 | |
58 def plugin_enabled(self): | |
59 self.fontcolor = str(self.plugindb.GetString("xxquotebox", "fontcolor", "#000000")) | |
60 self.bgcolor = str(self.plugindb.GetString("xxquotebox", "bgcolor", "#aaaaaa")) | |
61 self.size = int(self.plugindb.GetString("xxquotebox", "size", "3")) | |
62 self.border = int(self.plugindb.GetString("xxquotebox", "border", "0")) | |
63 self.italics = int(self.plugindb.GetString("xxquotebox", "italics", "0")) | |
64 self.bold = int(self.plugindb.GetString("xxquotebox", "bold", "1")) | |
65 self.boxtype = int(self.plugindb.GetString("xxquotebox", "boxtype", "1")) | |
66 | |
67 self.plugin_addcommand('/box', self.on_box, "'/box': Displays the current settings <b>OR</b> '/box *text*': Displays *text* in the box.") | |
68 self.plugin_addcommand('/box_size', self.on_box_size, "'/box_size *size*': Lets you set the size of the text in the box, where *size* is a number from 1 to 7. The default is 3.", False) | |
69 self.plugin_addcommand('/box_bgcol', self.on_box_bgcol, "'/box_bgcol': Brings up a color selection dialog for picking the background color of the box. The default is pale grey.", False) | |
70 self.plugin_addcommand('/box_fontcol', self.on_box_fontcol,"'/box_fontcol': Brings up a color selection dialog for picking the color of the font in the box. The default is black.", False) | |
71 self.plugin_addcommand('/box_border', self.on_box_border, "'/box_border': Toggles a small black border around the box.", False) | |
72 self.plugin_addcommand('/box_italics', self.on_box_italics,"'/box_italics': Toggles whether the text in the box should be italicized or not.", False) | |
73 self.plugin_addcommand('/box_bold', self.on_box_bold, "'/box_bold': Toggles whether the text in the box should be bolded or not.", False) | |
74 self.plugin_addcommand('/box_type', self.on_box_type, "'/box_type': Toggles between the old and new versions of the box. Defaults to new.", False) | |
75 self.plugin_addcommand('/box_default', self.on_box_default,"'/box_default': Sets plugin to default settings.", False) | |
76 self.plugin_addcommand('/quotebox', self.on_quotebox, "<b>TYPE /QUOTEBOX TO BEGIN.</b> Loads up a help node into gametree.") | |
77 | |
78 def plugin_disabled(self): | |
79 self.plugin_removecmd('/box') | |
80 self.plugin_removecmd('/box_size') | |
81 self.plugin_removecmd('/box_bgcol') | |
82 self.plugin_removecmd('/box_fontcol') | |
83 self.plugin_removecmd('/box_border') | |
84 self.plugin_removecmd('/box_italics') | |
85 self.plugin_removecmd('/box_bold') | |
86 self.plugin_removecmd('/box_type') | |
87 self.plugin_removecmd('/box_default') | |
88 self.plugin_removecmd('/box_quotebox') | |
89 | |
90 def save_changes(self): | |
91 self.plugindb.SetString("xxquotebox", "fontcolor",str(self.fontcolor)) | |
92 self.plugindb.SetString("xxquotebox", "bgcolor", str(self.bgcolor)) | |
93 self.plugindb.SetString("xxquotebox", "size", str(self.size)) | |
94 self.plugindb.SetString("xxquotebox", "border", str(self.border)) | |
95 self.plugindb.SetString("xxquotebox", "italics", str(self.italics)) | |
96 self.plugindb.SetString("xxquotebox", "bold", str(self.bold)) | |
97 self.plugindb.SetString("xxquotebox", "boxtype", str(self.boxtype)) | |
98 | |
99 def on_box(self, cmdargs): | |
100 #this is just an example function for a command you create. | |
101 # cmdargs contains everything you typed after the command | |
102 # so if you typed /test this is a test, cmdargs = this is a test | |
103 # args are the individual arguments split. For the above example | |
104 # args[0] = this , args[1] = is , args[2] = a , args[3] = test | |
105 args = cmdargs.split(None,-1) | |
106 | |
107 # shows status information of the plugin in a dialog window | |
108 if len(args) == 0: | |
109 if self.boxtype == 0: | |
110 msg_boxtype = "old" | |
111 else: | |
112 msg_boxtype = "new" | |
113 | |
114 self.dlg = wx.MessageDialog(None, | |
115 'Current settings used by the Quote Box plugin:\n'+ | |
116 '\nsize: '+str(self.size)+'\nbgcolor: '+self.bgcolor+ | |
117 '\nfontcolor: '+self.fontcolor+'\nborder: '+str(self.border)+ | |
118 '\nitalics: '+str(self.italics)+'\nbold: '+str(self.bold)+ | |
119 '\nboxtype: '+msg_boxtype+'\n'+ | |
120 '\nSee the Plugin Info from the Tools/Plugin menu for '+ | |
121 'more information.', 'Quote Box Current Settings', wx.OK) | |
122 self.dlg.ShowModal() | |
123 self.dlg.Destroy() | |
124 | |
125 # making a box and using the cmdargs as the text inside | |
126 else: | |
127 msg = cmdargs | |
128 if self.boxtype == 0: #old | |
129 box = '<table bgcolor="' + self.bgcolor + '" border="0" cellpadding="0" cellspacing="0" width="100%">' | |
130 box += '<tr><td><font size="' + str(self.size) + '" color="' + self.fontcolor + '">' | |
131 box += '<b>' + msg + '</b></font></table>' | |
132 self.chat.Post(box, True, True) | |
133 else: #new | |
134 if self.border: | |
135 border = " border='1'" | |
136 else: | |
137 border = "" | |
138 | |
139 if self.italics: | |
140 italics = "<i>" | |
141 enditalics = "</i>" | |
142 else: | |
143 italics = "" | |
144 enditalics = "" | |
145 | |
146 if self.bold: | |
147 bold = "<b>" | |
148 endbold = "</b>" | |
149 else: | |
150 bold = "" | |
151 endbold = "" | |
152 | |
153 box = '<br><center><table bgcolor="' + self.bgcolor + '" width="80%"' | |
154 box += 'cellpadding="' + str(int(self.size * 5)) + '" cellspacing="0" ' + border + '>' | |
155 box += '<tr><td><font size="' + str(self.size) + '" color="' + self.fontcolor + '">' | |
156 box += bold + italics + msg + enditalics + endbold | |
157 box += '</font></td></tr></table></center>' | |
158 self.chat.Post(box, True, True) | |
159 | |
160 # changes size of font, as well as cell-padding size | |
161 # cell padding size = font size * 5 | |
162 def on_box_size(self, cmdargs): | |
163 try: | |
164 self.size = int(cmdargs) | |
165 self.save_changes() | |
166 self.chat.InfoPost("Box size set to <b>" + str(self.size) + "</b>.") | |
167 except: | |
168 self.chat.InfoPost("That is not a valid font size.") | |
169 | |
170 # opens a color-choosing dialog for background color of table | |
171 def on_box_bgcol(self, cmdargs): | |
172 color = self.r_h.do_hex_color_dlg(None) | |
173 if color != None: | |
174 self.bgcolor = color | |
175 self.save_changes() | |
176 | |
177 # opens a color-choosing dialog for font color of text | |
178 def on_box_fontcol(self, cmdargs): | |
179 color = self.r_h.do_hex_color_dlg(None) | |
180 if color != None: | |
181 self.fontcolor = color | |
182 self.save_changes() | |
183 | |
184 # toggles whether border should be on or off | |
185 def on_box_border(self, cmdargs): | |
186 if self.border: | |
187 self.border=0 | |
188 self.chat.InfoPost("No longer using border on table.") | |
189 else: | |
190 self.border=1 | |
191 self.chat.InfoPost("Using border on table.") | |
192 self.save_changes() | |
193 | |
194 # toggles whether text should be italics or not | |
195 def on_box_italics(self, cmdargs): | |
196 if self.italics: | |
197 self.italics=0 | |
198 self.chat.InfoPost("No longer using italic text.") | |
199 else: | |
200 self.italics=1 | |
201 self.chat.InfoPost("Using italic text.") | |
202 self.save_changes() | |
203 | |
204 # toggles whether text should be bold or not | |
205 def on_box_bold(self, cmdargs): | |
206 if self.bold: | |
207 self.bold=0 | |
208 self.chat.InfoPost("No longer using bold text.") | |
209 else: | |
210 self.bold=1 | |
211 self.chat.InfoPost("Using bold text.") | |
212 self.save_changes() | |
213 | |
214 # toggles between old-style and new-style boxes | |
215 def on_box_type(self, cmdargs): | |
216 if self.boxtype: | |
217 self.boxtype=0 | |
218 self.chat.InfoPost("Now using old-style boxes (thin, full-width, left-aligned)") | |
219 else: | |
220 self.boxtype=1 | |
221 self.chat.InfoPost("Now using new-style boxes (in middle, with thick borders)") | |
222 self.save_changes() | |
223 | |
224 # reverts all quotebox settings back to default | |
225 def on_box_default(self, cmdargs): | |
226 self.fontcolor = "#000000" | |
227 self.bgcolor="#aaaaaa" | |
228 self.size = 3 | |
229 self.border = 0 | |
230 self.italics = 0 | |
231 self.bold = 1 | |
232 self.boxtype = 1 | |
233 | |
234 self.chat.InfoPost("Quotebox plugin reverted to default settings.") | |
235 self.save_changes() | |
236 | |
237 # loads up quotebox.xml as a node in the gametree | |
238 def on_quotebox(self, cmdargs): | |
239 f = open(orpg.dirpath.dir_struct["plugins"]+ "quotebox.xml","r") | |
240 self.gametree.insert_xml(f.read()) | |
241 f.close() | |
242 return 1 | |
243 |