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
|
173
|
35 from orpg.tools.settings import settings
|
155
|
36
|
|
37 def bool2int(b):
|
|
38 #in wxPython 2.5+, evt.Checked() returns True or False instead of 1.0 or 0.
|
|
39 #by running the results of that through this function, we convert it.
|
|
40 #if it was an int already, nothing changes. The difference between 1.0
|
|
41 #and 1, i.e. between ints and floats, is potentially dangerous when we
|
|
42 #use str() on it, but it seems to work fine right now.
|
|
43 if b: return 1
|
|
44 else: return 0
|
|
45
|
|
46 #################################
|
|
47 ## form container
|
|
48 #################################
|
|
49
|
|
50 class form_handler(container_handler):
|
|
51 """
|
|
52 <nodehandler name='?' module='forms' class='form_handler' >
|
|
53 <form width='100' height='100' />
|
|
54 </nodehandler>
|
|
55 """
|
|
56 def __init__(self,xml,tree_node):
|
|
57 container_handler.__init__(self, xml, tree_node)
|
|
58
|
|
59 def load_children(self):
|
|
60 self.atts = None
|
|
61 for child_xml in self.xml:
|
|
62 if child_xml.tag == "form": self.xml.remove(child_xml)
|
|
63 elif child_xml: self.tree.load_xml(child_xml, self.mytree_node)
|
|
64 if not self.xml.get('width'): self.xml.set('width', '400')
|
|
65 if not self.xml.get('height'): self.xml.set('height', '600')
|
|
66
|
|
67 def get_design_panel(self,parent):
|
|
68 return form_edit_panel(parent,self)
|
|
69
|
|
70 def get_use_panel(self,parent):
|
|
71 return form_panel(parent,self)
|
|
72
|
|
73 def on_drop(self,evt):
|
|
74 # make sure its a contorl node
|
|
75 container_handler.on_drop(self,evt)
|
|
76
|
|
77 class form_panel(ScrolledPanel):
|
|
78 def __init__(self, parent, handler):
|
|
79 ScrolledPanel.__init__(self, parent, wx.ID_ANY, style=wx.NO_BORDER|wx.VSCROLL|wx.HSCROLL)
|
|
80 self.height = int(handler.xml.get("height"))
|
|
81 self.width = int(handler.xml.get("width"))
|
|
82 self.SetSize((0,0))
|
|
83 self.handler = handler
|
|
84 self.parent = parent
|
|
85 self.main_sizer = wx.BoxSizer(wx.VERTICAL)
|
|
86 handler.tree.traverse(handler.mytree_node, self.create_child_wnd, None, False)
|
|
87 self.SetSizer(self.main_sizer)
|
|
88 self.SetAutoLayout(True)
|
|
89 self.SetupScrolling()
|
|
90 parent.SetSize(self.GetSize())
|
|
91 self.Fit()
|
|
92
|
|
93 def SetSize(self, xy):
|
|
94 (x, y) = self.GetSize()
|
|
95 (nx, ny) = xy
|
|
96 if x < nx:
|
|
97 x = nx+10
|
|
98 y += ny+11
|
|
99 ScrolledPanel.SetSize(self, (x, y))
|
|
100
|
|
101 def create_child_wnd(self, treenode, evt):
|
|
102 node = self.handler.tree.GetPyData(treenode)
|
|
103 panel = node.get_use_panel(self)
|
|
104 size = node.get_size_constraint()
|
|
105 if panel:
|
|
106 self.main_sizer.Add(panel, size, wx.EXPAND)
|
|
107 self.main_sizer.Add(wx.Size(10,10))
|
|
108
|
|
109 F_HEIGHT = wx.NewId()
|
|
110 F_WIDTH = wx.NewId()
|
|
111 class form_edit_panel(wx.Panel):
|
|
112 def __init__(self, parent, handler):
|
|
113 wx.Panel.__init__(self, parent, -1)
|
|
114 self.handler = handler
|
|
115 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Form Properties"), wx.VERTICAL)
|
|
116 wh_sizer = wx.BoxSizer(wx.HORIZONTAL)
|
|
117 self.text = { P_TITLE : wx.TextCtrl(self, P_TITLE, handler.xml.get('name')),
|
|
118 F_HEIGHT : wx.TextCtrl(self, F_HEIGHT, handler.xml.get('height')),
|
|
119 F_WIDTH : wx.TextCtrl(self, F_WIDTH, handler.xml.get('width'))
|
|
120 }
|
|
121
|
|
122 wh_sizer.Add(wx.StaticText(self, -1, "Width:"), 0, wx.ALIGN_CENTER)
|
|
123 wh_sizer.Add(wx.Size(10,10))
|
|
124 wh_sizer.Add(self.text[F_WIDTH], 0, wx.EXPAND)
|
|
125 wh_sizer.Add(wx.Size(10,10))
|
|
126 wh_sizer.Add(wx.StaticText(self, -1, "Height:"), 0, wx.ALIGN_CENTER)
|
|
127 wh_sizer.Add(wx.Size(10,10))
|
|
128 wh_sizer.Add(self.text[F_HEIGHT], 0, wx.EXPAND)
|
|
129
|
|
130 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND)
|
|
131 sizer.Add(self.text[P_TITLE], 0, wx.EXPAND)
|
|
132 sizer.Add(wx.Size(10,10))
|
|
133 sizer.Add(wh_sizer,0,wx.EXPAND)
|
|
134
|
|
135 self.SetSizer(sizer)
|
|
136 self.SetAutoLayout(True)
|
|
137 self.Fit()
|
|
138 parent.SetSize(self.GetBestSize())
|
|
139
|
|
140 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE)
|
|
141 self.Bind(wx.EVT_TEXT, self.on_text, id=F_HEIGHT)
|
|
142 self.Bind(wx.EVT_TEXT, self.on_text, id=F_WIDTH)
|
|
143
|
|
144 def on_text(self,evt):
|
|
145 id = evt.GetId()
|
|
146 txt = self.text[id].GetValue()
|
|
147 if not len(txt): return
|
|
148 if id == P_TITLE:
|
|
149 self.handler.xml.set('name',txt)
|
|
150 self.handler.rename(txt)
|
|
151 elif id == F_HEIGHT or id == F_WIDTH:
|
|
152 try: int(txt)
|
|
153 except: return 0
|
|
154 if id == F_HEIGHT: self.handler.xml.set("height",txt)
|
|
155 elif id == F_WIDTH: self.handler.xml.set("width",txt)
|
|
156
|
|
157 ##########################
|
|
158 ## control handler
|
|
159 ##########################
|
|
160 class control_handler(node_handler):
|
|
161 """ A nodehandler for form controls.
|
|
162 <nodehandler name='?' module='forms' class='control_handler' />
|
|
163 """
|
|
164 def __init__(self, xml, tree_node):
|
|
165 node_handler.__init__(self, xml, tree_node)
|
|
166
|
|
167 def get_size_constraint(self):
|
|
168 return 0
|
|
169
|
|
170 ##########################
|
|
171 ## textctrl handler
|
|
172 ##########################
|
|
173 #
|
|
174 # Updated by Snowdog (April 2003)
|
|
175 # Now includes Raw Send Mode (like the chat macro uses)
|
|
176 # and an option to remove the title from text when sent
|
|
177 # to the chat in the normal non-chat macro mode.
|
|
178 #
|
|
179 class textctrl_handler(node_handler):
|
|
180 """ <nodehandler class="textctrl_handler" module="form" name="">
|
|
181 <text multiline='0' send_button='0' raw_mode='0' hide_title='0'>Text In Node</text>
|
|
182 </nodehandler>
|
|
183 """
|
|
184 def __init__(self,xml,tree_node):
|
|
185 node_handler.__init__(self,xml,tree_node)
|
|
186 self.text_elem = self.xml.find('text')
|
|
187 if self.text_elem.get("send_button") == "": self.text_elem.set("send_button","0")
|
|
188 if self.text_elem.get("raw_mode") == "": self.text_elem.set("raw_mode","0")
|
|
189 if self.text_elem.get("hide_title") == "": self.text_elem.set("hide_title","0")
|
|
190
|
|
191 def get_design_panel(self,parent):
|
|
192 return textctrl_edit_panel(parent,self)
|
|
193
|
|
194 def get_use_panel(self,parent):
|
|
195 return text_panel(parent,self)
|
|
196
|
|
197 def get_size_constraint(self):
|
|
198 return int(self.text_elem.get("multiline",0))
|
|
199
|
|
200 def is_multi_line(self):
|
|
201 return int(self.text_elem.get("multiline",0))
|
|
202
|
|
203 def is_raw_send(self):
|
|
204 return int(self.text_elem.get("raw_mode",0))
|
|
205
|
|
206 def is_hide_title(self):
|
|
207 return int(self.text_elem.get("hide_title",0))
|
|
208
|
|
209 def has_send_button(self):
|
|
210 return int(self.text_elem.get("send_button",0))
|
|
211
|
|
212 def tohtml(self):
|
|
213 txt = self.get_value()
|
|
214 txt = string.replace(txt,'\n',"<br />")
|
|
215 if not self.is_hide_title(): 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(): sizer.Add(wx.Button(self, FORM_SEND_BUTTON, "Send"), 0, sizer_style)
|
|
249
|
|
250 self.sizer = sizer
|
|
251 self.SetSizer(sizer)
|
|
252 self.SetAutoLayout(True)
|
|
253
|
|
254 parent.SetSize(self.GetBestSize())
|
|
255 self.Bind(wx.EVT_TEXT, self.on_text, id=FORM_TEXT_CTRL)
|
132
|
256 self.Bind(wx.EVT_BUTTON, self.on_send, id=FORM_SEND_BUTTON)
|
|
257
|
|
258 def on_text(self, evt):
|
155
|
259 debug()
|
|
260 txt = self.text.GetValue()
|
|
261 #txt = strip_text(txt) ##Does not seem to exist.
|
|
262 self.handler.text_elem.text = txt
|
|
263
|
|
264 def on_send(self, evt):
|
132
|
265 txt = self.text.GetValue()
|
|
266 txt = self.chat.ParseMap(txt, self.handler.xml)
|
155
|
267 if not self.handler.is_raw_send():
|
|
268 self.chat.ParsePost(self.handler.tohtml(), True, True)
|
|
269 return 1
|
|
270 actionlist = txt.split("\n")
|
|
271 for line in actionlist:
|
|
272 if(line != ""):
|
|
273 if line[0] != "/": ## it's not a slash command
|
|
274 self.chat.ParsePost(line, True, True)
|
|
275 else:
|
|
276 action = line
|
|
277 self.chat.chat_cmds.docmd(action)
|
|
278 return 1
|
|
279
|
|
280 F_MULTI = wx.NewId()
|
|
281 F_SEND_BUTTON = wx.NewId()
|
|
282 F_RAW_SEND = wx.NewId()
|
|
283 F_HIDE_TITLE = wx.NewId()
|
|
284 F_TEXT = wx.NewId()
|
173
|
285 T_BUT_REF = wx.NewId()
|
155
|
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())
|
173
|
302 button_ref = wx.Button(self, T_BUT_REF, "Reference")
|
155
|
303
|
|
304 sizer.Add(wx.StaticText(self, P_TITLE, "Title:"), 0, wx.EXPAND)
|
|
305 sizer.Add(self.title, 0, wx.EXPAND)
|
|
306 sizer.Add(wx.Size(10,10))
|
|
307 sizer.Add(self.multi, 0, wx.EXPAND)
|
|
308 sizer.Add(self.raw_send, 0, wx.EXPAND)
|
|
309 sizer.Add(self.hide_title, 0, wx.EXPAND)
|
|
310 sizer.Add(self.send_button, 0 , wx.EXPAND)
|
173
|
311 sizer.Add(button_ref, 0)
|
155
|
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)
|
173
|
333 self.Bind(wx.EVT_BUTTON, self.on_reference, id=T_BUT_REF)
|
|
334
|
|
335 ## EZ_Tree Core TaS - Prof.Ebral ##
|
|
336 def on_reference(self, evt, car=None):
|
|
337 self.do_tree = wx.Frame(self, -1, 'Tree')
|
|
338 self.ez_tree = orpg.gametree.gametree
|
|
339 self.temp_wnd = self.ez_tree.game_tree(self.do_tree, self.ez_tree.EZ_REF)
|
|
340 self.temp_wnd.Bind(wx.EVT_LEFT_DCLICK, self.on_ldclick)
|
|
341 self.temp_wnd.load_tree(settings.get("gametree"))
|
|
342 self.do_tree.Show()
|
|
343
|
|
344 def on_ldclick(self, evt):
|
|
345 self.rename_flag = 0
|
|
346 pt = evt.GetPosition()
|
|
347 (item, flag) = self.temp_wnd.HitTest(pt)
|
|
348 if item.IsOk():
|
|
349 obj = self.temp_wnd.GetPyData(item)
|
|
350 self.temp_wnd.SelectItem(item)
|
|
351 start = self.handler.xml.get('map').split('::')
|
|
352 end = obj.xml.get('map').split('::')
|
174
|
353 if obj.xml.get('class') != 'rpg_grid_handler' or obj.xml.get('class') != 'textctrl_handler': do = 'None'
|
|
354 elif end[0] == '' or start[0] != end[0]: do = 'Root'
|
|
355 elif start == end: do = 'Child'
|
|
356 elif start != end: do = 'Parent'
|
|
357 if do == 'Root':
|
|
358 complete = "!@"
|
|
359 for e in end:
|
|
360 if e != '': complete += e +'::'
|
|
361 complete = complete + obj.xml.get('name') + '@!'
|
|
362 elif do == 'Parent':
|
|
363 while start[0] == end[0]:
|
|
364 top = start[0]
|
|
365 del end[0], start[0]
|
|
366 if len(start) == 0 or len(end) == 0: break
|
|
367 complete = "!#" + top + "::"
|
|
368 for e in end: complete += e +'::'
|
|
369 complete = complete + obj.xml.get('name') + '#!'
|
|
370 elif do == 'Child':
|
|
371 while start[0] == end[0]:
|
|
372 del end[0], start[0]
|
|
373 if len(start) == 0 or len(end) == 0: break
|
|
374 complete = "!!"
|
|
375 for e in end: complete += e +'::'
|
|
376 complete = complete + obj.xml.get('name') + '!!'
|
|
377 if do != 'None': self.text.AppendText(complete); self.on_text(evt)
|
173
|
378 self.do_tree.Destroy()
|
174
|
379 if do == 'None':
|
|
380 wx.MessageBox('Invalid Reference', 'Error')
|
173
|
381 ##### #####
|
155
|
382
|
|
383 def on_text(self,evt):
|
|
384 id = evt.GetId()
|
|
385 if id == P_TITLE:
|
|
386 txt = self.title.GetValue()
|
|
387 if not len(txt): return
|
|
388 self.handler.xml.set('name',txt)
|
|
389 self.handler.rename(txt)
|
|
390 if id == F_TEXT:
|
|
391 txt = self.text.GetValue()
|
|
392 #txt = strip_text(txt) ##Does not seem to exist.
|
|
393 self.handler.text_elem.text = txt
|
|
394
|
|
395 def on_button(self,evt):
|
|
396 self.handler.text_elem.set("multiline",str(bool2int(evt.Checked())))
|
|
397
|
|
398 def on_raw_button(self,evt):
|
|
399 self.handler.text_elem.set("raw_mode",str(bool2int(evt.Checked())))
|
|
400
|
|
401 def on_hide_button(self,evt):
|
|
402 self.handler.text_elem.set("hide_title",str(bool2int(evt.Checked())))
|
|
403
|
|
404 def on_send_button(self,evt):
|
|
405 self.handler.text_elem.set("send_button",str(bool2int(evt.Checked())))
|
|
406
|
|
407
|
|
408 #######################
|
|
409 ## listbox handler
|
|
410 #######################
|
|
411 #
|
|
412 # Updated by Snowdog (April 2003)
|
|
413 # Now includesan option to remove the title from
|
|
414 # text when sent to the chat.
|
|
415 #
|
|
416 L_DROP = 0
|
|
417 L_LIST = 1
|
|
418 L_RADIO = 2
|
|
419 L_CHECK = 3
|
|
420 L_ROLLER = 4
|
|
421
|
|
422 class listbox_handler(node_handler):
|
|
423 """
|
|
424 <nodehandler class="listbox_handler" module="forms" name="">
|
|
425 <list type="1" send_button='0' hide_title='0'>
|
|
426 <option value="" selected="" >Option Text I</option>
|
|
427 <option value="" selected="" >Option Text II</option>
|
|
428 </list>
|
|
429 </nodehandler>
|
|
430 """
|
|
431 def __init__(self,xml,tree_node):
|
|
432 node_handler.__init__(self,xml,tree_node)
|
173
|
433 self.list_reload()
|
|
434 #print xml
|
|
435 #print self.tree.GetItemParent(tree_node)
|
155
|
436 if self.list.get("send_button") == "": self.list.set("send_button","0")
|
141
|
437 if self.list.get("hide_title") == "": self.list.set("hide_title","0")
|
155
|
438 if self.list.get("raw_mode") == "": self.list.set("raw_mode","0")
|
|
439
|
173
|
440 def list_reload(self):
|
|
441 self.list = self.xml.find('list')
|
|
442 self.options = self.list.findall('option')
|
|
443 self.captions = []
|
|
444 for opt in self.options:
|
|
445 if opt.get('caption') == None: opt.set('caption', '')
|
|
446 self.captions.append(opt.get('caption'))
|
|
447
|
155
|
448 def get_design_panel(self,parent):
|
|
449 return listbox_edit_panel(parent,self)
|
|
450
|
|
451 def get_use_panel(self,parent):
|
|
452 return listbox_panel(parent,self)
|
|
453
|
|
454 def get_type(self):
|
|
455 return int(self.list.get("type"))
|
|
456
|
|
457 def set_type(self,type):
|
|
458 self.list.set("type",str(type))
|
|
459
|
|
460 def is_hide_title(self):
|
141
|
461 return int(self.list.get("hide_title", 0))
|
|
462
|
155
|
463 def is_raw_send(self):
|
|
464 return int(self.list.get("raw_mode",0))
|
|
465
|
|
466 # single selection methods
|
|
467 def get_selected_node(self):
|
|
468 for opt in self.options:
|
|
469 if opt.get("selected") == "1": return opt
|
|
470 return None
|
|
471
|
|
472 def get_selected_index(self):
|
|
473 i = 0
|
|
474 for opt in self.options:
|
|
475 if opt.get("selected") == "1": return i
|
|
476 i += 1
|
|
477 return 0
|
|
478
|
|
479 def get_selected_text(self):
|
|
480 node = self.get_selected_node()
|
|
481 if node: return node.text
|
|
482 else: return ""
|
|
483
|
|
484 # mult selection methods
|
|
485 def get_selections(self):
|
|
486 opts = []
|
|
487 for opt in self.options:
|
|
488 if opt.get("selected") == "1": opts.append(opt)
|
|
489 return opts
|
|
490
|
|
491 def get_selections_text(self):
|
|
492 opts = []
|
|
493 for opt in self.options:
|
|
494 if opt.get("selected") == "1": opts.append(opt.text)
|
|
495 return opts
|
|
496
|
|
497 def get_selections_index(self):
|
|
498 opts = []
|
|
499 i = 0
|
|
500 for opt in self.options:
|
|
501 if opt.get("selected") == "1": opts.append(i)
|
|
502 i += 1
|
|
503 return opts
|
|
504
|
|
505 # setting selection method
|
|
506 def set_selected_node(self,index,selected=1):
|
|
507 if self.get_type() != L_CHECK: self.clear_selections()
|
|
508 self.options[index].set("selected", str(bool2int(selected)))
|
|
509
|
|
510 def clear_selections(self):
|
|
511 for opt in self.options: opt.set("selected","0")
|
|
512
|
|
513 # misc methods
|
|
514 def get_options(self):
|
|
515 opts = []
|
|
516 for opt in self.options: opts.append(opt.text)
|
|
517 return opts
|
|
518
|
173
|
519 def get_captions(self):
|
|
520 captions = []
|
|
521 for opt in self.options: captions.append(opt.get("caption"))
|
|
522 self.captions = captions
|
|
523 return captions
|
|
524
|
|
525 def get_option(self, index):
|
155
|
526 return self.options[index].text
|
|
527
|
173
|
528 def get_caption(self, index):
|
|
529 captions = self.get_captions()
|
|
530 return captions[index] or ''
|
|
531
|
|
532 def add_option(self, caption, value):
|
155
|
533 elem = Element('option')
|
|
534 elem.set("value","0")
|
173
|
535 elem.set('caption', caption)
|
155
|
536 elem.set("selected","0")
|
173
|
537 elem.text = value
|
155
|
538 self.list.append(elem)
|
173
|
539 self.list_reload()
|
155
|
540
|
|
541 def remove_option(self,index):
|
|
542 self.list.remove(self.options[index])
|
173
|
543 self.list_reload()
|
155
|
544
|
173
|
545 def edit_option(self, index, value):
|
155
|
546 self.options[index].text = value
|
|
547
|
173
|
548 def edit_caption(self, index, value):
|
|
549 self.options[index].set('caption', value)
|
|
550 self.captions[index] = value
|
|
551
|
155
|
552 def has_send_button(self):
|
|
553 if self.list.get("send_button") == '0': return False
|
|
554 else: return True
|
|
555
|
|
556 def get_size_constraint(self):
|
|
557 if self.get_type() == L_DROP: return 0
|
|
558 else: return 1
|
|
559
|
|
560 def tohtml(self):
|
|
561 opts = self.get_selections_text()
|
|
562 text = ""
|
|
563 if not self.is_hide_title(): text = "<b>"+self.xml.get("name")+":</b> "
|
|
564 comma = ", "
|
|
565 text += comma.join(opts)
|
|
566 return text
|
|
567
|
|
568 def get_value(self):
|
141
|
569 return "\n".join(self.get_selections_text())
|
|
570
|
155
|
571 def on_send_to_chat(self, evt):
|
141
|
572 txt = self.get_selected_text()
|
|
573 txt = self.chat.ParseMap(txt, self.xml)
|
155
|
574 if not self.is_raw_send():
|
|
575 self.chat.ParsePost(self.tohtml(), True, True)
|
|
576 return 1
|
|
577 actionlist = self.get_selections_text()
|
141
|
578 for line in actionlist:
|
155
|
579 line = self.chat.ParseMap(line, self.xml)
|
|
580 if(line != ""):
|
|
581 if line[0] != "/": ## it's not a slash command
|
|
582 self.chat.ParsePost(line, True, True)
|
|
583 else:
|
|
584 action = line
|
|
585 self.chat.chat_cmds.docmd(action)
|
|
586 return 1
|
|
587
|
|
588
|
|
589 F_LIST = wx.NewId()
|
|
590 F_SEND = wx.NewId()
|
|
591
|
|
592
|
|
593 class listbox_panel(wx.Panel):
|
|
594 def __init__(self, parent, handler):
|
|
595 wx.Panel.__init__(self, parent, -1)
|
|
596 self.handler = handler
|
|
597 self.chat = handler.chat
|
173
|
598 opts = []
|
|
599 values = handler.get_options()
|
|
600 captions = handler.get_captions()
|
|
601 for value in values:
|
|
602 if captions[values.index(value)] != '': opts.append(captions[values.index(value)])
|
|
603 else: opts.append(value)
|
155
|
604 cur_opt = handler.get_selected_text()
|
|
605 type = handler.get_type()
|
|
606 label = handler.xml.get('name')
|
|
607
|
|
608 if type == L_DROP:
|
|
609 self.list = wx.ComboBox(self, F_LIST, cur_opt, choices=opts, style=wx.CB_READONLY)
|
|
610 if self.list.GetSize()[0] > 200:
|
|
611 self.list.Destroy()
|
|
612 self.list = wx.ComboBox(self, F_LIST, cur_opt, size=(200, -1), choices=opts, style=wx.CB_READONLY)
|
|
613 elif type == L_LIST: self.list = wx.ListBox(self,F_LIST,choices=opts)
|
|
614 elif type == L_RADIO: self.list = wx.RadioBox(self,F_LIST,label,choices=opts,majorDimension=3)
|
|
615 elif type == L_CHECK:
|
|
616 self.list = wx.CheckListBox(self,F_LIST,choices=opts)
|
|
617 self.set_checks()
|
|
618
|
|
619 for i in handler.get_selections_text():
|
|
620 if type == L_DROP: self.list.SetValue( i )
|
|
621 else: self.list.SetStringSelection( i )
|
|
622 if type == L_DROP: sizer = wx.BoxSizer(wx.HORIZONTAL)
|
|
623 else: sizer = wx.BoxSizer(wx.VERTICAL)
|
|
624
|
|
625 if type != L_RADIO:
|
|
626 sizer.Add(wx.StaticText(self, -1, label+": "), 0, wx.EXPAND)
|
|
627 sizer.Add(wx.Size(5,0))
|
|
628 sizer.Add(self.list, 1, wx.EXPAND)
|
|
629 if handler.has_send_button():
|
|
630 sizer.Add(wx.Button(self, F_SEND, "Send"), 0, wx.EXPAND)
|
|
631 self.Bind(wx.EVT_BUTTON, self.handler.on_send_to_chat, id=F_SEND)
|
|
632 self.sizer = sizer
|
|
633 self.SetSizer(sizer)
|
|
634 self.SetAutoLayout(True)
|
|
635 self.Fit()
|
|
636 parent.SetSize(self.GetBestSize())
|
|
637
|
|
638 if type == L_DROP: self.Bind(wx.EVT_COMBOBOX, self.on_change, id=F_LIST)
|
|
639 elif type == L_LIST: self.Bind(wx.EVT_LISTBOX, self.on_change, id=F_LIST)
|
|
640 elif type == L_RADIO: self.Bind(wx.EVT_RADIOBOX, self.on_change, id=F_LIST)
|
|
641 elif type == L_CHECK:self.Bind(wx.EVT_CHECKLISTBOX, self.on_check, id=F_LIST)
|
|
642 self.type = type
|
|
643
|
|
644 def on_change(self,evt):
|
|
645 self.handler.set_selected_node(self.list.GetSelection())
|
|
646
|
|
647 def on_check(self,evt):
|
141
|
648 for i in xrange(self.list.GetCount()): self.handler.set_selected_node(i, bool2int(self.list.IsChecked(i)))
|
155
|
649
|
|
650 def set_checks(self):
|
|
651 for i in self.handler.get_selections_index(): self.list.Check(i)
|
|
652
|
|
653
|
|
654 BUT_ADD = wx.NewId()
|
|
655 BUT_REM = wx.NewId()
|
173
|
656 BUT_REF = wx.NewId()
|
155
|
657 BUT_EDIT = wx.NewId()
|
|
658 F_TYPE = wx.NewId()
|
|
659 F_NO_TITLE = wx.NewId()
|
173
|
660 LIST_CTRL = wx.NewId()
|
155
|
661
|
|
662 class listbox_edit_panel(wx.Panel):
|
|
663 def __init__(self, parent, handler):
|
|
664 wx.Panel.__init__(self, parent, -1)
|
|
665 self.handler = handler
|
173
|
666 self.parent = parent
|
155
|
667 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "List Box Properties"), wx.VERTICAL)
|
|
668
|
|
669 self.text = wx.TextCtrl(self, P_TITLE, handler.xml.get('name'))
|
|
670
|
173
|
671 self.listbox = wx.ListCtrl(self, LIST_CTRL, style=wx.LC_REPORT)
|
|
672 self.listbox.InsertColumn(0, 'Caption')
|
|
673 self.listbox.InsertColumn(1, 'Value')
|
|
674 self.listbox.SetColumnWidth(0, 75)
|
|
675 self.listbox.SetColumnWidth(1, 300)
|
|
676 self.reload_options()
|
|
677
|
155
|
678 opts = ['Drop Down', 'List Box', 'Radio Box', 'Check List']
|
|
679 self.type_radios = wx.RadioBox(self,F_TYPE,"List Type",choices=opts)
|
|
680 self.type_radios.SetSelection(handler.get_type())
|
|
681
|
|
682 self.send_button = wx.CheckBox(self, F_SEND_BUTTON, " Send Button")
|
141
|
683 self.send_button.SetValue(handler.has_send_button())
|
|
684
|
155
|
685 self.raw_send = wx.CheckBox(self, F_RAW_SEND, " Send as Macro")
|
|
686 self.raw_send.SetValue(handler.is_raw_send())
|
|
687
|
|
688 self.hide_title = wx.CheckBox(self, F_NO_TITLE, " Hide Title")
|
|
689 self.hide_title.SetValue(handler.is_hide_title())
|
|
690
|
|
691 but_sizer = wx.BoxSizer(wx.HORIZONTAL)
|
|
692 but_sizer.Add(wx.Button(self, BUT_ADD, "Add"), 1, wx.EXPAND)
|
|
693 but_sizer.Add(wx.Size(10,10))
|
|
694 but_sizer.Add(wx.Button(self, BUT_EDIT, "Edit"), 1, wx.EXPAND)
|
|
695 but_sizer.Add(wx.Size(10,10))
|
|
696 but_sizer.Add(wx.Button(self, BUT_REM, "Remove"), 1, wx.EXPAND)
|
|
697
|
|
698 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND)
|
|
699 sizer.Add(self.text, 0, wx.EXPAND)
|
|
700 sizer.Add(wx.Size(10,10))
|
|
701 sizer.Add(self.type_radios, 0, wx.EXPAND)
|
|
702 sizer.Add(wx.Size(10,10))
|
|
703 sizer.Add(self.send_button, 0 , wx.EXPAND)
|
141
|
704 sizer.Add(self.hide_title, 0, wx.EXPAND)
|
155
|
705 sizer.Add(self.raw_send, 0, wx.EXPAND)
|
|
706 sizer.Add(wx.Size(10,10))
|
|
707 sizer.Add(wx.StaticText(self, -1, "Options:"), 0, wx.EXPAND)
|
|
708 sizer.Add(self.listbox,1,wx.EXPAND);
|
|
709 sizer.Add(but_sizer,0,wx.EXPAND)
|
|
710
|
|
711 self.SetSizer(sizer)
|
|
712 self.SetAutoLayout(True)
|
|
713 self.Fit()
|
|
714 parent.SetSize(self.GetBestSize())
|
|
715
|
|
716 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE)
|
|
717 self.Bind(wx.EVT_BUTTON, self.on_edit, id=BUT_EDIT)
|
|
718 self.Bind(wx.EVT_BUTTON, self.on_remove, id=BUT_REM)
|
|
719 self.Bind(wx.EVT_BUTTON, self.on_add, id=BUT_ADD)
|
|
720 self.Bind(wx.EVT_RADIOBOX, self.on_type, id=F_TYPE)
|
|
721 self.Bind(wx.EVT_CHECKBOX, self.on_hide_button, id=F_NO_TITLE)
|
141
|
722 self.Bind(wx.EVT_CHECKBOX, self.on_send_button, id=F_SEND_BUTTON)
|
155
|
723 self.Bind(wx.EVT_CHECKBOX, self.on_raw_button, id=F_RAW_SEND)
|
|
724
|
|
725 def on_type(self,evt):
|
|
726 self.handler.set_type(evt.GetInt())
|
|
727
|
|
728 def on_add(self,evt):
|
173
|
729 self.dlg = wx.Frame(self, -1, 'Text', size=(300,150))
|
|
730 edit_panel = wx.Panel(self.dlg, -1)
|
|
731 sizer = wx.GridBagSizer(1, 2)
|
|
732 edit_panel.SetSizer(sizer)
|
|
733 caption_text = wx.StaticText(edit_panel, -1, 'Caption')
|
|
734 self.caption_entry = wx.TextCtrl(edit_panel, -1, '')
|
|
735 value_text = wx.StaticText(edit_panel, -1, 'Value')
|
|
736 self.value_entry = wx.TextCtrl(edit_panel, -1, '')
|
|
737 button_ok = wx.Button(edit_panel, wx.ID_OK)
|
|
738 button_cancel = wx.Button(edit_panel, wx.ID_CANCEL)
|
|
739 button_ref = wx.Button(edit_panel, BUT_REF, "Reference")
|
|
740 sizer.Add(caption_text, (0,0))
|
|
741 sizer.Add(self.caption_entry, (0,1), span=(1,3), flag=wx.EXPAND)
|
|
742 sizer.Add(value_text, (1,0))
|
|
743 sizer.Add(self.value_entry, (1,1), span=(1,3), flag=wx.EXPAND)
|
|
744 sizer.Add(button_ok, (3,0))
|
|
745 sizer.Add(button_cancel, (3,1))
|
|
746 sizer.Add(button_ref, (3,2), flag=wx.EXPAND)
|
|
747 self.Bind(wx.EVT_BUTTON, self.on_reference, id=BUT_REF)
|
|
748 self.Bind(wx.EVT_BUTTON, self.on_add_option, id=wx.ID_OK)
|
|
749 self.Bind(wx.EVT_BUTTON, self.on_edit_cancel, id=wx.ID_CANCEL)
|
|
750 self.dlg.Show()
|
|
751
|
|
752 def on_add_option(self, evt):
|
|
753 self.handler.add_option(self.caption_entry.GetValue(), self.value_entry.GetValue())
|
155
|
754 self.reload_options()
|
173
|
755 self.dlg.Destroy()
|
|
756 return
|
|
757
|
|
758 ## EZ_Tree Core TaS - Prof.Ebral ##
|
|
759 def on_reference(self, evt, car=None):
|
|
760 self.do_tree = wx.Frame(self, -1, 'Tree')
|
|
761 self.ez_tree = orpg.gametree.gametree
|
|
762 self.temp_wnd = self.ez_tree.game_tree(self.do_tree, self.ez_tree.EZ_REF)
|
|
763 self.temp_wnd.Bind(wx.EVT_LEFT_DCLICK, self.on_ldclick)
|
|
764 self.temp_wnd.load_tree(settings.get("gametree"))
|
|
765 self.do_tree.Show()
|
|
766
|
|
767 def on_ldclick(self, evt):
|
|
768 self.rename_flag = 0
|
|
769 pt = evt.GetPosition()
|
|
770 (item, flag) = self.temp_wnd.HitTest(pt)
|
|
771 if item.IsOk():
|
|
772 obj = self.temp_wnd.GetPyData(item)
|
|
773 self.temp_wnd.SelectItem(item)
|
|
774 start = self.handler.xml.get('map').split('::')
|
|
775 end = obj.xml.get('map').split('::')
|
174
|
776 print obj.xml.get('class')
|
|
777 if obj.xml.get('class') != 'rpg_grid_handler' or obj.xml.get('class') != 'textctrl_handler': do = 'None'
|
|
778 elif end[0] == '' or start[0] != end[0]: do = 'Root'
|
|
779 elif start == end: do = 'Child'
|
|
780 elif start != end: do = 'Parent'
|
|
781 if do == 'Root':
|
|
782 complete = "!@"
|
|
783 for e in end:
|
|
784 if e != '': complete += e +'::'
|
|
785 complete = complete + obj.xml.get('name') + '@!'
|
|
786 elif do == 'Parent':
|
|
787 while start[0] == end[0]:
|
|
788 top = start[0]
|
|
789 del end[0], start[0]
|
|
790 if len(start) == 0 or len(end) == 0: break
|
|
791 complete = "!#" + top + "::"
|
|
792 for e in end: complete += e +'::'
|
|
793 complete = complete + obj.xml.get('name') + '#!'
|
|
794 elif do == 'Child':
|
|
795 while start[0] == end[0]:
|
|
796 del end[0], start[0]
|
|
797 if len(start) == 0 or len(end) == 0: break
|
|
798 complete = "!!"
|
|
799 for e in end: complete += e +'::'
|
|
800 complete = complete + obj.xml.get('name') + '!!'
|
|
801 if do != 'None': self.value_entry.AppendText(complete); self.reload_options()
|
173
|
802 self.do_tree.Destroy()
|
174
|
803 if do == 'None':
|
|
804 wx.MessageBox('Invalid Reference', 'Error')
|
173
|
805 ##### #####
|
|
806
|
|
807 def on_edit_ok(self, evt):
|
|
808 self.handler.edit_caption(self.index, self.caption_entry.GetValue())
|
|
809 self.handler.edit_option(self.index, self.value_entry.GetValue())
|
|
810 self.reload_options()
|
|
811 self.dlg.Destroy()
|
|
812 component.add('tree', component.get('tree_back')) ## Backup
|
|
813 return
|
|
814
|
|
815 def on_edit_cancel(self, evt):
|
|
816 self.dlg.Destroy()
|
|
817 component.add('tree', component.get('tree_back')) ## Backup
|
|
818 return
|
155
|
819
|
|
820 def on_remove(self,evt):
|
|
821 index = self.listbox.GetSelection()
|
|
822 if index >= 0:
|
|
823 self.handler.remove_option(index)
|
|
824 self.reload_options()
|
|
825
|
|
826 def on_edit(self,evt):
|
173
|
827 self.index = self.listbox.GetFocusedItem()
|
|
828 if self.index >= 0:
|
|
829 self.dlg = wx.Frame(self, -1, 'Text', size=(300,150))
|
|
830 edit_panel = wx.Panel(self.dlg, -1)
|
|
831 sizer = wx.GridBagSizer(1, 2)
|
|
832 edit_panel.SetSizer(sizer)
|
|
833 caption_text = wx.StaticText(edit_panel, -1, 'Caption')
|
|
834 self.caption_entry = wx.TextCtrl(edit_panel, -1, self.handler.get_caption(self.index))
|
|
835 value_text = wx.StaticText(edit_panel, -1, 'Value')
|
|
836 self.value_entry = wx.TextCtrl(edit_panel, -1, self.handler.get_option(self.index))
|
|
837 button_ok = wx.Button(edit_panel, wx.ID_OK)
|
|
838 button_cancel = wx.Button(edit_panel, wx.ID_CANCEL)
|
|
839 button_ref = wx.Button(edit_panel, BUT_REF, "Reference")
|
|
840 sizer.Add(caption_text, (0,0))
|
|
841 sizer.Add(self.caption_entry, (0,1), span=(1,3), flag=wx.EXPAND)
|
|
842 sizer.Add(value_text, (1,0))
|
|
843 sizer.Add(self.value_entry, (1,1), span=(1,3), flag=wx.EXPAND)
|
|
844 sizer.Add(button_ok, (3,0))
|
|
845 sizer.Add(button_cancel, (3,1))
|
|
846 sizer.Add(button_ref, (3,2), flag=wx.EXPAND)
|
|
847 self.Bind(wx.EVT_BUTTON, self.on_reference, id=BUT_REF)
|
|
848 self.Bind(wx.EVT_BUTTON, self.on_edit_ok, id=wx.ID_OK)
|
|
849 self.Bind(wx.EVT_BUTTON, self.on_edit_cancel, id=wx.ID_CANCEL)
|
|
850 self.dlg.Show()
|
155
|
851
|
|
852 def reload_options(self):
|
173
|
853 self.listbox.DeleteAllItems()
|
|
854 values = self.handler.get_options()
|
|
855 captions = self.handler.get_captions()
|
|
856 for index in range(len(values)):
|
|
857 self.listbox.Append((captions[index], values[index]))
|
155
|
858
|
|
859 def on_text(self,evt):
|
|
860 id = evt.GetId()
|
|
861 txt = self.text.GetValue()
|
|
862 if not len(txt): return
|
|
863 if id == P_TITLE:
|
|
864 self.handler.xml.set('name',txt)
|
|
865 self.handler.rename(txt)
|
|
866
|
|
867 def on_send_button(self,evt):
|
|
868 self.handler.list.set("send_button", str( bool2int(evt.Checked()) ))
|
|
869
|
|
870 def on_hide_button(self,evt):
|
141
|
871 self.handler.list.set("hide_title", str( bool2int(evt.Checked()) ))
|
|
872
|
155
|
873 def on_raw_button(self,evt):
|
|
874 self.handler.list.set("raw_mode",str(bool2int(evt.Checked())))
|
|
875
|
|
876
|
|
877 ###############################
|
|
878 ## link image handlers
|
|
879 ###############################
|
|
880
|
|
881 class link_handler(node_handler):
|
|
882 """ A nodehandler for URLs. Will open URL in a wxHTMLFrame
|
|
883 <nodehandler name='?' module='forms' class='link_handler' >
|
|
884 <link href='http//??.??' />
|
|
885 </nodehandler >
|
|
886 """
|
|
887 def __init__(self,xml,tree_node):
|
|
888 node_handler.__init__(self,xml,tree_node)
|
|
889 self.link = self.xml[0]
|
|
890
|
|
891 def on_use(self,evt):
|
|
892 href = self.link.get("href")
|
|
893 wb = webbrowser.get()
|
|
894 wb.open(href)
|
|
895
|
|
896 def get_design_panel(self,parent):
|
|
897 return link_edit_panel(parent,self)
|
|
898
|
|
899 def get_use_panel(self,parent):
|
|
900 return link_panel(parent,self)
|
|
901
|
|
902 def tohtml(self):
|
|
903 href = self.link.get("href")
|
|
904 title = self.xml.get("name")
|
|
905 return "<a href='"+href+"' >"+title+"</a>"
|
|
906
|
|
907 class link_panel(wx.StaticText):
|
|
908 def __init__(self,parent,handler):
|
|
909 self.handler = handler
|
|
910 label = handler.xml.get('name')
|
|
911 wx.StaticText.__init__(self,parent,-1,label)
|
|
912 self.SetForegroundColour(wx.BLUE)
|
|
913 self.Bind(wx.EVT_LEFT_DOWN, self.handler.on_use)
|
|
914
|
|
915 P_URL = wx.NewId()
|
|
916
|
|
917 class link_edit_panel(wx.Panel):
|
|
918 def __init__(self, parent, handler):
|
|
919 wx.Panel.__init__(self, parent, -1)
|
|
920 self.handler = handler
|
|
921 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Link Properties"), wx.VERTICAL)
|
|
922
|
|
923 self.text = {}
|
|
924 self.text[P_TITLE] = wx.TextCtrl(self, P_TITLE, handler.xml.get('name'))
|
|
925 self.text[P_URL] = wx.TextCtrl(self, P_URL, handler.link.get('href'))
|
|
926
|
|
927 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND)
|
|
928 sizer.Add(self.text[P_TITLE], 0, wx.EXPAND)
|
|
929 sizer.Add(wx.Size(10,10))
|
|
930 sizer.Add(wx.StaticText(self, -1, "URL:"), 0, wx.EXPAND)
|
|
931 sizer.Add(self.text[P_URL], 0, wx.EXPAND)
|
|
932 self.SetSizer(sizer)
|
|
933 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE)
|
|
934 self.Bind(wx.EVT_TEXT, self.on_text, id=P_URL)
|
|
935
|
|
936 def on_text(self,evt):
|
|
937 id = evt.GetId()
|
|
938 txt = self.text[id].GetValue()
|
|
939 if not len(txt): return
|
|
940 if id == P_TITLE:
|
|
941 self.handler.xml.set('name',txt)
|
|
942 self.handler.rename(txt)
|
|
943 elif id == P_URL: self.handler.link.set('href',txt)
|
|
944
|
|
945 ##########################
|
|
946 ## webimg node handler
|
|
947 ##########################
|
|
948 class webimg_handler(node_handler):
|
|
949 """ A nodehandler for URLs. Will open URL in a wxHTMLFrame
|
|
950 <nodehandler name='?' module='forms' class='webimg_handler' >
|
|
951 <link href='http//??.??' />
|
|
952 </nodehandler >
|
|
953 """
|
|
954 def __init__(self,xml,tree_node):
|
|
955 node_handler.__init__(self,xml,tree_node)
|
|
956 self.link = self.xml[0]
|
|
957
|
|
958 def get_design_panel(self,parent):
|
|
959 return link_edit_panel(parent,self)
|
|
960
|
|
961 def get_use_panel(self,parent):
|
|
962 img = img_helper().load_url(self.link.get("href"))
|
|
963 if not img is None: return wx.StaticBitmap(parent,-1,img,size= wx.Size(img.GetWidth(),img.GetHeight()))
|
|
964 return wx.EmptyBitmap(1, 1)
|
|
965
|
|
966 def tohtml(self):
|
|
967 href = self.link.get("href")
|
|
968 title = self.xml.get("name")
|
|
969 return "<img src='"+href+"' alt="+title+" >"
|