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