155
|
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 orpg.minidom as minidom
|
|
33 from orpg.orpg_xml import xml
|
|
34 from wx.lib.scrolledpanel import ScrolledPanel
|
|
35
|
|
36 def bool2int(b):
|
|
37 #in wxPython 2.5+, evt.Checked() returns True or False instead of 1.0 or 0.
|
|
38 #by running the results of that through this function, we convert it.
|
|
39 #if it was an int already, nothing changes. The difference between 1.0
|
|
40 #and 1, i.e. between ints and floats, is potentially dangerous when we
|
|
41 #use str() on it, but it seems to work fine right now.
|
|
42 if b: return 1
|
|
43 else: 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 def __init__(self,xml,tree_node):
|
|
56 container_handler.__init__(self, xml, tree_node)
|
|
57
|
|
58 def load_children(self):
|
|
59 self.atts = None
|
|
60 for child_xml in self.xml:
|
|
61 if child_xml.tag == "form": self.xml.remove(child_xml)
|
|
62 elif child_xml: self.tree.load_xml(child_xml, self.mytree_node)
|
|
63 if not self.xml.get('width'): self.xml.set('width', '400')
|
|
64 if not self.xml.get('height'): self.xml.set('height', '600')
|
|
65
|
|
66 def get_design_panel(self,parent):
|
|
67 return form_edit_panel(parent,self)
|
|
68
|
|
69 def get_use_panel(self,parent):
|
|
70 return form_panel(parent,self)
|
|
71
|
|
72 def on_drop(self,evt):
|
|
73 # make sure its a contorl node
|
|
74 container_handler.on_drop(self,evt)
|
|
75
|
|
76 class form_panel(ScrolledPanel):
|
|
77 def __init__(self, parent, handler):
|
|
78 ScrolledPanel.__init__(self, parent, wx.ID_ANY, style=wx.NO_BORDER|wx.VSCROLL|wx.HSCROLL)
|
|
79 self.height = int(handler.xml.get("height"))
|
|
80 self.width = int(handler.xml.get("width"))
|
|
81 self.SetSize((0,0))
|
|
82 self.handler = handler
|
|
83 self.parent = parent
|
|
84 self.main_sizer = wx.BoxSizer(wx.VERTICAL)
|
|
85 handler.tree.traverse(handler.mytree_node, self.create_child_wnd, None, False)
|
|
86 self.SetSizer(self.main_sizer)
|
|
87 self.SetAutoLayout(True)
|
|
88 self.SetupScrolling()
|
|
89 parent.SetSize(self.GetSize())
|
|
90 self.Fit()
|
|
91
|
|
92 def SetSize(self, xy):
|
|
93 (x, y) = self.GetSize()
|
|
94 (nx, ny) = xy
|
|
95 if x < nx:
|
|
96 x = nx+10
|
|
97 y += ny+11
|
|
98 ScrolledPanel.SetSize(self, (x, y))
|
|
99
|
|
100 def create_child_wnd(self, treenode, evt):
|
|
101 node = self.handler.tree.GetPyData(treenode)
|
|
102 panel = node.get_use_panel(self)
|
|
103 size = node.get_size_constraint()
|
|
104 if panel:
|
|
105 self.main_sizer.Add(panel, size, wx.EXPAND)
|
|
106 self.main_sizer.Add(wx.Size(10,10))
|
|
107
|
|
108 F_HEIGHT = wx.NewId()
|
|
109 F_WIDTH = wx.NewId()
|
|
110 class form_edit_panel(wx.Panel):
|
|
111 def __init__(self, parent, handler):
|
|
112 wx.Panel.__init__(self, parent, -1)
|
|
113 self.handler = handler
|
|
114 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Form Properties"), wx.VERTICAL)
|
|
115 wh_sizer = wx.BoxSizer(wx.HORIZONTAL)
|
|
116 self.text = { P_TITLE : wx.TextCtrl(self, P_TITLE, handler.xml.get('name')),
|
|
117 F_HEIGHT : wx.TextCtrl(self, F_HEIGHT, handler.xml.get('height')),
|
|
118 F_WIDTH : wx.TextCtrl(self, F_WIDTH, handler.xml.get('width'))
|
|
119 }
|
|
120
|
|
121 wh_sizer.Add(wx.StaticText(self, -1, "Width:"), 0, wx.ALIGN_CENTER)
|
|
122 wh_sizer.Add(wx.Size(10,10))
|
|
123 wh_sizer.Add(self.text[F_WIDTH], 0, wx.EXPAND)
|
|
124 wh_sizer.Add(wx.Size(10,10))
|
|
125 wh_sizer.Add(wx.StaticText(self, -1, "Height:"), 0, wx.ALIGN_CENTER)
|
|
126 wh_sizer.Add(wx.Size(10,10))
|
|
127 wh_sizer.Add(self.text[F_HEIGHT], 0, wx.EXPAND)
|
|
128
|
|
129 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND)
|
|
130 sizer.Add(self.text[P_TITLE], 0, wx.EXPAND)
|
|
131 sizer.Add(wx.Size(10,10))
|
|
132 sizer.Add(wh_sizer,0,wx.EXPAND)
|
|
133
|
|
134 self.SetSizer(sizer)
|
|
135 self.SetAutoLayout(True)
|
|
136 self.Fit()
|
|
137 parent.SetSize(self.GetBestSize())
|
|
138
|
|
139 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE)
|
|
140 self.Bind(wx.EVT_TEXT, self.on_text, id=F_HEIGHT)
|
|
141 self.Bind(wx.EVT_TEXT, self.on_text, id=F_WIDTH)
|
|
142
|
|
143 def on_text(self,evt):
|
|
144 id = evt.GetId()
|
|
145 txt = self.text[id].GetValue()
|
|
146 if not len(txt): return
|
|
147 if id == P_TITLE:
|
|
148 self.handler.xml.set('name',txt)
|
|
149 self.handler.rename(txt)
|
|
150 elif id == F_HEIGHT or id == F_WIDTH:
|
|
151 try: int(txt)
|
|
152 except: return 0
|
|
153 if id == F_HEIGHT: self.handler.xml.set("height",txt)
|
|
154 elif id == F_WIDTH: self.handler.xml.set("width",txt)
|
|
155
|
|
156 ##########################
|
|
157 ## control handler
|
|
158 ##########################
|
|
159 class control_handler(node_handler):
|
|
160 """ A nodehandler for form controls.
|
|
161 <nodehandler name='?' module='forms' class='control_handler' />
|
|
162 """
|
|
163 def __init__(self, xml, tree_node):
|
|
164 node_handler.__init__(self, xml, tree_node)
|
|
165
|
|
166 def get_size_constraint(self):
|
|
167 return 0
|
|
168
|
|
169 ##########################
|
|
170 ## textctrl handler
|
|
171 ##########################
|
|
172 #
|
|
173 # Updated by Snowdog (April 2003)
|
|
174 # Now includes Raw Send Mode (like the chat macro uses)
|
|
175 # and an option to remove the title from text when sent
|
|
176 # to the chat in the normal non-chat macro mode.
|
|
177 #
|
|
178 class textctrl_handler(node_handler):
|
|
179 """ <nodehandler class="textctrl_handler" module="form" name="">
|
|
180 <text multiline='0' send_button='0' raw_mode='0' hide_title='0'>Text In Node</text>
|
|
181 </nodehandler>
|
|
182 """
|
|
183 def __init__(self,xml,tree_node):
|
|
184 node_handler.__init__(self,xml,tree_node)
|
|
185 self.text_elem = self.xml.find('text')
|
|
186 if self.text_elem.get("send_button") == "": self.text_elem.set("send_button","0")
|
|
187 if self.text_elem.get("raw_mode") == "": self.text_elem.set("raw_mode","0")
|
|
188 if self.text_elem.get("hide_title") == "": self.text_elem.set("hide_title","0")
|
|
189
|
|
190 def get_design_panel(self,parent):
|
|
191 return textctrl_edit_panel(parent,self)
|
|
192
|
|
193 def get_use_panel(self,parent):
|
|
194 return text_panel(parent,self)
|
|
195
|
|
196 def get_size_constraint(self):
|
|
197 return int(self.text_elem.get("multiline",0))
|
|
198
|
|
199 def is_multi_line(self):
|
|
200 return int(self.text_elem.get("multiline",0))
|
|
201
|
|
202 def is_raw_send(self):
|
|
203 return int(self.text_elem.get("raw_mode",0))
|
|
204
|
|
205 def is_hide_title(self):
|
|
206 return int(self.text_elem.get("hide_title",0))
|
|
207
|
|
208 def has_send_button(self):
|
|
209 return int(self.text_elem.get("send_button",0))
|
|
210
|
|
211 def tohtml(self):
|
|
212 txt = self.get_value()
|
|
213 txt = string.replace(txt,'\n',"<br />")
|
|
214 if not self.is_hide_title(): txt = "<b>"+self.xml.get("name")+":</b> "+txt
|
|
215 return txt
|
|
216
|
|
217 def get_value(self):
|
|
218 return self.text_elem.text
|
|
219
|
|
220 def set_value(self, new_value):
|
|
221 self.text_elem.text = str(new_value)
|
|
222
|
|
223 FORM_TEXT_CTRL = wx.NewId()
|
|
224 FORM_SEND_BUTTON = wx.NewId()
|
|
225
|
|
226 class text_panel(wx.Panel):
|
|
227 def __init__(self, parent, handler):
|
|
228 wx.Panel.__init__(self, parent, -1)
|
|
229 self.chat = handler.chat
|
|
230 self.handler = handler
|
|
231 if handler.is_multi_line():
|
|
232 text_style = wx.TE_MULTILINE
|
|
233 sizer_style = wx.EXPAND
|
|
234 sizer = wx.BoxSizer(wx.VERTICAL)
|
|
235 else:
|
|
236 sizer_style = wx.ALIGN_CENTER
|
|
237 text_style = 0
|
|
238 sizer = wx.BoxSizer(wx.HORIZONTAL)
|
|
239
|
|
240 txt = handler.get_value()
|
|
241 if txt == None: txt = ''
|
|
242 self.text = wx.TextCtrl(self, FORM_TEXT_CTRL, txt, style=text_style)
|
|
243 sizer.Add(wx.StaticText(self, -1, handler.xml.get('name')+": "), 0, sizer_style)
|
|
244 sizer.Add(wx.Size(5,0))
|
|
245 sizer.Add(self.text, 1, sizer_style)
|
|
246
|
|
247 if handler.has_send_button(): sizer.Add(wx.Button(self, FORM_SEND_BUTTON, "Send"), 0, sizer_style)
|
|
248
|
|
249 self.sizer = sizer
|
|
250 self.SetSizer(sizer)
|
|
251 self.SetAutoLayout(True)
|
|
252
|
|
253 parent.SetSize(self.GetBestSize())
|
|
254 self.Bind(wx.EVT_TEXT, self.on_text, id=FORM_TEXT_CTRL)
|
132
|
255 self.Bind(wx.EVT_BUTTON, self.on_send, id=FORM_SEND_BUTTON)
|
|
256
|
|
257 def on_text(self, evt):
|
155
|
258 debug()
|
|
259 txt = self.text.GetValue()
|
|
260 #txt = strip_text(txt) ##Does not seem to exist.
|
|
261 self.handler.text_elem.text = txt
|
|
262
|
|
263 def on_send(self, evt):
|
132
|
264 txt = self.text.GetValue()
|
|
265 txt = self.chat.ParseMap(txt, self.handler.xml)
|
155
|
266 if not self.handler.is_raw_send():
|
|
267 self.chat.ParsePost(self.handler.tohtml(), True, True)
|
|
268 return 1
|
|
269 actionlist = txt.split("\n")
|
|
270 for line in actionlist:
|
|
271 if(line != ""):
|
|
272 if line[0] != "/": ## it's not a slash command
|
|
273 self.chat.ParsePost(line, True, True)
|
|
274 else:
|
|
275 action = line
|
|
276 self.chat.chat_cmds.docmd(action)
|
|
277 return 1
|
|
278
|
|
279 F_MULTI = wx.NewId()
|
|
280 F_SEND_BUTTON = wx.NewId()
|
|
281 F_RAW_SEND = wx.NewId()
|
|
282 F_HIDE_TITLE = wx.NewId()
|
|
283 F_TEXT = wx.NewId()
|
|
284
|
|
285 class textctrl_edit_panel(wx.Panel):
|
|
286 def __init__(self, parent, handler):
|
|
287 wx.Panel.__init__(self, parent, -1)
|
|
288 self.handler = handler
|
|
289 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Text Properties"), wx.VERTICAL)
|
|
290
|
|
291 self.title = wx.TextCtrl(self, P_TITLE, handler.xml.get('name'))
|
|
292 self.multi = wx.CheckBox(self, F_MULTI, " Multi-Line")
|
|
293 self.multi.SetValue(handler.is_multi_line())
|
|
294 self.raw_send = wx.CheckBox(self, F_RAW_SEND, " Send as Macro")
|
|
295 self.raw_send.SetValue(handler.is_raw_send())
|
|
296 self.hide_title = wx.CheckBox(self, F_HIDE_TITLE, " Hide Title")
|
|
297 self.hide_title.SetValue(handler.is_hide_title())
|
|
298 self.send_button = wx.CheckBox(self, F_SEND_BUTTON, " Send Button")
|
|
299 self.send_button.SetValue(handler.has_send_button())
|
|
300
|
|
301 sizer.Add(wx.StaticText(self, P_TITLE, "Title:"), 0, wx.EXPAND)
|
|
302 sizer.Add(self.title, 0, wx.EXPAND)
|
|
303 sizer.Add(wx.Size(10,10))
|
|
304 sizer.Add(self.multi, 0, wx.EXPAND)
|
|
305 sizer.Add(self.raw_send, 0, wx.EXPAND)
|
|
306 sizer.Add(self.hide_title, 0, wx.EXPAND)
|
|
307 sizer.Add(self.send_button, 0 , wx.EXPAND)
|
|
308 sizer.Add(wx.Size(10,10))
|
|
309 if handler.is_multi_line():
|
|
310 sizer_style = wx.EXPAND
|
|
311 text_style = wx.TE_MULTILINE
|
|
312 multi = 1
|
|
313 else:
|
|
314 sizer_style=wx.EXPAND
|
|
315 text_style = 0
|
|
316 multi = 0
|
|
317 self.text = wx.TextCtrl(self, F_TEXT, handler.get_value(),style=text_style)
|
|
318 sizer.Add(wx.Size(5,0))
|
|
319 sizer.Add(self.text, multi, sizer_style)
|
|
320 self.SetSizer(sizer)
|
|
321 self.SetAutoLayout(True)
|
|
322
|
|
323 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE)
|
|
324 self.Bind(wx.EVT_TEXT, self.on_text, id=F_TEXT)
|
|
325 self.Bind(wx.EVT_CHECKBOX, self.on_button, id=F_MULTI)
|
|
326 self.Bind(wx.EVT_CHECKBOX, self.on_raw_button, id=F_RAW_SEND)
|
|
327 self.Bind(wx.EVT_CHECKBOX, self.on_hide_button, id=F_HIDE_TITLE)
|
|
328 self.Bind(wx.EVT_CHECKBOX, self.on_send_button, id=F_SEND_BUTTON)
|
|
329
|
|
330 def on_text(self,evt):
|
|
331 id = evt.GetId()
|
|
332 if id == P_TITLE:
|
|
333 txt = self.title.GetValue()
|
|
334 if not len(txt): return
|
|
335 self.handler.xml.set('name',txt)
|
|
336 self.handler.rename(txt)
|
|
337 if id == F_TEXT:
|
|
338 txt = self.text.GetValue()
|
|
339 #txt = strip_text(txt) ##Does not seem to exist.
|
|
340 self.handler.text_elem.text = txt
|
|
341
|
|
342 def on_button(self,evt):
|
|
343 self.handler.text_elem.set("multiline",str(bool2int(evt.Checked())))
|
|
344
|
|
345 def on_raw_button(self,evt):
|
|
346 self.handler.text_elem.set("raw_mode",str(bool2int(evt.Checked())))
|
|
347
|
|
348 def on_hide_button(self,evt):
|
|
349 self.handler.text_elem.set("hide_title",str(bool2int(evt.Checked())))
|
|
350
|
|
351 def on_send_button(self,evt):
|
|
352 self.handler.text_elem.set("send_button",str(bool2int(evt.Checked())))
|
|
353
|
|
354
|
|
355 #######################
|
|
356 ## listbox handler
|
|
357 #######################
|
|
358 #
|
|
359 # Updated by Snowdog (April 2003)
|
|
360 # Now includesan option to remove the title from
|
|
361 # text when sent to the chat.
|
|
362 #
|
|
363 L_DROP = 0
|
|
364 L_LIST = 1
|
|
365 L_RADIO = 2
|
|
366 L_CHECK = 3
|
|
367 L_ROLLER = 4
|
|
368
|
|
369 class listbox_handler(node_handler):
|
|
370 """
|
|
371 <nodehandler class="listbox_handler" module="forms" name="">
|
|
372 <list type="1" send_button='0' hide_title='0'>
|
|
373 <option value="" selected="" >Option Text I</option>
|
|
374 <option value="" selected="" >Option Text II</option>
|
|
375 </list>
|
|
376 </nodehandler>
|
|
377 """
|
|
378 def __init__(self,xml,tree_node):
|
|
379 node_handler.__init__(self,xml,tree_node)
|
|
380 self.list = self.xml.find('list')
|
|
381 self.options = self.list.findall('option')
|
|
382 if self.list.get("send_button") == "": self.list.set("send_button","0")
|
141
|
383 if self.list.get("hide_title") == "": self.list.set("hide_title","0")
|
155
|
384 if self.list.get("raw_mode") == "": self.list.set("raw_mode","0")
|
|
385
|
|
386 def get_design_panel(self,parent):
|
|
387 return listbox_edit_panel(parent,self)
|
|
388
|
|
389 def get_use_panel(self,parent):
|
|
390 return listbox_panel(parent,self)
|
|
391
|
|
392 def get_type(self):
|
|
393 return int(self.list.get("type"))
|
|
394
|
|
395 def set_type(self,type):
|
|
396 self.list.set("type",str(type))
|
|
397
|
|
398 def is_hide_title(self):
|
141
|
399 return int(self.list.get("hide_title", 0))
|
|
400
|
155
|
401 def is_raw_send(self):
|
|
402 return int(self.list.get("raw_mode",0))
|
|
403
|
|
404 # single selection methods
|
|
405 def get_selected_node(self):
|
|
406 for opt in self.options:
|
|
407 if opt.get("selected") == "1": return opt
|
|
408 return None
|
|
409
|
|
410 def get_selected_index(self):
|
|
411 i = 0
|
|
412 for opt in self.options:
|
|
413 if opt.get("selected") == "1": return i
|
|
414 i += 1
|
|
415 return 0
|
|
416
|
|
417 def get_selected_text(self):
|
|
418 node = self.get_selected_node()
|
|
419 if node: return node.text
|
|
420 else: return ""
|
|
421
|
|
422 # mult selection methods
|
|
423 def get_selections(self):
|
|
424 opts = []
|
|
425 for opt in self.options:
|
|
426 if opt.get("selected") == "1": opts.append(opt)
|
|
427 return opts
|
|
428
|
|
429 def get_selections_text(self):
|
|
430 opts = []
|
|
431 for opt in self.options:
|
|
432 if opt.get("selected") == "1": opts.append(opt.text)
|
|
433 return opts
|
|
434
|
|
435 def get_selections_index(self):
|
|
436 opts = []
|
|
437 i = 0
|
|
438 for opt in self.options:
|
|
439 if opt.get("selected") == "1": opts.append(i)
|
|
440 i += 1
|
|
441 return opts
|
|
442
|
|
443 # setting selection method
|
|
444 def set_selected_node(self,index,selected=1):
|
|
445 if self.get_type() != L_CHECK: self.clear_selections()
|
|
446 self.options[index].set("selected", str(bool2int(selected)))
|
|
447
|
|
448 def clear_selections(self):
|
|
449 for opt in self.options: opt.set("selected","0")
|
|
450
|
|
451 # misc methods
|
|
452 def get_options(self):
|
|
453 opts = []
|
|
454 for opt in self.options: opts.append(opt.text)
|
|
455 return opts
|
|
456
|
|
457 def get_option(self,index):
|
|
458 return self.options[index].text
|
|
459
|
|
460 def add_option(self,opt):
|
|
461 elem = Element('option')
|
|
462 elem.set("value","0")
|
|
463 elem.set("selected","0")
|
|
464 elem.text = opt
|
|
465 self.list.append(elem)
|
|
466 self.options = self.list.findall('option')
|
|
467
|
|
468 def remove_option(self,index):
|
|
469 self.list.remove(self.options[index])
|
|
470 self.options = self.list.findall('option')
|
|
471
|
|
472 def edit_option(self,index,value):
|
|
473 self.options[index].text = value
|
|
474
|
|
475 def has_send_button(self):
|
|
476 if self.list.get("send_button") == '0': return False
|
|
477 else: return True
|
|
478
|
|
479 def get_size_constraint(self):
|
|
480 if self.get_type() == L_DROP: return 0
|
|
481 else: return 1
|
|
482
|
|
483 def tohtml(self):
|
|
484 opts = self.get_selections_text()
|
|
485 text = ""
|
|
486 if not self.is_hide_title(): text = "<b>"+self.xml.get("name")+":</b> "
|
|
487 comma = ", "
|
|
488 text += comma.join(opts)
|
|
489 return text
|
|
490
|
|
491 def get_value(self):
|
141
|
492 return "\n".join(self.get_selections_text())
|
|
493
|
155
|
494 def on_send_to_chat(self, evt):
|
141
|
495 txt = self.get_selected_text()
|
|
496 txt = self.chat.ParseMap(txt, self.xml)
|
155
|
497 if not self.is_raw_send():
|
|
498 self.chat.ParsePost(self.tohtml(), True, True)
|
|
499 return 1
|
|
500 actionlist = self.get_selections_text()
|
141
|
501 for line in actionlist:
|
155
|
502 line = self.chat.ParseMap(line, self.xml)
|
|
503 if(line != ""):
|
|
504 if line[0] != "/": ## it's not a slash command
|
|
505 self.chat.ParsePost(line, True, True)
|
|
506 else:
|
|
507 action = line
|
|
508 self.chat.chat_cmds.docmd(action)
|
|
509 return 1
|
|
510
|
|
511
|
|
512 F_LIST = wx.NewId()
|
|
513 F_SEND = wx.NewId()
|
|
514
|
|
515
|
|
516 class listbox_panel(wx.Panel):
|
|
517 def __init__(self, parent, handler):
|
|
518 wx.Panel.__init__(self, parent, -1)
|
|
519 self.handler = handler
|
|
520 self.chat = handler.chat
|
|
521 opts = handler.get_options()
|
|
522 cur_opt = handler.get_selected_text()
|
|
523 type = handler.get_type()
|
|
524 label = handler.xml.get('name')
|
|
525
|
|
526 if type == L_DROP:
|
|
527 self.list = wx.ComboBox(self, F_LIST, cur_opt, choices=opts, style=wx.CB_READONLY)
|
|
528 if self.list.GetSize()[0] > 200:
|
|
529 self.list.Destroy()
|
|
530 self.list = wx.ComboBox(self, F_LIST, cur_opt, size=(200, -1), choices=opts, style=wx.CB_READONLY)
|
|
531 elif type == L_LIST: self.list = wx.ListBox(self,F_LIST,choices=opts)
|
|
532 elif type == L_RADIO: self.list = wx.RadioBox(self,F_LIST,label,choices=opts,majorDimension=3)
|
|
533 elif type == L_CHECK:
|
|
534 self.list = wx.CheckListBox(self,F_LIST,choices=opts)
|
|
535 self.set_checks()
|
|
536
|
|
537 for i in handler.get_selections_text():
|
|
538 if type == L_DROP: self.list.SetValue( i )
|
|
539 else: self.list.SetStringSelection( i )
|
|
540 if type == L_DROP: sizer = wx.BoxSizer(wx.HORIZONTAL)
|
|
541 else: sizer = wx.BoxSizer(wx.VERTICAL)
|
|
542
|
|
543 if type != L_RADIO:
|
|
544 sizer.Add(wx.StaticText(self, -1, label+": "), 0, wx.EXPAND)
|
|
545 sizer.Add(wx.Size(5,0))
|
|
546 sizer.Add(self.list, 1, wx.EXPAND)
|
|
547 if handler.has_send_button():
|
|
548 sizer.Add(wx.Button(self, F_SEND, "Send"), 0, wx.EXPAND)
|
|
549 self.Bind(wx.EVT_BUTTON, self.handler.on_send_to_chat, id=F_SEND)
|
|
550 self.sizer = sizer
|
|
551 self.SetSizer(sizer)
|
|
552 self.SetAutoLayout(True)
|
|
553 self.Fit()
|
|
554 parent.SetSize(self.GetBestSize())
|
|
555
|
|
556 if type == L_DROP: self.Bind(wx.EVT_COMBOBOX, self.on_change, id=F_LIST)
|
|
557 elif type == L_LIST: self.Bind(wx.EVT_LISTBOX, self.on_change, id=F_LIST)
|
|
558 elif type == L_RADIO: self.Bind(wx.EVT_RADIOBOX, self.on_change, id=F_LIST)
|
|
559 elif type == L_CHECK:self.Bind(wx.EVT_CHECKLISTBOX, self.on_check, id=F_LIST)
|
|
560 self.type = type
|
|
561
|
|
562 def on_change(self,evt):
|
|
563 self.handler.set_selected_node(self.list.GetSelection())
|
|
564
|
|
565 def on_check(self,evt):
|
141
|
566 for i in xrange(self.list.GetCount()): self.handler.set_selected_node(i, bool2int(self.list.IsChecked(i)))
|
155
|
567
|
|
568 def set_checks(self):
|
|
569 for i in self.handler.get_selections_index(): self.list.Check(i)
|
|
570
|
|
571
|
|
572 BUT_ADD = wx.NewId()
|
|
573 BUT_REM = wx.NewId()
|
|
574 BUT_EDIT = wx.NewId()
|
|
575 F_TYPE = wx.NewId()
|
|
576 F_NO_TITLE = wx.NewId()
|
|
577
|
|
578 class listbox_edit_panel(wx.Panel):
|
|
579 def __init__(self, parent, handler):
|
|
580 wx.Panel.__init__(self, parent, -1)
|
|
581 self.handler = handler
|
|
582 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "List Box Properties"), wx.VERTICAL)
|
|
583
|
|
584 self.text = wx.TextCtrl(self, P_TITLE, handler.xml.get('name'))
|
|
585
|
|
586 opts = handler.get_options()
|
|
587 self.listbox = wx.ListBox(self, F_LIST, choices=opts, style=wx.LB_HSCROLL|wx.LB_SINGLE|wx.LB_NEEDED_SB)
|
|
588 opts = ['Drop Down', 'List Box', 'Radio Box', 'Check List']
|
|
589 self.type_radios = wx.RadioBox(self,F_TYPE,"List Type",choices=opts)
|
|
590 self.type_radios.SetSelection(handler.get_type())
|
|
591
|
|
592 self.send_button = wx.CheckBox(self, F_SEND_BUTTON, " Send Button")
|
141
|
593 self.send_button.SetValue(handler.has_send_button())
|
|
594
|
155
|
595 self.raw_send = wx.CheckBox(self, F_RAW_SEND, " Send as Macro")
|
|
596 self.raw_send.SetValue(handler.is_raw_send())
|
|
597
|
|
598 self.hide_title = wx.CheckBox(self, F_NO_TITLE, " Hide Title")
|
|
599 self.hide_title.SetValue(handler.is_hide_title())
|
|
600
|
|
601 but_sizer = wx.BoxSizer(wx.HORIZONTAL)
|
|
602 but_sizer.Add(wx.Button(self, BUT_ADD, "Add"), 1, wx.EXPAND)
|
|
603 but_sizer.Add(wx.Size(10,10))
|
|
604 but_sizer.Add(wx.Button(self, BUT_EDIT, "Edit"), 1, wx.EXPAND)
|
|
605 but_sizer.Add(wx.Size(10,10))
|
|
606 but_sizer.Add(wx.Button(self, BUT_REM, "Remove"), 1, wx.EXPAND)
|
|
607
|
|
608 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND)
|
|
609 sizer.Add(self.text, 0, wx.EXPAND)
|
|
610 sizer.Add(wx.Size(10,10))
|
|
611 sizer.Add(self.type_radios, 0, wx.EXPAND)
|
|
612 sizer.Add(wx.Size(10,10))
|
|
613 sizer.Add(self.send_button, 0 , wx.EXPAND)
|
141
|
614 sizer.Add(self.hide_title, 0, wx.EXPAND)
|
155
|
615 sizer.Add(self.raw_send, 0, wx.EXPAND)
|
|
616 sizer.Add(wx.Size(10,10))
|
|
617 sizer.Add(wx.StaticText(self, -1, "Options:"), 0, wx.EXPAND)
|
|
618 sizer.Add(self.listbox,1,wx.EXPAND);
|
|
619 sizer.Add(but_sizer,0,wx.EXPAND)
|
|
620
|
|
621 self.SetSizer(sizer)
|
|
622 self.SetAutoLayout(True)
|
|
623 self.Fit()
|
|
624 parent.SetSize(self.GetBestSize())
|
|
625
|
|
626 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE)
|
|
627 self.Bind(wx.EVT_BUTTON, self.on_edit, id=BUT_EDIT)
|
|
628 self.Bind(wx.EVT_BUTTON, self.on_remove, id=BUT_REM)
|
|
629 self.Bind(wx.EVT_BUTTON, self.on_add, id=BUT_ADD)
|
|
630 self.Bind(wx.EVT_RADIOBOX, self.on_type, id=F_TYPE)
|
|
631 self.Bind(wx.EVT_CHECKBOX, self.on_hide_button, id=F_NO_TITLE)
|
141
|
632 self.Bind(wx.EVT_CHECKBOX, self.on_send_button, id=F_SEND_BUTTON)
|
155
|
633 self.Bind(wx.EVT_CHECKBOX, self.on_raw_button, id=F_RAW_SEND)
|
|
634
|
|
635 def on_type(self,evt):
|
|
636 self.handler.set_type(evt.GetInt())
|
|
637
|
|
638 def on_add(self,evt):
|
|
639 dlg = wx.TextEntryDialog(self, 'Enter option?','Add Option', '')
|
|
640 if dlg.ShowModal() == wx.ID_OK:
|
|
641 self.handler.add_option(dlg.GetValue())
|
|
642 dlg.Destroy()
|
|
643 self.reload_options()
|
|
644
|
|
645 def on_remove(self,evt):
|
|
646 index = self.listbox.GetSelection()
|
|
647 if index >= 0:
|
|
648 self.handler.remove_option(index)
|
|
649 self.reload_options()
|
|
650
|
|
651 def on_edit(self,evt):
|
|
652 index = self.listbox.GetSelection()
|
|
653 if index >= 0:
|
|
654 txt = self.handler.get_option(index)
|
|
655 dlg = wx.TextEntryDialog(self, 'Enter option?','Edit Option', txt)
|
|
656 if dlg.ShowModal() == wx.ID_OK:
|
|
657 self.handler.edit_option(index,dlg.GetValue())
|
|
658 dlg.Destroy()
|
|
659 self.reload_options()
|
|
660
|
|
661 def reload_options(self):
|
|
662 self.listbox.Clear()
|
|
663 for opt in self.handler.get_options():
|
|
664 self.listbox.Append(opt)
|
|
665
|
|
666 def on_text(self,evt):
|
|
667 id = evt.GetId()
|
|
668 txt = self.text.GetValue()
|
|
669 if not len(txt): return
|
|
670 if id == P_TITLE:
|
|
671 self.handler.xml.set('name',txt)
|
|
672 self.handler.rename(txt)
|
|
673
|
|
674 def on_send_button(self,evt):
|
|
675 self.handler.list.set("send_button", str( bool2int(evt.Checked()) ))
|
|
676
|
|
677 def on_hide_button(self,evt):
|
141
|
678 self.handler.list.set("hide_title", str( bool2int(evt.Checked()) ))
|
|
679
|
155
|
680 def on_raw_button(self,evt):
|
|
681 self.handler.list.set("raw_mode",str(bool2int(evt.Checked())))
|
|
682
|
|
683
|
|
684 ###############################
|
|
685 ## link image handlers
|
|
686 ###############################
|
|
687
|
|
688 class link_handler(node_handler):
|
|
689 """ A nodehandler for URLs. Will open URL in a wxHTMLFrame
|
|
690 <nodehandler name='?' module='forms' class='link_handler' >
|
|
691 <link href='http//??.??' />
|
|
692 </nodehandler >
|
|
693 """
|
|
694 def __init__(self,xml,tree_node):
|
|
695 node_handler.__init__(self,xml,tree_node)
|
|
696 self.link = self.xml[0]
|
|
697
|
|
698 def on_use(self,evt):
|
|
699 href = self.link.get("href")
|
|
700 wb = webbrowser.get()
|
|
701 wb.open(href)
|
|
702
|
|
703 def get_design_panel(self,parent):
|
|
704 return link_edit_panel(parent,self)
|
|
705
|
|
706 def get_use_panel(self,parent):
|
|
707 return link_panel(parent,self)
|
|
708
|
|
709 def tohtml(self):
|
|
710 href = self.link.get("href")
|
|
711 title = self.xml.get("name")
|
|
712 return "<a href='"+href+"' >"+title+"</a>"
|
|
713
|
|
714 class link_panel(wx.StaticText):
|
|
715 def __init__(self,parent,handler):
|
|
716 self.handler = handler
|
|
717 label = handler.xml.get('name')
|
|
718 wx.StaticText.__init__(self,parent,-1,label)
|
|
719 self.SetForegroundColour(wx.BLUE)
|
|
720 self.Bind(wx.EVT_LEFT_DOWN, self.handler.on_use)
|
|
721
|
|
722 P_URL = wx.NewId()
|
|
723
|
|
724 class link_edit_panel(wx.Panel):
|
|
725 def __init__(self, parent, handler):
|
|
726 wx.Panel.__init__(self, parent, -1)
|
|
727 self.handler = handler
|
|
728 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Link Properties"), wx.VERTICAL)
|
|
729
|
|
730 self.text = {}
|
|
731 self.text[P_TITLE] = wx.TextCtrl(self, P_TITLE, handler.xml.get('name'))
|
|
732 self.text[P_URL] = wx.TextCtrl(self, P_URL, handler.link.get('href'))
|
|
733
|
|
734 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND)
|
|
735 sizer.Add(self.text[P_TITLE], 0, wx.EXPAND)
|
|
736 sizer.Add(wx.Size(10,10))
|
|
737 sizer.Add(wx.StaticText(self, -1, "URL:"), 0, wx.EXPAND)
|
|
738 sizer.Add(self.text[P_URL], 0, wx.EXPAND)
|
|
739 self.SetSizer(sizer)
|
|
740 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE)
|
|
741 self.Bind(wx.EVT_TEXT, self.on_text, id=P_URL)
|
|
742
|
|
743 def on_text(self,evt):
|
|
744 id = evt.GetId()
|
|
745 txt = self.text[id].GetValue()
|
|
746 if not len(txt): return
|
|
747 if id == P_TITLE:
|
|
748 self.handler.xml.set('name',txt)
|
|
749 self.handler.rename(txt)
|
|
750 elif id == P_URL: self.handler.link.set('href',txt)
|
|
751
|
|
752 ##########################
|
|
753 ## webimg node handler
|
|
754 ##########################
|
|
755 class webimg_handler(node_handler):
|
|
756 """ A nodehandler for URLs. Will open URL in a wxHTMLFrame
|
|
757 <nodehandler name='?' module='forms' class='webimg_handler' >
|
|
758 <link href='http//??.??' />
|
|
759 </nodehandler >
|
|
760 """
|
|
761 def __init__(self,xml,tree_node):
|
|
762 node_handler.__init__(self,xml,tree_node)
|
|
763 self.link = self.xml[0]
|
|
764
|
|
765 def get_design_panel(self,parent):
|
|
766 return link_edit_panel(parent,self)
|
|
767
|
|
768 def get_use_panel(self,parent):
|
|
769 img = img_helper().load_url(self.link.get("href"))
|
|
770 if not img is None: return wx.StaticBitmap(parent,-1,img,size= wx.Size(img.GetWidth(),img.GetHeight()))
|
|
771 return wx.EmptyBitmap(1, 1)
|
|
772
|
|
773 def tohtml(self):
|
|
774 href = self.link.get("href")
|
|
775 title = self.xml.get("name")
|
|
776 return "<img src='"+href+"' alt="+title+" >"
|