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