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