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')
|
141
|
384 if self.list.get("send_button") == "": self.list.set("send_button","0")
|
|
385 if self.list.get("hide_title") == "": self.list.set("hide_title","0")
|
|
386 if self.list.get("raw_mode") == "": self.list.set("raw_mode","0")
|
131
|
387
|
|
388 def get_design_panel(self,parent):
|
|
389 return listbox_edit_panel(parent,self)
|
|
390
|
|
391 def get_use_panel(self,parent):
|
|
392 return listbox_panel(parent,self)
|
|
393
|
|
394 def get_type(self):
|
|
395 return int(self.list.get("type"))
|
|
396
|
|
397 def set_type(self,type):
|
|
398 self.list.set("type",str(type))
|
|
399
|
|
400 def is_hide_title(self):
|
141
|
401 return int(self.list.get("hide_title", 0))
|
|
402
|
|
403 def is_raw_send(self):
|
|
404 return int(self.list.get("raw_mode",0))
|
131
|
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:
|
141
|
415 if opt.get("selected") == "1": return i
|
131
|
416 i += 1
|
|
417 return 0
|
|
418
|
|
419 def get_selected_text(self):
|
|
420 node = self.get_selected_node()
|
141
|
421 if node: return node.text
|
|
422 else: return ""
|
131
|
423
|
|
424 # mult selection methods
|
|
425 def get_selections(self):
|
|
426 opts = []
|
|
427 for opt in self.options:
|
141
|
428 if opt.get("selected") == "1": opts.append(opt)
|
131
|
429 return opts
|
|
430
|
|
431 def get_selections_text(self):
|
|
432 opts = []
|
|
433 for opt in self.options:
|
141
|
434 if opt.get("selected") == "1": opts.append(opt.text)
|
131
|
435 return opts
|
|
436
|
|
437 def get_selections_index(self):
|
|
438 opts = []
|
|
439 i = 0
|
|
440 for opt in self.options:
|
141
|
441 if opt.get("selected") == "1": opts.append(i)
|
131
|
442 i += 1
|
|
443 return opts
|
|
444
|
|
445 # setting selection method
|
|
446 def set_selected_node(self,index,selected=1):
|
141
|
447 if self.get_type() != L_CHECK: self.clear_selections()
|
131
|
448 self.options[index].set("selected", str(bool2int(selected)))
|
|
449
|
|
450 def clear_selections(self):
|
141
|
451 for opt in self.options: opt.set("selected","0")
|
131
|
452
|
|
453 # misc methods
|
|
454 def get_options(self):
|
|
455 opts = []
|
132
|
456 for opt in self.options: opts.append(opt.text)
|
131
|
457 return opts
|
|
458
|
|
459 def get_option(self,index):
|
|
460 return self.options[index].text
|
|
461
|
|
462 def add_option(self,opt):
|
|
463 elem = Element('option')
|
|
464 elem.set("value","0")
|
|
465 elem.set("selected","0")
|
|
466 elem.text = opt
|
|
467 self.list.append(elem)
|
|
468 self.options = self.list.findall('option')
|
|
469
|
|
470 def remove_option(self,index):
|
|
471 self.list.remove(self.options[index])
|
|
472 self.options = self.list.findall('option')
|
|
473
|
|
474 def edit_option(self,index,value):
|
|
475 self.options[index].text = value
|
|
476
|
|
477 def has_send_button(self):
|
132
|
478 if self.list.get("send_button") == '0': return False
|
|
479 else: return True
|
131
|
480
|
|
481 def get_size_constraint(self):
|
132
|
482 if self.get_type() == L_DROP: return 0
|
|
483 else: return 1
|
131
|
484
|
|
485 def tohtml(self):
|
|
486 opts = self.get_selections_text()
|
|
487 text = ""
|
132
|
488 if not self.is_hide_title(): text = "<b>"+self.xml.get("name")+":</b> "
|
131
|
489 comma = ", "
|
|
490 text += comma.join(opts)
|
|
491 return text
|
|
492
|
|
493 def get_value(self):
|
141
|
494 return "\n".join(self.get_selections_text())
|
|
495
|
|
496 def on_send_to_chat(self, evt):
|
|
497 txt = self.get_selected_text()
|
|
498 txt = self.chat.ParseMap(txt, self.xml)
|
|
499 if not self.is_raw_send():
|
|
500 self.chat.ParsePost(self.tohtml(), True, True)
|
|
501 return 1
|
|
502 actionlist = self.get_selections_text()
|
|
503 for line in actionlist:
|
|
504 line = self.chat.ParseMap(line, self.xml)
|
|
505 if(line != ""):
|
|
506 if line[0] != "/": ## it's not a slash command
|
|
507 self.chat.ParsePost(line, True, True)
|
|
508 else:
|
|
509 action = line
|
|
510 self.chat.chat_cmds.docmd(action)
|
|
511 return 1
|
131
|
512
|
|
513
|
|
514 F_LIST = wx.NewId()
|
|
515 F_SEND = wx.NewId()
|
|
516
|
|
517
|
|
518 class listbox_panel(wx.Panel):
|
|
519 def __init__(self, parent, handler):
|
|
520 wx.Panel.__init__(self, parent, -1)
|
|
521 self.handler = handler
|
|
522 self.chat = handler.chat
|
|
523 opts = handler.get_options()
|
|
524 cur_opt = handler.get_selected_text()
|
|
525 type = handler.get_type()
|
|
526 label = handler.xml.get('name')
|
|
527
|
|
528 if type == L_DROP:
|
|
529 self.list = wx.ComboBox(self, F_LIST, cur_opt, choices=opts, style=wx.CB_READONLY)
|
|
530 if self.list.GetSize()[0] > 200:
|
|
531 self.list.Destroy()
|
|
532 self.list = wx.ComboBox(self, F_LIST, cur_opt, size=(200, -1), choices=opts, style=wx.CB_READONLY)
|
141
|
533 elif type == L_LIST: self.list = wx.ListBox(self,F_LIST,choices=opts)
|
|
534 elif type == L_RADIO: self.list = wx.RadioBox(self,F_LIST,label,choices=opts,majorDimension=3)
|
131
|
535 elif type == L_CHECK:
|
|
536 self.list = wx.CheckListBox(self,F_LIST,choices=opts)
|
|
537 self.set_checks()
|
|
538
|
|
539 for i in handler.get_selections_text():
|
141
|
540 if type == L_DROP: self.list.SetValue( i )
|
|
541 else: self.list.SetStringSelection( i )
|
|
542 if type == L_DROP: sizer = wx.BoxSizer(wx.HORIZONTAL)
|
|
543 else: sizer = wx.BoxSizer(wx.VERTICAL)
|
131
|
544
|
|
545 if type != L_RADIO:
|
|
546 sizer.Add(wx.StaticText(self, -1, label+": "), 0, wx.EXPAND)
|
|
547 sizer.Add(wx.Size(5,0))
|
|
548
|
|
549 sizer.Add(self.list, 1, wx.EXPAND)
|
|
550
|
|
551 if handler.has_send_button():
|
|
552 sizer.Add(wx.Button(self, F_SEND, "Send"), 0, wx.EXPAND)
|
|
553 self.Bind(wx.EVT_BUTTON, self.handler.on_send_to_chat, id=F_SEND)
|
|
554
|
|
555 self.sizer = sizer
|
|
556 self.SetSizer(sizer)
|
|
557 self.SetAutoLayout(True)
|
|
558 self.Fit()
|
|
559
|
|
560 parent.SetSize(self.GetBestSize())
|
|
561
|
141
|
562 if type == L_DROP: self.Bind(wx.EVT_COMBOBOX, self.on_change, id=F_LIST)
|
|
563 elif type == L_LIST: self.Bind(wx.EVT_LISTBOX, self.on_change, id=F_LIST)
|
|
564 elif type == L_RADIO: self.Bind(wx.EVT_RADIOBOX, self.on_change, id=F_LIST)
|
|
565 elif type == L_CHECK:self.Bind(wx.EVT_CHECKLISTBOX, self.on_check, id=F_LIST)
|
131
|
566 self.type = type
|
|
567
|
|
568 def on_change(self,evt):
|
|
569 self.handler.set_selected_node(self.list.GetSelection())
|
|
570
|
|
571 def on_check(self,evt):
|
141
|
572 for i in xrange(self.list.GetCount()): self.handler.set_selected_node(i, bool2int(self.list.IsChecked(i)))
|
131
|
573
|
|
574 def set_checks(self):
|
141
|
575 for i in self.handler.get_selections_index(): self.list.Check(i)
|
131
|
576
|
|
577
|
|
578 BUT_ADD = wx.NewId()
|
|
579 BUT_REM = wx.NewId()
|
|
580 BUT_EDIT = wx.NewId()
|
|
581 F_TYPE = wx.NewId()
|
|
582 F_NO_TITLE = wx.NewId()
|
|
583
|
|
584 class listbox_edit_panel(wx.Panel):
|
|
585 def __init__(self, parent, handler):
|
|
586 wx.Panel.__init__(self, parent, -1)
|
|
587 self.handler = handler
|
|
588 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "List Box Properties"), wx.VERTICAL)
|
|
589
|
|
590 self.text = wx.TextCtrl(self, P_TITLE, handler.xml.get('name'))
|
|
591
|
|
592 opts = handler.get_options()
|
|
593 self.listbox = wx.ListBox(self, F_LIST, choices=opts, style=wx.LB_HSCROLL|wx.LB_SINGLE|wx.LB_NEEDED_SB)
|
|
594 opts = ['Drop Down', 'List Box', 'Radio Box', 'Check List']
|
|
595 self.type_radios = wx.RadioBox(self,F_TYPE,"List Type",choices=opts)
|
|
596 self.type_radios.SetSelection(handler.get_type())
|
|
597
|
|
598 self.send_button = wx.CheckBox(self, F_SEND_BUTTON, " Send Button")
|
141
|
599 self.send_button.SetValue(handler.has_send_button())
|
|
600
|
|
601 self.raw_send = wx.CheckBox(self, F_RAW_SEND, " Send as Macro")
|
|
602 self.raw_send.SetValue(handler.is_raw_send())
|
131
|
603
|
|
604 self.hide_title = wx.CheckBox(self, F_NO_TITLE, " Hide Title")
|
|
605 self.hide_title.SetValue(handler.is_hide_title())
|
|
606
|
|
607 but_sizer = wx.BoxSizer(wx.HORIZONTAL)
|
|
608 but_sizer.Add(wx.Button(self, BUT_ADD, "Add"), 1, wx.EXPAND)
|
|
609 but_sizer.Add(wx.Size(10,10))
|
|
610 but_sizer.Add(wx.Button(self, BUT_EDIT, "Edit"), 1, wx.EXPAND)
|
|
611 but_sizer.Add(wx.Size(10,10))
|
|
612 but_sizer.Add(wx.Button(self, BUT_REM, "Remove"), 1, wx.EXPAND)
|
|
613
|
|
614 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND)
|
|
615 sizer.Add(self.text, 0, wx.EXPAND)
|
|
616 sizer.Add(wx.Size(10,10))
|
|
617 sizer.Add(self.type_radios, 0, wx.EXPAND)
|
|
618 sizer.Add(wx.Size(10,10))
|
|
619 sizer.Add(self.send_button, 0 , wx.EXPAND)
|
141
|
620 sizer.Add(self.hide_title, 0, wx.EXPAND)
|
|
621 sizer.Add(self.raw_send, 0, wx.EXPAND)
|
131
|
622 sizer.Add(wx.Size(10,10))
|
|
623 sizer.Add(wx.StaticText(self, -1, "Options:"), 0, wx.EXPAND)
|
|
624 sizer.Add(self.listbox,1,wx.EXPAND);
|
|
625 sizer.Add(but_sizer,0,wx.EXPAND)
|
|
626
|
|
627 self.SetSizer(sizer)
|
|
628 self.SetAutoLayout(True)
|
|
629 self.Fit()
|
|
630 parent.SetSize(self.GetBestSize())
|
|
631
|
|
632 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE)
|
|
633 self.Bind(wx.EVT_BUTTON, self.on_edit, id=BUT_EDIT)
|
|
634 self.Bind(wx.EVT_BUTTON, self.on_remove, id=BUT_REM)
|
|
635 self.Bind(wx.EVT_BUTTON, self.on_add, id=BUT_ADD)
|
|
636 self.Bind(wx.EVT_RADIOBOX, self.on_type, id=F_TYPE)
|
|
637 self.Bind(wx.EVT_CHECKBOX, self.on_hide_button, id=F_NO_TITLE)
|
141
|
638 self.Bind(wx.EVT_CHECKBOX, self.on_send_button, id=F_SEND_BUTTON)
|
|
639 self.Bind(wx.EVT_CHECKBOX, self.on_raw_button, id=F_RAW_SEND)
|
131
|
640
|
|
641 def on_type(self,evt):
|
|
642 self.handler.set_type(evt.GetInt())
|
|
643
|
|
644 def on_add(self,evt):
|
|
645 dlg = wx.TextEntryDialog(self, 'Enter option?','Add Option', '')
|
|
646 if dlg.ShowModal() == wx.ID_OK:
|
|
647 self.handler.add_option(dlg.GetValue())
|
|
648 dlg.Destroy()
|
|
649 self.reload_options()
|
|
650
|
|
651 def on_remove(self,evt):
|
|
652 index = self.listbox.GetSelection()
|
|
653 if index >= 0:
|
|
654 self.handler.remove_option(index)
|
|
655 self.reload_options()
|
|
656
|
|
657 def on_edit(self,evt):
|
|
658 index = self.listbox.GetSelection()
|
|
659 if index >= 0:
|
|
660 txt = self.handler.get_option(index)
|
|
661 dlg = wx.TextEntryDialog(self, 'Enter option?','Edit Option', txt)
|
|
662 if dlg.ShowModal() == wx.ID_OK:
|
|
663 self.handler.edit_option(index,dlg.GetValue())
|
|
664 dlg.Destroy()
|
|
665 self.reload_options()
|
|
666
|
|
667 def reload_options(self):
|
|
668 self.listbox.Clear()
|
|
669 for opt in self.handler.get_options():
|
|
670 self.listbox.Append(opt)
|
|
671
|
|
672 def on_text(self,evt):
|
|
673 id = evt.GetId()
|
|
674 txt = self.text.GetValue()
|
|
675 if not len(txt): return
|
|
676 if id == P_TITLE:
|
|
677 self.handler.xml.set('name',txt)
|
|
678 self.handler.rename(txt)
|
|
679
|
|
680 def on_send_button(self,evt):
|
|
681 self.handler.list.set("send_button", str( bool2int(evt.Checked()) ))
|
|
682
|
|
683 def on_hide_button(self,evt):
|
141
|
684 self.handler.list.set("hide_title", str( bool2int(evt.Checked()) ))
|
|
685
|
|
686 def on_raw_button(self,evt):
|
|
687 self.handler.list.set("raw_mode",str(bool2int(evt.Checked())))
|
131
|
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+" >"
|