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