130
|
1 # Copyright (C) 2000-2001 The OpenRPG Project
|
|
2 #
|
|
3 # openrpg-dev@lists.sourceforge.net
|
|
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 2 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, write to the Free Software
|
|
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
18 # --
|
|
19 #
|
|
20 # File: forms.py
|
|
21 # Author: Chris Davis
|
|
22 # Maintainer:
|
|
23 # Version:
|
|
24 # $Id: forms.py,v 1.53 2007/04/21 23:00:51 digitalxero Exp $
|
|
25 #
|
|
26 # Description: The file contains code for the form based nodehanlers
|
|
27 #
|
|
28
|
|
29 __version__ = "$Id: forms.py,v 1.53 2007/04/21 23:00:51 digitalxero Exp $"
|
|
30
|
|
31 from containers import *
|
|
32 import wx.lib.scrolledpanel
|
|
33
|
|
34 def bool2int(b):
|
|
35 #in wxPython 2.5+, evt.Checked() returns True or False instead of 1.0 or 0.
|
|
36 #by running the results of that through this function, we convert it.
|
|
37 #if it was an int already, nothing changes. The difference between 1.0
|
|
38 #and 1, i.e. between ints and floats, is potentially dangerous when we
|
|
39 #use str() on it, but it seems to work fine right now.
|
|
40 if b:
|
|
41 return 1
|
|
42 else:
|
|
43 return 0
|
|
44
|
|
45 #################################
|
|
46 ## form container
|
|
47 #################################
|
|
48
|
|
49 class form_handler(container_handler):
|
|
50 """
|
|
51 <nodehandler name='?' module='forms' class='form_handler' >
|
|
52 <form width='100' height='100' />
|
|
53 </nodehandler>
|
|
54 """
|
|
55
|
|
56 def __init__(self,xml,tree_node):
|
|
57 container_handler.__init__(self,xml,tree_node)
|
|
58
|
|
59 def load_children(self):
|
|
60 self.atts = None
|
|
61 for child_xml in self.xml:
|
|
62 if child_xml.tag == "form":
|
|
63 self.atts = child_xml
|
|
64 else:
|
|
65 self.tree.load_xml(child_xml,self.mytree_node)
|
|
66 if not self.atts:
|
|
67 self.atts = ET.Element('form')
|
|
68 self.atts.set("width","400")
|
|
69 self.atts.set("height","600")
|
|
70 self.xml.append(self.atts)
|
|
71
|
|
72 def get_design_panel(self,parent):
|
|
73 return form_edit_panel(parent,self)
|
|
74
|
|
75 def get_use_panel(self,parent):
|
|
76 return form_panel(parent,self)
|
|
77
|
|
78 def on_drop(self,evt):
|
|
79 # make sure its a contorl node
|
|
80 container_handler.on_drop(self,evt)
|
|
81
|
|
82
|
|
83 class form_panel(wx.lib.scrolledpanel.ScrolledPanel):
|
|
84 def __init__(self, parent, handler):
|
|
85 wx.lib.scrolledpanel.ScrolledPanel.__init__(self, parent, wx.ID_ANY, style=wx.NO_BORDER|wx.VSCROLL|wx.HSCROLL)
|
|
86 self.height = int(handler.atts.get("height"))
|
|
87 self.width = int(handler.atts.get("width"))
|
|
88
|
|
89
|
|
90 self.SetSize((0,0))
|
|
91 self.handler = handler
|
|
92 self.parent = parent
|
|
93 self.main_sizer = wx.BoxSizer(wx.VERTICAL)
|
|
94 handler.tree.traverse(handler.mytree_node, self.create_child_wnd, None, False)
|
|
95
|
|
96 self.SetSizer(self.main_sizer)
|
|
97 self.SetAutoLayout(True)
|
|
98
|
|
99 self.SetupScrolling()
|
|
100
|
|
101 parent.SetSize(self.GetSize())
|
|
102 self.Fit()
|
|
103
|
|
104
|
|
105 def SetSize(self, xy):
|
|
106 (x, y) = self.GetSize()
|
|
107 (nx, ny) = xy
|
|
108 if x < nx:
|
|
109 x = nx+10
|
|
110 y += ny+11
|
|
111 wx.lib.scrolledpanel.ScrolledPanel.SetSize(self, (x, y))
|
|
112
|
|
113
|
|
114 def create_child_wnd(self, treenode, evt):
|
|
115 node = self.handler.tree.GetPyData(treenode)
|
|
116 panel = node.get_use_panel(self)
|
|
117 size = node.get_size_constraint()
|
|
118 if panel:
|
|
119 self.main_sizer.Add(panel, size, wx.EXPAND)
|
|
120 self.main_sizer.Add(wx.Size(10,10))
|
|
121
|
|
122
|
|
123
|
|
124 F_HEIGHT = wx.NewId()
|
|
125 F_WIDTH = wx.NewId()
|
|
126 class form_edit_panel(wx.Panel):
|
|
127 def __init__(self, parent, handler):
|
|
128 wx.Panel.__init__(self, parent, -1)
|
|
129 self.handler = handler
|
|
130 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Form Properties"), wx.VERTICAL)
|
|
131 wh_sizer = wx.BoxSizer(wx.HORIZONTAL)
|
|
132 self.text = { P_TITLE : wx.TextCtrl(self, P_TITLE, handler.xml.get('name')),
|
|
133 F_HEIGHT : wx.TextCtrl(self, F_HEIGHT, handler.atts.get('height')),
|
|
134 F_WIDTH : wx.TextCtrl(self, F_WIDTH, handler.atts.get('width'))
|
|
135 }
|
|
136
|
|
137 wh_sizer.Add(wx.StaticText(self, -1, "Width:"), 0, wx.ALIGN_CENTER)
|
|
138 wh_sizer.Add(wx.Size(10,10))
|
|
139 wh_sizer.Add(self.text[F_WIDTH], 0, wx.EXPAND)
|
|
140 wh_sizer.Add(wx.Size(10,10))
|
|
141 wh_sizer.Add(wx.StaticText(self, -1, "Height:"), 0, wx.ALIGN_CENTER)
|
|
142 wh_sizer.Add(wx.Size(10,10))
|
|
143 wh_sizer.Add(self.text[F_HEIGHT], 0, wx.EXPAND)
|
|
144
|
|
145 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND)
|
|
146 sizer.Add(self.text[P_TITLE], 0, wx.EXPAND)
|
|
147 sizer.Add(wx.Size(10,10))
|
|
148 sizer.Add(wh_sizer,0,wx.EXPAND)
|
|
149
|
|
150 self.SetSizer(sizer)
|
|
151 self.SetAutoLayout(True)
|
|
152 self.Fit()
|
|
153 parent.SetSize(self.GetBestSize())
|
|
154
|
|
155 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE)
|
|
156 self.Bind(wx.EVT_TEXT, self.on_text, id=F_HEIGHT)
|
|
157 self.Bind(wx.EVT_TEXT, self.on_text, id=F_WIDTH)
|
|
158
|
|
159 def on_text(self,evt):
|
|
160 id = evt.GetId()
|
|
161 txt = self.text[id].GetValue()
|
|
162 if not len(txt): return
|
|
163 if id == P_TITLE:
|
|
164 self.handler.xml.set('name',txt)
|
|
165 self.handler.rename(txt)
|
|
166 elif id == F_HEIGHT or id == F_WIDTH:
|
|
167 try:
|
|
168 int(txt)
|
|
169 except:
|
|
170 return 0
|
|
171 if id == F_HEIGHT:
|
|
172 self.handler.atts.set("height",txt)
|
|
173 elif id == F_WIDTH:
|
|
174 self.handler.atts.set("width",txt)
|
|
175
|
|
176
|
|
177
|
|
178
|
|
179
|
|
180 ##########################
|
|
181 ## control handler
|
|
182 ##########################
|
|
183 class control_handler(node_handler):
|
|
184 """ A nodehandler for form controls.
|
|
185 <nodehandler name='?' module='forms' class='control_handler' />
|
|
186 """
|
|
187 def __init__(self,xml,tree_node):
|
|
188 node_handler.__init__(self,xml,tree_node)
|
|
189
|
|
190 def get_size_constraint(self):
|
|
191 return 0
|
|
192
|
|
193
|
|
194 ##########################
|
|
195 ## textctrl handler
|
|
196 ##########################
|
|
197 #
|
|
198 # Updated by Snowdog (April 2003)
|
|
199 # Now includes Raw Send Mode (like the chat macro uses)
|
|
200 # and an option to remove the title from text when sent
|
|
201 # to the chat in the normal non-chat macro mode.
|
|
202 #
|
|
203 class textctrl_handler(node_handler):
|
|
204 """ <nodehandler class="textctrl_handler" module="form" name="">
|
|
205 <text multiline='0' send_button='0' raw_mode='0' hide_title='0'>Text In Node</text>
|
|
206 </nodehandler>
|
|
207 """
|
|
208 def __init__(self,xml,tree_node):
|
|
209 node_handler.__init__(self,xml,tree_node)
|
|
210 self.text_elem = self.xml.find('text')
|
|
211 if self.text_elem.get("send_button") == "":
|
|
212 self.text_elem.set("send_button","0")
|
|
213 if self.text_elem.get("raw_mode") == "":
|
|
214 self.text_elem.set("raw_mode","0")
|
|
215 if self.text_elem.get("hide_title") == "":
|
|
216 self.text_elem.set("hide_title","0")
|
|
217
|
|
218 def get_design_panel(self,parent):
|
|
219 return textctrl_edit_panel(parent,self)
|
|
220
|
|
221 def get_use_panel(self,parent):
|
|
222 return text_panel(parent,self)
|
|
223
|
|
224 def get_size_constraint(self):
|
|
225 return int(self.text_elem.get("multiline",0))
|
|
226
|
|
227 def is_multi_line(self):
|
|
228 return int(self.text_elem.get("multiline",0))
|
|
229
|
|
230 def is_raw_send(self):
|
|
231 return int(self.text_elem.get("raw_mode",0))
|
|
232
|
|
233 def is_hide_title(self):
|
|
234 return int(self.text_elem.get("hide_title",0))
|
|
235
|
|
236 def has_send_button(self):
|
|
237 return int(self.text_elem.get("send_button",0))
|
|
238
|
|
239 def tohtml(self):
|
|
240 txt = self.get_value()
|
|
241 txt = string.replace(txt,'\n',"<br />")
|
|
242 if not self.is_hide_title():
|
|
243 txt = "<b>"+self.xml.get("name")+":</b> "+txt
|
|
244 return txt
|
|
245
|
|
246 def get_value(self):
|
|
247 return getText(self.text_elem)
|
|
248
|
|
249 def set_value(self, new_value):
|
|
250 self.text_elem.text = str(new_value)
|
|
251
|
|
252
|
|
253
|
|
254 FORM_TEXT_CTRL = wx.NewId()
|
|
255 FORM_SEND_BUTTON = wx.NewId()
|
|
256
|
|
257 class text_panel(wx.Panel):
|
|
258 def __init__(self, parent, handler):
|
|
259 wx.Panel.__init__(self, parent, -1)
|
|
260 self.chat = handler.chat
|
|
261 self.handler = handler
|
|
262 if handler.is_multi_line():
|
|
263 text_style = wx.TE_MULTILINE
|
|
264 sizer_style = wx.EXPAND
|
|
265 sizer = wx.BoxSizer(wx.VERTICAL)
|
|
266 else:
|
|
267 sizer_style = wx.ALIGN_CENTER
|
|
268 text_style = 0
|
|
269 sizer = wx.BoxSizer(wx.HORIZONTAL)
|
|
270
|
|
271 txt = handler.get_value()
|
|
272 ## if self.handler.tree.ContainsReference(txt):
|
|
273 ## txt = self.handler.tree.ReplaceReferences(txt, False)
|
|
274 ## text_style |= wx.TE_READONLY
|
|
275
|
|
276 self.text = wx.TextCtrl(self, FORM_TEXT_CTRL, txt, style=text_style)
|
|
277 sizer.Add(wx.StaticText(self, -1, handler.xml.get('name')+": "), 0, sizer_style)
|
|
278 sizer.Add(wx.Size(5,0))
|
|
279 sizer.Add(self.text, 1, sizer_style)
|
|
280
|
|
281 if handler.has_send_button():
|
|
282 sizer.Add(wx.Button(self, FORM_SEND_BUTTON, "Send"), 0, sizer_style)
|
|
283
|
|
284 self.sizer = sizer
|
|
285 self.SetSizer(sizer)
|
|
286 self.SetAutoLayout(True)
|
|
287
|
|
288 parent.SetSize(self.GetBestSize())
|
|
289 self.Bind(wx.EVT_TEXT, self.on_text, id=FORM_TEXT_CTRL)
|
|
290 self.Bind(wx.EVT_BUTTON, self.on_send, id=FORM_SEND_BUTTON)
|
|
291
|
|
292 def on_text(self,evt):
|
|
293 txt = self.text.GetValue()
|
|
294 txt = strip_text(txt)
|
|
295 self.handler.text_elem.text = txt
|
|
296
|
|
297 def on_send(self,evt):
|
|
298 txt = self.text.GetValue()
|
|
299 if not self.handler.is_raw_send():
|
|
300 #self.chat.ParsePost(self.tohtml(),True,True)
|
|
301 self.chat.ParsePost(self.handler.tohtml(),True,True)
|
|
302 return 1
|
|
303 actionlist = txt.split("\n")
|
|
304 for line in actionlist:
|
|
305 if(line != ""):
|
|
306 if line[0] != "/": ## it's not a slash command
|
|
307 self.chat.ParsePost(line,True,True)
|
|
308 else:
|
|
309 action = line
|
|
310 self.chat.chat_cmds.docmd(action)
|
|
311 return 1
|
|
312
|
|
313 F_MULTI = wx.NewId()
|
|
314 F_SEND_BUTTON = wx.NewId()
|
|
315 F_RAW_SEND = wx.NewId()
|
|
316 F_HIDE_TITLE = wx.NewId()
|
|
317 F_TEXT = wx.NewId()
|
|
318
|
|
319 class textctrl_edit_panel(wx.Panel):
|
|
320 def __init__(self, parent, handler):
|
|
321 wx.Panel.__init__(self, parent, -1)
|
|
322 self.handler = handler
|
|
323 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Text Properties"), wx.VERTICAL)
|
|
324
|
|
325 self.title = wx.TextCtrl(self, P_TITLE, handler.xml.get('name'))
|
|
326 self.multi = wx.CheckBox(self, F_MULTI, " Multi-Line")
|
|
327 self.multi.SetValue(handler.is_multi_line())
|
|
328 self.raw_send = wx.CheckBox(self, F_RAW_SEND, " Send as Macro")
|
|
329 self.raw_send.SetValue(handler.is_raw_send())
|
|
330 self.hide_title = wx.CheckBox(self, F_HIDE_TITLE, " Hide Title")
|
|
331 self.hide_title.SetValue(handler.is_hide_title())
|
|
332 self.send_button = wx.CheckBox(self, F_SEND_BUTTON, " Send Button")
|
|
333 self.send_button.SetValue(handler.has_send_button())
|
|
334
|
|
335 sizer.Add(wx.StaticText(self, P_TITLE, "Title:"), 0, wx.EXPAND)
|
|
336 sizer.Add(self.title, 0, wx.EXPAND)
|
|
337 sizer.Add(wx.Size(10,10))
|
|
338 sizer.Add(self.multi, 0, wx.EXPAND)
|
|
339 sizer.Add(self.raw_send, 0, wx.EXPAND)
|
|
340 sizer.Add(self.hide_title, 0, wx.EXPAND)
|
|
341 sizer.Add(self.send_button, 0 , wx.EXPAND)
|
|
342 sizer.Add(wx.Size(10,10))
|
|
343 if handler.is_multi_line():
|
|
344 sizer_style = wx.EXPAND
|
|
345 text_style = wx.TE_MULTILINE
|
|
346 multi = 1
|
|
347 else:
|
|
348 sizer_style=wx.EXPAND
|
|
349 text_style = 0
|
|
350 multi = 0
|
|
351 self.text = wx.TextCtrl(self, F_TEXT, handler.get_value(),style=text_style)
|
|
352 sizer.Add(wx.Size(5,0))
|
|
353 sizer.Add(self.text, multi, sizer_style)
|
|
354 self.SetSizer(sizer)
|
|
355 self.SetAutoLayout(True)
|
|
356
|
|
357 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE)
|
|
358 self.Bind(wx.EVT_TEXT, self.on_text, id=F_TEXT)
|
|
359 self.Bind(wx.EVT_CHECKBOX, self.on_button, id=F_MULTI)
|
|
360 self.Bind(wx.EVT_CHECKBOX, self.on_raw_button, id=F_RAW_SEND)
|
|
361 self.Bind(wx.EVT_CHECKBOX, self.on_hide_button, id=F_HIDE_TITLE)
|
|
362 self.Bind(wx.EVT_CHECKBOX, self.on_send_button, id=F_SEND_BUTTON)
|
|
363
|
|
364 def on_text(self,evt):
|
|
365 id = evt.GetId()
|
|
366 if id == P_TITLE:
|
|
367 txt = self.title.GetValue()
|
|
368 if not len(txt): return
|
|
369 self.handler.xml.set('name',txt)
|
|
370 self.handler.rename(txt)
|
|
371 if id == F_TEXT:
|
|
372 txt = self.text.GetValue()
|
|
373 txt = strip_text(txt)
|
|
374 self.handler.text_elem.text = txt
|
|
375
|
|
376 def on_button(self,evt):
|
|
377 self.handler.text_elem.set("multiline",str(bool2int(evt.Checked())))
|
|
378
|
|
379 def on_raw_button(self,evt):
|
|
380 self.handler.text_elem.set("raw_mode",str(bool2int(evt.Checked())))
|
|
381
|
|
382 def on_hide_button(self,evt):
|
|
383 self.handler.text_elem.set("hide_title",str(bool2int(evt.Checked())))
|
|
384
|
|
385 def on_send_button(self,evt):
|
|
386 self.handler.text_elem.set("send_button",str(bool2int(evt.Checked())))
|
|
387
|
|
388
|
|
389 #######################
|
|
390 ## listbox handler
|
|
391 #######################
|
|
392 #
|
|
393 # Updated by Snowdog (April 2003)
|
|
394 # Now includesan option to remove the title from
|
|
395 # text when sent to the chat.
|
|
396 #
|
|
397 L_DROP = 0
|
|
398 L_LIST = 1
|
|
399 L_RADIO = 2
|
|
400 L_CHECK = 3
|
|
401 L_ROLLER = 4
|
|
402
|
|
403 class listbox_handler(node_handler):
|
|
404 """
|
|
405 <nodehandler class="listbox_handler" module="forms" name="">
|
|
406 <list type="1" send_button='0' hide_title='0'>
|
|
407 <option value="" selected="" >Option Text I</option>
|
|
408 <option value="" selected="" >Option Text II</option>
|
|
409 </list>
|
|
410 </nodehandler>
|
|
411 """
|
|
412 def __init__(self,xml,tree_node):
|
|
413 node_handler.__init__(self,xml,tree_node)
|
|
414 self.list = self.xml.find('list')
|
|
415 self.options = self.list.findall('option')
|
|
416 if self.list.get("send_button") == "":
|
|
417 self.list.set("send_button","0")
|
|
418 if self.list.get("hide_title") == "":
|
|
419 self.list.set("hide_title","0")
|
|
420
|
|
421 def get_design_panel(self,parent):
|
|
422 return listbox_edit_panel(parent,self)
|
|
423
|
|
424 def get_use_panel(self,parent):
|
|
425 return listbox_panel(parent,self)
|
|
426
|
|
427 def get_type(self):
|
|
428 return int(self.list.get("type"))
|
|
429
|
|
430 def set_type(self,type):
|
|
431 self.list.set("type",str(type))
|
|
432
|
|
433 def is_hide_title(self):
|
|
434 return int(self.list.get("hide_title",0))
|
|
435
|
|
436 # single selection methods
|
|
437 def get_selected_node(self):
|
|
438 for opt in self.options:
|
|
439 if opt.get("selected") == "1": return opt
|
|
440 return None
|
|
441
|
|
442 def get_selected_index(self):
|
|
443 i = 0
|
|
444 for opt in self.options:
|
|
445 if opt.get("selected") == "1":
|
|
446 return i
|
|
447 i += 1
|
|
448 return 0
|
|
449
|
|
450 def get_selected_text(self):
|
|
451 node = self.get_selected_node()
|
|
452 if node:
|
|
453 return getText(node)
|
|
454 else:
|
|
455 return ""
|
|
456
|
|
457
|
|
458 # mult selection methods
|
|
459
|
|
460 def get_selections(self):
|
|
461 opts = []
|
|
462 for opt in self.options:
|
|
463 if opt.get("selected") == "1":
|
|
464 opts.append(opt)
|
|
465 return opts
|
|
466
|
|
467 def get_selections_text(self):
|
|
468 opts = []
|
|
469 for opt in self.options:
|
|
470 if opt.get("selected") == "1":
|
|
471 opts.append(getText(opt))
|
|
472 return opts
|
|
473
|
|
474 def get_selections_index(self):
|
|
475 opts = []
|
|
476 i = 0
|
|
477 for opt in self.options:
|
|
478 if opt.get("selected") == "1":
|
|
479 opts.append(i)
|
|
480 i += 1
|
|
481 return opts
|
|
482
|
|
483 # setting selection method
|
|
484
|
|
485 def set_selected_node(self,index,selected=1):
|
|
486 if self.get_type() != L_CHECK:
|
|
487 self.clear_selections()
|
|
488 self.options[index].set("selected", str(bool2int(selected)))
|
|
489
|
|
490 def clear_selections(self):
|
|
491 for opt in self.options:
|
|
492 opt.set("selected","0")
|
|
493
|
|
494 # misc methods
|
|
495
|
|
496 def get_options(self):
|
|
497 opts = []
|
|
498 for opt in self.options:
|
|
499 opts.append(getText(opt))
|
|
500 return opts
|
|
501
|
|
502 def get_option(self,index):
|
|
503 return getText(self.options[index])
|
|
504
|
|
505 def add_option(self,opt):
|
|
506 elem = ET.Element('option')
|
|
507 elem.set("value","0")
|
|
508 elem.set("selected","0")
|
|
509 elem.text = opt
|
|
510 self.list.append(elem)
|
|
511 self.options = self.list.findall('option')
|
|
512
|
|
513 def remove_option(self,index):
|
|
514 self.list.remove(self.options[index])
|
|
515 self.options = self.list.findall('option')
|
|
516
|
|
517 def edit_option(self,index,value):
|
|
518 self.options[index].text = value
|
|
519
|
|
520 def has_send_button(self):
|
|
521 if self.list.get("send_button") == '0':
|
|
522 return False
|
|
523 else:
|
|
524 return True
|
|
525
|
|
526 def get_size_constraint(self):
|
|
527 if self.get_type() == L_DROP:
|
|
528 return 0
|
|
529 else:
|
|
530 return 1
|
|
531
|
|
532 def tohtml(self):
|
|
533 opts = self.get_selections_text()
|
|
534 text = ""
|
|
535 if not self.is_hide_title():
|
|
536 text = "<b>"+self.xml.get("name")+":</b> "
|
|
537 comma = ", "
|
|
538 text += comma.join(opts)
|
|
539 return text
|
|
540
|
|
541 def get_value(self):
|
|
542 return "\n".join(self.get_selections_text())
|
|
543
|
|
544 F_LIST = wx.NewId()
|
|
545 F_SEND = wx.NewId()
|
|
546
|
|
547
|
|
548 class listbox_panel(wx.Panel):
|
|
549 def __init__(self, parent, handler):
|
|
550 wx.Panel.__init__(self, parent, -1)
|
|
551 self.handler = handler
|
|
552 self.chat = handler.chat
|
|
553 opts = handler.get_options()
|
|
554 cur_opt = handler.get_selected_text()
|
|
555 type = handler.get_type()
|
|
556 label = handler.xml.get('name')
|
|
557
|
|
558 if type == L_DROP:
|
|
559 self.list = wx.ComboBox(self, F_LIST, cur_opt, choices=opts, style=wx.CB_READONLY)
|
|
560 if self.list.GetSize()[0] > 200:
|
|
561 self.list.Destroy()
|
|
562 self.list = wx.ComboBox(self, F_LIST, cur_opt, size=(200, -1), choices=opts, style=wx.CB_READONLY)
|
|
563 elif type == L_LIST:
|
|
564 self.list = wx.ListBox(self,F_LIST,choices=opts)
|
|
565 elif type == L_RADIO:
|
|
566 self.list = wx.RadioBox(self,F_LIST,label,choices=opts,majorDimension=3)
|
|
567 elif type == L_CHECK:
|
|
568 self.list = wx.CheckListBox(self,F_LIST,choices=opts)
|
|
569 self.set_checks()
|
|
570
|
|
571 for i in handler.get_selections_text():
|
|
572 if type == L_DROP:
|
|
573 self.list.SetValue( i )
|
|
574 else:
|
|
575 self.list.SetStringSelection( i )
|
|
576
|
|
577 if type == L_DROP:
|
|
578 sizer = wx.BoxSizer(wx.HORIZONTAL)
|
|
579
|
|
580 else:
|
|
581 sizer = wx.BoxSizer(wx.VERTICAL)
|
|
582
|
|
583 if type != L_RADIO:
|
|
584 sizer.Add(wx.StaticText(self, -1, label+": "), 0, wx.EXPAND)
|
|
585 sizer.Add(wx.Size(5,0))
|
|
586
|
|
587 sizer.Add(self.list, 1, wx.EXPAND)
|
|
588
|
|
589 if handler.has_send_button():
|
|
590 sizer.Add(wx.Button(self, F_SEND, "Send"), 0, wx.EXPAND)
|
|
591 self.Bind(wx.EVT_BUTTON, self.handler.on_send_to_chat, id=F_SEND)
|
|
592
|
|
593 self.sizer = sizer
|
|
594 self.SetSizer(sizer)
|
|
595 self.SetAutoLayout(True)
|
|
596 self.Fit()
|
|
597
|
|
598 parent.SetSize(self.GetBestSize())
|
|
599
|
|
600 if type == L_DROP:
|
|
601 self.Bind(wx.EVT_COMBOBOX, self.on_change, id=F_LIST)
|
|
602 elif type == L_LIST:
|
|
603 self.Bind(wx.EVT_LISTBOX, self.on_change, id=F_LIST)
|
|
604 elif type == L_RADIO:
|
|
605 self.Bind(wx.EVT_RADIOBOX, self.on_change, id=F_LIST)
|
|
606 elif type == L_CHECK:
|
|
607 self.Bind(wx.EVT_CHECKLISTBOX, self.on_check, id=F_LIST)
|
|
608
|
|
609
|
|
610 self.type = type
|
|
611
|
|
612
|
|
613 def on_change(self,evt):
|
|
614 self.handler.set_selected_node(self.list.GetSelection())
|
|
615
|
|
616 def on_check(self,evt):
|
|
617 for i in xrange(self.list.GetCount()):
|
|
618 self.handler.set_selected_node(i, bool2int(self.list.IsChecked(i)))
|
|
619
|
|
620 def set_checks(self):
|
|
621 for i in self.handler.get_selections_index():
|
|
622 self.list.Check(i)
|
|
623
|
|
624
|
|
625
|
|
626 BUT_ADD = wx.NewId()
|
|
627 BUT_REM = wx.NewId()
|
|
628 BUT_EDIT = wx.NewId()
|
|
629 F_TYPE = wx.NewId()
|
|
630 F_NO_TITLE = wx.NewId()
|
|
631
|
|
632 class listbox_edit_panel(wx.Panel):
|
|
633 def __init__(self, parent, handler):
|
|
634 wx.Panel.__init__(self, parent, -1)
|
|
635 self.handler = handler
|
|
636 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "List Box Properties"), wx.VERTICAL)
|
|
637
|
|
638 self.text = wx.TextCtrl(self, P_TITLE, handler.xml.get('name'))
|
|
639
|
|
640 opts = handler.get_options()
|
|
641 self.listbox = wx.ListBox(self, F_LIST, choices=opts, style=wx.LB_HSCROLL|wx.LB_SINGLE|wx.LB_NEEDED_SB)
|
|
642 opts = ['Drop Down', 'List Box', 'Radio Box', 'Check List']
|
|
643 self.type_radios = wx.RadioBox(self,F_TYPE,"List Type",choices=opts)
|
|
644 self.type_radios.SetSelection(handler.get_type())
|
|
645
|
|
646 self.send_button = wx.CheckBox(self, F_SEND_BUTTON, " Send Button")
|
|
647 self.send_button.SetValue(handler.has_send_button())
|
|
648
|
|
649 self.hide_title = wx.CheckBox(self, F_NO_TITLE, " Hide Title")
|
|
650 self.hide_title.SetValue(handler.is_hide_title())
|
|
651
|
|
652 but_sizer = wx.BoxSizer(wx.HORIZONTAL)
|
|
653 but_sizer.Add(wx.Button(self, BUT_ADD, "Add"), 1, wx.EXPAND)
|
|
654 but_sizer.Add(wx.Size(10,10))
|
|
655 but_sizer.Add(wx.Button(self, BUT_EDIT, "Edit"), 1, wx.EXPAND)
|
|
656 but_sizer.Add(wx.Size(10,10))
|
|
657 but_sizer.Add(wx.Button(self, BUT_REM, "Remove"), 1, wx.EXPAND)
|
|
658
|
|
659 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND)
|
|
660 sizer.Add(self.text, 0, wx.EXPAND)
|
|
661 sizer.Add(wx.Size(10,10))
|
|
662 sizer.Add(self.type_radios, 0, wx.EXPAND)
|
|
663 sizer.Add(wx.Size(10,10))
|
|
664 sizer.Add(self.send_button, 0 , wx.EXPAND)
|
|
665 sizer.Add(self.hide_title, 0, wx.EXPAND)
|
|
666 sizer.Add(wx.Size(10,10))
|
|
667 sizer.Add(wx.StaticText(self, -1, "Options:"), 0, wx.EXPAND)
|
|
668 sizer.Add(self.listbox,1,wx.EXPAND);
|
|
669 sizer.Add(but_sizer,0,wx.EXPAND)
|
|
670
|
|
671 self.SetSizer(sizer)
|
|
672 self.SetAutoLayout(True)
|
|
673 self.Fit()
|
|
674 parent.SetSize(self.GetBestSize())
|
|
675
|
|
676 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE)
|
|
677 self.Bind(wx.EVT_BUTTON, self.on_edit, id=BUT_EDIT)
|
|
678 self.Bind(wx.EVT_BUTTON, self.on_remove, id=BUT_REM)
|
|
679 self.Bind(wx.EVT_BUTTON, self.on_add, id=BUT_ADD)
|
|
680 self.Bind(wx.EVT_RADIOBOX, self.on_type, id=F_TYPE)
|
|
681 self.Bind(wx.EVT_CHECKBOX, self.on_hide_button, id=F_NO_TITLE)
|
|
682 self.Bind(wx.EVT_CHECKBOX, self.on_send_button, id=F_SEND_BUTTON)
|
|
683
|
|
684 def on_type(self,evt):
|
|
685 self.handler.set_type(evt.GetInt())
|
|
686
|
|
687 def on_add(self,evt):
|
|
688 dlg = wx.TextEntryDialog(self, 'Enter option?','Add Option', '')
|
|
689 if dlg.ShowModal() == wx.ID_OK:
|
|
690 self.handler.add_option(dlg.GetValue())
|
|
691 dlg.Destroy()
|
|
692 self.reload_options()
|
|
693
|
|
694 def on_remove(self,evt):
|
|
695 index = self.listbox.GetSelection()
|
|
696 if index >= 0:
|
|
697 self.handler.remove_option(index)
|
|
698 self.reload_options()
|
|
699
|
|
700 def on_edit(self,evt):
|
|
701 index = self.listbox.GetSelection()
|
|
702 if index >= 0:
|
|
703 txt = self.handler.get_option(index)
|
|
704 dlg = wx.TextEntryDialog(self, 'Enter option?','Edit Option', txt)
|
|
705 if dlg.ShowModal() == wx.ID_OK:
|
|
706 self.handler.edit_option(index,dlg.GetValue())
|
|
707 dlg.Destroy()
|
|
708 self.reload_options()
|
|
709
|
|
710 def reload_options(self):
|
|
711 self.listbox.Clear()
|
|
712 for opt in self.handler.get_options():
|
|
713 self.listbox.Append(opt)
|
|
714
|
|
715 def on_text(self,evt):
|
|
716 id = evt.GetId()
|
|
717 txt = self.text.GetValue()
|
|
718 if not len(txt): return
|
|
719 if id == P_TITLE:
|
|
720 self.handler.xml.set('name',txt)
|
|
721 self.handler.rename(txt)
|
|
722
|
|
723 def on_send_button(self,evt):
|
|
724 self.handler.list.set("send_button", str( bool2int(evt.Checked()) ))
|
|
725
|
|
726 def on_hide_button(self,evt):
|
|
727 self.handler.list.set("hide_title", str( bool2int(evt.Checked()) ))
|
|
728
|
|
729
|
|
730 ###############################
|
|
731 ## link image handlers
|
|
732 ###############################
|
|
733
|
|
734 class link_handler(node_handler):
|
|
735 """ A nodehandler for URLs. Will open URL in a wxHTMLFrame
|
|
736 <nodehandler name='?' module='forms' class='link_handler' >
|
|
737 <link href='http//??.??' />
|
|
738 </nodehandler >
|
|
739 """
|
|
740 def __init__(self,xml,tree_node):
|
|
741 node_handler.__init__(self,xml,tree_node)
|
|
742 self.link = self.xml[0]
|
|
743
|
|
744 def on_use(self,evt):
|
|
745 href = self.link.get("href")
|
|
746 wb = webbrowser.get()
|
|
747 wb.open(href)
|
|
748
|
|
749 def get_design_panel(self,parent):
|
|
750 return link_edit_panel(parent,self)
|
|
751
|
|
752 def get_use_panel(self,parent):
|
|
753 return link_panel(parent,self)
|
|
754
|
|
755 def tohtml(self):
|
|
756 href = self.link.get("href")
|
|
757 title = self.xml.get("name")
|
|
758 return "<a href=\""+href+"\" >"+title+"</a>"
|
|
759
|
|
760 class link_panel(wx.StaticText):
|
|
761 def __init__(self,parent,handler):
|
|
762 self.handler = handler
|
|
763 label = handler.xml.get('name')
|
|
764 wx.StaticText.__init__(self,parent,-1,label)
|
|
765 self.SetForegroundColour(wx.BLUE)
|
|
766 self.Bind(wx.EVT_LEFT_DOWN, self.handler.on_use)
|
|
767
|
|
768
|
|
769 P_URL = wx.NewId()
|
|
770
|
|
771 class link_edit_panel(wx.Panel):
|
|
772 def __init__(self, parent, handler):
|
|
773 wx.Panel.__init__(self, parent, -1)
|
|
774 self.handler = handler
|
|
775 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Link Properties"), wx.VERTICAL)
|
|
776
|
|
777 self.text = {}
|
|
778 self.text[P_TITLE] = wx.TextCtrl(self, P_TITLE, handler.xml.get('name'))
|
|
779 self.text[P_URL] = wx.TextCtrl(self, P_URL, handler.link.get('href'))
|
|
780
|
|
781 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND)
|
|
782 sizer.Add(self.text[P_TITLE], 0, wx.EXPAND)
|
|
783 sizer.Add(wx.Size(10,10))
|
|
784 sizer.Add(wx.StaticText(self, -1, "URL:"), 0, wx.EXPAND)
|
|
785 sizer.Add(self.text[P_URL], 0, wx.EXPAND)
|
|
786 self.SetSizer(sizer)
|
|
787 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE)
|
|
788 self.Bind(wx.EVT_TEXT, self.on_text, id=P_URL)
|
|
789
|
|
790 def on_text(self,evt):
|
|
791 id = evt.GetId()
|
|
792 txt = self.text[id].GetValue()
|
|
793 if not len(txt): return
|
|
794 if id == P_TITLE:
|
|
795 self.handler.xml.set('name',txt)
|
|
796 self.handler.rename(txt)
|
|
797 elif id == P_URL:
|
|
798 self.handler.link.set('href',txt)
|
|
799
|
|
800 ##########################
|
|
801 ## webimg node handler
|
|
802 ##########################
|
|
803 class webimg_handler(node_handler):
|
|
804 """ A nodehandler for URLs. Will open URL in a wxHTMLFrame
|
|
805 <nodehandler name='?' module='forms' class='webimg_handler' >
|
|
806 <link href='http//??.??' />
|
|
807 </nodehandler >
|
|
808 """
|
|
809 def __init__(self,xml,tree_node):
|
|
810 node_handler.__init__(self,xml,tree_node)
|
|
811 self.link = self.xml[0]
|
|
812
|
|
813 def get_design_panel(self,parent):
|
|
814 return link_edit_panel(parent,self)
|
|
815
|
|
816 def get_use_panel(self,parent):
|
|
817 img = img_helper().load_url(self.link.get("href"))
|
|
818 if not img is None:
|
|
819 return wx.StaticBitmap(parent,-1,img,size= wx.Size(img.GetWidth(),img.GetHeight()))
|
|
820 return wx.EmptyBitmap(1, 1)
|
|
821
|
|
822 def tohtml(self):
|
|
823 href = self.link.get("href")
|
|
824 title = self.xml.get("name")
|
|
825 return "<img src=\""+href+"\" alt="+title+" >"
|
|
826
|
|
827
|
|
828
|
|
829 #######################
|
|
830 ## resource handler
|
|
831 #######################
|
|
832
|
|
833 class resource_handler(node_handler):
|
|
834 """
|
|
835 <nodehandler class="resource_handler" module="forms" name="">
|
|
836 <resource base="5" current="4" checks="1">Multi-line macro</resource>
|
|
837 </nodehandler>
|
|
838 """
|
|
839 def __init__(self,xml,tree_node):
|
|
840 node_handler.__init__(self,xml,tree_node)
|
|
841 self.resource = self.xml.find('resource')
|
|
842 if self.resource.get("checks") == "":
|
|
843 self.resource.set("checks","1")
|
|
844 if self.resource.get("base") == "":
|
|
845 self.resource.set("base","1")
|
|
846 if self.resource.get("current") == "":
|
|
847 self.resource.set("current", self.resource.get("base"))
|
|
848
|
|
849 def get_design_panel(self,parent):
|
|
850 return resource_edit_panel(parent,self)
|
|
851
|
|
852 def get_use_panel(self,parent):
|
|
853 return resource_panel(parent,self)
|
|
854
|
|
855 def tohtml(self):
|
|
856 # decrement the current value or post a "nothing left" message
|
|
857 # print the multi-line macro
|
|
858 return "resource"
|
|
859
|
|
860 def use_checks(self):
|
|
861 if self.resource.get("checks") == "1":
|
|
862 return True
|
|
863 return False
|
|
864
|
|
865 def get_base(self):
|
|
866 return int(self.resource.get("base",0))
|
|
867
|
|
868 def get_current(self):
|
|
869 return int(self.resource.get("current",0))
|
|
870
|
|
871 def get_macro(self):
|
|
872 return getText(self.resource)
|
|
873
|
|
874 def get_value(self):
|
|
875 return self.resource.get("current")
|
|
876
|
|
877 def set_value(self, new_value):
|
|
878 self.resource.set("current", new_value)
|
|
879
|
|
880
|
|
881 RESOURCE_RESET = wx.NewId()
|
|
882 RESOURCE_CHECKS = wx.NewId()
|
|
883 RESOURCE_NUMBER = wx.NewId()
|
|
884 RESOURCE_DONE = wx.NewId()
|
|
885
|
|
886
|
|
887 class resource_panel(wx.Panel):
|
|
888 def __init__(self, parent, handler):
|
|
889 wx.Panel.__init__(self, parent, -1)
|
|
890 self.handler = handler
|
|
891 self.chat = handler.chat
|
|
892
|
|
893 sizer = wx.BoxSizer(wx.HORIZONTAL)
|
|
894 # sizer.Add(wx.Button(self, RESOURCE_RESET, "Reset"))
|
|
895 sizer.Add(wx.StaticText(self, -1, handler.xml.get('name')+": "), 1, wx.ALIGN_RIGHT)
|
|
896 if self.handler.use_checks():
|
|
897 grid = wx.GridSizer(1, 11, 0, 0)
|
|
898 sizer.Add(grid, 0, wx.ALIGN_RIGHT)
|
|
899 self.checks = []
|
|
900 used = self.handler.get_base() - self.handler.get_current()
|
|
901 for i in range(self.handler.get_base()):
|
|
902 self.checks.append(wx.CheckBox(self, RESOURCE_CHECKS, ""))
|
|
903 checked = False
|
|
904 if i < used:
|
|
905 checked = True
|
|
906 self.checks[i].SetValue(checked)
|
|
907 grid.Add(self.checks[i])
|
|
908 if i-int(i/10)*10==4:
|
|
909 grid.Add(wx.Size(1,1))
|
|
910 else:
|
|
911 self.number = wx.TextCtrl(self, RESOURCE_NUMBER, self.handler.resource.get("current"))
|
|
912 sizer.Add(self.number, 0, wx.ALIGN_RIGHT)
|
|
913 sizer.Add(wx.Size(10,10), 0, wx.ALIGN_RIGHT)
|
|
914 sizer.Add(wx.Button(self, RESOURCE_DONE, "Apply"), 0, wx.ALIGN_RIGHT)
|
|
915 # self.chat.InfoPost("res 10")
|
|
916 sizer.SetMinSize(wx.Size(380,10))
|
|
917 self.sizer = sizer
|
|
918 self.SetSizer(sizer)
|
|
919 self.SetAutoLayout(True)
|
|
920 self.Fit()
|
|
921 # self.chat.InfoPost("res 20")
|
|
922 self.Bind(wx.EVT_BUTTON, self.on_reset, id=RESOURCE_RESET)
|
|
923 self.Bind(wx.EVT_BUTTON, self.on_done, id=RESOURCE_DONE)
|
|
924
|
|
925
|
|
926 def on_reset(self,evt):
|
|
927 # uncheck all the check boxes or set the text to max
|
|
928 if self.handler.use_checks():
|
|
929 for c in self.checks:
|
|
930 c.SetValue(False)
|
|
931 else:
|
|
932 self.number.SetValue(self.handler.resource.get("base"))
|
|
933 self.handler.resource.set("current", self.handler.resource.get("base"))
|
|
934
|
|
935 def on_done(self,evt):
|
|
936 # save the changes back to the handler
|
|
937 current = 0
|
|
938 if self.handler.use_checks():
|
|
939 for c in self.checks:
|
|
940 if not c.GetValue():
|
|
941 current += 1
|
|
942 else:
|
|
943 # validate text
|
|
944 current = int(self.number.GetValue())
|
|
945 change = self.handler.get_current()-current
|
|
946 if change > 0:
|
|
947 macro_text = self.handler.get_macro()
|
|
948 macro_text = macro_text.replace("_NAME_",self.handler.xml.get("name"))
|
|
949 macro_text = macro_text.replace("_CHANGE_", str(change))
|
|
950 macro_text = macro_text.replace("_CURRENT_", str(current))
|
|
951 self.handler.chat.ParsePost(macro_text, True, True)
|
|
952 self.handler.resource.set("current",str(current))
|
|
953
|
|
954
|
|
955 RES_EDIT_TITLE = wx.NewId()
|
|
956 RES_EDIT_BASE = wx.NewId()
|
|
957 RES_EDIT_CURRENT = wx.NewId()
|
|
958 RES_EDIT_CHECKS = wx.NewId()
|
|
959 RES_EDIT_MACRO = wx.NewId()
|
|
960
|
|
961
|
|
962 class resource_edit_panel(wx.Panel):
|
|
963 def __init__(self, parent, handler):
|
|
964 wx.Panel.__init__(self, parent, -1)
|
|
965 self.handler = handler
|
|
966
|
|
967 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Resource Properties"), wx.VERTICAL)
|
|
968 sizer.Add(wx.StaticText(self, -1, "Name of resource:"), 0, wx.EXPAND)
|
|
969 self.title = wx.TextCtrl(self, RES_EDIT_TITLE, self.handler.xml.get('name'))
|
|
970 sizer.Add(self.title, 0, wx.EXPAND)
|
|
971 sizer.Add(wx.Size(10,10))
|
|
972
|
|
973 sizer.Add(wx.StaticText(self, -1, "Base amount of resource:"), 0, wx.EXPAND)
|
|
974 self.base = wx.TextCtrl(self, RES_EDIT_BASE, self.handler.resource.get("base"))
|
|
975 sizer.Add(self.base, 0, wx.EXPAND)
|
|
976 sizer.Add(wx.Size(10,10))
|
|
977
|
|
978 sizer.Add(wx.StaticText(self, -1, "Current amount of resource:"), 0, wx.EXPAND)
|
|
979 self.current = wx.TextCtrl(self, RES_EDIT_CURRENT, self.handler.resource.get("current"))
|
|
980 sizer.Add(self.current, 0, wx.EXPAND)
|
|
981 sizer.Add(wx.Size(10,10))
|
|
982
|
|
983 opts = ['Text Number', 'Check Boxes']
|
|
984 self.radio = wx.RadioBox(self, RES_EDIT_CHECKS, "Amount of resource is represented by:", choices=opts)
|
|
985 if self.handler.use_checks():
|
|
986 self.radio.SetSelection(1)
|
|
987 else:
|
|
988 self.radio.SetSelection(0)
|
|
989 sizer.Add(self.radio, 0, wx.EXPAND)
|
|
990 sizer.Add(wx.Size(10,10))
|
|
991
|
|
992 sizer.Add(wx.StaticText(self, -1, "Send the following macro:"), 0, wx.EXPAND)
|
|
993 self.macro = wx.TextCtrl(self, RES_EDIT_MACRO, self.handler.get_macro(), style=wx.TE_MULTILINE)
|
|
994 sizer.Add(self.macro, 1, wx.EXPAND)
|
|
995
|
|
996 self.SetSizer(sizer)
|
|
997 self.SetAutoLayout(True)
|
|
998 self.Fit()
|
|
999 parent.SetSize(self.GetBestSize())
|
|
1000
|
|
1001 self.Bind(wx.EVT_TEXT, self.on_title, id=RES_EDIT_TITLE)
|
|
1002 self.Bind(wx.EVT_TEXT, self.on_base, id=RES_EDIT_BASE)
|
|
1003 self.Bind(wx.EVT_TEXT, self.on_current, id=RES_EDIT_CURRENT)
|
|
1004 self.Bind(wx.EVT_RADIOBOX, self.on_type, id=RES_EDIT_CHECKS)
|
|
1005 self.Bind(wx.EVT_TEXT, self.on_macro, id=RES_EDIT_MACRO)
|
|
1006
|
|
1007
|
|
1008 def on_title(self, evt):
|
|
1009 if len(self.title.GetValue()):
|
|
1010 self.handler.xml.set('name', self.title.GetValue())
|
|
1011 self.handler.rename(self.title.GetValue())
|
|
1012
|
|
1013 def on_base(self, evt):
|
|
1014 try:
|
|
1015 b = int(self.base.GetValue())
|
|
1016 self.handler.resource.set("base",str(b))
|
|
1017 except:
|
|
1018 pass
|
|
1019
|
|
1020 def on_current(self, evt):
|
|
1021 try:
|
|
1022 c = int(self.current.GetValue())
|
|
1023 self.handler.resource.set("current",str(c))
|
|
1024 except:
|
|
1025 pass
|
|
1026
|
|
1027 def on_type(self,evt):
|
|
1028 self.handler.resource.set("checks",str(self.radio.GetSelection()))
|
|
1029
|
|
1030 def on_macro(self,evt):
|
|
1031 self.handler.resource.text = self.macro.GetValue()
|
|
1032
|
|
1033
|
|
1034 #######################
|
|
1035 ## bonus handler
|
|
1036 #######################
|
|
1037
|
|
1038 class bonus_handler(node_handler):
|
|
1039 """
|
|
1040 <nodehandler class="bonus_handler" module="forms" name="">
|
|
1041 <bonus value="2" type="optional">Multi-line list of node references</bonus>
|
|
1042 </nodehandler>
|
|
1043 """
|
|
1044 def __init__(self,xml,tree_node):
|
|
1045 node_handler.__init__(self,xml,tree_node)
|
|
1046 self.bonus_xml = self.xml.find('bonus')
|
|
1047 self.add_to_bonus_map()
|
|
1048
|
|
1049 def get_design_panel(self,parent):
|
|
1050 return bonus_edit_panel(parent,self)
|
|
1051
|
|
1052 def get_use_panel(self,parent):# there is no 'use' for a bonus
|
|
1053 return bonus_edit_panel(parent,self)
|
|
1054
|
|
1055 def tohtml(self):
|
|
1056 return "bonus"# there is no 'send to chat' or 'pretty print'
|
|
1057
|
|
1058 def get_value(self):
|
|
1059 return self.bonus_xml.get('value', '')
|
|
1060
|
|
1061 def delete(self):
|
|
1062 self.remove_from_bonus_map()
|
|
1063 return node_handler.delete(self)
|
|
1064
|
|
1065 def add_to_bonus_map(self):
|
|
1066 for target in getText(self.bonus_xml).split('\n'):
|
|
1067 self.tree.AddBonus(target, self)
|
|
1068
|
|
1069 def remove_from_bonus_map(self):
|
|
1070 for target in getText(self.bonus_xml).split('\n'):
|
|
1071 self.tree.RemoveBonus(target, self)
|
|
1072
|
|
1073
|
|
1074
|
|
1075 BONUS_EDIT_TITLE = wx.NewId()
|
|
1076 BONUS_EDIT_VALUE = wx.NewId()
|
|
1077 BONUS_EDIT_TYPE = wx.NewId()
|
|
1078 BONUS_EDIT_REF = wx.NewId()
|
|
1079
|
|
1080
|
|
1081 class bonus_edit_panel(wx.Panel):
|
|
1082 def __init__(self, parent, handler):
|
|
1083 wx.Panel.__init__(self, parent, -1)
|
|
1084 self.handler = handler
|
|
1085
|
|
1086 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Bonus Properties"), wx.VERTICAL)
|
|
1087 sizer.Add(wx.StaticText(self, -1, "Name of bonus:"), 0, wx.EXPAND)
|
|
1088 self.title = wx.TextCtrl(self, BONUS_EDIT_TITLE, self.handler.xml.get('name'))
|
|
1089 sizer.Add(self.title, 0, wx.EXPAND)
|
|
1090 sizer.Add(wx.Size(10,10))
|
|
1091
|
|
1092 sizer.Add(wx.StaticText(self, -1, "Size of bonus:"), 0, wx.EXPAND)
|
|
1093 self.value = wx.TextCtrl(self, BONUS_EDIT_VALUE, self.handler.bonus_xml.get('value', ''))
|
|
1094 sizer.Add(self.value, 0, wx.EXPAND)
|
|
1095 sizer.Add(wx.Size(10,10))
|
|
1096
|
|
1097 sizer.Add(wx.StaticText(self, -1, "Type of bonus:"), 0, wx.EXPAND)
|
|
1098 self.type = wx.TextCtrl(self, BONUS_EDIT_TYPE, self.handler.bonus_xml.get("type"))
|
|
1099 sizer.Add(self.type, 0, wx.EXPAND)
|
|
1100 sizer.Add(wx.Size(10,10))
|
|
1101
|
|
1102 sizer.Add(wx.StaticText(self, -1, "Add to the following nodes:"), 0, wx.EXPAND)
|
|
1103 self.ref = wx.TextCtrl(self, BONUS_EDIT_REF, getText(self.handler.bonus_xml), style=wx.TE_MULTILINE)
|
|
1104 sizer.Add(self.ref, 1, wx.EXPAND)
|
|
1105
|
|
1106 self.SetSizer(sizer)
|
|
1107 self.SetAutoLayout(True)
|
|
1108 self.Fit()
|
|
1109 parent.SetSize(self.GetBestSize())
|
|
1110
|
|
1111 self.Bind(wx.EVT_TEXT, self.on_title, id=BONUS_EDIT_TITLE)# too many calls - should call only upon close
|
|
1112 self.Bind(wx.EVT_TEXT, self.on_value, id=BONUS_EDIT_VALUE)
|
|
1113 self.Bind(wx.EVT_TEXT, self.on_type, id=BONUS_EDIT_TYPE)
|
|
1114 self.Bind(wx.EVT_TEXT, self.on_ref, id=BONUS_EDIT_REF)
|
|
1115
|
|
1116
|
|
1117 def on_title(self, evt):
|
|
1118 if len(self.title.GetValue()):
|
|
1119 self.handler.xml.set('name', self.title.GetValue())
|
|
1120 self.handler.rename(self.title.GetValue())
|
|
1121
|
|
1122 def on_value(self, evt):
|
|
1123 self.handler.bonus_xml.set('value', self.value.GetValue())
|
|
1124
|
|
1125 def on_type(self, evt):
|
|
1126 self.handler.bonus_xml.set('type', self.type.GetValue())
|
|
1127
|
|
1128 def on_ref(self, evt):
|
|
1129 self.handler.remove_from_bonus_map()
|
|
1130 self.handler.bonus_xml.text = self.ref.GetValue()
|
|
1131 self.handler.add_to_bonus_map()
|