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:
|
195
|
24 # $Id: forms.py,v Traipse 'Ornery-Orc' prof.ebral Exp $
|
155
|
25 #
|
|
26 # Description: The file contains code for the form based nodehanlers
|
|
27 #
|
|
28
|
195
|
29 __version__ = "$Id: forms.py,v Traipse 'Ornery-Orc' prof.ebral Exp $"
|
155
|
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
|
195
|
36 from orpg.tools.InterParse import Parse
|
155
|
37
|
|
38 def bool2int(b):
|
|
39 #in wxPython 2.5+, evt.Checked() returns True or False instead of 1.0 or 0.
|
|
40 #by running the results of that through this function, we convert it.
|
|
41 #if it was an int already, nothing changes. The difference between 1.0
|
|
42 #and 1, i.e. between ints and floats, is potentially dangerous when we
|
|
43 #use str() on it, but it seems to work fine right now.
|
|
44 if b: return 1
|
|
45 else: return 0
|
|
46
|
|
47 #################################
|
|
48 ## form container
|
|
49 #################################
|
|
50
|
|
51 class form_handler(container_handler):
|
|
52 """
|
|
53 <nodehandler name='?' module='forms' class='form_handler' >
|
|
54 <form width='100' height='100' />
|
|
55 </nodehandler>
|
|
56 """
|
|
57 def __init__(self,xml,tree_node):
|
|
58 container_handler.__init__(self, xml, tree_node)
|
|
59
|
|
60 def load_children(self):
|
|
61 self.atts = None
|
|
62 for child_xml in self.xml:
|
|
63 if child_xml.tag == "form": self.xml.remove(child_xml)
|
|
64 elif child_xml: self.tree.load_xml(child_xml, self.mytree_node)
|
|
65 if not self.xml.get('width'): self.xml.set('width', '400')
|
|
66 if not self.xml.get('height'): self.xml.set('height', '600')
|
|
67
|
|
68 def get_design_panel(self,parent):
|
|
69 return form_edit_panel(parent,self)
|
|
70
|
|
71 def get_use_panel(self,parent):
|
|
72 return form_panel(parent,self)
|
|
73
|
|
74 def on_drop(self,evt):
|
|
75 # make sure its a contorl node
|
|
76 container_handler.on_drop(self,evt)
|
|
77
|
|
78 class form_panel(ScrolledPanel):
|
|
79 def __init__(self, parent, handler):
|
|
80 ScrolledPanel.__init__(self, parent, wx.ID_ANY, style=wx.NO_BORDER|wx.VSCROLL|wx.HSCROLL)
|
|
81 self.height = int(handler.xml.get("height"))
|
|
82 self.width = int(handler.xml.get("width"))
|
|
83 self.SetSize((0,0))
|
|
84 self.handler = handler
|
|
85 self.parent = parent
|
|
86 self.main_sizer = wx.BoxSizer(wx.VERTICAL)
|
|
87 handler.tree.traverse(handler.mytree_node, self.create_child_wnd, None, False)
|
|
88 self.SetSizer(self.main_sizer)
|
|
89 self.SetAutoLayout(True)
|
|
90 self.SetupScrolling()
|
|
91 parent.SetSize(self.GetSize())
|
|
92 self.Fit()
|
|
93
|
|
94 def SetSize(self, xy):
|
|
95 (x, y) = self.GetSize()
|
|
96 (nx, ny) = xy
|
|
97 if x < nx:
|
|
98 x = nx+10
|
|
99 y += ny+11
|
|
100 ScrolledPanel.SetSize(self, (x, y))
|
|
101
|
|
102 def create_child_wnd(self, treenode, evt):
|
|
103 node = self.handler.tree.GetPyData(treenode)
|
|
104 panel = node.get_use_panel(self)
|
|
105 size = node.get_size_constraint()
|
|
106 if panel:
|
|
107 self.main_sizer.Add(panel, size, wx.EXPAND)
|
|
108 self.main_sizer.Add(wx.Size(10,10))
|
|
109
|
|
110 F_HEIGHT = wx.NewId()
|
|
111 F_WIDTH = wx.NewId()
|
|
112 class form_edit_panel(wx.Panel):
|
|
113 def __init__(self, parent, handler):
|
|
114 wx.Panel.__init__(self, parent, -1)
|
|
115 self.handler = handler
|
|
116 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Form Properties"), wx.VERTICAL)
|
|
117 wh_sizer = wx.BoxSizer(wx.HORIZONTAL)
|
|
118 self.text = { P_TITLE : wx.TextCtrl(self, P_TITLE, handler.xml.get('name')),
|
|
119 F_HEIGHT : wx.TextCtrl(self, F_HEIGHT, handler.xml.get('height')),
|
|
120 F_WIDTH : wx.TextCtrl(self, F_WIDTH, handler.xml.get('width'))
|
|
121 }
|
|
122
|
|
123 wh_sizer.Add(wx.StaticText(self, -1, "Width:"), 0, wx.ALIGN_CENTER)
|
|
124 wh_sizer.Add(wx.Size(10,10))
|
|
125 wh_sizer.Add(self.text[F_WIDTH], 0, wx.EXPAND)
|
|
126 wh_sizer.Add(wx.Size(10,10))
|
|
127 wh_sizer.Add(wx.StaticText(self, -1, "Height:"), 0, wx.ALIGN_CENTER)
|
|
128 wh_sizer.Add(wx.Size(10,10))
|
|
129 wh_sizer.Add(self.text[F_HEIGHT], 0, wx.EXPAND)
|
|
130
|
|
131 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND)
|
|
132 sizer.Add(self.text[P_TITLE], 0, wx.EXPAND)
|
|
133 sizer.Add(wx.Size(10,10))
|
|
134 sizer.Add(wh_sizer,0,wx.EXPAND)
|
|
135
|
|
136 self.SetSizer(sizer)
|
|
137 self.SetAutoLayout(True)
|
|
138 self.Fit()
|
|
139 parent.SetSize(self.GetBestSize())
|
|
140
|
|
141 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE)
|
|
142 self.Bind(wx.EVT_TEXT, self.on_text, id=F_HEIGHT)
|
|
143 self.Bind(wx.EVT_TEXT, self.on_text, id=F_WIDTH)
|
|
144
|
|
145 def on_text(self,evt):
|
|
146 id = evt.GetId()
|
|
147 txt = self.text[id].GetValue()
|
|
148 if not len(txt): return
|
|
149 if id == P_TITLE:
|
|
150 self.handler.xml.set('name',txt)
|
|
151 self.handler.rename(txt)
|
|
152 elif id == F_HEIGHT or id == F_WIDTH:
|
|
153 try: int(txt)
|
|
154 except: return 0
|
|
155 if id == F_HEIGHT: self.handler.xml.set("height",txt)
|
|
156 elif id == F_WIDTH: self.handler.xml.set("width",txt)
|
|
157
|
|
158 ##########################
|
|
159 ## control handler
|
|
160 ##########################
|
|
161 class control_handler(node_handler):
|
|
162 """ A nodehandler for form controls.
|
|
163 <nodehandler name='?' module='forms' class='control_handler' />
|
|
164 """
|
|
165 def __init__(self, xml, tree_node):
|
|
166 node_handler.__init__(self, xml, tree_node)
|
|
167
|
|
168 def get_size_constraint(self):
|
|
169 return 0
|
|
170
|
|
171 ##########################
|
|
172 ## textctrl handler
|
|
173 ##########################
|
|
174 #
|
|
175 # Updated by Snowdog (April 2003)
|
|
176 # Now includes Raw Send Mode (like the chat macro uses)
|
|
177 # and an option to remove the title from text when sent
|
|
178 # to the chat in the normal non-chat macro mode.
|
|
179 #
|
|
180 class textctrl_handler(node_handler):
|
|
181 """ <nodehandler class="textctrl_handler" module="form" name="">
|
|
182 <text multiline='0' send_button='0' raw_mode='0' hide_title='0'>Text In Node</text>
|
|
183 </nodehandler>
|
|
184 """
|
|
185 def __init__(self,xml,tree_node):
|
|
186 node_handler.__init__(self,xml,tree_node)
|
|
187 self.text_elem = self.xml.find('text')
|
|
188 if self.text_elem.get("send_button") == "": self.text_elem.set("send_button","0")
|
|
189 if self.text_elem.get("raw_mode") == "": self.text_elem.set("raw_mode","0")
|
|
190 if self.text_elem.get("hide_title") == "": self.text_elem.set("hide_title","0")
|
|
191
|
|
192 def get_design_panel(self,parent):
|
|
193 return textctrl_edit_panel(parent,self)
|
|
194
|
|
195 def get_use_panel(self,parent):
|
|
196 return text_panel(parent,self)
|
|
197
|
|
198 def get_size_constraint(self):
|
|
199 return int(self.text_elem.get("multiline",0))
|
|
200
|
|
201 def is_multi_line(self):
|
|
202 return int(self.text_elem.get("multiline",0))
|
|
203
|
|
204 def is_raw_send(self):
|
|
205 return int(self.text_elem.get("raw_mode",0))
|
|
206
|
|
207 def is_hide_title(self):
|
|
208 return int(self.text_elem.get("hide_title",0))
|
|
209
|
|
210 def has_send_button(self):
|
|
211 return int(self.text_elem.get("send_button",0))
|
|
212
|
|
213 def tohtml(self):
|
|
214 txt = self.get_value()
|
|
215 txt = string.replace(txt,'\n',"<br />")
|
|
216 if not self.is_hide_title(): txt = "<b>"+self.xml.get("name")+":</b> "+txt
|
|
217 return txt
|
|
218
|
|
219 def get_value(self):
|
|
220 return self.text_elem.text
|
|
221
|
|
222 def set_value(self, new_value):
|
|
223 self.text_elem.text = str(new_value)
|
|
224
|
|
225 FORM_TEXT_CTRL = wx.NewId()
|
|
226 FORM_SEND_BUTTON = wx.NewId()
|
|
227
|
|
228 class text_panel(wx.Panel):
|
|
229 def __init__(self, parent, handler):
|
|
230 wx.Panel.__init__(self, parent, -1)
|
|
231 self.chat = handler.chat
|
|
232 self.handler = handler
|
|
233 if handler.is_multi_line():
|
|
234 text_style = wx.TE_MULTILINE
|
|
235 sizer_style = wx.EXPAND
|
|
236 sizer = wx.BoxSizer(wx.VERTICAL)
|
|
237 else:
|
|
238 sizer_style = wx.ALIGN_CENTER
|
|
239 text_style = 0
|
|
240 sizer = wx.BoxSizer(wx.HORIZONTAL)
|
|
241
|
|
242 txt = handler.get_value()
|
|
243 if txt == None: txt = ''
|
|
244 self.text = wx.TextCtrl(self, FORM_TEXT_CTRL, txt, style=text_style)
|
|
245 sizer.Add(wx.StaticText(self, -1, handler.xml.get('name')+": "), 0, sizer_style)
|
|
246 sizer.Add(wx.Size(5,0))
|
|
247 sizer.Add(self.text, 1, sizer_style)
|
|
248
|
|
249 if handler.has_send_button(): sizer.Add(wx.Button(self, FORM_SEND_BUTTON, "Send"), 0, sizer_style)
|
|
250
|
|
251 self.sizer = sizer
|
|
252 self.SetSizer(sizer)
|
|
253 self.SetAutoLayout(True)
|
|
254
|
|
255 parent.SetSize(self.GetBestSize())
|
|
256 self.Bind(wx.EVT_TEXT, self.on_text, id=FORM_TEXT_CTRL)
|
132
|
257 self.Bind(wx.EVT_BUTTON, self.on_send, id=FORM_SEND_BUTTON)
|
|
258
|
|
259 def on_text(self, evt):
|
155
|
260 txt = self.text.GetValue()
|
|
261 #txt = strip_text(txt) ##Does not seem to exist.
|
|
262 self.handler.text_elem.text = txt
|
|
263
|
|
264 def on_send(self, evt):
|
132
|
265 txt = self.text.GetValue()
|
195
|
266 txt = Parse.ParseLogic(txt, self.handler.xml)
|
155
|
267 if not self.handler.is_raw_send():
|
195
|
268 Parse.Post(self.handler.tohtml(), True, True)
|
155
|
269 return 1
|
|
270 actionlist = txt.split("\n")
|
|
271 for line in actionlist:
|
195
|
272 line = Parse.ParseLogic(line, self.handler.xml)
|
155
|
273 if(line != ""):
|
|
274 if line[0] != "/": ## it's not a slash command
|
195
|
275 Parse.Post(line, True, True)
|
155
|
276 else:
|
|
277 action = line
|
|
278 self.chat.chat_cmds.docmd(action)
|
|
279 return 1
|
|
280
|
|
281 F_MULTI = wx.NewId()
|
|
282 F_SEND_BUTTON = wx.NewId()
|
|
283 F_RAW_SEND = wx.NewId()
|
|
284 F_HIDE_TITLE = wx.NewId()
|
|
285 F_TEXT = wx.NewId()
|
173
|
286 T_BUT_REF = wx.NewId()
|
155
|
287
|
|
288 class textctrl_edit_panel(wx.Panel):
|
|
289 def __init__(self, parent, handler):
|
|
290 wx.Panel.__init__(self, parent, -1)
|
|
291 self.handler = handler
|
180
|
292 self.parent = parent
|
155
|
293 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Text Properties"), wx.VERTICAL)
|
|
294
|
|
295 self.title = wx.TextCtrl(self, P_TITLE, handler.xml.get('name'))
|
|
296 self.multi = wx.CheckBox(self, F_MULTI, " Multi-Line")
|
|
297 self.multi.SetValue(handler.is_multi_line())
|
|
298 self.raw_send = wx.CheckBox(self, F_RAW_SEND, " Send as Macro")
|
|
299 self.raw_send.SetValue(handler.is_raw_send())
|
|
300 self.hide_title = wx.CheckBox(self, F_HIDE_TITLE, " Hide Title")
|
|
301 self.hide_title.SetValue(handler.is_hide_title())
|
|
302 self.send_button = wx.CheckBox(self, F_SEND_BUTTON, " Send Button")
|
|
303 self.send_button.SetValue(handler.has_send_button())
|
173
|
304 button_ref = wx.Button(self, T_BUT_REF, "Reference")
|
155
|
305
|
|
306 sizer.Add(wx.StaticText(self, P_TITLE, "Title:"), 0, wx.EXPAND)
|
|
307 sizer.Add(self.title, 0, wx.EXPAND)
|
|
308 sizer.Add(wx.Size(10,10))
|
|
309 sizer.Add(self.multi, 0, wx.EXPAND)
|
|
310 sizer.Add(self.raw_send, 0, wx.EXPAND)
|
|
311 sizer.Add(self.hide_title, 0, wx.EXPAND)
|
|
312 sizer.Add(self.send_button, 0 , wx.EXPAND)
|
173
|
313 sizer.Add(button_ref, 0)
|
155
|
314 sizer.Add(wx.Size(10,10))
|
|
315 if handler.is_multi_line():
|
|
316 sizer_style = wx.EXPAND
|
|
317 text_style = wx.TE_MULTILINE
|
|
318 multi = 1
|
|
319 else:
|
|
320 sizer_style=wx.EXPAND
|
|
321 text_style = 0
|
|
322 multi = 0
|
|
323 self.text = wx.TextCtrl(self, F_TEXT, handler.get_value(),style=text_style)
|
|
324 sizer.Add(wx.Size(5,0))
|
|
325 sizer.Add(self.text, multi, sizer_style)
|
|
326 self.SetSizer(sizer)
|
|
327 self.SetAutoLayout(True)
|
|
328
|
|
329 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE)
|
|
330 self.Bind(wx.EVT_TEXT, self.on_text, id=F_TEXT)
|
|
331 self.Bind(wx.EVT_CHECKBOX, self.on_button, id=F_MULTI)
|
|
332 self.Bind(wx.EVT_CHECKBOX, self.on_raw_button, id=F_RAW_SEND)
|
|
333 self.Bind(wx.EVT_CHECKBOX, self.on_hide_button, id=F_HIDE_TITLE)
|
|
334 self.Bind(wx.EVT_CHECKBOX, self.on_send_button, id=F_SEND_BUTTON)
|
173
|
335 self.Bind(wx.EVT_BUTTON, self.on_reference, id=T_BUT_REF)
|
180
|
336 self.parent.Bind(wx.EVT_CLOSE, self.tree_failsafe)
|
173
|
337
|
|
338 ## EZ_Tree Core TaS - Prof.Ebral ##
|
|
339 def on_reference(self, evt, car=None):
|
178
|
340 self.do_tree = wx.Frame(self, -1, 'EZ Tree')
|
173
|
341 self.ez_tree = orpg.gametree.gametree
|
|
342 self.temp_wnd = self.ez_tree.game_tree(self.do_tree, self.ez_tree.EZ_REF)
|
|
343 self.temp_wnd.Bind(wx.EVT_LEFT_DCLICK, self.on_ldclick)
|
178
|
344 component.get('tree_fs').save_tree(settings.get("gametree"))
|
173
|
345 self.temp_wnd.load_tree(settings.get("gametree"))
|
|
346 self.do_tree.Show()
|
|
347
|
180
|
348 def tree_failsafe(self, evt):
|
|
349 self.parent.Destroy()
|
|
350 component.add('tree', component.get('tree_fs')) ## Backup
|
|
351
|
176
|
352 def get_grid_ref(self, obj, complete):
|
|
353 self.temp_wnd.Freeze()
|
|
354 self.grid_ref = complete
|
178
|
355 self.mini_grid = wx.Frame(self, -1, 'EZ Tree Mini Grid')
|
176
|
356 self.temp_grid = obj.get_use_panel(self.mini_grid)
|
|
357 self.temp_grid.grid.Bind(wx.grid.EVT_GRID_CELL_LEFT_DCLICK, self.on_grid_ldclick)
|
|
358 self.mini_grid.Show()
|
|
359
|
|
360 def on_grid_ldclick(self, evt):
|
|
361 complete = self.grid_ref
|
|
362 row = str(evt.GetRow()+1)
|
|
363 col = str(evt.GetCol()+1)
|
|
364 complete = complete[:len(complete)-2] + '::'+'('+row+','+col+')'+complete[len(complete)-2:]
|
|
365 self.text.AppendText(complete); self.on_text(evt)
|
178
|
366 self.mini_grid.Destroy()
|
176
|
367
|
173
|
368 def on_ldclick(self, evt):
|
|
369 self.rename_flag = 0
|
|
370 pt = evt.GetPosition()
|
|
371 (item, flag) = self.temp_wnd.HitTest(pt)
|
|
372 if item.IsOk():
|
|
373 obj = self.temp_wnd.GetPyData(item)
|
|
374 self.temp_wnd.SelectItem(item)
|
|
375 start = self.handler.xml.get('map').split('::')
|
|
376 end = obj.xml.get('map').split('::')
|
175
|
377 if obj.xml.get('class') not in ['rpg_grid_handler', 'textctrl_handler']: do = 'None'
|
174
|
378 elif end[0] == '' or start[0] != end[0]: do = 'Root'
|
|
379 elif start == end: do = 'Child'
|
|
380 elif start != end: do = 'Parent'
|
|
381 if do == 'Root':
|
|
382 complete = "!@"
|
|
383 for e in end:
|
|
384 if e != '': complete += e +'::'
|
|
385 complete = complete + obj.xml.get('name') + '@!'
|
|
386 elif do == 'Parent':
|
|
387 while start[0] == end[0]:
|
|
388 del end[0], start[0]
|
|
389 if len(start) == 0 or len(end) == 0: break
|
181
|
390 complete = "!#"
|
174
|
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()
|
195
|
599 txt = Parse.ParseLogic(txt, self.xml)
|
155
|
600 if not self.is_raw_send():
|
195
|
601 Parse.Post(self.tohtml(), True, True)
|
155
|
602 return 1
|
|
603 actionlist = self.get_selections_text()
|
141
|
604 for line in actionlist:
|
195
|
605 line = Parse.ParseLogic(line, self.xml)
|
155
|
606 if(line != ""):
|
|
607 if line[0] != "/": ## it's not a slash command
|
195
|
608 Parse.Post(line, True, True)
|
155
|
609 else:
|
|
610 action = line
|
|
611 self.chat.chat_cmds.docmd(action)
|
|
612 return 1
|
|
613
|
|
614
|
|
615 F_LIST = wx.NewId()
|
|
616 F_SEND = wx.NewId()
|
|
617
|
|
618
|
|
619 class listbox_panel(wx.Panel):
|
|
620 def __init__(self, parent, handler):
|
|
621 wx.Panel.__init__(self, parent, -1)
|
|
622 self.handler = handler
|
|
623 self.chat = handler.chat
|
173
|
624 opts = []
|
|
625 values = handler.get_options()
|
|
626 captions = handler.get_captions()
|
|
627 for value in values:
|
|
628 if captions[values.index(value)] != '': opts.append(captions[values.index(value)])
|
|
629 else: opts.append(value)
|
155
|
630 cur_opt = handler.get_selected_text()
|
|
631 type = handler.get_type()
|
|
632 label = handler.xml.get('name')
|
|
633
|
|
634 if type == L_DROP:
|
|
635 self.list = wx.ComboBox(self, F_LIST, cur_opt, choices=opts, style=wx.CB_READONLY)
|
|
636 if self.list.GetSize()[0] > 200:
|
|
637 self.list.Destroy()
|
|
638 self.list = wx.ComboBox(self, F_LIST, cur_opt, size=(200, -1), choices=opts, style=wx.CB_READONLY)
|
|
639 elif type == L_LIST: self.list = wx.ListBox(self,F_LIST,choices=opts)
|
|
640 elif type == L_RADIO: self.list = wx.RadioBox(self,F_LIST,label,choices=opts,majorDimension=3)
|
|
641 elif type == L_CHECK:
|
|
642 self.list = wx.CheckListBox(self,F_LIST,choices=opts)
|
|
643 self.set_checks()
|
|
644
|
|
645 for i in handler.get_selections_text():
|
|
646 if type == L_DROP: self.list.SetValue( i )
|
|
647 else: self.list.SetStringSelection( i )
|
|
648 if type == L_DROP: sizer = wx.BoxSizer(wx.HORIZONTAL)
|
|
649 else: sizer = wx.BoxSizer(wx.VERTICAL)
|
|
650
|
|
651 if type != L_RADIO:
|
|
652 sizer.Add(wx.StaticText(self, -1, label+": "), 0, wx.EXPAND)
|
|
653 sizer.Add(wx.Size(5,0))
|
|
654 sizer.Add(self.list, 1, wx.EXPAND)
|
|
655 if handler.has_send_button():
|
|
656 sizer.Add(wx.Button(self, F_SEND, "Send"), 0, wx.EXPAND)
|
|
657 self.Bind(wx.EVT_BUTTON, self.handler.on_send_to_chat, id=F_SEND)
|
|
658 self.sizer = sizer
|
|
659 self.SetSizer(sizer)
|
|
660 self.SetAutoLayout(True)
|
|
661 self.Fit()
|
|
662 parent.SetSize(self.GetBestSize())
|
|
663
|
|
664 if type == L_DROP: self.Bind(wx.EVT_COMBOBOX, self.on_change, id=F_LIST)
|
|
665 elif type == L_LIST: self.Bind(wx.EVT_LISTBOX, self.on_change, id=F_LIST)
|
|
666 elif type == L_RADIO: self.Bind(wx.EVT_RADIOBOX, self.on_change, id=F_LIST)
|
|
667 elif type == L_CHECK:self.Bind(wx.EVT_CHECKLISTBOX, self.on_check, id=F_LIST)
|
|
668 self.type = type
|
|
669
|
|
670 def on_change(self,evt):
|
|
671 self.handler.set_selected_node(self.list.GetSelection())
|
|
672
|
|
673 def on_check(self,evt):
|
141
|
674 for i in xrange(self.list.GetCount()): self.handler.set_selected_node(i, bool2int(self.list.IsChecked(i)))
|
155
|
675
|
|
676 def set_checks(self):
|
|
677 for i in self.handler.get_selections_index(): self.list.Check(i)
|
|
678
|
|
679
|
|
680 BUT_ADD = wx.NewId()
|
|
681 BUT_REM = wx.NewId()
|
173
|
682 BUT_REF = wx.NewId()
|
155
|
683 BUT_EDIT = wx.NewId()
|
|
684 F_TYPE = wx.NewId()
|
|
685 F_NO_TITLE = wx.NewId()
|
173
|
686 LIST_CTRL = wx.NewId()
|
155
|
687
|
|
688 class listbox_edit_panel(wx.Panel):
|
|
689 def __init__(self, parent, handler):
|
|
690 wx.Panel.__init__(self, parent, -1)
|
|
691 self.handler = handler
|
173
|
692 self.parent = parent
|
155
|
693 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "List Box Properties"), wx.VERTICAL)
|
|
694
|
|
695 self.text = wx.TextCtrl(self, P_TITLE, handler.xml.get('name'))
|
173
|
696 self.listbox = wx.ListCtrl(self, LIST_CTRL, style=wx.LC_REPORT)
|
|
697 self.listbox.InsertColumn(0, 'Caption')
|
|
698 self.listbox.InsertColumn(1, 'Value')
|
|
699 self.listbox.SetColumnWidth(0, 75)
|
|
700 self.listbox.SetColumnWidth(1, 300)
|
|
701 self.reload_options()
|
|
702
|
155
|
703 opts = ['Drop Down', 'List Box', 'Radio Box', 'Check List']
|
|
704 self.type_radios = wx.RadioBox(self,F_TYPE,"List Type",choices=opts)
|
|
705 self.type_radios.SetSelection(handler.get_type())
|
|
706
|
|
707 self.send_button = wx.CheckBox(self, F_SEND_BUTTON, " Send Button")
|
141
|
708 self.send_button.SetValue(handler.has_send_button())
|
|
709
|
155
|
710 self.raw_send = wx.CheckBox(self, F_RAW_SEND, " Send as Macro")
|
|
711 self.raw_send.SetValue(handler.is_raw_send())
|
|
712
|
|
713 self.hide_title = wx.CheckBox(self, F_NO_TITLE, " Hide Title")
|
|
714 self.hide_title.SetValue(handler.is_hide_title())
|
|
715
|
|
716 but_sizer = wx.BoxSizer(wx.HORIZONTAL)
|
|
717 but_sizer.Add(wx.Button(self, BUT_ADD, "Add"), 1, wx.EXPAND)
|
|
718 but_sizer.Add(wx.Size(10,10))
|
|
719 but_sizer.Add(wx.Button(self, BUT_EDIT, "Edit"), 1, wx.EXPAND)
|
|
720 but_sizer.Add(wx.Size(10,10))
|
|
721 but_sizer.Add(wx.Button(self, BUT_REM, "Remove"), 1, wx.EXPAND)
|
|
722
|
|
723 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND)
|
|
724 sizer.Add(self.text, 0, wx.EXPAND)
|
|
725 sizer.Add(wx.Size(10,10))
|
|
726 sizer.Add(self.type_radios, 0, wx.EXPAND)
|
|
727 sizer.Add(wx.Size(10,10))
|
|
728 sizer.Add(self.send_button, 0 , wx.EXPAND)
|
141
|
729 sizer.Add(self.hide_title, 0, wx.EXPAND)
|
155
|
730 sizer.Add(self.raw_send, 0, wx.EXPAND)
|
|
731 sizer.Add(wx.Size(10,10))
|
|
732 sizer.Add(wx.StaticText(self, -1, "Options:"), 0, wx.EXPAND)
|
|
733 sizer.Add(self.listbox,1,wx.EXPAND);
|
|
734 sizer.Add(but_sizer,0,wx.EXPAND)
|
|
735
|
|
736 self.SetSizer(sizer)
|
|
737 self.SetAutoLayout(True)
|
|
738 self.Fit()
|
|
739 parent.SetSize(self.GetBestSize())
|
|
740
|
|
741 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE)
|
|
742 self.Bind(wx.EVT_BUTTON, self.on_edit, id=BUT_EDIT)
|
|
743 self.Bind(wx.EVT_BUTTON, self.on_remove, id=BUT_REM)
|
|
744 self.Bind(wx.EVT_BUTTON, self.on_add, id=BUT_ADD)
|
|
745 self.Bind(wx.EVT_RADIOBOX, self.on_type, id=F_TYPE)
|
|
746 self.Bind(wx.EVT_CHECKBOX, self.on_hide_button, id=F_NO_TITLE)
|
141
|
747 self.Bind(wx.EVT_CHECKBOX, self.on_send_button, id=F_SEND_BUTTON)
|
155
|
748 self.Bind(wx.EVT_CHECKBOX, self.on_raw_button, id=F_RAW_SEND)
|
|
749
|
|
750 def on_type(self,evt):
|
|
751 self.handler.set_type(evt.GetInt())
|
|
752
|
|
753 def on_add(self,evt):
|
173
|
754 self.dlg = wx.Frame(self, -1, 'Text', size=(300,150))
|
|
755 edit_panel = wx.Panel(self.dlg, -1)
|
195
|
756 sizer = wx.GridBagSizer(1, 1)
|
173
|
757 edit_panel.SetSizer(sizer)
|
|
758 caption_text = wx.StaticText(edit_panel, -1, 'Caption')
|
|
759 self.caption_entry = wx.TextCtrl(edit_panel, -1, '')
|
|
760 value_text = wx.StaticText(edit_panel, -1, 'Value')
|
|
761 self.value_entry = wx.TextCtrl(edit_panel, -1, '')
|
|
762 button_ok = wx.Button(edit_panel, wx.ID_OK)
|
|
763 button_cancel = wx.Button(edit_panel, wx.ID_CANCEL)
|
|
764 button_ref = wx.Button(edit_panel, BUT_REF, "Reference")
|
|
765 sizer.Add(caption_text, (0,0))
|
195
|
766 sizer.Add(self.caption_entry, (0,1), span=(1,4), flag=wx.EXPAND)
|
173
|
767 sizer.Add(value_text, (1,0))
|
195
|
768 sizer.Add(self.value_entry, (1,1), span=(1,4), flag=wx.EXPAND)
|
173
|
769 sizer.Add(button_ok, (3,0))
|
|
770 sizer.Add(button_cancel, (3,1))
|
|
771 sizer.Add(button_ref, (3,2), flag=wx.EXPAND)
|
195
|
772 sizer.AddGrowableCol(3)
|
|
773 sizer.AddGrowableRow(2)
|
|
774 self.dlg.SetSize((275, 125))
|
|
775 self.dlg.SetMinSize((275, 125))
|
|
776 self.dlg.Layout()
|
173
|
777 self.Bind(wx.EVT_BUTTON, self.on_reference, id=BUT_REF)
|
|
778 self.Bind(wx.EVT_BUTTON, self.on_add_option, id=wx.ID_OK)
|
|
779 self.Bind(wx.EVT_BUTTON, self.on_edit_cancel, id=wx.ID_CANCEL)
|
|
780 self.dlg.Show()
|
|
781
|
|
782 def on_add_option(self, evt):
|
|
783 self.handler.add_option(self.caption_entry.GetValue(), self.value_entry.GetValue())
|
155
|
784 self.reload_options()
|
173
|
785 self.dlg.Destroy()
|
180
|
786 component.add('tree', component.get('tree_fs')) ## Backup
|
173
|
787 return
|
|
788
|
|
789 ## EZ_Tree Core TaS - Prof.Ebral ##
|
|
790 def on_reference(self, evt, car=None):
|
178
|
791 self.do_tree = wx.Frame(self, -1, 'EZ Tree')
|
173
|
792 self.ez_tree = orpg.gametree.gametree
|
|
793 self.temp_wnd = self.ez_tree.game_tree(self.do_tree, self.ez_tree.EZ_REF)
|
|
794 self.temp_wnd.Bind(wx.EVT_LEFT_DCLICK, self.on_ldclick)
|
178
|
795 component.get('tree_fs').save_tree(settings.get("gametree"))
|
173
|
796 self.temp_wnd.load_tree(settings.get("gametree"))
|
|
797 self.do_tree.Show()
|
|
798
|
176
|
799 def get_grid_ref(self, obj, complete):
|
|
800 self.temp_wnd.Freeze()
|
|
801 self.grid_ref = complete
|
178
|
802 self.mini_grid = wx.Frame(self, -1, 'EZ Tree Grid')
|
176
|
803 self.temp_grid = obj.get_use_panel(self.mini_grid)
|
|
804 self.temp_grid.grid.Bind(wx.grid.EVT_GRID_CELL_LEFT_DCLICK, self.on_grid_ldclick)
|
|
805 self.mini_grid.Show()
|
|
806
|
|
807 def on_grid_ldclick(self, evt):
|
|
808 complete = self.grid_ref
|
|
809 row = str(evt.GetRow()+1)
|
|
810 col = str(evt.GetCol()+1)
|
|
811 complete = complete[:len(complete)-2] + '::'+'('+row+','+col+')'+complete[len(complete)-2:]
|
|
812 self.value_entry.AppendText(complete)
|
178
|
813 self.mini_grid.Destroy()
|
176
|
814
|
173
|
815 def on_ldclick(self, evt):
|
|
816 self.rename_flag = 0
|
|
817 pt = evt.GetPosition()
|
|
818 (item, flag) = self.temp_wnd.HitTest(pt)
|
|
819 if item.IsOk():
|
|
820 obj = self.temp_wnd.GetPyData(item)
|
|
821 self.temp_wnd.SelectItem(item)
|
|
822 start = self.handler.xml.get('map').split('::')
|
|
823 end = obj.xml.get('map').split('::')
|
176
|
824 if obj.xml.get('class') not in ['rpg_grid_handler', 'textctrl_handler']: do = 'None'
|
174
|
825 elif end[0] == '' or start[0] != end[0]: do = 'Root'
|
|
826 elif start == end: do = 'Child'
|
|
827 elif start != end: do = 'Parent'
|
|
828 if do == 'Root':
|
|
829 complete = "!@"
|
|
830 for e in end:
|
|
831 if e != '': complete += e +'::'
|
|
832 complete = complete + obj.xml.get('name') + '@!'
|
|
833 elif do == 'Parent':
|
|
834 while start[0] == end[0]:
|
|
835 del end[0], start[0]
|
|
836 if len(start) == 0 or len(end) == 0: break
|
181
|
837 complete = "!#"
|
174
|
838 for e in end: complete += e +'::'
|
|
839 complete = complete + obj.xml.get('name') + '#!'
|
|
840 elif do == 'Child':
|
|
841 while start[0] == end[0]:
|
|
842 del end[0], start[0]
|
|
843 if len(start) == 0 or len(end) == 0: break
|
|
844 complete = "!!"
|
|
845 for e in end: complete += e +'::'
|
|
846 complete = complete + obj.xml.get('name') + '!!'
|
176
|
847 if do != 'None':
|
|
848 if obj.xml.get('class') == 'rpg_grid_handler':
|
|
849 self.get_grid_ref(obj, complete)
|
|
850 else: self.value_entry.AppendText(complete); self.reload_options()
|
173
|
851 self.do_tree.Destroy()
|
174
|
852 if do == 'None':
|
|
853 wx.MessageBox('Invalid Reference', 'Error')
|
173
|
854 ##### #####
|
|
855
|
|
856 def on_edit_ok(self, evt):
|
|
857 self.handler.edit_caption(self.index, self.caption_entry.GetValue())
|
|
858 self.handler.edit_option(self.index, self.value_entry.GetValue())
|
|
859 self.reload_options()
|
|
860 self.dlg.Destroy()
|
180
|
861 component.add('tree', component.get('tree_fs')) ## Backup
|
173
|
862 return
|
|
863
|
|
864 def on_edit_cancel(self, evt):
|
|
865 self.dlg.Destroy()
|
180
|
866 component.add('tree', component.get('tree_fs')) ## Backup
|
173
|
867 return
|
155
|
868
|
|
869 def on_remove(self,evt):
|
182
|
870 index = self.listbox.GetFocusedItem()
|
155
|
871 if index >= 0:
|
|
872 self.handler.remove_option(index)
|
|
873 self.reload_options()
|
|
874
|
|
875 def on_edit(self,evt):
|
173
|
876 self.index = self.listbox.GetFocusedItem()
|
|
877 if self.index >= 0:
|
|
878 self.dlg = wx.Frame(self, -1, 'Text', size=(300,150))
|
|
879 edit_panel = wx.Panel(self.dlg, -1)
|
|
880 sizer = wx.GridBagSizer(1, 2)
|
|
881 edit_panel.SetSizer(sizer)
|
|
882 caption_text = wx.StaticText(edit_panel, -1, 'Caption')
|
|
883 self.caption_entry = wx.TextCtrl(edit_panel, -1, self.handler.get_caption(self.index))
|
|
884 value_text = wx.StaticText(edit_panel, -1, 'Value')
|
|
885 self.value_entry = wx.TextCtrl(edit_panel, -1, self.handler.get_option(self.index))
|
|
886 button_ok = wx.Button(edit_panel, wx.ID_OK)
|
|
887 button_cancel = wx.Button(edit_panel, wx.ID_CANCEL)
|
|
888 button_ref = wx.Button(edit_panel, BUT_REF, "Reference")
|
|
889 sizer.Add(caption_text, (0,0))
|
195
|
890 sizer.Add(self.caption_entry, (0,1), span=(1,4), flag=wx.EXPAND)
|
173
|
891 sizer.Add(value_text, (1,0))
|
195
|
892 sizer.Add(self.value_entry, (1,1), span=(1,4), flag=wx.EXPAND)
|
173
|
893 sizer.Add(button_ok, (3,0))
|
|
894 sizer.Add(button_cancel, (3,1))
|
|
895 sizer.Add(button_ref, (3,2), flag=wx.EXPAND)
|
195
|
896 sizer.AddGrowableCol(3)
|
|
897 sizer.AddGrowableRow(2)
|
|
898 self.dlg.SetSize((275, 125))
|
|
899 self.dlg.SetMinSize((275, 125))
|
|
900 self.dlg.Layout()
|
173
|
901 self.Bind(wx.EVT_BUTTON, self.on_reference, id=BUT_REF)
|
|
902 self.Bind(wx.EVT_BUTTON, self.on_edit_ok, id=wx.ID_OK)
|
|
903 self.Bind(wx.EVT_BUTTON, self.on_edit_cancel, id=wx.ID_CANCEL)
|
|
904 self.dlg.Show()
|
155
|
905
|
|
906 def reload_options(self):
|
173
|
907 self.listbox.DeleteAllItems()
|
|
908 values = self.handler.get_options()
|
|
909 captions = self.handler.get_captions()
|
|
910 for index in range(len(values)):
|
|
911 self.listbox.Append((captions[index], values[index]))
|
155
|
912
|
|
913 def on_text(self,evt):
|
|
914 id = evt.GetId()
|
|
915 txt = self.text.GetValue()
|
|
916 if not len(txt): return
|
|
917 if id == P_TITLE:
|
|
918 self.handler.xml.set('name',txt)
|
|
919 self.handler.rename(txt)
|
|
920
|
|
921 def on_send_button(self,evt):
|
|
922 self.handler.list.set("send_button", str( bool2int(evt.Checked()) ))
|
|
923
|
|
924 def on_hide_button(self,evt):
|
141
|
925 self.handler.list.set("hide_title", str( bool2int(evt.Checked()) ))
|
|
926
|
155
|
927 def on_raw_button(self,evt):
|
|
928 self.handler.list.set("raw_mode",str(bool2int(evt.Checked())))
|
|
929
|
|
930
|
|
931 ###############################
|
|
932 ## link image handlers
|
|
933 ###############################
|
|
934
|
|
935 class link_handler(node_handler):
|
|
936 """ A nodehandler for URLs. Will open URL in a wxHTMLFrame
|
|
937 <nodehandler name='?' module='forms' class='link_handler' >
|
|
938 <link href='http//??.??' />
|
|
939 </nodehandler >
|
|
940 """
|
|
941 def __init__(self,xml,tree_node):
|
|
942 node_handler.__init__(self,xml,tree_node)
|
|
943 self.link = self.xml[0]
|
|
944
|
|
945 def on_use(self,evt):
|
|
946 href = self.link.get("href")
|
|
947 wb = webbrowser.get()
|
|
948 wb.open(href)
|
|
949
|
|
950 def get_design_panel(self,parent):
|
|
951 return link_edit_panel(parent,self)
|
|
952
|
|
953 def get_use_panel(self,parent):
|
|
954 return link_panel(parent,self)
|
|
955
|
|
956 def tohtml(self):
|
|
957 href = self.link.get("href")
|
|
958 title = self.xml.get("name")
|
|
959 return "<a href='"+href+"' >"+title+"</a>"
|
|
960
|
|
961 class link_panel(wx.StaticText):
|
|
962 def __init__(self,parent,handler):
|
|
963 self.handler = handler
|
|
964 label = handler.xml.get('name')
|
|
965 wx.StaticText.__init__(self,parent,-1,label)
|
|
966 self.SetForegroundColour(wx.BLUE)
|
|
967 self.Bind(wx.EVT_LEFT_DOWN, self.handler.on_use)
|
|
968
|
|
969 P_URL = wx.NewId()
|
|
970
|
|
971 class link_edit_panel(wx.Panel):
|
|
972 def __init__(self, parent, handler):
|
|
973 wx.Panel.__init__(self, parent, -1)
|
|
974 self.handler = handler
|
|
975 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Link Properties"), wx.VERTICAL)
|
|
976
|
|
977 self.text = {}
|
|
978 self.text[P_TITLE] = wx.TextCtrl(self, P_TITLE, handler.xml.get('name'))
|
|
979 self.text[P_URL] = wx.TextCtrl(self, P_URL, handler.link.get('href'))
|
|
980
|
|
981 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND)
|
|
982 sizer.Add(self.text[P_TITLE], 0, wx.EXPAND)
|
|
983 sizer.Add(wx.Size(10,10))
|
|
984 sizer.Add(wx.StaticText(self, -1, "URL:"), 0, wx.EXPAND)
|
|
985 sizer.Add(self.text[P_URL], 0, wx.EXPAND)
|
|
986 self.SetSizer(sizer)
|
|
987 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE)
|
|
988 self.Bind(wx.EVT_TEXT, self.on_text, id=P_URL)
|
|
989
|
|
990 def on_text(self,evt):
|
|
991 id = evt.GetId()
|
|
992 txt = self.text[id].GetValue()
|
|
993 if not len(txt): return
|
|
994 if id == P_TITLE:
|
|
995 self.handler.xml.set('name',txt)
|
|
996 self.handler.rename(txt)
|
|
997 elif id == P_URL: self.handler.link.set('href',txt)
|
|
998
|
|
999 ##########################
|
|
1000 ## webimg node handler
|
|
1001 ##########################
|
|
1002 class webimg_handler(node_handler):
|
|
1003 """ A nodehandler for URLs. Will open URL in a wxHTMLFrame
|
|
1004 <nodehandler name='?' module='forms' class='webimg_handler' >
|
|
1005 <link href='http//??.??' />
|
|
1006 </nodehandler >
|
|
1007 """
|
|
1008 def __init__(self,xml,tree_node):
|
|
1009 node_handler.__init__(self,xml,tree_node)
|
|
1010 self.link = self.xml[0]
|
|
1011
|
|
1012 def get_design_panel(self,parent):
|
|
1013 return link_edit_panel(parent,self)
|
|
1014
|
|
1015 def get_use_panel(self,parent):
|
|
1016 img = img_helper().load_url(self.link.get("href"))
|
|
1017 if not img is None: return wx.StaticBitmap(parent,-1,img,size= wx.Size(img.GetWidth(),img.GetHeight()))
|
|
1018 return wx.EmptyBitmap(1, 1)
|
|
1019
|
|
1020 def tohtml(self):
|
|
1021 href = self.link.get("href")
|
|
1022 title = self.xml.get("name")
|
|
1023 return "<img src='"+href+"' alt="+title+" >"
|