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:
|
184
|
24 # $Id: forms.py,v Traipse 'Ornery-Orc' prof.ebral Exp $
|
156
|
25 #
|
|
26 # Description: The file contains code for the form based nodehanlers
|
|
27 #
|
|
28
|
184
|
29 __version__ = "$Id: forms.py,v Traipse 'Ornery-Orc' prof.ebral Exp $"
|
156
|
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)
|
184
|
757 sizer = wx.GridBagSizer(1, 1)
|
183
|
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))
|
184
|
767 sizer.Add(self.caption_entry, (0,1), span=(1,4), flag=wx.EXPAND)
|
183
|
768 sizer.Add(value_text, (1,0))
|
184
|
769 sizer.Add(self.value_entry, (1,1), span=(1,4), flag=wx.EXPAND)
|
183
|
770 sizer.Add(button_ok, (3,0))
|
|
771 sizer.Add(button_cancel, (3,1))
|
|
772 sizer.Add(button_ref, (3,2), flag=wx.EXPAND)
|
184
|
773 sizer.AddGrowableCol(3)
|
|
774 sizer.AddGrowableRow(2)
|
|
775 self.dlg.SetSize((275, 125))
|
|
776 self.dlg.SetMinSize((275, 125))
|
|
777 self.dlg.Layout()
|
183
|
778 self.Bind(wx.EVT_BUTTON, self.on_reference, id=BUT_REF)
|
|
779 self.Bind(wx.EVT_BUTTON, self.on_add_option, id=wx.ID_OK)
|
|
780 self.Bind(wx.EVT_BUTTON, self.on_edit_cancel, id=wx.ID_CANCEL)
|
|
781 self.dlg.Show()
|
|
782
|
|
783 def on_add_option(self, evt):
|
|
784 self.handler.add_option(self.caption_entry.GetValue(), self.value_entry.GetValue())
|
156
|
785 self.reload_options()
|
183
|
786 self.dlg.Destroy()
|
|
787 component.add('tree', component.get('tree_fs')) ## Backup
|
|
788 return
|
|
789
|
|
790 ## EZ_Tree Core TaS - Prof.Ebral ##
|
|
791 def on_reference(self, evt, car=None):
|
|
792 self.do_tree = wx.Frame(self, -1, 'EZ Tree')
|
|
793 self.ez_tree = orpg.gametree.gametree
|
|
794 self.temp_wnd = self.ez_tree.game_tree(self.do_tree, self.ez_tree.EZ_REF)
|
|
795 self.temp_wnd.Bind(wx.EVT_LEFT_DCLICK, self.on_ldclick)
|
|
796 component.get('tree_fs').save_tree(settings.get("gametree"))
|
|
797 self.temp_wnd.load_tree(settings.get("gametree"))
|
|
798 self.do_tree.Show()
|
|
799
|
|
800 def get_grid_ref(self, obj, complete):
|
|
801 self.temp_wnd.Freeze()
|
|
802 self.grid_ref = complete
|
|
803 self.mini_grid = wx.Frame(self, -1, 'EZ Tree Grid')
|
|
804 self.temp_grid = obj.get_use_panel(self.mini_grid)
|
|
805 self.temp_grid.grid.Bind(wx.grid.EVT_GRID_CELL_LEFT_DCLICK, self.on_grid_ldclick)
|
|
806 self.mini_grid.Show()
|
|
807
|
|
808 def on_grid_ldclick(self, evt):
|
|
809 complete = self.grid_ref
|
|
810 row = str(evt.GetRow()+1)
|
|
811 col = str(evt.GetCol()+1)
|
|
812 complete = complete[:len(complete)-2] + '::'+'('+row+','+col+')'+complete[len(complete)-2:]
|
|
813 self.value_entry.AppendText(complete)
|
|
814 self.mini_grid.Destroy()
|
|
815
|
|
816 def on_ldclick(self, evt):
|
|
817 self.rename_flag = 0
|
|
818 pt = evt.GetPosition()
|
|
819 (item, flag) = self.temp_wnd.HitTest(pt)
|
|
820 if item.IsOk():
|
|
821 obj = self.temp_wnd.GetPyData(item)
|
|
822 self.temp_wnd.SelectItem(item)
|
|
823 start = self.handler.xml.get('map').split('::')
|
|
824 end = obj.xml.get('map').split('::')
|
|
825 if obj.xml.get('class') not in ['rpg_grid_handler', 'textctrl_handler']: do = 'None'
|
|
826 elif end[0] == '' or start[0] != end[0]: do = 'Root'
|
|
827 elif start == end: do = 'Child'
|
|
828 elif start != end: do = 'Parent'
|
|
829 if do == 'Root':
|
|
830 complete = "!@"
|
|
831 for e in end:
|
|
832 if e != '': complete += e +'::'
|
|
833 complete = complete + obj.xml.get('name') + '@!'
|
|
834 elif do == 'Parent':
|
|
835 while start[0] == end[0]:
|
|
836 del end[0], start[0]
|
|
837 if len(start) == 0 or len(end) == 0: break
|
|
838 complete = "!#"
|
|
839 for e in end: complete += e +'::'
|
|
840 complete = complete + obj.xml.get('name') + '#!'
|
|
841 elif do == 'Child':
|
|
842 while start[0] == end[0]:
|
|
843 del end[0], start[0]
|
|
844 if len(start) == 0 or len(end) == 0: break
|
|
845 complete = "!!"
|
|
846 for e in end: complete += e +'::'
|
|
847 complete = complete + obj.xml.get('name') + '!!'
|
|
848 if do != 'None':
|
|
849 if obj.xml.get('class') == 'rpg_grid_handler':
|
|
850 self.get_grid_ref(obj, complete)
|
|
851 else: self.value_entry.AppendText(complete); self.reload_options()
|
|
852 self.do_tree.Destroy()
|
|
853 if do == 'None':
|
|
854 wx.MessageBox('Invalid Reference', 'Error')
|
|
855 ##### #####
|
|
856
|
|
857 def on_edit_ok(self, evt):
|
|
858 self.handler.edit_caption(self.index, self.caption_entry.GetValue())
|
|
859 self.handler.edit_option(self.index, self.value_entry.GetValue())
|
|
860 self.reload_options()
|
|
861 self.dlg.Destroy()
|
|
862 component.add('tree', component.get('tree_fs')) ## Backup
|
|
863 return
|
|
864
|
|
865 def on_edit_cancel(self, evt):
|
|
866 self.dlg.Destroy()
|
|
867 component.add('tree', component.get('tree_fs')) ## Backup
|
|
868 return
|
156
|
869
|
|
870 def on_remove(self,evt):
|
183
|
871 index = self.listbox.GetFocusedItem()
|
156
|
872 if index >= 0:
|
|
873 self.handler.remove_option(index)
|
|
874 self.reload_options()
|
|
875
|
|
876 def on_edit(self,evt):
|
183
|
877 self.index = self.listbox.GetFocusedItem()
|
|
878 if self.index >= 0:
|
|
879 self.dlg = wx.Frame(self, -1, 'Text', size=(300,150))
|
|
880 edit_panel = wx.Panel(self.dlg, -1)
|
|
881 sizer = wx.GridBagSizer(1, 2)
|
|
882 edit_panel.SetSizer(sizer)
|
|
883 caption_text = wx.StaticText(edit_panel, -1, 'Caption')
|
|
884 self.caption_entry = wx.TextCtrl(edit_panel, -1, self.handler.get_caption(self.index))
|
|
885 value_text = wx.StaticText(edit_panel, -1, 'Value')
|
|
886 self.value_entry = wx.TextCtrl(edit_panel, -1, self.handler.get_option(self.index))
|
|
887 button_ok = wx.Button(edit_panel, wx.ID_OK)
|
|
888 button_cancel = wx.Button(edit_panel, wx.ID_CANCEL)
|
|
889 button_ref = wx.Button(edit_panel, BUT_REF, "Reference")
|
|
890 sizer.Add(caption_text, (0,0))
|
184
|
891 sizer.Add(self.caption_entry, (0,1), span=(1,4), flag=wx.EXPAND)
|
183
|
892 sizer.Add(value_text, (1,0))
|
184
|
893 sizer.Add(self.value_entry, (1,1), span=(1,4), flag=wx.EXPAND)
|
183
|
894 sizer.Add(button_ok, (3,0))
|
|
895 sizer.Add(button_cancel, (3,1))
|
|
896 sizer.Add(button_ref, (3,2), flag=wx.EXPAND)
|
184
|
897 sizer.AddGrowableCol(3)
|
|
898 sizer.AddGrowableRow(2)
|
|
899 self.dlg.SetSize((275, 125))
|
|
900 self.dlg.SetMinSize((275, 125))
|
|
901 self.dlg.Layout()
|
183
|
902 self.Bind(wx.EVT_BUTTON, self.on_reference, id=BUT_REF)
|
|
903 self.Bind(wx.EVT_BUTTON, self.on_edit_ok, id=wx.ID_OK)
|
|
904 self.Bind(wx.EVT_BUTTON, self.on_edit_cancel, id=wx.ID_CANCEL)
|
|
905 self.dlg.Show()
|
156
|
906
|
|
907 def reload_options(self):
|
183
|
908 self.listbox.DeleteAllItems()
|
|
909 values = self.handler.get_options()
|
|
910 captions = self.handler.get_captions()
|
|
911 for index in range(len(values)):
|
|
912 self.listbox.Append((captions[index], values[index]))
|
156
|
913
|
|
914 def on_text(self,evt):
|
|
915 id = evt.GetId()
|
|
916 txt = self.text.GetValue()
|
|
917 if not len(txt): return
|
|
918 if id == P_TITLE:
|
|
919 self.handler.xml.set('name',txt)
|
|
920 self.handler.rename(txt)
|
|
921
|
|
922 def on_send_button(self,evt):
|
|
923 self.handler.list.set("send_button", str( bool2int(evt.Checked()) ))
|
|
924
|
|
925 def on_hide_button(self,evt):
|
142
|
926 self.handler.list.set("hide_title", str( bool2int(evt.Checked()) ))
|
|
927
|
156
|
928 def on_raw_button(self,evt):
|
|
929 self.handler.list.set("raw_mode",str(bool2int(evt.Checked())))
|
|
930
|
|
931
|
|
932 ###############################
|
|
933 ## link image handlers
|
|
934 ###############################
|
|
935
|
|
936 class link_handler(node_handler):
|
|
937 """ A nodehandler for URLs. Will open URL in a wxHTMLFrame
|
|
938 <nodehandler name='?' module='forms' class='link_handler' >
|
|
939 <link href='http//??.??' />
|
|
940 </nodehandler >
|
|
941 """
|
|
942 def __init__(self,xml,tree_node):
|
|
943 node_handler.__init__(self,xml,tree_node)
|
|
944 self.link = self.xml[0]
|
|
945
|
|
946 def on_use(self,evt):
|
|
947 href = self.link.get("href")
|
|
948 wb = webbrowser.get()
|
|
949 wb.open(href)
|
|
950
|
|
951 def get_design_panel(self,parent):
|
|
952 return link_edit_panel(parent,self)
|
|
953
|
|
954 def get_use_panel(self,parent):
|
|
955 return link_panel(parent,self)
|
|
956
|
|
957 def tohtml(self):
|
|
958 href = self.link.get("href")
|
|
959 title = self.xml.get("name")
|
|
960 return "<a href='"+href+"' >"+title+"</a>"
|
|
961
|
|
962 class link_panel(wx.StaticText):
|
|
963 def __init__(self,parent,handler):
|
|
964 self.handler = handler
|
|
965 label = handler.xml.get('name')
|
|
966 wx.StaticText.__init__(self,parent,-1,label)
|
|
967 self.SetForegroundColour(wx.BLUE)
|
|
968 self.Bind(wx.EVT_LEFT_DOWN, self.handler.on_use)
|
|
969
|
|
970 P_URL = wx.NewId()
|
|
971
|
|
972 class link_edit_panel(wx.Panel):
|
|
973 def __init__(self, parent, handler):
|
|
974 wx.Panel.__init__(self, parent, -1)
|
|
975 self.handler = handler
|
|
976 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Link Properties"), wx.VERTICAL)
|
|
977
|
|
978 self.text = {}
|
|
979 self.text[P_TITLE] = wx.TextCtrl(self, P_TITLE, handler.xml.get('name'))
|
|
980 self.text[P_URL] = wx.TextCtrl(self, P_URL, handler.link.get('href'))
|
|
981
|
|
982 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND)
|
|
983 sizer.Add(self.text[P_TITLE], 0, wx.EXPAND)
|
|
984 sizer.Add(wx.Size(10,10))
|
|
985 sizer.Add(wx.StaticText(self, -1, "URL:"), 0, wx.EXPAND)
|
|
986 sizer.Add(self.text[P_URL], 0, wx.EXPAND)
|
|
987 self.SetSizer(sizer)
|
|
988 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE)
|
|
989 self.Bind(wx.EVT_TEXT, self.on_text, id=P_URL)
|
|
990
|
|
991 def on_text(self,evt):
|
|
992 id = evt.GetId()
|
|
993 txt = self.text[id].GetValue()
|
|
994 if not len(txt): return
|
|
995 if id == P_TITLE:
|
|
996 self.handler.xml.set('name',txt)
|
|
997 self.handler.rename(txt)
|
|
998 elif id == P_URL: self.handler.link.set('href',txt)
|
|
999
|
|
1000 ##########################
|
|
1001 ## webimg node handler
|
|
1002 ##########################
|
|
1003 class webimg_handler(node_handler):
|
|
1004 """ A nodehandler for URLs. Will open URL in a wxHTMLFrame
|
|
1005 <nodehandler name='?' module='forms' class='webimg_handler' >
|
|
1006 <link href='http//??.??' />
|
|
1007 </nodehandler >
|
|
1008 """
|
|
1009 def __init__(self,xml,tree_node):
|
|
1010 node_handler.__init__(self,xml,tree_node)
|
|
1011 self.link = self.xml[0]
|
|
1012
|
|
1013 def get_design_panel(self,parent):
|
|
1014 return link_edit_panel(parent,self)
|
|
1015
|
|
1016 def get_use_panel(self,parent):
|
|
1017 img = img_helper().load_url(self.link.get("href"))
|
|
1018 if not img is None: return wx.StaticBitmap(parent,-1,img,size= wx.Size(img.GetWidth(),img.GetHeight()))
|
|
1019 return wx.EmptyBitmap(1, 1)
|
|
1020
|
|
1021 def tohtml(self):
|
|
1022 href = self.link.get("href")
|
|
1023 title = self.xml.get("name")
|
|
1024 return "<img src='"+href+"' alt="+title+" >"
|