28
|
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 Traipse 'Ornery-Orc' prof.ebral Exp $
|
|
25 #
|
|
26 # Description: The file contains code for the form based nodehanlers
|
|
27 #
|
|
28
|
|
29 __version__ = "$Id: forms.py,v Traipse 'Ornery-Orc' prof.ebral Exp $"
|
|
30
|
27
|
31 from containers import *
|
|
32 import orpg.minidom as minidom
|
28
|
33 from orpg.orpg_xml import xml
|
|
34 from wx.lib.scrolledpanel import ScrolledPanel
|
|
35 from orpg.tools.settings import settings
|
|
36 from orpg.tools.InterParse import Parse
|
|
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()
|
31
|
112 class form_edit_panel(ScrolledPanel):
|
28
|
113 def __init__(self, parent, handler):
|
31
|
114 ScrolledPanel.__init__(self, parent, wx.ID_ANY, style=wx.NO_BORDER|wx.VSCROLL|wx.HSCROLL)
|
28
|
115 self.handler = handler
|
31
|
116 self.main_sizer = wx.BoxSizer(wx.VERTICAL)
|
28
|
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
|
31
|
131 self.main_sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND)
|
|
132 self.main_sizer.Add(self.text[P_TITLE], 0, wx.EXPAND)
|
|
133 self.main_sizer.Add(wx.Size(10,10))
|
|
134 self.main_sizer.Add(wh_sizer,0,wx.EXPAND)
|
|
135 handler.tree.traverse(handler.mytree_node, self.create_child_wnd, None, False)
|
28
|
136
|
31
|
137 self.SetSizer(self.main_sizer)
|
28
|
138 self.SetAutoLayout(True)
|
31
|
139 self.SetupScrolling()
|
|
140 parent.SetSize(self.GetSize())
|
28
|
141 self.Fit()
|
|
142
|
|
143 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE)
|
|
144 self.Bind(wx.EVT_TEXT, self.on_text, id=F_HEIGHT)
|
|
145 self.Bind(wx.EVT_TEXT, self.on_text, id=F_WIDTH)
|
|
146
|
|
147 def on_text(self,evt):
|
|
148 id = evt.GetId()
|
|
149 txt = self.text[id].GetValue()
|
|
150 if not len(txt): return
|
|
151 if id == P_TITLE:
|
|
152 self.handler.xml.set('name',txt)
|
|
153 self.handler.rename(txt)
|
|
154 elif id == F_HEIGHT or id == F_WIDTH:
|
|
155 try: int(txt)
|
|
156 except: return 0
|
|
157 if id == F_HEIGHT: self.handler.xml.set("height",txt)
|
|
158 elif id == F_WIDTH: self.handler.xml.set("width",txt)
|
|
159
|
31
|
160 def create_child_wnd(self, treenode, evt):
|
|
161 node = self.handler.tree.GetPyData(treenode)
|
|
162 panel = node.get_design_panel(self)
|
|
163 size = node.get_size_constraint()
|
|
164 if panel:
|
|
165 self.main_sizer.Add(panel, size, wx.EXPAND)
|
|
166 self.main_sizer.Add(wx.Size(10,10))
|
|
167
|
28
|
168 ##########################
|
|
169 ## control handler
|
|
170 ##########################
|
|
171 class control_handler(node_handler):
|
|
172 """ A nodehandler for form controls.
|
|
173 <nodehandler name='?' module='forms' class='control_handler' />
|
|
174 """
|
|
175 def __init__(self, xml, tree_node):
|
|
176 node_handler.__init__(self, xml, tree_node)
|
|
177
|
|
178 def get_size_constraint(self):
|
|
179 return 0
|
|
180
|
|
181 ##########################
|
|
182 ## textctrl handler
|
|
183 ##########################
|
|
184 #
|
|
185 # Updated by Snowdog (April 2003)
|
|
186 # Now includes Raw Send Mode (like the chat macro uses)
|
|
187 # and an option to remove the title from text when sent
|
|
188 # to the chat in the normal non-chat macro mode.
|
|
189 #
|
|
190 class textctrl_handler(node_handler):
|
|
191 """ <nodehandler class="textctrl_handler" module="form" name="">
|
|
192 <text multiline='0' send_button='0' raw_mode='0' hide_title='0'>Text In Node</text>
|
|
193 </nodehandler>
|
|
194 """
|
|
195 def __init__(self,xml,tree_node):
|
|
196 node_handler.__init__(self,xml,tree_node)
|
|
197 self.text_elem = self.xml.find('text')
|
|
198 if self.text_elem.get("send_button") == "": self.text_elem.set("send_button","0")
|
|
199 if self.text_elem.get("raw_mode") == "": self.text_elem.set("raw_mode","0")
|
|
200 if self.text_elem.get("hide_title") == "": self.text_elem.set("hide_title","0")
|
|
201
|
|
202 def get_design_panel(self,parent):
|
|
203 return textctrl_edit_panel(parent,self)
|
|
204
|
|
205 def get_use_panel(self,parent):
|
|
206 return text_panel(parent,self)
|
|
207
|
|
208 def get_size_constraint(self):
|
|
209 return int(self.text_elem.get("multiline",0))
|
|
210
|
|
211 def is_multi_line(self):
|
|
212 return int(self.text_elem.get("multiline",0))
|
|
213
|
|
214 def is_raw_send(self):
|
|
215 return int(self.text_elem.get("raw_mode",0))
|
|
216
|
|
217 def is_hide_title(self):
|
|
218 return int(self.text_elem.get("hide_title",0))
|
|
219
|
|
220 def has_send_button(self):
|
|
221 return int(self.text_elem.get("send_button",0))
|
|
222
|
|
223 def tohtml(self):
|
|
224 txt = self.get_value()
|
|
225 txt = string.replace(txt,'\n',"<br />")
|
|
226 if not self.is_hide_title(): txt = "<b>"+self.xml.get("name")+":</b> "+txt
|
|
227 return txt
|
|
228
|
|
229 def get_value(self):
|
|
230 return self.text_elem.text
|
|
231
|
|
232 def set_value(self, new_value):
|
|
233 self.text_elem.text = str(new_value)
|
|
234
|
|
235 FORM_TEXT_CTRL = wx.NewId()
|
|
236 FORM_SEND_BUTTON = wx.NewId()
|
|
237
|
|
238 class text_panel(wx.Panel):
|
|
239 def __init__(self, parent, handler):
|
|
240 wx.Panel.__init__(self, parent, -1)
|
|
241 self.chat = handler.chat
|
|
242 self.handler = handler
|
|
243 if handler.is_multi_line():
|
|
244 text_style = wx.TE_MULTILINE
|
|
245 sizer_style = wx.EXPAND
|
|
246 sizer = wx.BoxSizer(wx.VERTICAL)
|
|
247 else:
|
|
248 sizer_style = wx.ALIGN_CENTER
|
|
249 text_style = 0
|
|
250 sizer = wx.BoxSizer(wx.HORIZONTAL)
|
|
251
|
|
252 txt = handler.get_value()
|
|
253 if txt == None: txt = ''
|
|
254 self.text = wx.TextCtrl(self, FORM_TEXT_CTRL, txt, style=text_style)
|
|
255 sizer.Add(wx.StaticText(self, -1, handler.xml.get('name')+": "), 0, sizer_style)
|
|
256 sizer.Add(wx.Size(5,0))
|
|
257 sizer.Add(self.text, 1, sizer_style)
|
|
258
|
|
259 if handler.has_send_button(): sizer.Add(wx.Button(self, FORM_SEND_BUTTON, "Send"), 0, sizer_style)
|
|
260
|
|
261 self.sizer = sizer
|
|
262 self.SetSizer(sizer)
|
|
263 self.SetAutoLayout(True)
|
|
264
|
|
265 parent.SetSize(self.GetBestSize())
|
|
266 self.Bind(wx.EVT_TEXT, self.on_text, id=FORM_TEXT_CTRL)
|
|
267 self.Bind(wx.EVT_BUTTON, self.on_send, id=FORM_SEND_BUTTON)
|
|
268
|
|
269 def on_text(self, evt):
|
|
270 txt = self.text.GetValue()
|
|
271 #txt = strip_text(txt) ##Does not seem to exist.
|
|
272 self.handler.text_elem.text = txt
|
|
273
|
|
274 def on_send(self, evt):
|
|
275 txt = self.text.GetValue()
|
31
|
276 txt = Parse.ParseLogic(txt, self.handler.xml)
|
28
|
277 if not self.handler.is_raw_send():
|
31
|
278 Parse.Post(self.handler.tohtml(), self.chat, True, True)
|
28
|
279 return 1
|
|
280 actionlist = txt.split("\n")
|
|
281 for line in actionlist:
|
31
|
282 line = Parse.ParseLogic(line, self.handler.xml)
|
28
|
283 if(line != ""):
|
|
284 if line[0] != "/": ## it's not a slash command
|
31
|
285 Parse.Post(line, self.chat, True, True)
|
28
|
286 else:
|
|
287 action = line
|
|
288 self.chat.chat_cmds.docmd(action)
|
|
289 return 1
|
|
290
|
|
291 F_MULTI = wx.NewId()
|
|
292 F_SEND_BUTTON = wx.NewId()
|
|
293 F_RAW_SEND = wx.NewId()
|
|
294 F_HIDE_TITLE = wx.NewId()
|
|
295 F_TEXT = wx.NewId()
|
|
296 T_BUT_REF = wx.NewId()
|
|
297
|
|
298 class textctrl_edit_panel(wx.Panel):
|
|
299 def __init__(self, parent, handler):
|
|
300 wx.Panel.__init__(self, parent, -1)
|
|
301 self.handler = handler
|
|
302 self.parent = parent
|
|
303 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Text Properties"), wx.VERTICAL)
|
|
304
|
|
305 self.title = wx.TextCtrl(self, P_TITLE, handler.xml.get('name'))
|
|
306 self.multi = wx.CheckBox(self, F_MULTI, " Multi-Line")
|
|
307 self.multi.SetValue(handler.is_multi_line())
|
|
308 self.raw_send = wx.CheckBox(self, F_RAW_SEND, " Send as Macro")
|
|
309 self.raw_send.SetValue(handler.is_raw_send())
|
|
310 self.hide_title = wx.CheckBox(self, F_HIDE_TITLE, " Hide Title")
|
|
311 self.hide_title.SetValue(handler.is_hide_title())
|
|
312 self.send_button = wx.CheckBox(self, F_SEND_BUTTON, " Send Button")
|
|
313 self.send_button.SetValue(handler.has_send_button())
|
|
314 button_ref = wx.Button(self, T_BUT_REF, "Reference")
|
|
315
|
|
316 sizer.Add(wx.StaticText(self, P_TITLE, "Title:"), 0, wx.EXPAND)
|
|
317 sizer.Add(self.title, 0, wx.EXPAND)
|
|
318 sizer.Add(wx.Size(10,10))
|
|
319 sizer.Add(self.multi, 0, wx.EXPAND)
|
|
320 sizer.Add(self.raw_send, 0, wx.EXPAND)
|
|
321 sizer.Add(self.hide_title, 0, wx.EXPAND)
|
|
322 sizer.Add(self.send_button, 0 , wx.EXPAND)
|
|
323 sizer.Add(button_ref, 0)
|
|
324 sizer.Add(wx.Size(10,10))
|
|
325 if handler.is_multi_line():
|
|
326 sizer_style = wx.EXPAND
|
|
327 text_style = wx.TE_MULTILINE
|
|
328 multi = 1
|
|
329 else:
|
|
330 sizer_style=wx.EXPAND
|
|
331 text_style = 0
|
|
332 multi = 0
|
31
|
333 self.text = wx.TextCtrl(self, F_TEXT, handler.get_value() or '',style=text_style)
|
28
|
334 sizer.Add(wx.Size(5,0))
|
|
335 sizer.Add(self.text, multi, sizer_style)
|
|
336 self.SetSizer(sizer)
|
|
337 self.SetAutoLayout(True)
|
|
338
|
|
339 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE)
|
|
340 self.Bind(wx.EVT_TEXT, self.on_text, id=F_TEXT)
|
|
341 self.Bind(wx.EVT_CHECKBOX, self.on_button, id=F_MULTI)
|
|
342 self.Bind(wx.EVT_CHECKBOX, self.on_raw_button, id=F_RAW_SEND)
|
|
343 self.Bind(wx.EVT_CHECKBOX, self.on_hide_button, id=F_HIDE_TITLE)
|
|
344 self.Bind(wx.EVT_CHECKBOX, self.on_send_button, id=F_SEND_BUTTON)
|
|
345 self.Bind(wx.EVT_BUTTON, self.on_reference, id=T_BUT_REF)
|
|
346 self.parent.Bind(wx.EVT_CLOSE, self.tree_failsafe)
|
|
347
|
|
348 ## EZ_Tree Core TaS - Prof.Ebral ##
|
|
349 def on_reference(self, evt, car=None):
|
|
350 self.do_tree = wx.Frame(self, -1, 'EZ Tree')
|
|
351 self.ez_tree = orpg.gametree.gametree
|
|
352 self.temp_wnd = self.ez_tree.game_tree(self.do_tree, self.ez_tree.EZ_REF)
|
|
353 self.temp_wnd.Bind(wx.EVT_LEFT_DCLICK, self.on_ldclick)
|
|
354 component.get('tree_fs').save_tree(settings.get("gametree"))
|
|
355 self.temp_wnd.load_tree(settings.get("gametree"))
|
|
356 self.do_tree.Show()
|
|
357
|
|
358 def tree_failsafe(self, evt):
|
|
359 self.parent.Destroy()
|
|
360 component.add('tree', component.get('tree_fs')) ## Backup
|
|
361
|
|
362 def get_grid_ref(self, obj, complete):
|
|
363 self.temp_wnd.Freeze()
|
|
364 self.grid_ref = complete
|
|
365 self.mini_grid = wx.Frame(self, -1, 'EZ Tree Mini Grid')
|
|
366 self.temp_grid = obj.get_use_panel(self.mini_grid)
|
|
367 self.temp_grid.grid.Bind(wx.grid.EVT_GRID_CELL_LEFT_DCLICK, self.on_grid_ldclick)
|
|
368 self.mini_grid.Show()
|
|
369
|
|
370 def on_grid_ldclick(self, evt):
|
|
371 complete = self.grid_ref
|
|
372 row = str(evt.GetRow()+1)
|
|
373 col = str(evt.GetCol()+1)
|
|
374 complete = complete[:len(complete)-2] + '::'+'('+row+','+col+')'+complete[len(complete)-2:]
|
|
375 self.text.AppendText(complete); self.on_text(evt)
|
|
376 self.mini_grid.Destroy()
|
|
377
|
|
378 def on_ldclick(self, evt):
|
|
379 self.rename_flag = 0
|
|
380 pt = evt.GetPosition()
|
|
381 (item, flag) = self.temp_wnd.HitTest(pt)
|
|
382 if item.IsOk():
|
|
383 obj = self.temp_wnd.GetPyData(item)
|
|
384 self.temp_wnd.SelectItem(item)
|
|
385 start = self.handler.xml.get('map').split('::')
|
|
386 end = obj.xml.get('map').split('::')
|
|
387 if obj.xml.get('class') not in ['rpg_grid_handler', 'textctrl_handler']: do = 'None'
|
|
388 elif end[0] == '' or start[0] != end[0]: do = 'Root'
|
|
389 elif start == end: do = 'Child'
|
|
390 elif start != end: do = 'Parent'
|
|
391 if do == 'Root':
|
|
392 complete = "!@"
|
|
393 for e in end:
|
|
394 if e != '': complete += e +'::'
|
|
395 complete = complete + obj.xml.get('name') + '@!'
|
|
396 elif do == 'Parent':
|
|
397 while start[0] == end[0]:
|
|
398 del end[0], start[0]
|
|
399 if len(start) == 0 or len(end) == 0: break
|
|
400 complete = "!#"
|
|
401 for e in end: complete += e +'::'
|
|
402 complete = complete + obj.xml.get('name') + '#!'
|
|
403 elif do == 'Child':
|
|
404 while start[0] == end[0]:
|
|
405 del end[0], start[0]
|
|
406 if len(start) == 0 or len(end) == 0: break
|
|
407 complete = "!!"
|
|
408 for e in end: complete += e +'::'
|
|
409 complete = complete + obj.xml.get('name') + '!!'
|
|
410 if do != 'None':
|
|
411 if obj.xml.get('class') == 'rpg_grid_handler':
|
|
412 self.get_grid_ref(obj, complete)
|
|
413 else: self.text.AppendText(complete); self.on_text(evt)
|
|
414 self.do_tree.Destroy()
|
|
415 if do == 'None':
|
|
416 wx.MessageBox('Invalid Reference', 'Error')
|
|
417 ##### #####
|
|
418
|
|
419 def on_text(self,evt):
|
|
420 id = evt.GetId()
|
|
421 if id == P_TITLE:
|
|
422 txt = self.title.GetValue()
|
|
423 if not len(txt): return
|
|
424 self.handler.xml.set('name',txt)
|
|
425 self.handler.rename(txt)
|
|
426 if id == F_TEXT:
|
|
427 txt = self.text.GetValue()
|
|
428 #txt = strip_text(txt) ##Does not seem to exist.
|
|
429 self.handler.text_elem.text = txt
|
|
430
|
|
431 def on_button(self,evt):
|
|
432 self.handler.text_elem.set("multiline",str(bool2int(evt.Checked())))
|
|
433
|
|
434 def on_raw_button(self,evt):
|
|
435 self.handler.text_elem.set("raw_mode",str(bool2int(evt.Checked())))
|
|
436
|
|
437 def on_hide_button(self,evt):
|
|
438 self.handler.text_elem.set("hide_title",str(bool2int(evt.Checked())))
|
|
439
|
|
440 def on_send_button(self,evt):
|
|
441 self.handler.text_elem.set("send_button",str(bool2int(evt.Checked())))
|
|
442
|
|
443
|
|
444 #######################
|
|
445 ## listbox handler
|
|
446 #######################
|
|
447 #
|
|
448 # Updated by Snowdog (April 2003)
|
|
449 # Now includesan option to remove the title from
|
|
450 # text when sent to the chat.
|
|
451 #
|
|
452 L_DROP = 0
|
|
453 L_LIST = 1
|
|
454 L_RADIO = 2
|
|
455 L_CHECK = 3
|
|
456 L_ROLLER = 4
|
|
457
|
|
458 class listbox_handler(node_handler):
|
|
459 """
|
|
460 <nodehandler class="listbox_handler" module="forms" name="">
|
|
461 <list type="1" send_button='0' hide_title='0'>
|
|
462 <option value="" selected="" >Option Text I</option>
|
|
463 <option value="" selected="" >Option Text II</option>
|
|
464 </list>
|
|
465 </nodehandler>
|
|
466 """
|
|
467 def __init__(self,xml,tree_node):
|
|
468 node_handler.__init__(self,xml,tree_node)
|
|
469 self.list_reload()
|
|
470 #print xml
|
|
471 #print self.tree.GetItemParent(tree_node)
|
|
472 if self.list.get("send_button") == "": self.list.set("send_button","0")
|
|
473 if self.list.get("hide_title") == "": self.list.set("hide_title","0")
|
|
474 if self.list.get("raw_mode") == "": self.list.set("raw_mode","0")
|
|
475
|
|
476 def list_reload(self):
|
|
477 self.list = self.xml.find('list')
|
|
478 self.options = self.list.findall('option')
|
|
479 self.captions = []
|
|
480 for opt in self.options:
|
|
481 if opt.get('caption') == None: opt.set('caption', '')
|
|
482 self.captions.append(opt.get('caption'))
|
|
483
|
|
484 def get_design_panel(self,parent):
|
|
485 return listbox_edit_panel(parent,self)
|
|
486
|
|
487 def get_use_panel(self,parent):
|
|
488 return listbox_panel(parent,self)
|
|
489
|
|
490 def get_type(self):
|
|
491 return int(self.list.get("type"))
|
|
492
|
|
493 def set_type(self,type):
|
|
494 self.list.set("type",str(type))
|
|
495
|
|
496 def is_hide_title(self):
|
|
497 return int(self.list.get("hide_title", 0))
|
|
498
|
|
499 def is_raw_send(self):
|
|
500 return int(self.list.get("raw_mode",0))
|
|
501
|
|
502 # single selection methods
|
|
503 def get_selected_node(self):
|
|
504 for opt in self.options:
|
|
505 if opt.get("selected") == "1": return opt
|
|
506 return None
|
|
507
|
|
508 def get_selected_index(self):
|
|
509 i = 0
|
|
510 for opt in self.options:
|
|
511 if opt.get("selected") == "1": return i
|
|
512 i += 1
|
|
513 return 0
|
|
514
|
|
515 def get_selected_text(self):
|
|
516 node = self.get_selected_node()
|
|
517 if node: return node.text
|
|
518 else: return ""
|
|
519
|
|
520 # mult selection methods
|
|
521 def get_selections(self):
|
|
522 opts = []
|
|
523 for opt in self.options:
|
|
524 if opt.get("selected") == "1": opts.append(opt)
|
|
525 return opts
|
|
526
|
|
527 def get_selections_text(self):
|
|
528 opts = []
|
|
529 for opt in self.options:
|
|
530 if opt.get("selected") == "1": opts.append(opt.text)
|
|
531 return opts
|
|
532
|
|
533 def get_selections_index(self):
|
|
534 opts = []
|
|
535 i = 0
|
|
536 for opt in self.options:
|
|
537 if opt.get("selected") == "1": opts.append(i)
|
|
538 i += 1
|
|
539 return opts
|
|
540
|
|
541 # setting selection method
|
|
542 def set_selected_node(self,index,selected=1):
|
|
543 if self.get_type() != L_CHECK: self.clear_selections()
|
|
544 self.options[index].set("selected", str(bool2int(selected)))
|
|
545
|
|
546 def clear_selections(self):
|
|
547 for opt in self.options: opt.set("selected","0")
|
|
548
|
|
549 # misc methods
|
|
550 def get_options(self):
|
|
551 opts = []
|
|
552 for opt in self.options: opts.append(opt.text)
|
|
553 return opts
|
|
554
|
|
555 def get_captions(self):
|
|
556 captions = []
|
|
557 for opt in self.options: captions.append(opt.get("caption"))
|
|
558 self.captions = captions
|
|
559 return captions
|
|
560
|
|
561 def get_option(self, index):
|
|
562 return self.options[index].text
|
|
563
|
|
564 def get_caption(self, index):
|
|
565 captions = self.get_captions()
|
|
566 return captions[index] or ''
|
|
567
|
|
568 def add_option(self, caption, value):
|
|
569 elem = Element('option')
|
|
570 elem.set("value","0")
|
|
571 elem.set('caption', caption)
|
|
572 elem.set("selected","0")
|
|
573 elem.text = value
|
|
574 self.list.append(elem)
|
|
575 self.list_reload()
|
|
576
|
|
577 def remove_option(self,index):
|
|
578 self.list.remove(self.options[index])
|
|
579 self.list_reload()
|
|
580
|
|
581 def edit_option(self, index, value):
|
|
582 self.options[index].text = value
|
|
583
|
|
584 def edit_caption(self, index, value):
|
|
585 self.options[index].set('caption', value)
|
|
586 self.captions[index] = value
|
|
587
|
|
588 def has_send_button(self):
|
|
589 if self.list.get("send_button") == '0': return False
|
|
590 else: return True
|
|
591
|
|
592 def get_size_constraint(self):
|
|
593 if self.get_type() == L_DROP: return 0
|
|
594 else: return 1
|
|
595
|
|
596 def tohtml(self):
|
|
597 opts = self.get_selections_text()
|
|
598 text = ""
|
|
599 if not self.is_hide_title(): text = "<b>"+self.xml.get("name")+":</b> "
|
|
600 comma = ", "
|
|
601 text += comma.join(opts)
|
|
602 return text
|
|
603
|
|
604 def get_value(self):
|
|
605 return "\n".join(self.get_selections_text())
|
|
606
|
|
607 def on_send_to_chat(self, evt):
|
|
608 txt = self.get_selected_text()
|
31
|
609 txt = Parse.ParseLogic(txt, self.xml)
|
28
|
610 if not self.is_raw_send():
|
31
|
611 Parse.Post(self.tohtml(), self.chat, True, True)
|
28
|
612 return 1
|
|
613 actionlist = self.get_selections_text()
|
|
614 for line in actionlist:
|
31
|
615 line = Parse.ParseLogic(line, self.xml)
|
28
|
616 if(line != ""):
|
|
617 if line[0] != "/": ## it's not a slash command
|
31
|
618 Parse.Post(line, self.chat, True, True)
|
28
|
619 else:
|
|
620 action = line
|
|
621 self.chat.chat_cmds.docmd(action)
|
|
622 return 1
|
|
623
|
|
624
|
|
625 F_LIST = wx.NewId()
|
|
626 F_SEND = wx.NewId()
|
|
627
|
|
628
|
|
629 class listbox_panel(wx.Panel):
|
|
630 def __init__(self, parent, handler):
|
|
631 wx.Panel.__init__(self, parent, -1)
|
31
|
632 #ScrolledPanel.__init__(self, parent, wx.ID_ANY, style=wx.NO_BORDER|wx.VSCROLL|wx.HSCROLL)
|
28
|
633 self.handler = handler
|
|
634 self.chat = handler.chat
|
|
635 opts = []
|
|
636 values = handler.get_options()
|
|
637 captions = handler.get_captions()
|
|
638 for value in values:
|
|
639 if captions[values.index(value)] != '': opts.append(captions[values.index(value)])
|
|
640 else: opts.append(value)
|
|
641 cur_opt = handler.get_selected_text()
|
|
642 type = handler.get_type()
|
|
643 label = handler.xml.get('name')
|
|
644
|
|
645 if type == L_DROP:
|
|
646 self.list = wx.ComboBox(self, F_LIST, cur_opt, choices=opts, style=wx.CB_READONLY)
|
|
647 if self.list.GetSize()[0] > 200:
|
|
648 self.list.Destroy()
|
|
649 self.list = wx.ComboBox(self, F_LIST, cur_opt, size=(200, -1), choices=opts, style=wx.CB_READONLY)
|
31
|
650 elif type == L_LIST: self.list = wx.ListBox(self, F_LIST, choices=opts)
|
|
651 elif type == L_RADIO: self.list = wx.RadioBox(self, F_LIST, label, choices=opts, majorDimension=3)
|
28
|
652 elif type == L_CHECK:
|
|
653 self.list = wx.CheckListBox(self,F_LIST,choices=opts)
|
|
654 self.set_checks()
|
|
655
|
|
656 for i in handler.get_selections_text():
|
|
657 if type == L_DROP: self.list.SetValue( i )
|
|
658 else: self.list.SetStringSelection( i )
|
|
659 if type == L_DROP: sizer = wx.BoxSizer(wx.HORIZONTAL)
|
|
660 else: sizer = wx.BoxSizer(wx.VERTICAL)
|
|
661
|
|
662 if type != L_RADIO:
|
31
|
663 sizer.Add(wx.StaticText(self, -1, label+": "), 0, wx.EXPAND|wx.ALL)
|
|
664 sizer.Add(self.list, 1, wx.EXPAND|wx.ALL)
|
28
|
665 if handler.has_send_button():
|
31
|
666 sizer.Add(wx.Button(self, F_SEND, "Send"), 0, wx.EXPAND|wx.ALL)
|
28
|
667 self.Bind(wx.EVT_BUTTON, self.handler.on_send_to_chat, id=F_SEND)
|
|
668 self.sizer = sizer
|
|
669 self.SetSizer(sizer)
|
|
670 self.SetAutoLayout(True)
|
31
|
671 #self.SetupScrolling()
|
|
672 #parent.SetSize(self.GetBestSize())
|
28
|
673 self.Fit()
|
|
674
|
|
675 if type == L_DROP: self.Bind(wx.EVT_COMBOBOX, self.on_change, id=F_LIST)
|
|
676 elif type == L_LIST: self.Bind(wx.EVT_LISTBOX, self.on_change, id=F_LIST)
|
|
677 elif type == L_RADIO: self.Bind(wx.EVT_RADIOBOX, self.on_change, id=F_LIST)
|
|
678 elif type == L_CHECK:self.Bind(wx.EVT_CHECKLISTBOX, self.on_check, id=F_LIST)
|
|
679 self.type = type
|
|
680
|
|
681 def on_change(self,evt):
|
|
682 self.handler.set_selected_node(self.list.GetSelection())
|
|
683
|
|
684 def on_check(self,evt):
|
|
685 for i in xrange(self.list.GetCount()): self.handler.set_selected_node(i, bool2int(self.list.IsChecked(i)))
|
|
686
|
|
687 def set_checks(self):
|
|
688 for i in self.handler.get_selections_index(): self.list.Check(i)
|
|
689
|
|
690
|
|
691 BUT_ADD = wx.NewId()
|
|
692 BUT_REM = wx.NewId()
|
|
693 BUT_REF = wx.NewId()
|
|
694 BUT_EDIT = wx.NewId()
|
|
695 F_TYPE = wx.NewId()
|
|
696 F_NO_TITLE = wx.NewId()
|
|
697 LIST_CTRL = wx.NewId()
|
|
698
|
|
699 class listbox_edit_panel(wx.Panel):
|
|
700 def __init__(self, parent, handler):
|
|
701 wx.Panel.__init__(self, parent, -1)
|
|
702 self.handler = handler
|
|
703 self.parent = parent
|
|
704 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "List Box Properties"), wx.VERTICAL)
|
|
705
|
|
706 self.text = wx.TextCtrl(self, P_TITLE, handler.xml.get('name'))
|
|
707 self.listbox = wx.ListCtrl(self, LIST_CTRL, style=wx.LC_REPORT)
|
|
708 self.listbox.InsertColumn(0, 'Caption')
|
|
709 self.listbox.InsertColumn(1, 'Value')
|
|
710 self.listbox.SetColumnWidth(0, 75)
|
|
711 self.listbox.SetColumnWidth(1, 300)
|
|
712 self.reload_options()
|
|
713
|
|
714 opts = ['Drop Down', 'List Box', 'Radio Box', 'Check List']
|
|
715 self.type_radios = wx.RadioBox(self,F_TYPE,"List Type",choices=opts)
|
|
716 self.type_radios.SetSelection(handler.get_type())
|
|
717
|
|
718 self.send_button = wx.CheckBox(self, F_SEND_BUTTON, " Send Button")
|
|
719 self.send_button.SetValue(handler.has_send_button())
|
|
720
|
|
721 self.raw_send = wx.CheckBox(self, F_RAW_SEND, " Send as Macro")
|
|
722 self.raw_send.SetValue(handler.is_raw_send())
|
|
723
|
|
724 self.hide_title = wx.CheckBox(self, F_NO_TITLE, " Hide Title")
|
|
725 self.hide_title.SetValue(handler.is_hide_title())
|
|
726
|
|
727 but_sizer = wx.BoxSizer(wx.HORIZONTAL)
|
|
728 but_sizer.Add(wx.Button(self, BUT_ADD, "Add"), 1, wx.EXPAND)
|
|
729 but_sizer.Add(wx.Size(10,10))
|
|
730 but_sizer.Add(wx.Button(self, BUT_EDIT, "Edit"), 1, wx.EXPAND)
|
|
731 but_sizer.Add(wx.Size(10,10))
|
|
732 but_sizer.Add(wx.Button(self, BUT_REM, "Remove"), 1, wx.EXPAND)
|
|
733
|
|
734 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND)
|
|
735 sizer.Add(self.text, 0, wx.EXPAND)
|
|
736 sizer.Add(wx.Size(10,10))
|
|
737 sizer.Add(self.type_radios, 0, wx.EXPAND)
|
|
738 sizer.Add(wx.Size(10,10))
|
|
739 sizer.Add(self.send_button, 0 , wx.EXPAND)
|
|
740 sizer.Add(self.hide_title, 0, wx.EXPAND)
|
|
741 sizer.Add(self.raw_send, 0, wx.EXPAND)
|
|
742 sizer.Add(wx.Size(10,10))
|
|
743 sizer.Add(wx.StaticText(self, -1, "Options:"), 0, wx.EXPAND)
|
|
744 sizer.Add(self.listbox,1,wx.EXPAND);
|
|
745 sizer.Add(but_sizer,0,wx.EXPAND)
|
|
746
|
|
747 self.SetSizer(sizer)
|
|
748 self.SetAutoLayout(True)
|
|
749 self.Fit()
|
|
750 parent.SetSize(self.GetBestSize())
|
|
751
|
|
752 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE)
|
|
753 self.Bind(wx.EVT_BUTTON, self.on_edit, id=BUT_EDIT)
|
|
754 self.Bind(wx.EVT_BUTTON, self.on_remove, id=BUT_REM)
|
|
755 self.Bind(wx.EVT_BUTTON, self.on_add, id=BUT_ADD)
|
|
756 self.Bind(wx.EVT_RADIOBOX, self.on_type, id=F_TYPE)
|
|
757 self.Bind(wx.EVT_CHECKBOX, self.on_hide_button, id=F_NO_TITLE)
|
|
758 self.Bind(wx.EVT_CHECKBOX, self.on_send_button, id=F_SEND_BUTTON)
|
|
759 self.Bind(wx.EVT_CHECKBOX, self.on_raw_button, id=F_RAW_SEND)
|
|
760
|
|
761 def on_type(self,evt):
|
|
762 self.handler.set_type(evt.GetInt())
|
|
763
|
|
764 def on_add(self,evt):
|
|
765 self.dlg = wx.Frame(self, -1, 'Text', size=(300,150))
|
|
766 edit_panel = wx.Panel(self.dlg, -1)
|
|
767 sizer = wx.GridBagSizer(1, 1)
|
|
768 edit_panel.SetSizer(sizer)
|
|
769 caption_text = wx.StaticText(edit_panel, -1, 'Caption')
|
|
770 self.caption_entry = wx.TextCtrl(edit_panel, -1, '')
|
|
771 value_text = wx.StaticText(edit_panel, -1, 'Value')
|
|
772 self.value_entry = wx.TextCtrl(edit_panel, -1, '')
|
|
773 button_ok = wx.Button(edit_panel, wx.ID_OK)
|
|
774 button_cancel = wx.Button(edit_panel, wx.ID_CANCEL)
|
|
775 button_ref = wx.Button(edit_panel, BUT_REF, "Reference")
|
|
776 sizer.Add(caption_text, (0,0))
|
|
777 sizer.Add(self.caption_entry, (0,1), span=(1,4), flag=wx.EXPAND)
|
|
778 sizer.Add(value_text, (1,0))
|
|
779 sizer.Add(self.value_entry, (1,1), span=(1,4), flag=wx.EXPAND)
|
|
780 sizer.Add(button_ok, (3,0))
|
|
781 sizer.Add(button_cancel, (3,1))
|
|
782 sizer.Add(button_ref, (3,2), flag=wx.EXPAND)
|
|
783 sizer.AddGrowableCol(3)
|
|
784 sizer.AddGrowableRow(2)
|
|
785 self.dlg.SetSize((275, 125))
|
|
786 self.dlg.SetMinSize((275, 125))
|
|
787 self.dlg.Layout()
|
|
788 self.Bind(wx.EVT_BUTTON, self.on_reference, id=BUT_REF)
|
|
789 self.Bind(wx.EVT_BUTTON, self.on_add_option, id=wx.ID_OK)
|
|
790 self.Bind(wx.EVT_BUTTON, self.on_edit_cancel, id=wx.ID_CANCEL)
|
|
791 self.dlg.Show()
|
|
792
|
|
793 def on_add_option(self, evt):
|
|
794 self.handler.add_option(self.caption_entry.GetValue(), self.value_entry.GetValue())
|
|
795 self.reload_options()
|
|
796 self.dlg.Destroy()
|
|
797 component.add('tree', component.get('tree_fs')) ## Backup
|
|
798 return
|
|
799
|
|
800 ## EZ_Tree Core TaS - Prof.Ebral ##
|
|
801 def on_reference(self, evt, car=None):
|
|
802 self.do_tree = wx.Frame(self, -1, 'EZ Tree')
|
|
803 self.ez_tree = orpg.gametree.gametree
|
|
804 self.temp_wnd = self.ez_tree.game_tree(self.do_tree, self.ez_tree.EZ_REF)
|
|
805 self.temp_wnd.Bind(wx.EVT_LEFT_DCLICK, self.on_ldclick)
|
|
806 component.get('tree_fs').save_tree(settings.get("gametree"))
|
|
807 self.temp_wnd.load_tree(settings.get("gametree"))
|
|
808 self.do_tree.Show()
|
|
809
|
|
810 def get_grid_ref(self, obj, complete):
|
|
811 self.temp_wnd.Freeze()
|
|
812 self.grid_ref = complete
|
|
813 self.mini_grid = wx.Frame(self, -1, 'EZ Tree Grid')
|
|
814 self.temp_grid = obj.get_use_panel(self.mini_grid)
|
|
815 self.temp_grid.grid.Bind(wx.grid.EVT_GRID_CELL_LEFT_DCLICK, self.on_grid_ldclick)
|
|
816 self.mini_grid.Show()
|
|
817
|
|
818 def on_grid_ldclick(self, evt):
|
|
819 complete = self.grid_ref
|
|
820 row = str(evt.GetRow()+1)
|
|
821 col = str(evt.GetCol()+1)
|
|
822 complete = complete[:len(complete)-2] + '::'+'('+row+','+col+')'+complete[len(complete)-2:]
|
|
823 self.value_entry.AppendText(complete)
|
|
824 self.mini_grid.Destroy()
|
|
825
|
|
826 def on_ldclick(self, evt):
|
|
827 self.rename_flag = 0
|
|
828 pt = evt.GetPosition()
|
|
829 (item, flag) = self.temp_wnd.HitTest(pt)
|
|
830 if item.IsOk():
|
|
831 obj = self.temp_wnd.GetPyData(item)
|
|
832 self.temp_wnd.SelectItem(item)
|
|
833 start = self.handler.xml.get('map').split('::')
|
|
834 end = obj.xml.get('map').split('::')
|
|
835 if obj.xml.get('class') not in ['rpg_grid_handler', 'textctrl_handler']: do = 'None'
|
|
836 elif end[0] == '' or start[0] != end[0]: do = 'Root'
|
|
837 elif start == end: do = 'Child'
|
|
838 elif start != end: do = 'Parent'
|
|
839 if do == 'Root':
|
|
840 complete = "!@"
|
|
841 for e in end:
|
|
842 if e != '': complete += e +'::'
|
|
843 complete = complete + obj.xml.get('name') + '@!'
|
|
844 elif do == 'Parent':
|
|
845 while start[0] == end[0]:
|
|
846 del end[0], start[0]
|
|
847 if len(start) == 0 or len(end) == 0: break
|
|
848 complete = "!#"
|
|
849 for e in end: complete += e +'::'
|
|
850 complete = complete + obj.xml.get('name') + '#!'
|
|
851 elif do == 'Child':
|
|
852 while start[0] == end[0]:
|
|
853 del end[0], start[0]
|
|
854 if len(start) == 0 or len(end) == 0: break
|
|
855 complete = "!!"
|
|
856 for e in end: complete += e +'::'
|
|
857 complete = complete + obj.xml.get('name') + '!!'
|
|
858 if do != 'None':
|
|
859 if obj.xml.get('class') == 'rpg_grid_handler':
|
|
860 self.get_grid_ref(obj, complete)
|
|
861 else: self.value_entry.AppendText(complete); self.reload_options()
|
|
862 self.do_tree.Destroy()
|
|
863 if do == 'None':
|
|
864 wx.MessageBox('Invalid Reference', 'Error')
|
|
865 ##### #####
|
|
866
|
|
867 def on_edit_ok(self, evt):
|
|
868 self.handler.edit_caption(self.index, self.caption_entry.GetValue())
|
|
869 self.handler.edit_option(self.index, self.value_entry.GetValue())
|
|
870 self.reload_options()
|
|
871 self.dlg.Destroy()
|
|
872 component.add('tree', component.get('tree_fs')) ## Backup
|
|
873 return
|
|
874
|
|
875 def on_edit_cancel(self, evt):
|
|
876 self.dlg.Destroy()
|
|
877 component.add('tree', component.get('tree_fs')) ## Backup
|
|
878 return
|
|
879
|
|
880 def on_remove(self,evt):
|
|
881 index = self.listbox.GetFocusedItem()
|
|
882 if index >= 0:
|
|
883 self.handler.remove_option(index)
|
|
884 self.reload_options()
|
|
885
|
|
886 def on_edit(self,evt):
|
|
887 self.index = self.listbox.GetFocusedItem()
|
|
888 if self.index >= 0:
|
|
889 self.dlg = wx.Frame(self, -1, 'Text', size=(300,150))
|
|
890 edit_panel = wx.Panel(self.dlg, -1)
|
|
891 sizer = wx.GridBagSizer(1, 2)
|
|
892 edit_panel.SetSizer(sizer)
|
|
893 caption_text = wx.StaticText(edit_panel, -1, 'Caption')
|
|
894 self.caption_entry = wx.TextCtrl(edit_panel, -1, self.handler.get_caption(self.index))
|
|
895 value_text = wx.StaticText(edit_panel, -1, 'Value')
|
|
896 self.value_entry = wx.TextCtrl(edit_panel, -1, self.handler.get_option(self.index))
|
|
897 button_ok = wx.Button(edit_panel, wx.ID_OK)
|
|
898 button_cancel = wx.Button(edit_panel, wx.ID_CANCEL)
|
|
899 button_ref = wx.Button(edit_panel, BUT_REF, "Reference")
|
|
900 sizer.Add(caption_text, (0,0))
|
|
901 sizer.Add(self.caption_entry, (0,1), span=(1,4), flag=wx.EXPAND)
|
|
902 sizer.Add(value_text, (1,0))
|
|
903 sizer.Add(self.value_entry, (1,1), span=(1,4), flag=wx.EXPAND)
|
|
904 sizer.Add(button_ok, (3,0))
|
|
905 sizer.Add(button_cancel, (3,1))
|
|
906 sizer.Add(button_ref, (3,2), flag=wx.EXPAND)
|
|
907 sizer.AddGrowableCol(3)
|
|
908 sizer.AddGrowableRow(2)
|
|
909 self.dlg.SetSize((275, 125))
|
|
910 self.dlg.SetMinSize((275, 125))
|
|
911 self.dlg.Layout()
|
|
912 self.Bind(wx.EVT_BUTTON, self.on_reference, id=BUT_REF)
|
|
913 self.Bind(wx.EVT_BUTTON, self.on_edit_ok, id=wx.ID_OK)
|
|
914 self.Bind(wx.EVT_BUTTON, self.on_edit_cancel, id=wx.ID_CANCEL)
|
|
915 self.dlg.Show()
|
|
916
|
|
917 def reload_options(self):
|
|
918 self.listbox.DeleteAllItems()
|
|
919 values = self.handler.get_options()
|
|
920 captions = self.handler.get_captions()
|
|
921 for index in range(len(values)):
|
|
922 self.listbox.Append((captions[index], values[index]))
|
|
923
|
|
924 def on_text(self,evt):
|
|
925 id = evt.GetId()
|
|
926 txt = self.text.GetValue()
|
|
927 if not len(txt): return
|
|
928 if id == P_TITLE:
|
|
929 self.handler.xml.set('name',txt)
|
|
930 self.handler.rename(txt)
|
|
931
|
|
932 def on_send_button(self,evt):
|
|
933 self.handler.list.set("send_button", str( bool2int(evt.Checked()) ))
|
|
934
|
|
935 def on_hide_button(self,evt):
|
|
936 self.handler.list.set("hide_title", str( bool2int(evt.Checked()) ))
|
|
937
|
|
938 def on_raw_button(self,evt):
|
|
939 self.handler.list.set("raw_mode",str(bool2int(evt.Checked())))
|
|
940
|
|
941
|
|
942 ###############################
|
|
943 ## link image handlers
|
|
944 ###############################
|
|
945
|
|
946 class link_handler(node_handler):
|
|
947 """ A nodehandler for URLs. Will open URL in a wxHTMLFrame
|
|
948 <nodehandler name='?' module='forms' class='link_handler' >
|
|
949 <link href='http//??.??' />
|
|
950 </nodehandler >
|
|
951 """
|
|
952 def __init__(self,xml,tree_node):
|
|
953 node_handler.__init__(self,xml,tree_node)
|
|
954 self.link = self.xml[0]
|
|
955
|
|
956 def on_use(self,evt):
|
|
957 href = self.link.get("href")
|
|
958 wb = webbrowser.get()
|
|
959 wb.open(href)
|
|
960
|
|
961 def get_design_panel(self,parent):
|
|
962 return link_edit_panel(parent,self)
|
|
963
|
|
964 def get_use_panel(self,parent):
|
|
965 return link_panel(parent,self)
|
|
966
|
|
967 def tohtml(self):
|
|
968 href = self.link.get("href")
|
|
969 title = self.xml.get("name")
|
|
970 return "<a href='"+href+"' >"+title+"</a>"
|
|
971
|
|
972 class link_panel(wx.StaticText):
|
|
973 def __init__(self,parent,handler):
|
|
974 self.handler = handler
|
|
975 label = handler.xml.get('name')
|
|
976 wx.StaticText.__init__(self,parent,-1,label)
|
|
977 self.SetForegroundColour(wx.BLUE)
|
|
978 self.Bind(wx.EVT_LEFT_DOWN, self.handler.on_use)
|
|
979
|
|
980 P_URL = wx.NewId()
|
|
981
|
|
982 class link_edit_panel(wx.Panel):
|
|
983 def __init__(self, parent, handler):
|
|
984 wx.Panel.__init__(self, parent, -1)
|
|
985 self.handler = handler
|
|
986 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Link Properties"), wx.VERTICAL)
|
|
987
|
|
988 self.text = {}
|
|
989 self.text[P_TITLE] = wx.TextCtrl(self, P_TITLE, handler.xml.get('name'))
|
|
990 self.text[P_URL] = wx.TextCtrl(self, P_URL, handler.link.get('href'))
|
|
991
|
|
992 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND)
|
|
993 sizer.Add(self.text[P_TITLE], 0, wx.EXPAND)
|
|
994 sizer.Add(wx.Size(10,10))
|
|
995 sizer.Add(wx.StaticText(self, -1, "URL:"), 0, wx.EXPAND)
|
|
996 sizer.Add(self.text[P_URL], 0, wx.EXPAND)
|
|
997 self.SetSizer(sizer)
|
|
998 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE)
|
|
999 self.Bind(wx.EVT_TEXT, self.on_text, id=P_URL)
|
|
1000
|
|
1001 def on_text(self,evt):
|
|
1002 id = evt.GetId()
|
|
1003 txt = self.text[id].GetValue()
|
|
1004 if not len(txt): return
|
|
1005 if id == P_TITLE:
|
|
1006 self.handler.xml.set('name',txt)
|
|
1007 self.handler.rename(txt)
|
|
1008 elif id == P_URL: self.handler.link.set('href',txt)
|
|
1009
|
|
1010 ##########################
|
|
1011 ## webimg node handler
|
|
1012 ##########################
|
|
1013 class webimg_handler(node_handler):
|
|
1014 """ A nodehandler for URLs. Will open URL in a wxHTMLFrame
|
|
1015 <nodehandler name='?' module='forms' class='webimg_handler' >
|
|
1016 <link href='http//??.??' />
|
|
1017 </nodehandler >
|
|
1018 """
|
|
1019 def __init__(self,xml,tree_node):
|
|
1020 node_handler.__init__(self,xml,tree_node)
|
|
1021 self.link = self.xml[0]
|
|
1022
|
|
1023 def get_design_panel(self,parent):
|
|
1024 return link_edit_panel(parent,self)
|
|
1025
|
|
1026 def get_use_panel(self,parent):
|
|
1027 img = img_helper().load_url(self.link.get("href"))
|
|
1028 if not img is None: return wx.StaticBitmap(parent,-1,img,size= wx.Size(img.GetWidth(),img.GetHeight()))
|
|
1029 return wx.EmptyBitmap(1, 1)
|
|
1030
|
|
1031 def tohtml(self):
|
|
1032 href = self.link.get("href")
|
|
1033 title = self.xml.get("name")
|
|
1034 return "<img src='"+href+"' alt="+title+" >"
|