131
|
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')
|
132
|
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")
|
131
|
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():
|
|
215 txt = "<b>"+self.xml.get("name")+":</b> "+txt
|
|
216 return txt
|
|
217
|
|
218 def get_value(self):
|
|
219 return self.text_elem.text
|
|
220
|
|
221 def set_value(self, new_value):
|
|
222 self.text_elem.text = str(new_value)
|
|
223
|
|
224 FORM_TEXT_CTRL = wx.NewId()
|
|
225 FORM_SEND_BUTTON = wx.NewId()
|
|
226
|
|
227 class text_panel(wx.Panel):
|
|
228 def __init__(self, parent, handler):
|
|
229 wx.Panel.__init__(self, parent, -1)
|
|
230 self.chat = handler.chat
|
|
231 self.handler = handler
|
|
232 if handler.is_multi_line():
|
|
233 text_style = wx.TE_MULTILINE
|
|
234 sizer_style = wx.EXPAND
|
|
235 sizer = wx.BoxSizer(wx.VERTICAL)
|
|
236 else:
|
|
237 sizer_style = wx.ALIGN_CENTER
|
|
238 text_style = 0
|
|
239 sizer = wx.BoxSizer(wx.HORIZONTAL)
|
|
240
|
|
241 txt = handler.get_value()
|
|
242 if txt == None: txt = ''
|
|
243 self.text = wx.TextCtrl(self, FORM_TEXT_CTRL, txt, style=text_style)
|
|
244 sizer.Add(wx.StaticText(self, -1, handler.xml.get('name')+": "), 0, sizer_style)
|
|
245 sizer.Add(wx.Size(5,0))
|
|
246 sizer.Add(self.text, 1, sizer_style)
|
|
247
|
|
248 if handler.has_send_button():
|
|
249 sizer.Add(wx.Button(self, FORM_SEND_BUTTON, "Send"), 0, sizer_style)
|
|
250
|
|
251 self.sizer = sizer
|
|
252 self.SetSizer(sizer)
|
|
253 self.SetAutoLayout(True)
|
|
254
|
|
255 parent.SetSize(self.GetBestSize())
|
|
256 self.Bind(wx.EVT_TEXT, self.on_text, id=FORM_TEXT_CTRL)
|
132
|
257 self.Bind(wx.EVT_BUTTON, self.on_send, id=FORM_SEND_BUTTON)
|
|
258
|
|
259 def on_text(self, evt):
|
|
260 debug()
|
131
|
261 txt = self.text.GetValue()
|
|
262 #txt = strip_text(txt) ##Does not seem to exist.
|
|
263 self.handler.text_elem.text = txt
|
|
264
|
132
|
265 def on_send(self, evt):
|
|
266 txt = self.text.GetValue()
|
|
267 txt = self.chat.ParseMap(txt, self.handler.xml)
|
131
|
268 if not self.handler.is_raw_send():
|
132
|
269 self.chat.ParsePost(self.handler.tohtml(), True, True)
|
131
|
270 return 1
|
|
271 actionlist = txt.split("\n")
|
|
272 for line in actionlist:
|
|
273 if(line != ""):
|
|
274 if line[0] != "/": ## it's not a slash command
|
132
|
275 self.chat.ParsePost(line, True, True)
|
131
|
276 else:
|
|
277 action = line
|
|
278 self.chat.chat_cmds.docmd(action)
|
|
279 return 1
|
|
280
|
|
281 F_MULTI = wx.NewId()
|
|
282 F_SEND_BUTTON = wx.NewId()
|
|
283 F_RAW_SEND = wx.NewId()
|
|
284 F_HIDE_TITLE = wx.NewId()
|
|
285 F_TEXT = wx.NewId()
|
|
286
|
|
287 class textctrl_edit_panel(wx.Panel):
|
|
288 def __init__(self, parent, handler):
|
|
289 wx.Panel.__init__(self, parent, -1)
|
|
290 self.handler = handler
|
|
291 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Text Properties"), wx.VERTICAL)
|
|
292
|
|
293 self.title = wx.TextCtrl(self, P_TITLE, handler.xml.get('name'))
|
|
294 self.multi = wx.CheckBox(self, F_MULTI, " Multi-Line")
|
|
295 self.multi.SetValue(handler.is_multi_line())
|
|
296 self.raw_send = wx.CheckBox(self, F_RAW_SEND, " Send as Macro")
|
|
297 self.raw_send.SetValue(handler.is_raw_send())
|
|
298 self.hide_title = wx.CheckBox(self, F_HIDE_TITLE, " Hide Title")
|
|
299 self.hide_title.SetValue(handler.is_hide_title())
|
|
300 self.send_button = wx.CheckBox(self, F_SEND_BUTTON, " Send Button")
|
|
301 self.send_button.SetValue(handler.has_send_button())
|
|
302
|
|
303 sizer.Add(wx.StaticText(self, P_TITLE, "Title:"), 0, wx.EXPAND)
|
|
304 sizer.Add(self.title, 0, wx.EXPAND)
|
|
305 sizer.Add(wx.Size(10,10))
|
|
306 sizer.Add(self.multi, 0, wx.EXPAND)
|
|
307 sizer.Add(self.raw_send, 0, wx.EXPAND)
|
|
308 sizer.Add(self.hide_title, 0, wx.EXPAND)
|
|
309 sizer.Add(self.send_button, 0 , wx.EXPAND)
|
|
310 sizer.Add(wx.Size(10,10))
|
|
311 if handler.is_multi_line():
|
|
312 sizer_style = wx.EXPAND
|
|
313 text_style = wx.TE_MULTILINE
|
|
314 multi = 1
|
|
315 else:
|
|
316 sizer_style=wx.EXPAND
|
|
317 text_style = 0
|
|
318 multi = 0
|
|
319 self.text = wx.TextCtrl(self, F_TEXT, handler.get_value(),style=text_style)
|
|
320 sizer.Add(wx.Size(5,0))
|
|
321 sizer.Add(self.text, multi, sizer_style)
|
|
322 self.SetSizer(sizer)
|
|
323 self.SetAutoLayout(True)
|
|
324
|
|
325 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE)
|
|
326 self.Bind(wx.EVT_TEXT, self.on_text, id=F_TEXT)
|
|
327 self.Bind(wx.EVT_CHECKBOX, self.on_button, id=F_MULTI)
|
|
328 self.Bind(wx.EVT_CHECKBOX, self.on_raw_button, id=F_RAW_SEND)
|
|
329 self.Bind(wx.EVT_CHECKBOX, self.on_hide_button, id=F_HIDE_TITLE)
|
|
330 self.Bind(wx.EVT_CHECKBOX, self.on_send_button, id=F_SEND_BUTTON)
|
|
331
|
|
332 def on_text(self,evt):
|
|
333 id = evt.GetId()
|
|
334 if id == P_TITLE:
|
|
335 txt = self.title.GetValue()
|
|
336 if not len(txt): return
|
|
337 self.handler.xml.set('name',txt)
|
|
338 self.handler.rename(txt)
|
|
339 if id == F_TEXT:
|
|
340 txt = self.text.GetValue()
|
|
341 #txt = strip_text(txt) ##Does not seem to exist.
|
|
342 self.handler.text_elem.text = txt
|
|
343
|
|
344 def on_button(self,evt):
|
|
345 self.handler.text_elem.set("multiline",str(bool2int(evt.Checked())))
|
|
346
|
|
347 def on_raw_button(self,evt):
|
|
348 self.handler.text_elem.set("raw_mode",str(bool2int(evt.Checked())))
|
|
349
|
|
350 def on_hide_button(self,evt):
|
|
351 self.handler.text_elem.set("hide_title",str(bool2int(evt.Checked())))
|
|
352
|
|
353 def on_send_button(self,evt):
|
|
354 self.handler.text_elem.set("send_button",str(bool2int(evt.Checked())))
|
|
355
|
|
356
|
|
357 #######################
|
|
358 ## listbox handler
|
|
359 #######################
|
|
360 #
|
|
361 # Updated by Snowdog (April 2003)
|
|
362 # Now includesan option to remove the title from
|
|
363 # text when sent to the chat.
|
|
364 #
|
|
365 L_DROP = 0
|
|
366 L_LIST = 1
|
|
367 L_RADIO = 2
|
|
368 L_CHECK = 3
|
|
369 L_ROLLER = 4
|
|
370
|
|
371 class listbox_handler(node_handler):
|
|
372 """
|
|
373 <nodehandler class="listbox_handler" module="forms" name="">
|
|
374 <list type="1" send_button='0' hide_title='0'>
|
|
375 <option value="" selected="" >Option Text I</option>
|
|
376 <option value="" selected="" >Option Text II</option>
|
|
377 </list>
|
|
378 </nodehandler>
|
|
379 """
|
|
380 def __init__(self,xml,tree_node):
|
|
381 node_handler.__init__(self,xml,tree_node)
|
|
382 self.list = self.xml.find('list')
|
|
383 self.options = self.list.findall('option')
|
|
384 if self.list.get("send_button") == "":
|
|
385 self.list.set("send_button","0")
|
|
386 if self.list.get("hide_title") == "":
|
|
387 self.list.set("hide_title","0")
|
|
388
|
|
389 def get_design_panel(self,parent):
|
|
390 return listbox_edit_panel(parent,self)
|
|
391
|
|
392 def get_use_panel(self,parent):
|
|
393 return listbox_panel(parent,self)
|
|
394
|
|
395 def get_type(self):
|
|
396 return int(self.list.get("type"))
|
|
397
|
|
398 def set_type(self,type):
|
|
399 self.list.set("type",str(type))
|
|
400
|
|
401 def is_hide_title(self):
|
|
402 return int(self.list.get("hide_title", 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":
|
|
414 return i
|
|
415 i += 1
|
|
416 return 0
|
|
417
|
|
418 def get_selected_text(self):
|
|
419 node = self.get_selected_node()
|
|
420 if node:
|
|
421 return node.text
|
|
422 else:
|
|
423 return ""
|
|
424
|
|
425
|
|
426 # mult selection methods
|
|
427 def get_selections(self):
|
|
428 opts = []
|
|
429 for opt in self.options:
|
|
430 if opt.get("selected") == "1":
|
|
431 opts.append(opt)
|
|
432 return opts
|
|
433
|
|
434 def get_selections_text(self):
|
|
435 opts = []
|
|
436 for opt in self.options:
|
|
437 if opt.get("selected") == "1":
|
|
438 opts.append(opt.text)
|
|
439 return opts
|
|
440
|
|
441 def get_selections_index(self):
|
|
442 opts = []
|
|
443 i = 0
|
|
444 for opt in self.options:
|
|
445 if opt.get("selected") == "1":
|
|
446 opts.append(i)
|
|
447 i += 1
|
|
448 return opts
|
|
449
|
|
450 # setting selection method
|
|
451 def set_selected_node(self,index,selected=1):
|
|
452 if self.get_type() != L_CHECK:
|
|
453 self.clear_selections()
|
|
454 self.options[index].set("selected", str(bool2int(selected)))
|
|
455
|
|
456 def clear_selections(self):
|
|
457 for opt in self.options:
|
|
458 opt.set("selected","0")
|
|
459
|
|
460 # misc methods
|
|
461 def get_options(self):
|
|
462 opts = []
|
132
|
463 for opt in self.options: opts.append(opt.text)
|
131
|
464 return opts
|
|
465
|
|
466 def get_option(self,index):
|
|
467 return self.options[index].text
|
|
468
|
|
469 def add_option(self,opt):
|
|
470 elem = Element('option')
|
|
471 elem.set("value","0")
|
|
472 elem.set("selected","0")
|
|
473 elem.text = opt
|
|
474 self.list.append(elem)
|
|
475 self.options = self.list.findall('option')
|
|
476
|
|
477 def remove_option(self,index):
|
|
478 self.list.remove(self.options[index])
|
|
479 self.options = self.list.findall('option')
|
|
480
|
|
481 def edit_option(self,index,value):
|
|
482 self.options[index].text = value
|
|
483
|
|
484 def has_send_button(self):
|
132
|
485 if self.list.get("send_button") == '0': return False
|
|
486 else: return True
|
131
|
487
|
|
488 def get_size_constraint(self):
|
132
|
489 if self.get_type() == L_DROP: return 0
|
|
490 else: return 1
|
131
|
491
|
|
492 def tohtml(self):
|
|
493 opts = self.get_selections_text()
|
|
494 text = ""
|
132
|
495 if not self.is_hide_title(): text = "<b>"+self.xml.get("name")+":</b> "
|
131
|
496 comma = ", "
|
|
497 text += comma.join(opts)
|
|
498 return text
|
|
499
|
|
500 def get_value(self):
|
|
501 return "\n".join(self.get_selections_text())
|
|
502
|
|
503
|
|
504 F_LIST = wx.NewId()
|
|
505 F_SEND = wx.NewId()
|
|
506
|
|
507
|
|
508 class listbox_panel(wx.Panel):
|
|
509 def __init__(self, parent, handler):
|
|
510 wx.Panel.__init__(self, parent, -1)
|
|
511 self.handler = handler
|
|
512 self.chat = handler.chat
|
|
513 opts = handler.get_options()
|
|
514 cur_opt = handler.get_selected_text()
|
|
515 type = handler.get_type()
|
|
516 label = handler.xml.get('name')
|
|
517
|
|
518 if type == L_DROP:
|
|
519 self.list = wx.ComboBox(self, F_LIST, cur_opt, choices=opts, style=wx.CB_READONLY)
|
|
520 if self.list.GetSize()[0] > 200:
|
|
521 self.list.Destroy()
|
|
522 self.list = wx.ComboBox(self, F_LIST, cur_opt, size=(200, -1), choices=opts, style=wx.CB_READONLY)
|
|
523 elif type == L_LIST:
|
|
524 self.list = wx.ListBox(self,F_LIST,choices=opts)
|
|
525 elif type == L_RADIO:
|
|
526 self.list = wx.RadioBox(self,F_LIST,label,choices=opts,majorDimension=3)
|
|
527 elif type == L_CHECK:
|
|
528 self.list = wx.CheckListBox(self,F_LIST,choices=opts)
|
|
529 self.set_checks()
|
|
530
|
|
531 for i in handler.get_selections_text():
|
|
532 if type == L_DROP:
|
|
533 self.list.SetValue( i )
|
|
534 else:
|
|
535 self.list.SetStringSelection( i )
|
|
536
|
|
537 if type == L_DROP:
|
|
538 sizer = wx.BoxSizer(wx.HORIZONTAL)
|
|
539
|
|
540 else:
|
|
541 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
|
|
547 sizer.Add(self.list, 1, wx.EXPAND)
|
|
548
|
|
549 if handler.has_send_button():
|
|
550 sizer.Add(wx.Button(self, F_SEND, "Send"), 0, wx.EXPAND)
|
|
551 self.Bind(wx.EVT_BUTTON, self.handler.on_send_to_chat, id=F_SEND)
|
|
552
|
|
553 self.sizer = sizer
|
|
554 self.SetSizer(sizer)
|
|
555 self.SetAutoLayout(True)
|
|
556 self.Fit()
|
|
557
|
|
558 parent.SetSize(self.GetBestSize())
|
|
559
|
|
560 if type == L_DROP:
|
|
561 self.Bind(wx.EVT_COMBOBOX, self.on_change, id=F_LIST)
|
|
562 elif type == L_LIST:
|
|
563 self.Bind(wx.EVT_LISTBOX, self.on_change, id=F_LIST)
|
|
564 elif type == L_RADIO:
|
|
565 self.Bind(wx.EVT_RADIOBOX, self.on_change, id=F_LIST)
|
|
566 elif type == L_CHECK:
|
|
567 self.Bind(wx.EVT_CHECKLISTBOX, self.on_check, id=F_LIST)
|
|
568
|
|
569
|
|
570 self.type = type
|
|
571
|
|
572
|
|
573 def on_change(self,evt):
|
|
574 self.handler.set_selected_node(self.list.GetSelection())
|
|
575
|
|
576 def on_check(self,evt):
|
|
577 for i in xrange(self.list.GetCount()):
|
|
578 self.handler.set_selected_node(i, bool2int(self.list.IsChecked(i)))
|
|
579
|
|
580 def set_checks(self):
|
|
581 for i in self.handler.get_selections_index():
|
|
582 self.list.Check(i)
|
|
583
|
|
584
|
|
585
|
|
586 BUT_ADD = wx.NewId()
|
|
587 BUT_REM = wx.NewId()
|
|
588 BUT_EDIT = wx.NewId()
|
|
589 F_TYPE = wx.NewId()
|
|
590 F_NO_TITLE = wx.NewId()
|
|
591
|
|
592 class listbox_edit_panel(wx.Panel):
|
|
593 def __init__(self, parent, handler):
|
|
594 wx.Panel.__init__(self, parent, -1)
|
|
595 self.handler = handler
|
|
596 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "List Box Properties"), wx.VERTICAL)
|
|
597
|
|
598 self.text = wx.TextCtrl(self, P_TITLE, handler.xml.get('name'))
|
|
599
|
|
600 opts = handler.get_options()
|
|
601 self.listbox = wx.ListBox(self, F_LIST, choices=opts, style=wx.LB_HSCROLL|wx.LB_SINGLE|wx.LB_NEEDED_SB)
|
|
602 opts = ['Drop Down', 'List Box', 'Radio Box', 'Check List']
|
|
603 self.type_radios = wx.RadioBox(self,F_TYPE,"List Type",choices=opts)
|
|
604 self.type_radios.SetSelection(handler.get_type())
|
|
605
|
|
606 self.send_button = wx.CheckBox(self, F_SEND_BUTTON, " Send Button")
|
|
607 self.send_button.SetValue(handler.has_send_button())
|
|
608
|
|
609 self.hide_title = wx.CheckBox(self, F_NO_TITLE, " Hide Title")
|
|
610 self.hide_title.SetValue(handler.is_hide_title())
|
|
611
|
|
612 but_sizer = wx.BoxSizer(wx.HORIZONTAL)
|
|
613 but_sizer.Add(wx.Button(self, BUT_ADD, "Add"), 1, wx.EXPAND)
|
|
614 but_sizer.Add(wx.Size(10,10))
|
|
615 but_sizer.Add(wx.Button(self, BUT_EDIT, "Edit"), 1, wx.EXPAND)
|
|
616 but_sizer.Add(wx.Size(10,10))
|
|
617 but_sizer.Add(wx.Button(self, BUT_REM, "Remove"), 1, wx.EXPAND)
|
|
618
|
|
619 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND)
|
|
620 sizer.Add(self.text, 0, wx.EXPAND)
|
|
621 sizer.Add(wx.Size(10,10))
|
|
622 sizer.Add(self.type_radios, 0, wx.EXPAND)
|
|
623 sizer.Add(wx.Size(10,10))
|
|
624 sizer.Add(self.send_button, 0 , wx.EXPAND)
|
|
625 sizer.Add(self.hide_title, 0, wx.EXPAND)
|
|
626 sizer.Add(wx.Size(10,10))
|
|
627 sizer.Add(wx.StaticText(self, -1, "Options:"), 0, wx.EXPAND)
|
|
628 sizer.Add(self.listbox,1,wx.EXPAND);
|
|
629 sizer.Add(but_sizer,0,wx.EXPAND)
|
|
630
|
|
631 self.SetSizer(sizer)
|
|
632 self.SetAutoLayout(True)
|
|
633 self.Fit()
|
|
634 parent.SetSize(self.GetBestSize())
|
|
635
|
|
636 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE)
|
|
637 self.Bind(wx.EVT_BUTTON, self.on_edit, id=BUT_EDIT)
|
|
638 self.Bind(wx.EVT_BUTTON, self.on_remove, id=BUT_REM)
|
|
639 self.Bind(wx.EVT_BUTTON, self.on_add, id=BUT_ADD)
|
|
640 self.Bind(wx.EVT_RADIOBOX, self.on_type, id=F_TYPE)
|
|
641 self.Bind(wx.EVT_CHECKBOX, self.on_hide_button, id=F_NO_TITLE)
|
|
642 self.Bind(wx.EVT_CHECKBOX, self.on_send_button, id=F_SEND_BUTTON)
|
|
643
|
|
644 def on_type(self,evt):
|
|
645 self.handler.set_type(evt.GetInt())
|
|
646
|
|
647 def on_add(self,evt):
|
|
648 dlg = wx.TextEntryDialog(self, 'Enter option?','Add Option', '')
|
|
649 if dlg.ShowModal() == wx.ID_OK:
|
|
650 self.handler.add_option(dlg.GetValue())
|
|
651 dlg.Destroy()
|
|
652 self.reload_options()
|
|
653
|
|
654 def on_remove(self,evt):
|
|
655 index = self.listbox.GetSelection()
|
|
656 if index >= 0:
|
|
657 self.handler.remove_option(index)
|
|
658 self.reload_options()
|
|
659
|
|
660 def on_edit(self,evt):
|
|
661 index = self.listbox.GetSelection()
|
|
662 if index >= 0:
|
|
663 txt = self.handler.get_option(index)
|
|
664 dlg = wx.TextEntryDialog(self, 'Enter option?','Edit Option', txt)
|
|
665 if dlg.ShowModal() == wx.ID_OK:
|
|
666 self.handler.edit_option(index,dlg.GetValue())
|
|
667 dlg.Destroy()
|
|
668 self.reload_options()
|
|
669
|
|
670 def reload_options(self):
|
|
671 self.listbox.Clear()
|
|
672 for opt in self.handler.get_options():
|
|
673 self.listbox.Append(opt)
|
|
674
|
|
675 def on_text(self,evt):
|
|
676 id = evt.GetId()
|
|
677 txt = self.text.GetValue()
|
|
678 if not len(txt): return
|
|
679 if id == P_TITLE:
|
|
680 self.handler.xml.set('name',txt)
|
|
681 self.handler.rename(txt)
|
|
682
|
|
683 def on_send_button(self,evt):
|
|
684 self.handler.list.set("send_button", str( bool2int(evt.Checked()) ))
|
|
685
|
|
686 def on_hide_button(self,evt):
|
|
687 self.handler.list.set("hide_title", str( bool2int(evt.Checked()) ))
|
|
688
|
|
689
|
|
690 ###############################
|
|
691 ## link image handlers
|
|
692 ###############################
|
|
693
|
|
694 class link_handler(node_handler):
|
|
695 """ A nodehandler for URLs. Will open URL in a wxHTMLFrame
|
|
696 <nodehandler name='?' module='forms' class='link_handler' >
|
|
697 <link href='http//??.??' />
|
|
698 </nodehandler >
|
|
699 """
|
|
700 def __init__(self,xml,tree_node):
|
|
701 node_handler.__init__(self,xml,tree_node)
|
|
702 self.link = self.xml[0]
|
|
703
|
|
704 def on_use(self,evt):
|
|
705 href = self.link.get("href")
|
|
706 wb = webbrowser.get()
|
|
707 wb.open(href)
|
|
708
|
|
709 def get_design_panel(self,parent):
|
|
710 return link_edit_panel(parent,self)
|
|
711
|
|
712 def get_use_panel(self,parent):
|
|
713 return link_panel(parent,self)
|
|
714
|
|
715 def tohtml(self):
|
|
716 href = self.link.get("href")
|
|
717 title = self.xml.get("name")
|
|
718 return "<a href=\""+href+"\" >"+title+"</a>"
|
|
719
|
|
720 class link_panel(wx.StaticText):
|
|
721 def __init__(self,parent,handler):
|
|
722 self.handler = handler
|
|
723 label = handler.xml.get('name')
|
|
724 wx.StaticText.__init__(self,parent,-1,label)
|
|
725 self.SetForegroundColour(wx.BLUE)
|
|
726 self.Bind(wx.EVT_LEFT_DOWN, self.handler.on_use)
|
|
727
|
|
728
|
|
729 P_URL = wx.NewId()
|
|
730
|
|
731 class link_edit_panel(wx.Panel):
|
|
732 def __init__(self, parent, handler):
|
|
733 wx.Panel.__init__(self, parent, -1)
|
|
734 self.handler = handler
|
|
735 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Link Properties"), wx.VERTICAL)
|
|
736
|
|
737 self.text = {}
|
|
738 self.text[P_TITLE] = wx.TextCtrl(self, P_TITLE, handler.xml.get('name'))
|
|
739 self.text[P_URL] = wx.TextCtrl(self, P_URL, handler.link.get('href'))
|
|
740
|
|
741 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND)
|
|
742 sizer.Add(self.text[P_TITLE], 0, wx.EXPAND)
|
|
743 sizer.Add(wx.Size(10,10))
|
|
744 sizer.Add(wx.StaticText(self, -1, "URL:"), 0, wx.EXPAND)
|
|
745 sizer.Add(self.text[P_URL], 0, wx.EXPAND)
|
|
746 self.SetSizer(sizer)
|
|
747 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE)
|
|
748 self.Bind(wx.EVT_TEXT, self.on_text, id=P_URL)
|
|
749
|
|
750 def on_text(self,evt):
|
|
751 id = evt.GetId()
|
|
752 txt = self.text[id].GetValue()
|
|
753 if not len(txt): return
|
|
754 if id == P_TITLE:
|
|
755 self.handler.xml.set('name',txt)
|
|
756 self.handler.rename(txt)
|
|
757 elif id == P_URL:
|
|
758 self.handler.link.set('href',txt)
|
|
759
|
|
760 ##########################
|
|
761 ## webimg node handler
|
|
762 ##########################
|
|
763 class webimg_handler(node_handler):
|
|
764 """ A nodehandler for URLs. Will open URL in a wxHTMLFrame
|
|
765 <nodehandler name='?' module='forms' class='webimg_handler' >
|
|
766 <link href='http//??.??' />
|
|
767 </nodehandler >
|
|
768 """
|
|
769 def __init__(self,xml,tree_node):
|
|
770 node_handler.__init__(self,xml,tree_node)
|
|
771 self.link = self.xml[0]
|
|
772
|
|
773 def get_design_panel(self,parent):
|
|
774 return link_edit_panel(parent,self)
|
|
775
|
|
776 def get_use_panel(self,parent):
|
|
777 img = img_helper().load_url(self.link.get("href"))
|
|
778 if not img is None:
|
|
779 return wx.StaticBitmap(parent,-1,img,size= wx.Size(img.GetWidth(),img.GetHeight()))
|
|
780 return wx.EmptyBitmap(1, 1)
|
|
781
|
|
782 def tohtml(self):
|
|
783 href = self.link.get("href")
|
|
784 title = self.xml.get("name")
|
|
785 return "<img src=\""+href+"\" alt="+title+" >"
|