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)
|
176
|
267 txt = self.chat.ParseParent(txt, self.handler.xml.get('map'))
|
155
|
268 if not self.handler.is_raw_send():
|
|
269 self.chat.ParsePost(self.handler.tohtml(), True, True)
|
|
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
|
|
275 self.chat.ParsePost(line, True, True)
|
|
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()
|
173
|
286 T_BUT_REF = wx.NewId()
|
155
|
287
|
|
288 class textctrl_edit_panel(wx.Panel):
|
|
289 def __init__(self, parent, handler):
|
|
290 wx.Panel.__init__(self, parent, -1)
|
|
291 self.handler = handler
|
|
292 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Text Properties"), wx.VERTICAL)
|
|
293
|
|
294 self.title = wx.TextCtrl(self, P_TITLE, handler.xml.get('name'))
|
|
295 self.multi = wx.CheckBox(self, F_MULTI, " Multi-Line")
|
|
296 self.multi.SetValue(handler.is_multi_line())
|
|
297 self.raw_send = wx.CheckBox(self, F_RAW_SEND, " Send as Macro")
|
|
298 self.raw_send.SetValue(handler.is_raw_send())
|
|
299 self.hide_title = wx.CheckBox(self, F_HIDE_TITLE, " Hide Title")
|
|
300 self.hide_title.SetValue(handler.is_hide_title())
|
|
301 self.send_button = wx.CheckBox(self, F_SEND_BUTTON, " Send Button")
|
|
302 self.send_button.SetValue(handler.has_send_button())
|
173
|
303 button_ref = wx.Button(self, T_BUT_REF, "Reference")
|
155
|
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)
|
173
|
312 sizer.Add(button_ref, 0)
|
155
|
313 sizer.Add(wx.Size(10,10))
|
|
314 if handler.is_multi_line():
|
|
315 sizer_style = wx.EXPAND
|
|
316 text_style = wx.TE_MULTILINE
|
|
317 multi = 1
|
|
318 else:
|
|
319 sizer_style=wx.EXPAND
|
|
320 text_style = 0
|
|
321 multi = 0
|
|
322 self.text = wx.TextCtrl(self, F_TEXT, handler.get_value(),style=text_style)
|
|
323 sizer.Add(wx.Size(5,0))
|
|
324 sizer.Add(self.text, multi, sizer_style)
|
|
325 self.SetSizer(sizer)
|
|
326 self.SetAutoLayout(True)
|
|
327
|
|
328 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE)
|
|
329 self.Bind(wx.EVT_TEXT, self.on_text, id=F_TEXT)
|
|
330 self.Bind(wx.EVT_CHECKBOX, self.on_button, id=F_MULTI)
|
|
331 self.Bind(wx.EVT_CHECKBOX, self.on_raw_button, id=F_RAW_SEND)
|
|
332 self.Bind(wx.EVT_CHECKBOX, self.on_hide_button, id=F_HIDE_TITLE)
|
|
333 self.Bind(wx.EVT_CHECKBOX, self.on_send_button, id=F_SEND_BUTTON)
|
173
|
334 self.Bind(wx.EVT_BUTTON, self.on_reference, id=T_BUT_REF)
|
|
335
|
|
336 ## EZ_Tree Core TaS - Prof.Ebral ##
|
|
337 def on_reference(self, evt, car=None):
|
178
|
338 self.do_tree = wx.Frame(self, -1, 'EZ Tree')
|
173
|
339 self.ez_tree = orpg.gametree.gametree
|
|
340 self.temp_wnd = self.ez_tree.game_tree(self.do_tree, self.ez_tree.EZ_REF)
|
|
341 self.temp_wnd.Bind(wx.EVT_LEFT_DCLICK, self.on_ldclick)
|
178
|
342 component.get('tree_fs').save_tree(settings.get("gametree"))
|
173
|
343 self.temp_wnd.load_tree(settings.get("gametree"))
|
|
344 self.do_tree.Show()
|
|
345
|
176
|
346 def get_grid_ref(self, obj, complete):
|
|
347 self.temp_wnd.Freeze()
|
|
348 self.grid_ref = complete
|
178
|
349 self.mini_grid = wx.Frame(self, -1, 'EZ Tree Mini Grid')
|
176
|
350 self.temp_grid = obj.get_use_panel(self.mini_grid)
|
|
351 self.temp_grid.grid.Bind(wx.grid.EVT_GRID_CELL_LEFT_DCLICK, self.on_grid_ldclick)
|
|
352 self.mini_grid.Show()
|
|
353
|
|
354 def on_grid_ldclick(self, evt):
|
|
355 complete = self.grid_ref
|
|
356 row = str(evt.GetRow()+1)
|
|
357 col = str(evt.GetCol()+1)
|
|
358 complete = complete[:len(complete)-2] + '::'+'('+row+','+col+')'+complete[len(complete)-2:]
|
|
359 self.text.AppendText(complete); self.on_text(evt)
|
178
|
360 self.mini_grid.Destroy()
|
176
|
361
|
173
|
362 def on_ldclick(self, evt):
|
|
363 self.rename_flag = 0
|
|
364 pt = evt.GetPosition()
|
|
365 (item, flag) = self.temp_wnd.HitTest(pt)
|
|
366 if item.IsOk():
|
|
367 obj = self.temp_wnd.GetPyData(item)
|
|
368 self.temp_wnd.SelectItem(item)
|
|
369 start = self.handler.xml.get('map').split('::')
|
|
370 end = obj.xml.get('map').split('::')
|
175
|
371 if obj.xml.get('class') not in ['rpg_grid_handler', 'textctrl_handler']: do = 'None'
|
174
|
372 elif end[0] == '' or start[0] != end[0]: do = 'Root'
|
|
373 elif start == end: do = 'Child'
|
|
374 elif start != end: do = 'Parent'
|
|
375 if do == 'Root':
|
|
376 complete = "!@"
|
|
377 for e in end:
|
|
378 if e != '': complete += e +'::'
|
|
379 complete = complete + obj.xml.get('name') + '@!'
|
|
380 elif do == 'Parent':
|
|
381 while start[0] == end[0]:
|
|
382 top = start[0]
|
|
383 del end[0], start[0]
|
|
384 if len(start) == 0 or len(end) == 0: break
|
|
385 complete = "!#" + top + "::"
|
|
386 for e in end: complete += e +'::'
|
|
387 complete = complete + obj.xml.get('name') + '#!'
|
|
388 elif do == 'Child':
|
|
389 while start[0] == end[0]:
|
|
390 del end[0], start[0]
|
|
391 if len(start) == 0 or len(end) == 0: break
|
|
392 complete = "!!"
|
|
393 for e in end: complete += e +'::'
|
|
394 complete = complete + obj.xml.get('name') + '!!'
|
176
|
395 if do != 'None':
|
|
396 if obj.xml.get('class') == 'rpg_grid_handler':
|
|
397 self.get_grid_ref(obj, complete)
|
|
398 else: self.text.AppendText(complete); self.on_text(evt)
|
173
|
399 self.do_tree.Destroy()
|
174
|
400 if do == 'None':
|
|
401 wx.MessageBox('Invalid Reference', 'Error')
|
173
|
402 ##### #####
|
155
|
403
|
|
404 def on_text(self,evt):
|
|
405 id = evt.GetId()
|
|
406 if id == P_TITLE:
|
|
407 txt = self.title.GetValue()
|
|
408 if not len(txt): return
|
|
409 self.handler.xml.set('name',txt)
|
|
410 self.handler.rename(txt)
|
|
411 if id == F_TEXT:
|
|
412 txt = self.text.GetValue()
|
|
413 #txt = strip_text(txt) ##Does not seem to exist.
|
|
414 self.handler.text_elem.text = txt
|
|
415
|
|
416 def on_button(self,evt):
|
|
417 self.handler.text_elem.set("multiline",str(bool2int(evt.Checked())))
|
|
418
|
|
419 def on_raw_button(self,evt):
|
|
420 self.handler.text_elem.set("raw_mode",str(bool2int(evt.Checked())))
|
|
421
|
|
422 def on_hide_button(self,evt):
|
|
423 self.handler.text_elem.set("hide_title",str(bool2int(evt.Checked())))
|
|
424
|
|
425 def on_send_button(self,evt):
|
|
426 self.handler.text_elem.set("send_button",str(bool2int(evt.Checked())))
|
|
427
|
|
428
|
|
429 #######################
|
|
430 ## listbox handler
|
|
431 #######################
|
|
432 #
|
|
433 # Updated by Snowdog (April 2003)
|
|
434 # Now includesan option to remove the title from
|
|
435 # text when sent to the chat.
|
|
436 #
|
|
437 L_DROP = 0
|
|
438 L_LIST = 1
|
|
439 L_RADIO = 2
|
|
440 L_CHECK = 3
|
|
441 L_ROLLER = 4
|
|
442
|
|
443 class listbox_handler(node_handler):
|
|
444 """
|
|
445 <nodehandler class="listbox_handler" module="forms" name="">
|
|
446 <list type="1" send_button='0' hide_title='0'>
|
|
447 <option value="" selected="" >Option Text I</option>
|
|
448 <option value="" selected="" >Option Text II</option>
|
|
449 </list>
|
|
450 </nodehandler>
|
|
451 """
|
|
452 def __init__(self,xml,tree_node):
|
|
453 node_handler.__init__(self,xml,tree_node)
|
173
|
454 self.list_reload()
|
|
455 #print xml
|
|
456 #print self.tree.GetItemParent(tree_node)
|
155
|
457 if self.list.get("send_button") == "": self.list.set("send_button","0")
|
141
|
458 if self.list.get("hide_title") == "": self.list.set("hide_title","0")
|
155
|
459 if self.list.get("raw_mode") == "": self.list.set("raw_mode","0")
|
|
460
|
173
|
461 def list_reload(self):
|
|
462 self.list = self.xml.find('list')
|
|
463 self.options = self.list.findall('option')
|
|
464 self.captions = []
|
|
465 for opt in self.options:
|
|
466 if opt.get('caption') == None: opt.set('caption', '')
|
|
467 self.captions.append(opt.get('caption'))
|
|
468
|
155
|
469 def get_design_panel(self,parent):
|
|
470 return listbox_edit_panel(parent,self)
|
|
471
|
|
472 def get_use_panel(self,parent):
|
|
473 return listbox_panel(parent,self)
|
|
474
|
|
475 def get_type(self):
|
|
476 return int(self.list.get("type"))
|
|
477
|
|
478 def set_type(self,type):
|
|
479 self.list.set("type",str(type))
|
|
480
|
|
481 def is_hide_title(self):
|
141
|
482 return int(self.list.get("hide_title", 0))
|
|
483
|
155
|
484 def is_raw_send(self):
|
|
485 return int(self.list.get("raw_mode",0))
|
|
486
|
|
487 # single selection methods
|
|
488 def get_selected_node(self):
|
|
489 for opt in self.options:
|
|
490 if opt.get("selected") == "1": return opt
|
|
491 return None
|
|
492
|
|
493 def get_selected_index(self):
|
|
494 i = 0
|
|
495 for opt in self.options:
|
|
496 if opt.get("selected") == "1": return i
|
|
497 i += 1
|
|
498 return 0
|
|
499
|
|
500 def get_selected_text(self):
|
|
501 node = self.get_selected_node()
|
|
502 if node: return node.text
|
|
503 else: return ""
|
|
504
|
|
505 # mult selection methods
|
|
506 def get_selections(self):
|
|
507 opts = []
|
|
508 for opt in self.options:
|
|
509 if opt.get("selected") == "1": opts.append(opt)
|
|
510 return opts
|
|
511
|
|
512 def get_selections_text(self):
|
|
513 opts = []
|
|
514 for opt in self.options:
|
|
515 if opt.get("selected") == "1": opts.append(opt.text)
|
|
516 return opts
|
|
517
|
|
518 def get_selections_index(self):
|
|
519 opts = []
|
|
520 i = 0
|
|
521 for opt in self.options:
|
|
522 if opt.get("selected") == "1": opts.append(i)
|
|
523 i += 1
|
|
524 return opts
|
|
525
|
|
526 # setting selection method
|
|
527 def set_selected_node(self,index,selected=1):
|
|
528 if self.get_type() != L_CHECK: self.clear_selections()
|
|
529 self.options[index].set("selected", str(bool2int(selected)))
|
|
530
|
|
531 def clear_selections(self):
|
|
532 for opt in self.options: opt.set("selected","0")
|
|
533
|
|
534 # misc methods
|
|
535 def get_options(self):
|
|
536 opts = []
|
|
537 for opt in self.options: opts.append(opt.text)
|
|
538 return opts
|
|
539
|
173
|
540 def get_captions(self):
|
|
541 captions = []
|
|
542 for opt in self.options: captions.append(opt.get("caption"))
|
|
543 self.captions = captions
|
|
544 return captions
|
|
545
|
|
546 def get_option(self, index):
|
155
|
547 return self.options[index].text
|
|
548
|
173
|
549 def get_caption(self, index):
|
|
550 captions = self.get_captions()
|
|
551 return captions[index] or ''
|
|
552
|
|
553 def add_option(self, caption, value):
|
155
|
554 elem = Element('option')
|
|
555 elem.set("value","0")
|
173
|
556 elem.set('caption', caption)
|
155
|
557 elem.set("selected","0")
|
173
|
558 elem.text = value
|
155
|
559 self.list.append(elem)
|
173
|
560 self.list_reload()
|
155
|
561
|
|
562 def remove_option(self,index):
|
|
563 self.list.remove(self.options[index])
|
173
|
564 self.list_reload()
|
155
|
565
|
173
|
566 def edit_option(self, index, value):
|
155
|
567 self.options[index].text = value
|
|
568
|
173
|
569 def edit_caption(self, index, value):
|
|
570 self.options[index].set('caption', value)
|
|
571 self.captions[index] = value
|
|
572
|
155
|
573 def has_send_button(self):
|
|
574 if self.list.get("send_button") == '0': return False
|
|
575 else: return True
|
|
576
|
|
577 def get_size_constraint(self):
|
|
578 if self.get_type() == L_DROP: return 0
|
|
579 else: return 1
|
|
580
|
|
581 def tohtml(self):
|
|
582 opts = self.get_selections_text()
|
|
583 text = ""
|
|
584 if not self.is_hide_title(): text = "<b>"+self.xml.get("name")+":</b> "
|
|
585 comma = ", "
|
|
586 text += comma.join(opts)
|
|
587 return text
|
|
588
|
|
589 def get_value(self):
|
141
|
590 return "\n".join(self.get_selections_text())
|
|
591
|
155
|
592 def on_send_to_chat(self, evt):
|
141
|
593 txt = self.get_selected_text()
|
|
594 txt = self.chat.ParseMap(txt, self.xml)
|
176
|
595 txt = self.chat.ParseParent(txt, self.xml.get('map'))
|
155
|
596 if not self.is_raw_send():
|
|
597 self.chat.ParsePost(self.tohtml(), True, True)
|
|
598 return 1
|
|
599 actionlist = self.get_selections_text()
|
141
|
600 for line in actionlist:
|
155
|
601 line = self.chat.ParseMap(line, self.xml)
|
176
|
602 line = self.chat.ParseParent(line, self.xml.get('map'))
|
155
|
603 if(line != ""):
|
|
604 if line[0] != "/": ## it's not a slash command
|
|
605 self.chat.ParsePost(line, True, True)
|
|
606 else:
|
|
607 action = line
|
|
608 self.chat.chat_cmds.docmd(action)
|
|
609 return 1
|
|
610
|
|
611
|
|
612 F_LIST = wx.NewId()
|
|
613 F_SEND = wx.NewId()
|
|
614
|
|
615
|
|
616 class listbox_panel(wx.Panel):
|
|
617 def __init__(self, parent, handler):
|
|
618 wx.Panel.__init__(self, parent, -1)
|
|
619 self.handler = handler
|
|
620 self.chat = handler.chat
|
173
|
621 opts = []
|
|
622 values = handler.get_options()
|
|
623 captions = handler.get_captions()
|
|
624 for value in values:
|
|
625 if captions[values.index(value)] != '': opts.append(captions[values.index(value)])
|
|
626 else: opts.append(value)
|
155
|
627 cur_opt = handler.get_selected_text()
|
|
628 type = handler.get_type()
|
|
629 label = handler.xml.get('name')
|
|
630
|
|
631 if type == L_DROP:
|
|
632 self.list = wx.ComboBox(self, F_LIST, cur_opt, choices=opts, style=wx.CB_READONLY)
|
|
633 if self.list.GetSize()[0] > 200:
|
|
634 self.list.Destroy()
|
|
635 self.list = wx.ComboBox(self, F_LIST, cur_opt, size=(200, -1), choices=opts, style=wx.CB_READONLY)
|
|
636 elif type == L_LIST: self.list = wx.ListBox(self,F_LIST,choices=opts)
|
|
637 elif type == L_RADIO: self.list = wx.RadioBox(self,F_LIST,label,choices=opts,majorDimension=3)
|
|
638 elif type == L_CHECK:
|
|
639 self.list = wx.CheckListBox(self,F_LIST,choices=opts)
|
|
640 self.set_checks()
|
|
641
|
|
642 for i in handler.get_selections_text():
|
|
643 if type == L_DROP: self.list.SetValue( i )
|
|
644 else: self.list.SetStringSelection( i )
|
|
645 if type == L_DROP: sizer = wx.BoxSizer(wx.HORIZONTAL)
|
|
646 else: sizer = wx.BoxSizer(wx.VERTICAL)
|
|
647
|
|
648 if type != L_RADIO:
|
|
649 sizer.Add(wx.StaticText(self, -1, label+": "), 0, wx.EXPAND)
|
|
650 sizer.Add(wx.Size(5,0))
|
|
651 sizer.Add(self.list, 1, wx.EXPAND)
|
|
652 if handler.has_send_button():
|
|
653 sizer.Add(wx.Button(self, F_SEND, "Send"), 0, wx.EXPAND)
|
|
654 self.Bind(wx.EVT_BUTTON, self.handler.on_send_to_chat, id=F_SEND)
|
|
655 self.sizer = sizer
|
|
656 self.SetSizer(sizer)
|
|
657 self.SetAutoLayout(True)
|
|
658 self.Fit()
|
|
659 parent.SetSize(self.GetBestSize())
|
|
660
|
|
661 if type == L_DROP: self.Bind(wx.EVT_COMBOBOX, self.on_change, id=F_LIST)
|
|
662 elif type == L_LIST: self.Bind(wx.EVT_LISTBOX, self.on_change, id=F_LIST)
|
|
663 elif type == L_RADIO: self.Bind(wx.EVT_RADIOBOX, self.on_change, id=F_LIST)
|
|
664 elif type == L_CHECK:self.Bind(wx.EVT_CHECKLISTBOX, self.on_check, id=F_LIST)
|
|
665 self.type = type
|
|
666
|
|
667 def on_change(self,evt):
|
|
668 self.handler.set_selected_node(self.list.GetSelection())
|
|
669
|
|
670 def on_check(self,evt):
|
141
|
671 for i in xrange(self.list.GetCount()): self.handler.set_selected_node(i, bool2int(self.list.IsChecked(i)))
|
155
|
672
|
|
673 def set_checks(self):
|
|
674 for i in self.handler.get_selections_index(): self.list.Check(i)
|
|
675
|
|
676
|
|
677 BUT_ADD = wx.NewId()
|
|
678 BUT_REM = wx.NewId()
|
173
|
679 BUT_REF = wx.NewId()
|
155
|
680 BUT_EDIT = wx.NewId()
|
|
681 F_TYPE = wx.NewId()
|
|
682 F_NO_TITLE = wx.NewId()
|
173
|
683 LIST_CTRL = wx.NewId()
|
155
|
684
|
|
685 class listbox_edit_panel(wx.Panel):
|
|
686 def __init__(self, parent, handler):
|
|
687 wx.Panel.__init__(self, parent, -1)
|
|
688 self.handler = handler
|
173
|
689 self.parent = parent
|
155
|
690 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "List Box Properties"), wx.VERTICAL)
|
|
691
|
|
692 self.text = wx.TextCtrl(self, P_TITLE, handler.xml.get('name'))
|
|
693
|
173
|
694 self.listbox = wx.ListCtrl(self, LIST_CTRL, style=wx.LC_REPORT)
|
|
695 self.listbox.InsertColumn(0, 'Caption')
|
|
696 self.listbox.InsertColumn(1, 'Value')
|
|
697 self.listbox.SetColumnWidth(0, 75)
|
|
698 self.listbox.SetColumnWidth(1, 300)
|
|
699 self.reload_options()
|
|
700
|
155
|
701 opts = ['Drop Down', 'List Box', 'Radio Box', 'Check List']
|
|
702 self.type_radios = wx.RadioBox(self,F_TYPE,"List Type",choices=opts)
|
|
703 self.type_radios.SetSelection(handler.get_type())
|
|
704
|
|
705 self.send_button = wx.CheckBox(self, F_SEND_BUTTON, " Send Button")
|
141
|
706 self.send_button.SetValue(handler.has_send_button())
|
|
707
|
155
|
708 self.raw_send = wx.CheckBox(self, F_RAW_SEND, " Send as Macro")
|
|
709 self.raw_send.SetValue(handler.is_raw_send())
|
|
710
|
|
711 self.hide_title = wx.CheckBox(self, F_NO_TITLE, " Hide Title")
|
|
712 self.hide_title.SetValue(handler.is_hide_title())
|
|
713
|
|
714 but_sizer = wx.BoxSizer(wx.HORIZONTAL)
|
|
715 but_sizer.Add(wx.Button(self, BUT_ADD, "Add"), 1, wx.EXPAND)
|
|
716 but_sizer.Add(wx.Size(10,10))
|
|
717 but_sizer.Add(wx.Button(self, BUT_EDIT, "Edit"), 1, wx.EXPAND)
|
|
718 but_sizer.Add(wx.Size(10,10))
|
|
719 but_sizer.Add(wx.Button(self, BUT_REM, "Remove"), 1, wx.EXPAND)
|
|
720
|
|
721 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND)
|
|
722 sizer.Add(self.text, 0, wx.EXPAND)
|
|
723 sizer.Add(wx.Size(10,10))
|
|
724 sizer.Add(self.type_radios, 0, wx.EXPAND)
|
|
725 sizer.Add(wx.Size(10,10))
|
|
726 sizer.Add(self.send_button, 0 , wx.EXPAND)
|
141
|
727 sizer.Add(self.hide_title, 0, wx.EXPAND)
|
155
|
728 sizer.Add(self.raw_send, 0, wx.EXPAND)
|
|
729 sizer.Add(wx.Size(10,10))
|
|
730 sizer.Add(wx.StaticText(self, -1, "Options:"), 0, wx.EXPAND)
|
|
731 sizer.Add(self.listbox,1,wx.EXPAND);
|
|
732 sizer.Add(but_sizer,0,wx.EXPAND)
|
|
733
|
|
734 self.SetSizer(sizer)
|
|
735 self.SetAutoLayout(True)
|
|
736 self.Fit()
|
|
737 parent.SetSize(self.GetBestSize())
|
|
738
|
|
739 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE)
|
|
740 self.Bind(wx.EVT_BUTTON, self.on_edit, id=BUT_EDIT)
|
|
741 self.Bind(wx.EVT_BUTTON, self.on_remove, id=BUT_REM)
|
|
742 self.Bind(wx.EVT_BUTTON, self.on_add, id=BUT_ADD)
|
|
743 self.Bind(wx.EVT_RADIOBOX, self.on_type, id=F_TYPE)
|
|
744 self.Bind(wx.EVT_CHECKBOX, self.on_hide_button, id=F_NO_TITLE)
|
141
|
745 self.Bind(wx.EVT_CHECKBOX, self.on_send_button, id=F_SEND_BUTTON)
|
155
|
746 self.Bind(wx.EVT_CHECKBOX, self.on_raw_button, id=F_RAW_SEND)
|
|
747
|
|
748 def on_type(self,evt):
|
|
749 self.handler.set_type(evt.GetInt())
|
|
750
|
|
751 def on_add(self,evt):
|
173
|
752 self.dlg = wx.Frame(self, -1, 'Text', size=(300,150))
|
|
753 edit_panel = wx.Panel(self.dlg, -1)
|
|
754 sizer = wx.GridBagSizer(1, 2)
|
|
755 edit_panel.SetSizer(sizer)
|
|
756 caption_text = wx.StaticText(edit_panel, -1, 'Caption')
|
|
757 self.caption_entry = wx.TextCtrl(edit_panel, -1, '')
|
|
758 value_text = wx.StaticText(edit_panel, -1, 'Value')
|
|
759 self.value_entry = wx.TextCtrl(edit_panel, -1, '')
|
|
760 button_ok = wx.Button(edit_panel, wx.ID_OK)
|
|
761 button_cancel = wx.Button(edit_panel, wx.ID_CANCEL)
|
|
762 button_ref = wx.Button(edit_panel, BUT_REF, "Reference")
|
|
763 sizer.Add(caption_text, (0,0))
|
|
764 sizer.Add(self.caption_entry, (0,1), span=(1,3), flag=wx.EXPAND)
|
|
765 sizer.Add(value_text, (1,0))
|
|
766 sizer.Add(self.value_entry, (1,1), span=(1,3), flag=wx.EXPAND)
|
|
767 sizer.Add(button_ok, (3,0))
|
|
768 sizer.Add(button_cancel, (3,1))
|
|
769 sizer.Add(button_ref, (3,2), flag=wx.EXPAND)
|
|
770 self.Bind(wx.EVT_BUTTON, self.on_reference, id=BUT_REF)
|
|
771 self.Bind(wx.EVT_BUTTON, self.on_add_option, id=wx.ID_OK)
|
|
772 self.Bind(wx.EVT_BUTTON, self.on_edit_cancel, id=wx.ID_CANCEL)
|
|
773 self.dlg.Show()
|
|
774
|
|
775 def on_add_option(self, evt):
|
|
776 self.handler.add_option(self.caption_entry.GetValue(), self.value_entry.GetValue())
|
155
|
777 self.reload_options()
|
173
|
778 self.dlg.Destroy()
|
|
779 return
|
|
780
|
|
781 ## EZ_Tree Core TaS - Prof.Ebral ##
|
|
782 def on_reference(self, evt, car=None):
|
178
|
783 self.do_tree = wx.Frame(self, -1, 'EZ Tree')
|
173
|
784 self.ez_tree = orpg.gametree.gametree
|
|
785 self.temp_wnd = self.ez_tree.game_tree(self.do_tree, self.ez_tree.EZ_REF)
|
|
786 self.temp_wnd.Bind(wx.EVT_LEFT_DCLICK, self.on_ldclick)
|
178
|
787 component.get('tree_fs').save_tree(settings.get("gametree"))
|
173
|
788 self.temp_wnd.load_tree(settings.get("gametree"))
|
|
789 self.do_tree.Show()
|
|
790
|
176
|
791 def get_grid_ref(self, obj, complete):
|
|
792 self.temp_wnd.Freeze()
|
|
793 self.grid_ref = complete
|
178
|
794 self.mini_grid = wx.Frame(self, -1, 'EZ Tree Grid')
|
176
|
795 self.temp_grid = obj.get_use_panel(self.mini_grid)
|
|
796 self.temp_grid.grid.Bind(wx.grid.EVT_GRID_CELL_LEFT_DCLICK, self.on_grid_ldclick)
|
|
797 self.mini_grid.Show()
|
|
798
|
|
799 def on_grid_ldclick(self, evt):
|
|
800 complete = self.grid_ref
|
|
801 row = str(evt.GetRow()+1)
|
|
802 col = str(evt.GetCol()+1)
|
|
803 complete = complete[:len(complete)-2] + '::'+'('+row+','+col+')'+complete[len(complete)-2:]
|
|
804 self.value_entry.AppendText(complete)
|
178
|
805 self.mini_grid.Destroy()
|
176
|
806
|
173
|
807 def on_ldclick(self, evt):
|
|
808 self.rename_flag = 0
|
|
809 pt = evt.GetPosition()
|
|
810 (item, flag) = self.temp_wnd.HitTest(pt)
|
|
811 if item.IsOk():
|
|
812 obj = self.temp_wnd.GetPyData(item)
|
|
813 self.temp_wnd.SelectItem(item)
|
|
814 start = self.handler.xml.get('map').split('::')
|
|
815 end = obj.xml.get('map').split('::')
|
176
|
816 if obj.xml.get('class') not in ['rpg_grid_handler', 'textctrl_handler']: do = 'None'
|
174
|
817 elif end[0] == '' or start[0] != end[0]: do = 'Root'
|
|
818 elif start == end: do = 'Child'
|
|
819 elif start != end: do = 'Parent'
|
|
820 if do == 'Root':
|
|
821 complete = "!@"
|
|
822 for e in end:
|
|
823 if e != '': complete += e +'::'
|
|
824 complete = complete + obj.xml.get('name') + '@!'
|
|
825 elif do == 'Parent':
|
|
826 while start[0] == end[0]:
|
|
827 top = start[0]
|
|
828 del end[0], start[0]
|
|
829 if len(start) == 0 or len(end) == 0: break
|
|
830 complete = "!#" + top + "::"
|
|
831 for e in end: complete += e +'::'
|
|
832 complete = complete + obj.xml.get('name') + '#!'
|
|
833 elif do == 'Child':
|
|
834 while start[0] == end[0]:
|
|
835 del end[0], start[0]
|
|
836 if len(start) == 0 or len(end) == 0: break
|
|
837 complete = "!!"
|
|
838 for e in end: complete += e +'::'
|
|
839 complete = complete + obj.xml.get('name') + '!!'
|
176
|
840 if do != 'None':
|
|
841 if obj.xml.get('class') == 'rpg_grid_handler':
|
|
842 self.get_grid_ref(obj, complete)
|
|
843 else: self.value_entry.AppendText(complete); self.reload_options()
|
173
|
844 self.do_tree.Destroy()
|
174
|
845 if do == 'None':
|
|
846 wx.MessageBox('Invalid Reference', 'Error')
|
173
|
847 ##### #####
|
|
848
|
|
849 def on_edit_ok(self, evt):
|
|
850 self.handler.edit_caption(self.index, self.caption_entry.GetValue())
|
|
851 self.handler.edit_option(self.index, self.value_entry.GetValue())
|
|
852 self.reload_options()
|
|
853 self.dlg.Destroy()
|
178
|
854 #component.add('tree', component.get('tree_fs')) ## Backup
|
173
|
855 return
|
|
856
|
|
857 def on_edit_cancel(self, evt):
|
|
858 self.dlg.Destroy()
|
178
|
859 #component.add('tree', component.get('tree_fs')) ## Backup
|
173
|
860 return
|
155
|
861
|
|
862 def on_remove(self,evt):
|
|
863 index = self.listbox.GetSelection()
|
|
864 if index >= 0:
|
|
865 self.handler.remove_option(index)
|
|
866 self.reload_options()
|
|
867
|
|
868 def on_edit(self,evt):
|
173
|
869 self.index = self.listbox.GetFocusedItem()
|
|
870 if self.index >= 0:
|
|
871 self.dlg = wx.Frame(self, -1, 'Text', size=(300,150))
|
|
872 edit_panel = wx.Panel(self.dlg, -1)
|
|
873 sizer = wx.GridBagSizer(1, 2)
|
|
874 edit_panel.SetSizer(sizer)
|
|
875 caption_text = wx.StaticText(edit_panel, -1, 'Caption')
|
|
876 self.caption_entry = wx.TextCtrl(edit_panel, -1, self.handler.get_caption(self.index))
|
|
877 value_text = wx.StaticText(edit_panel, -1, 'Value')
|
|
878 self.value_entry = wx.TextCtrl(edit_panel, -1, self.handler.get_option(self.index))
|
|
879 button_ok = wx.Button(edit_panel, wx.ID_OK)
|
|
880 button_cancel = wx.Button(edit_panel, wx.ID_CANCEL)
|
|
881 button_ref = wx.Button(edit_panel, BUT_REF, "Reference")
|
|
882 sizer.Add(caption_text, (0,0))
|
|
883 sizer.Add(self.caption_entry, (0,1), span=(1,3), flag=wx.EXPAND)
|
|
884 sizer.Add(value_text, (1,0))
|
|
885 sizer.Add(self.value_entry, (1,1), span=(1,3), flag=wx.EXPAND)
|
|
886 sizer.Add(button_ok, (3,0))
|
|
887 sizer.Add(button_cancel, (3,1))
|
|
888 sizer.Add(button_ref, (3,2), flag=wx.EXPAND)
|
|
889 self.Bind(wx.EVT_BUTTON, self.on_reference, id=BUT_REF)
|
|
890 self.Bind(wx.EVT_BUTTON, self.on_edit_ok, id=wx.ID_OK)
|
|
891 self.Bind(wx.EVT_BUTTON, self.on_edit_cancel, id=wx.ID_CANCEL)
|
|
892 self.dlg.Show()
|
155
|
893
|
|
894 def reload_options(self):
|
173
|
895 self.listbox.DeleteAllItems()
|
|
896 values = self.handler.get_options()
|
|
897 captions = self.handler.get_captions()
|
|
898 for index in range(len(values)):
|
|
899 self.listbox.Append((captions[index], values[index]))
|
155
|
900
|
|
901 def on_text(self,evt):
|
|
902 id = evt.GetId()
|
|
903 txt = self.text.GetValue()
|
|
904 if not len(txt): return
|
|
905 if id == P_TITLE:
|
|
906 self.handler.xml.set('name',txt)
|
|
907 self.handler.rename(txt)
|
|
908
|
|
909 def on_send_button(self,evt):
|
|
910 self.handler.list.set("send_button", str( bool2int(evt.Checked()) ))
|
|
911
|
|
912 def on_hide_button(self,evt):
|
141
|
913 self.handler.list.set("hide_title", str( bool2int(evt.Checked()) ))
|
|
914
|
155
|
915 def on_raw_button(self,evt):
|
|
916 self.handler.list.set("raw_mode",str(bool2int(evt.Checked())))
|
|
917
|
|
918
|
|
919 ###############################
|
|
920 ## link image handlers
|
|
921 ###############################
|
|
922
|
|
923 class link_handler(node_handler):
|
|
924 """ A nodehandler for URLs. Will open URL in a wxHTMLFrame
|
|
925 <nodehandler name='?' module='forms' class='link_handler' >
|
|
926 <link href='http//??.??' />
|
|
927 </nodehandler >
|
|
928 """
|
|
929 def __init__(self,xml,tree_node):
|
|
930 node_handler.__init__(self,xml,tree_node)
|
|
931 self.link = self.xml[0]
|
|
932
|
|
933 def on_use(self,evt):
|
|
934 href = self.link.get("href")
|
|
935 wb = webbrowser.get()
|
|
936 wb.open(href)
|
|
937
|
|
938 def get_design_panel(self,parent):
|
|
939 return link_edit_panel(parent,self)
|
|
940
|
|
941 def get_use_panel(self,parent):
|
|
942 return link_panel(parent,self)
|
|
943
|
|
944 def tohtml(self):
|
|
945 href = self.link.get("href")
|
|
946 title = self.xml.get("name")
|
|
947 return "<a href='"+href+"' >"+title+"</a>"
|
|
948
|
|
949 class link_panel(wx.StaticText):
|
|
950 def __init__(self,parent,handler):
|
|
951 self.handler = handler
|
|
952 label = handler.xml.get('name')
|
|
953 wx.StaticText.__init__(self,parent,-1,label)
|
|
954 self.SetForegroundColour(wx.BLUE)
|
|
955 self.Bind(wx.EVT_LEFT_DOWN, self.handler.on_use)
|
|
956
|
|
957 P_URL = wx.NewId()
|
|
958
|
|
959 class link_edit_panel(wx.Panel):
|
|
960 def __init__(self, parent, handler):
|
|
961 wx.Panel.__init__(self, parent, -1)
|
|
962 self.handler = handler
|
|
963 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Link Properties"), wx.VERTICAL)
|
|
964
|
|
965 self.text = {}
|
|
966 self.text[P_TITLE] = wx.TextCtrl(self, P_TITLE, handler.xml.get('name'))
|
|
967 self.text[P_URL] = wx.TextCtrl(self, P_URL, handler.link.get('href'))
|
|
968
|
|
969 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND)
|
|
970 sizer.Add(self.text[P_TITLE], 0, wx.EXPAND)
|
|
971 sizer.Add(wx.Size(10,10))
|
|
972 sizer.Add(wx.StaticText(self, -1, "URL:"), 0, wx.EXPAND)
|
|
973 sizer.Add(self.text[P_URL], 0, wx.EXPAND)
|
|
974 self.SetSizer(sizer)
|
|
975 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE)
|
|
976 self.Bind(wx.EVT_TEXT, self.on_text, id=P_URL)
|
|
977
|
|
978 def on_text(self,evt):
|
|
979 id = evt.GetId()
|
|
980 txt = self.text[id].GetValue()
|
|
981 if not len(txt): return
|
|
982 if id == P_TITLE:
|
|
983 self.handler.xml.set('name',txt)
|
|
984 self.handler.rename(txt)
|
|
985 elif id == P_URL: self.handler.link.set('href',txt)
|
|
986
|
|
987 ##########################
|
|
988 ## webimg node handler
|
|
989 ##########################
|
|
990 class webimg_handler(node_handler):
|
|
991 """ A nodehandler for URLs. Will open URL in a wxHTMLFrame
|
|
992 <nodehandler name='?' module='forms' class='webimg_handler' >
|
|
993 <link href='http//??.??' />
|
|
994 </nodehandler >
|
|
995 """
|
|
996 def __init__(self,xml,tree_node):
|
|
997 node_handler.__init__(self,xml,tree_node)
|
|
998 self.link = self.xml[0]
|
|
999
|
|
1000 def get_design_panel(self,parent):
|
|
1001 return link_edit_panel(parent,self)
|
|
1002
|
|
1003 def get_use_panel(self,parent):
|
|
1004 img = img_helper().load_url(self.link.get("href"))
|
|
1005 if not img is None: return wx.StaticBitmap(parent,-1,img,size= wx.Size(img.GetWidth(),img.GetHeight()))
|
|
1006 return wx.EmptyBitmap(1, 1)
|
|
1007
|
|
1008 def tohtml(self):
|
|
1009 href = self.link.get("href")
|
|
1010 title = self.xml.get("name")
|
|
1011 return "<img src='"+href+"' alt="+title+" >"
|