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