155
|
1 # Copyright (C) 2000-2001 The OpenRPG Project
|
|
2 #
|
|
3 # openrpg-dev@lists.sourceforge.net
|
|
4 #
|
|
5 # This program is free software; you can redistribute it and/or modify
|
|
6 # it under the terms of the GNU General Public License as published by
|
|
7 # the Free Software Foundation; either version 2 of the License, or
|
|
8 # (at your option) any later version.
|
|
9 #
|
|
10 # This program is distributed in the hope that it will be useful,
|
|
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 # GNU General Public License for more details.
|
|
14 #
|
|
15 # You should have received a copy of the GNU General Public License
|
|
16 # along with this program; if not, write to the Free Software
|
|
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
18 # --
|
|
19 #
|
|
20 # File: forms.py
|
|
21 # Author: Chris Davis
|
|
22 # Maintainer:
|
|
23 # Version:
|
|
24 # $Id: forms.py,v 1.53 2007/04/21 23:00:51 digitalxero Exp $
|
|
25 #
|
|
26 # Description: The file contains code for the form based nodehanlers
|
|
27 #
|
|
28
|
|
29 __version__ = "$Id: forms.py,v 1.53 2007/04/21 23:00:51 digitalxero Exp $"
|
|
30
|
|
31 from containers import *
|
|
32 import orpg.minidom as minidom
|
|
33 from orpg.orpg_xml import xml
|
|
34 from wx.lib.scrolledpanel import ScrolledPanel
|
173
|
35 from orpg.tools.settings import settings
|
155
|
36
|
|
37 def bool2int(b):
|
|
38 #in wxPython 2.5+, evt.Checked() returns True or False instead of 1.0 or 0.
|
|
39 #by running the results of that through this function, we convert it.
|
|
40 #if it was an int already, nothing changes. The difference between 1.0
|
|
41 #and 1, i.e. between ints and floats, is potentially dangerous when we
|
|
42 #use str() on it, but it seems to work fine right now.
|
|
43 if b: return 1
|
|
44 else: return 0
|
|
45
|
|
46 #################################
|
|
47 ## form container
|
|
48 #################################
|
|
49
|
|
50 class form_handler(container_handler):
|
|
51 """
|
|
52 <nodehandler name='?' module='forms' class='form_handler' >
|
|
53 <form width='100' height='100' />
|
|
54 </nodehandler>
|
|
55 """
|
|
56 def __init__(self,xml,tree_node):
|
|
57 container_handler.__init__(self, xml, tree_node)
|
|
58
|
|
59 def load_children(self):
|
|
60 self.atts = None
|
|
61 for child_xml in self.xml:
|
|
62 if child_xml.tag == "form": self.xml.remove(child_xml)
|
|
63 elif child_xml: self.tree.load_xml(child_xml, self.mytree_node)
|
|
64 if not self.xml.get('width'): self.xml.set('width', '400')
|
|
65 if not self.xml.get('height'): self.xml.set('height', '600')
|
|
66
|
|
67 def get_design_panel(self,parent):
|
|
68 return form_edit_panel(parent,self)
|
|
69
|
|
70 def get_use_panel(self,parent):
|
|
71 return form_panel(parent,self)
|
|
72
|
|
73 def on_drop(self,evt):
|
|
74 # make sure its a contorl node
|
|
75 container_handler.on_drop(self,evt)
|
|
76
|
|
77 class form_panel(ScrolledPanel):
|
|
78 def __init__(self, parent, handler):
|
|
79 ScrolledPanel.__init__(self, parent, wx.ID_ANY, style=wx.NO_BORDER|wx.VSCROLL|wx.HSCROLL)
|
|
80 self.height = int(handler.xml.get("height"))
|
|
81 self.width = int(handler.xml.get("width"))
|
|
82 self.SetSize((0,0))
|
|
83 self.handler = handler
|
|
84 self.parent = parent
|
|
85 self.main_sizer = wx.BoxSizer(wx.VERTICAL)
|
|
86 handler.tree.traverse(handler.mytree_node, self.create_child_wnd, None, False)
|
|
87 self.SetSizer(self.main_sizer)
|
|
88 self.SetAutoLayout(True)
|
|
89 self.SetupScrolling()
|
|
90 parent.SetSize(self.GetSize())
|
|
91 self.Fit()
|
|
92
|
|
93 def SetSize(self, xy):
|
|
94 (x, y) = self.GetSize()
|
|
95 (nx, ny) = xy
|
|
96 if x < nx:
|
|
97 x = nx+10
|
|
98 y += ny+11
|
|
99 ScrolledPanel.SetSize(self, (x, y))
|
|
100
|
|
101 def create_child_wnd(self, treenode, evt):
|
|
102 node = self.handler.tree.GetPyData(treenode)
|
|
103 panel = node.get_use_panel(self)
|
|
104 size = node.get_size_constraint()
|
|
105 if panel:
|
|
106 self.main_sizer.Add(panel, size, wx.EXPAND)
|
|
107 self.main_sizer.Add(wx.Size(10,10))
|
|
108
|
|
109 F_HEIGHT = wx.NewId()
|
|
110 F_WIDTH = wx.NewId()
|
|
111 class form_edit_panel(wx.Panel):
|
|
112 def __init__(self, parent, handler):
|
|
113 wx.Panel.__init__(self, parent, -1)
|
|
114 self.handler = handler
|
|
115 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Form Properties"), wx.VERTICAL)
|
|
116 wh_sizer = wx.BoxSizer(wx.HORIZONTAL)
|
|
117 self.text = { P_TITLE : wx.TextCtrl(self, P_TITLE, handler.xml.get('name')),
|
|
118 F_HEIGHT : wx.TextCtrl(self, F_HEIGHT, handler.xml.get('height')),
|
|
119 F_WIDTH : wx.TextCtrl(self, F_WIDTH, handler.xml.get('width'))
|
|
120 }
|
|
121
|
|
122 wh_sizer.Add(wx.StaticText(self, -1, "Width:"), 0, wx.ALIGN_CENTER)
|
|
123 wh_sizer.Add(wx.Size(10,10))
|
|
124 wh_sizer.Add(self.text[F_WIDTH], 0, wx.EXPAND)
|
|
125 wh_sizer.Add(wx.Size(10,10))
|
|
126 wh_sizer.Add(wx.StaticText(self, -1, "Height:"), 0, wx.ALIGN_CENTER)
|
|
127 wh_sizer.Add(wx.Size(10,10))
|
|
128 wh_sizer.Add(self.text[F_HEIGHT], 0, wx.EXPAND)
|
|
129
|
|
130 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND)
|
|
131 sizer.Add(self.text[P_TITLE], 0, wx.EXPAND)
|
|
132 sizer.Add(wx.Size(10,10))
|
|
133 sizer.Add(wh_sizer,0,wx.EXPAND)
|
|
134
|
|
135 self.SetSizer(sizer)
|
|
136 self.SetAutoLayout(True)
|
|
137 self.Fit()
|
|
138 parent.SetSize(self.GetBestSize())
|
|
139
|
|
140 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE)
|
|
141 self.Bind(wx.EVT_TEXT, self.on_text, id=F_HEIGHT)
|
|
142 self.Bind(wx.EVT_TEXT, self.on_text, id=F_WIDTH)
|
|
143
|
|
144 def on_text(self,evt):
|
|
145 id = evt.GetId()
|
|
146 txt = self.text[id].GetValue()
|
|
147 if not len(txt): return
|
|
148 if id == P_TITLE:
|
|
149 self.handler.xml.set('name',txt)
|
|
150 self.handler.rename(txt)
|
|
151 elif id == F_HEIGHT or id == F_WIDTH:
|
|
152 try: int(txt)
|
|
153 except: return 0
|
|
154 if id == F_HEIGHT: self.handler.xml.set("height",txt)
|
|
155 elif id == F_WIDTH: self.handler.xml.set("width",txt)
|
|
156
|
|
157 ##########################
|
|
158 ## control handler
|
|
159 ##########################
|
|
160 class control_handler(node_handler):
|
|
161 """ A nodehandler for form controls.
|
|
162 <nodehandler name='?' module='forms' class='control_handler' />
|
|
163 """
|
|
164 def __init__(self, xml, tree_node):
|
|
165 node_handler.__init__(self, xml, tree_node)
|
|
166
|
|
167 def get_size_constraint(self):
|
|
168 return 0
|
|
169
|
|
170 ##########################
|
|
171 ## textctrl handler
|
|
172 ##########################
|
|
173 #
|
|
174 # Updated by Snowdog (April 2003)
|
|
175 # Now includes Raw Send Mode (like the chat macro uses)
|
|
176 # and an option to remove the title from text when sent
|
|
177 # to the chat in the normal non-chat macro mode.
|
|
178 #
|
|
179 class textctrl_handler(node_handler):
|
|
180 """ <nodehandler class="textctrl_handler" module="form" name="">
|
|
181 <text multiline='0' send_button='0' raw_mode='0' hide_title='0'>Text In Node</text>
|
|
182 </nodehandler>
|
|
183 """
|
|
184 def __init__(self,xml,tree_node):
|
|
185 node_handler.__init__(self,xml,tree_node)
|
|
186 self.text_elem = self.xml.find('text')
|
|
187 if self.text_elem.get("send_button") == "": self.text_elem.set("send_button","0")
|
|
188 if self.text_elem.get("raw_mode") == "": self.text_elem.set("raw_mode","0")
|
|
189 if self.text_elem.get("hide_title") == "": self.text_elem.set("hide_title","0")
|
|
190
|
|
191 def get_design_panel(self,parent):
|
|
192 return textctrl_edit_panel(parent,self)
|
|
193
|
|
194 def get_use_panel(self,parent):
|
|
195 return text_panel(parent,self)
|
|
196
|
|
197 def get_size_constraint(self):
|
|
198 return int(self.text_elem.get("multiline",0))
|
|
199
|
|
200 def is_multi_line(self):
|
|
201 return int(self.text_elem.get("multiline",0))
|
|
202
|
|
203 def is_raw_send(self):
|
|
204 return int(self.text_elem.get("raw_mode",0))
|
|
205
|
|
206 def is_hide_title(self):
|
|
207 return int(self.text_elem.get("hide_title",0))
|
|
208
|
|
209 def has_send_button(self):
|
|
210 return int(self.text_elem.get("send_button",0))
|
|
211
|
|
212 def tohtml(self):
|
|
213 txt = self.get_value()
|
|
214 txt = string.replace(txt,'\n',"<br />")
|
|
215 if not self.is_hide_title(): txt = "<b>"+self.xml.get("name")+":</b> "+txt
|
|
216 return txt
|
|
217
|
|
218 def get_value(self):
|
|
219 return self.text_elem.text
|
|
220
|
|
221 def set_value(self, new_value):
|
|
222 self.text_elem.text = str(new_value)
|
|
223
|
|
224 FORM_TEXT_CTRL = wx.NewId()
|
|
225 FORM_SEND_BUTTON = wx.NewId()
|
|
226
|
|
227 class text_panel(wx.Panel):
|
|
228 def __init__(self, parent, handler):
|
|
229 wx.Panel.__init__(self, parent, -1)
|
|
230 self.chat = handler.chat
|
|
231 self.handler = handler
|
|
232 if handler.is_multi_line():
|
|
233 text_style = wx.TE_MULTILINE
|
|
234 sizer_style = wx.EXPAND
|
|
235 sizer = wx.BoxSizer(wx.VERTICAL)
|
|
236 else:
|
|
237 sizer_style = wx.ALIGN_CENTER
|
|
238 text_style = 0
|
|
239 sizer = wx.BoxSizer(wx.HORIZONTAL)
|
|
240
|
|
241 txt = handler.get_value()
|
|
242 if txt == None: txt = ''
|
|
243 self.text = wx.TextCtrl(self, FORM_TEXT_CTRL, txt, style=text_style)
|
|
244 sizer.Add(wx.StaticText(self, -1, handler.xml.get('name')+": "), 0, sizer_style)
|
|
245 sizer.Add(wx.Size(5,0))
|
|
246 sizer.Add(self.text, 1, sizer_style)
|
|
247
|
|
248 if handler.has_send_button(): sizer.Add(wx.Button(self, FORM_SEND_BUTTON, "Send"), 0, sizer_style)
|
|
249
|
|
250 self.sizer = sizer
|
|
251 self.SetSizer(sizer)
|
|
252 self.SetAutoLayout(True)
|
|
253
|
|
254 parent.SetSize(self.GetBestSize())
|
|
255 self.Bind(wx.EVT_TEXT, self.on_text, id=FORM_TEXT_CTRL)
|
132
|
256 self.Bind(wx.EVT_BUTTON, self.on_send, id=FORM_SEND_BUTTON)
|
|
257
|
|
258 def on_text(self, evt):
|
155
|
259 debug()
|
|
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()
|
|
266 txt = self.chat.ParseMap(txt, self.handler.xml)
|
155
|
267 if not self.handler.is_raw_send():
|
|
268 self.chat.ParsePost(self.handler.tohtml(), True, True)
|
|
269 return 1
|
|
270 actionlist = txt.split("\n")
|
|
271 for line in actionlist:
|
|
272 if(line != ""):
|
|
273 if line[0] != "/": ## it's not a slash command
|
|
274 self.chat.ParsePost(line, True, True)
|
|
275 else:
|
|
276 action = line
|
|
277 self.chat.chat_cmds.docmd(action)
|
|
278 return 1
|
|
279
|
|
280 F_MULTI = wx.NewId()
|
|
281 F_SEND_BUTTON = wx.NewId()
|
|
282 F_RAW_SEND = wx.NewId()
|
|
283 F_HIDE_TITLE = wx.NewId()
|
|
284 F_TEXT = wx.NewId()
|
173
|
285 T_BUT_REF = wx.NewId()
|
155
|
286
|
|
287 class textctrl_edit_panel(wx.Panel):
|
|
288 def __init__(self, parent, handler):
|
|
289 wx.Panel.__init__(self, parent, -1)
|
|
290 self.handler = handler
|
|
291 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Text Properties"), wx.VERTICAL)
|
|
292
|
|
293 self.title = wx.TextCtrl(self, P_TITLE, handler.xml.get('name'))
|
|
294 self.multi = wx.CheckBox(self, F_MULTI, " Multi-Line")
|
|
295 self.multi.SetValue(handler.is_multi_line())
|
|
296 self.raw_send = wx.CheckBox(self, F_RAW_SEND, " Send as Macro")
|
|
297 self.raw_send.SetValue(handler.is_raw_send())
|
|
298 self.hide_title = wx.CheckBox(self, F_HIDE_TITLE, " Hide Title")
|
|
299 self.hide_title.SetValue(handler.is_hide_title())
|
|
300 self.send_button = wx.CheckBox(self, F_SEND_BUTTON, " Send Button")
|
|
301 self.send_button.SetValue(handler.has_send_button())
|
173
|
302 button_ref = wx.Button(self, T_BUT_REF, "Reference")
|
155
|
303
|
|
304 sizer.Add(wx.StaticText(self, P_TITLE, "Title:"), 0, wx.EXPAND)
|
|
305 sizer.Add(self.title, 0, wx.EXPAND)
|
|
306 sizer.Add(wx.Size(10,10))
|
|
307 sizer.Add(self.multi, 0, wx.EXPAND)
|
|
308 sizer.Add(self.raw_send, 0, wx.EXPAND)
|
|
309 sizer.Add(self.hide_title, 0, wx.EXPAND)
|
|
310 sizer.Add(self.send_button, 0 , wx.EXPAND)
|
173
|
311 sizer.Add(button_ref, 0)
|
155
|
312 sizer.Add(wx.Size(10,10))
|
|
313 if handler.is_multi_line():
|
|
314 sizer_style = wx.EXPAND
|
|
315 text_style = wx.TE_MULTILINE
|
|
316 multi = 1
|
|
317 else:
|
|
318 sizer_style=wx.EXPAND
|
|
319 text_style = 0
|
|
320 multi = 0
|
|
321 self.text = wx.TextCtrl(self, F_TEXT, handler.get_value(),style=text_style)
|
|
322 sizer.Add(wx.Size(5,0))
|
|
323 sizer.Add(self.text, multi, sizer_style)
|
|
324 self.SetSizer(sizer)
|
|
325 self.SetAutoLayout(True)
|
|
326
|
|
327 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE)
|
|
328 self.Bind(wx.EVT_TEXT, self.on_text, id=F_TEXT)
|
|
329 self.Bind(wx.EVT_CHECKBOX, self.on_button, id=F_MULTI)
|
|
330 self.Bind(wx.EVT_CHECKBOX, self.on_raw_button, id=F_RAW_SEND)
|
|
331 self.Bind(wx.EVT_CHECKBOX, self.on_hide_button, id=F_HIDE_TITLE)
|
|
332 self.Bind(wx.EVT_CHECKBOX, self.on_send_button, id=F_SEND_BUTTON)
|
173
|
333 self.Bind(wx.EVT_BUTTON, self.on_reference, id=T_BUT_REF)
|
|
334
|
|
335 ## EZ_Tree Core TaS - Prof.Ebral ##
|
|
336 def on_reference(self, evt, car=None):
|
|
337 self.do_tree = wx.Frame(self, -1, 'Tree')
|
|
338 self.ez_tree = orpg.gametree.gametree
|
|
339 self.temp_wnd = self.ez_tree.game_tree(self.do_tree, self.ez_tree.EZ_REF)
|
|
340 self.temp_wnd.Bind(wx.EVT_LEFT_DCLICK, self.on_ldclick)
|
|
341 self.temp_wnd.load_tree(settings.get("gametree"))
|
|
342 self.do_tree.Show()
|
|
343
|
|
344 def on_ldclick(self, evt):
|
|
345 self.rename_flag = 0
|
|
346 pt = evt.GetPosition()
|
|
347 (item, flag) = self.temp_wnd.HitTest(pt)
|
|
348 if item.IsOk():
|
|
349 obj = self.temp_wnd.GetPyData(item)
|
|
350 self.temp_wnd.SelectItem(item)
|
|
351 start = self.handler.xml.get('map').split('::')
|
|
352 end = obj.xml.get('map').split('::')
|
|
353 x = 0
|
|
354 if start[x] == end[x]:
|
|
355 try:
|
|
356 while start[x] == end[x]:
|
|
357 del end[x], start[x]
|
|
358 x += 1
|
|
359 except:
|
|
360 complete = "!!"
|
|
361 for e in end: complete += e +'::'
|
|
362 complete = complete + obj.xml.get('name') + '!!'
|
|
363 self.text.AppendText(complete); self.on_text(evt)
|
|
364 self.do_tree.Destroy()
|
|
365 ##### #####
|
155
|
366
|
|
367 def on_text(self,evt):
|
|
368 id = evt.GetId()
|
|
369 if id == P_TITLE:
|
|
370 txt = self.title.GetValue()
|
|
371 if not len(txt): return
|
|
372 self.handler.xml.set('name',txt)
|
|
373 self.handler.rename(txt)
|
|
374 if id == F_TEXT:
|
|
375 txt = self.text.GetValue()
|
|
376 #txt = strip_text(txt) ##Does not seem to exist.
|
|
377 self.handler.text_elem.text = txt
|
|
378
|
|
379 def on_button(self,evt):
|
|
380 self.handler.text_elem.set("multiline",str(bool2int(evt.Checked())))
|
|
381
|
|
382 def on_raw_button(self,evt):
|
|
383 self.handler.text_elem.set("raw_mode",str(bool2int(evt.Checked())))
|
|
384
|
|
385 def on_hide_button(self,evt):
|
|
386 self.handler.text_elem.set("hide_title",str(bool2int(evt.Checked())))
|
|
387
|
|
388 def on_send_button(self,evt):
|
|
389 self.handler.text_elem.set("send_button",str(bool2int(evt.Checked())))
|
|
390
|
|
391
|
|
392 #######################
|
|
393 ## listbox handler
|
|
394 #######################
|
|
395 #
|
|
396 # Updated by Snowdog (April 2003)
|
|
397 # Now includesan option to remove the title from
|
|
398 # text when sent to the chat.
|
|
399 #
|
|
400 L_DROP = 0
|
|
401 L_LIST = 1
|
|
402 L_RADIO = 2
|
|
403 L_CHECK = 3
|
|
404 L_ROLLER = 4
|
|
405
|
|
406 class listbox_handler(node_handler):
|
|
407 """
|
|
408 <nodehandler class="listbox_handler" module="forms" name="">
|
|
409 <list type="1" send_button='0' hide_title='0'>
|
|
410 <option value="" selected="" >Option Text I</option>
|
|
411 <option value="" selected="" >Option Text II</option>
|
|
412 </list>
|
|
413 </nodehandler>
|
|
414 """
|
|
415 def __init__(self,xml,tree_node):
|
|
416 node_handler.__init__(self,xml,tree_node)
|
173
|
417 self.list_reload()
|
|
418 #print xml
|
|
419 #print self.tree.GetItemParent(tree_node)
|
155
|
420 if self.list.get("send_button") == "": self.list.set("send_button","0")
|
141
|
421 if self.list.get("hide_title") == "": self.list.set("hide_title","0")
|
155
|
422 if self.list.get("raw_mode") == "": self.list.set("raw_mode","0")
|
|
423
|
173
|
424 def list_reload(self):
|
|
425 self.list = self.xml.find('list')
|
|
426 self.options = self.list.findall('option')
|
|
427 self.captions = []
|
|
428 for opt in self.options:
|
|
429 if opt.get('caption') == None: opt.set('caption', '')
|
|
430 self.captions.append(opt.get('caption'))
|
|
431
|
155
|
432 def get_design_panel(self,parent):
|
|
433 return listbox_edit_panel(parent,self)
|
|
434
|
|
435 def get_use_panel(self,parent):
|
|
436 return listbox_panel(parent,self)
|
|
437
|
|
438 def get_type(self):
|
|
439 return int(self.list.get("type"))
|
|
440
|
|
441 def set_type(self,type):
|
|
442 self.list.set("type",str(type))
|
|
443
|
|
444 def is_hide_title(self):
|
141
|
445 return int(self.list.get("hide_title", 0))
|
|
446
|
155
|
447 def is_raw_send(self):
|
|
448 return int(self.list.get("raw_mode",0))
|
|
449
|
|
450 # single selection methods
|
|
451 def get_selected_node(self):
|
|
452 for opt in self.options:
|
|
453 if opt.get("selected") == "1": return opt
|
|
454 return None
|
|
455
|
|
456 def get_selected_index(self):
|
|
457 i = 0
|
|
458 for opt in self.options:
|
|
459 if opt.get("selected") == "1": return i
|
|
460 i += 1
|
|
461 return 0
|
|
462
|
|
463 def get_selected_text(self):
|
|
464 node = self.get_selected_node()
|
|
465 if node: return node.text
|
|
466 else: return ""
|
|
467
|
|
468 # mult selection methods
|
|
469 def get_selections(self):
|
|
470 opts = []
|
|
471 for opt in self.options:
|
|
472 if opt.get("selected") == "1": opts.append(opt)
|
|
473 return opts
|
|
474
|
|
475 def get_selections_text(self):
|
|
476 opts = []
|
|
477 for opt in self.options:
|
|
478 if opt.get("selected") == "1": opts.append(opt.text)
|
|
479 return opts
|
|
480
|
|
481 def get_selections_index(self):
|
|
482 opts = []
|
|
483 i = 0
|
|
484 for opt in self.options:
|
|
485 if opt.get("selected") == "1": opts.append(i)
|
|
486 i += 1
|
|
487 return opts
|
|
488
|
|
489 # setting selection method
|
|
490 def set_selected_node(self,index,selected=1):
|
|
491 if self.get_type() != L_CHECK: self.clear_selections()
|
|
492 self.options[index].set("selected", str(bool2int(selected)))
|
|
493
|
|
494 def clear_selections(self):
|
|
495 for opt in self.options: opt.set("selected","0")
|
|
496
|
|
497 # misc methods
|
|
498 def get_options(self):
|
|
499 opts = []
|
|
500 for opt in self.options: opts.append(opt.text)
|
|
501 return opts
|
|
502
|
173
|
503 def get_captions(self):
|
|
504 captions = []
|
|
505 for opt in self.options: captions.append(opt.get("caption"))
|
|
506 self.captions = captions
|
|
507 return captions
|
|
508
|
|
509 def get_option(self, index):
|
155
|
510 return self.options[index].text
|
|
511
|
173
|
512 def get_caption(self, index):
|
|
513 captions = self.get_captions()
|
|
514 return captions[index] or ''
|
|
515
|
|
516 def add_option(self, caption, value):
|
155
|
517 elem = Element('option')
|
|
518 elem.set("value","0")
|
173
|
519 elem.set('caption', caption)
|
155
|
520 elem.set("selected","0")
|
173
|
521 elem.text = value
|
155
|
522 self.list.append(elem)
|
173
|
523 self.list_reload()
|
155
|
524
|
|
525 def remove_option(self,index):
|
|
526 self.list.remove(self.options[index])
|
173
|
527 self.list_reload()
|
155
|
528
|
173
|
529 def edit_option(self, index, value):
|
155
|
530 self.options[index].text = value
|
|
531
|
173
|
532 def edit_caption(self, index, value):
|
|
533 self.options[index].set('caption', value)
|
|
534 self.captions[index] = value
|
|
535
|
155
|
536 def has_send_button(self):
|
|
537 if self.list.get("send_button") == '0': return False
|
|
538 else: return True
|
|
539
|
|
540 def get_size_constraint(self):
|
|
541 if self.get_type() == L_DROP: return 0
|
|
542 else: return 1
|
|
543
|
|
544 def tohtml(self):
|
|
545 opts = self.get_selections_text()
|
|
546 text = ""
|
|
547 if not self.is_hide_title(): text = "<b>"+self.xml.get("name")+":</b> "
|
|
548 comma = ", "
|
|
549 text += comma.join(opts)
|
|
550 return text
|
|
551
|
|
552 def get_value(self):
|
141
|
553 return "\n".join(self.get_selections_text())
|
|
554
|
155
|
555 def on_send_to_chat(self, evt):
|
141
|
556 txt = self.get_selected_text()
|
|
557 txt = self.chat.ParseMap(txt, self.xml)
|
155
|
558 if not self.is_raw_send():
|
|
559 self.chat.ParsePost(self.tohtml(), True, True)
|
|
560 return 1
|
|
561 actionlist = self.get_selections_text()
|
141
|
562 for line in actionlist:
|
155
|
563 line = self.chat.ParseMap(line, self.xml)
|
|
564 if(line != ""):
|
|
565 if line[0] != "/": ## it's not a slash command
|
|
566 self.chat.ParsePost(line, True, True)
|
|
567 else:
|
|
568 action = line
|
|
569 self.chat.chat_cmds.docmd(action)
|
|
570 return 1
|
|
571
|
|
572
|
|
573 F_LIST = wx.NewId()
|
|
574 F_SEND = wx.NewId()
|
|
575
|
|
576
|
|
577 class listbox_panel(wx.Panel):
|
|
578 def __init__(self, parent, handler):
|
|
579 wx.Panel.__init__(self, parent, -1)
|
|
580 self.handler = handler
|
|
581 self.chat = handler.chat
|
173
|
582 opts = []
|
|
583 values = handler.get_options()
|
|
584 captions = handler.get_captions()
|
|
585 for value in values:
|
|
586 if captions[values.index(value)] != '': opts.append(captions[values.index(value)])
|
|
587 else: opts.append(value)
|
155
|
588 cur_opt = handler.get_selected_text()
|
|
589 type = handler.get_type()
|
|
590 label = handler.xml.get('name')
|
|
591
|
|
592 if type == L_DROP:
|
|
593 self.list = wx.ComboBox(self, F_LIST, cur_opt, choices=opts, style=wx.CB_READONLY)
|
|
594 if self.list.GetSize()[0] > 200:
|
|
595 self.list.Destroy()
|
|
596 self.list = wx.ComboBox(self, F_LIST, cur_opt, size=(200, -1), choices=opts, style=wx.CB_READONLY)
|
|
597 elif type == L_LIST: self.list = wx.ListBox(self,F_LIST,choices=opts)
|
|
598 elif type == L_RADIO: self.list = wx.RadioBox(self,F_LIST,label,choices=opts,majorDimension=3)
|
|
599 elif type == L_CHECK:
|
|
600 self.list = wx.CheckListBox(self,F_LIST,choices=opts)
|
|
601 self.set_checks()
|
|
602
|
|
603 for i in handler.get_selections_text():
|
|
604 if type == L_DROP: self.list.SetValue( i )
|
|
605 else: self.list.SetStringSelection( i )
|
|
606 if type == L_DROP: sizer = wx.BoxSizer(wx.HORIZONTAL)
|
|
607 else: sizer = wx.BoxSizer(wx.VERTICAL)
|
|
608
|
|
609 if type != L_RADIO:
|
|
610 sizer.Add(wx.StaticText(self, -1, label+": "), 0, wx.EXPAND)
|
|
611 sizer.Add(wx.Size(5,0))
|
|
612 sizer.Add(self.list, 1, wx.EXPAND)
|
|
613 if handler.has_send_button():
|
|
614 sizer.Add(wx.Button(self, F_SEND, "Send"), 0, wx.EXPAND)
|
|
615 self.Bind(wx.EVT_BUTTON, self.handler.on_send_to_chat, id=F_SEND)
|
|
616 self.sizer = sizer
|
|
617 self.SetSizer(sizer)
|
|
618 self.SetAutoLayout(True)
|
|
619 self.Fit()
|
|
620 parent.SetSize(self.GetBestSize())
|
|
621
|
|
622 if type == L_DROP: self.Bind(wx.EVT_COMBOBOX, self.on_change, id=F_LIST)
|
|
623 elif type == L_LIST: self.Bind(wx.EVT_LISTBOX, self.on_change, id=F_LIST)
|
|
624 elif type == L_RADIO: self.Bind(wx.EVT_RADIOBOX, self.on_change, id=F_LIST)
|
|
625 elif type == L_CHECK:self.Bind(wx.EVT_CHECKLISTBOX, self.on_check, id=F_LIST)
|
|
626 self.type = type
|
|
627
|
|
628 def on_change(self,evt):
|
|
629 self.handler.set_selected_node(self.list.GetSelection())
|
|
630
|
|
631 def on_check(self,evt):
|
141
|
632 for i in xrange(self.list.GetCount()): self.handler.set_selected_node(i, bool2int(self.list.IsChecked(i)))
|
155
|
633
|
|
634 def set_checks(self):
|
|
635 for i in self.handler.get_selections_index(): self.list.Check(i)
|
|
636
|
|
637
|
|
638 BUT_ADD = wx.NewId()
|
|
639 BUT_REM = wx.NewId()
|
173
|
640 BUT_REF = wx.NewId()
|
155
|
641 BUT_EDIT = wx.NewId()
|
|
642 F_TYPE = wx.NewId()
|
|
643 F_NO_TITLE = wx.NewId()
|
173
|
644 LIST_CTRL = wx.NewId()
|
155
|
645
|
|
646 class listbox_edit_panel(wx.Panel):
|
|
647 def __init__(self, parent, handler):
|
|
648 wx.Panel.__init__(self, parent, -1)
|
|
649 self.handler = handler
|
173
|
650 self.parent = parent
|
155
|
651 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "List Box Properties"), wx.VERTICAL)
|
|
652
|
|
653 self.text = wx.TextCtrl(self, P_TITLE, handler.xml.get('name'))
|
|
654
|
173
|
655 self.listbox = wx.ListCtrl(self, LIST_CTRL, style=wx.LC_REPORT)
|
|
656 self.listbox.InsertColumn(0, 'Caption')
|
|
657 self.listbox.InsertColumn(1, 'Value')
|
|
658 self.listbox.SetColumnWidth(0, 75)
|
|
659 self.listbox.SetColumnWidth(1, 300)
|
|
660 self.reload_options()
|
|
661
|
155
|
662 opts = ['Drop Down', 'List Box', 'Radio Box', 'Check List']
|
|
663 self.type_radios = wx.RadioBox(self,F_TYPE,"List Type",choices=opts)
|
|
664 self.type_radios.SetSelection(handler.get_type())
|
|
665
|
|
666 self.send_button = wx.CheckBox(self, F_SEND_BUTTON, " Send Button")
|
141
|
667 self.send_button.SetValue(handler.has_send_button())
|
|
668
|
155
|
669 self.raw_send = wx.CheckBox(self, F_RAW_SEND, " Send as Macro")
|
|
670 self.raw_send.SetValue(handler.is_raw_send())
|
|
671
|
|
672 self.hide_title = wx.CheckBox(self, F_NO_TITLE, " Hide Title")
|
|
673 self.hide_title.SetValue(handler.is_hide_title())
|
|
674
|
|
675 but_sizer = wx.BoxSizer(wx.HORIZONTAL)
|
|
676 but_sizer.Add(wx.Button(self, BUT_ADD, "Add"), 1, wx.EXPAND)
|
|
677 but_sizer.Add(wx.Size(10,10))
|
|
678 but_sizer.Add(wx.Button(self, BUT_EDIT, "Edit"), 1, wx.EXPAND)
|
|
679 but_sizer.Add(wx.Size(10,10))
|
|
680 but_sizer.Add(wx.Button(self, BUT_REM, "Remove"), 1, wx.EXPAND)
|
|
681
|
|
682 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND)
|
|
683 sizer.Add(self.text, 0, wx.EXPAND)
|
|
684 sizer.Add(wx.Size(10,10))
|
|
685 sizer.Add(self.type_radios, 0, wx.EXPAND)
|
|
686 sizer.Add(wx.Size(10,10))
|
|
687 sizer.Add(self.send_button, 0 , wx.EXPAND)
|
141
|
688 sizer.Add(self.hide_title, 0, wx.EXPAND)
|
155
|
689 sizer.Add(self.raw_send, 0, wx.EXPAND)
|
|
690 sizer.Add(wx.Size(10,10))
|
|
691 sizer.Add(wx.StaticText(self, -1, "Options:"), 0, wx.EXPAND)
|
|
692 sizer.Add(self.listbox,1,wx.EXPAND);
|
|
693 sizer.Add(but_sizer,0,wx.EXPAND)
|
|
694
|
|
695 self.SetSizer(sizer)
|
|
696 self.SetAutoLayout(True)
|
|
697 self.Fit()
|
|
698 parent.SetSize(self.GetBestSize())
|
|
699
|
|
700 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE)
|
|
701 self.Bind(wx.EVT_BUTTON, self.on_edit, id=BUT_EDIT)
|
|
702 self.Bind(wx.EVT_BUTTON, self.on_remove, id=BUT_REM)
|
|
703 self.Bind(wx.EVT_BUTTON, self.on_add, id=BUT_ADD)
|
|
704 self.Bind(wx.EVT_RADIOBOX, self.on_type, id=F_TYPE)
|
|
705 self.Bind(wx.EVT_CHECKBOX, self.on_hide_button, id=F_NO_TITLE)
|
141
|
706 self.Bind(wx.EVT_CHECKBOX, self.on_send_button, id=F_SEND_BUTTON)
|
155
|
707 self.Bind(wx.EVT_CHECKBOX, self.on_raw_button, id=F_RAW_SEND)
|
|
708
|
|
709 def on_type(self,evt):
|
|
710 self.handler.set_type(evt.GetInt())
|
|
711
|
|
712 def on_add(self,evt):
|
173
|
713 self.dlg = wx.Frame(self, -1, 'Text', size=(300,150))
|
|
714 edit_panel = wx.Panel(self.dlg, -1)
|
|
715 sizer = wx.GridBagSizer(1, 2)
|
|
716 edit_panel.SetSizer(sizer)
|
|
717 caption_text = wx.StaticText(edit_panel, -1, 'Caption')
|
|
718 self.caption_entry = wx.TextCtrl(edit_panel, -1, '')
|
|
719 value_text = wx.StaticText(edit_panel, -1, 'Value')
|
|
720 self.value_entry = wx.TextCtrl(edit_panel, -1, '')
|
|
721 button_ok = wx.Button(edit_panel, wx.ID_OK)
|
|
722 button_cancel = wx.Button(edit_panel, wx.ID_CANCEL)
|
|
723 button_ref = wx.Button(edit_panel, BUT_REF, "Reference")
|
|
724 sizer.Add(caption_text, (0,0))
|
|
725 sizer.Add(self.caption_entry, (0,1), span=(1,3), flag=wx.EXPAND)
|
|
726 sizer.Add(value_text, (1,0))
|
|
727 sizer.Add(self.value_entry, (1,1), span=(1,3), flag=wx.EXPAND)
|
|
728 sizer.Add(button_ok, (3,0))
|
|
729 sizer.Add(button_cancel, (3,1))
|
|
730 sizer.Add(button_ref, (3,2), flag=wx.EXPAND)
|
|
731 self.Bind(wx.EVT_BUTTON, self.on_reference, id=BUT_REF)
|
|
732 self.Bind(wx.EVT_BUTTON, self.on_add_option, id=wx.ID_OK)
|
|
733 self.Bind(wx.EVT_BUTTON, self.on_edit_cancel, id=wx.ID_CANCEL)
|
|
734 self.dlg.Show()
|
|
735
|
|
736 def on_add_option(self, evt):
|
|
737 self.handler.add_option(self.caption_entry.GetValue(), self.value_entry.GetValue())
|
155
|
738 self.reload_options()
|
173
|
739 self.dlg.Destroy()
|
|
740 return
|
|
741
|
|
742 ## EZ_Tree Core TaS - Prof.Ebral ##
|
|
743 def on_reference(self, evt, car=None):
|
|
744 self.do_tree = wx.Frame(self, -1, 'Tree')
|
|
745 self.ez_tree = orpg.gametree.gametree
|
|
746 self.temp_wnd = self.ez_tree.game_tree(self.do_tree, self.ez_tree.EZ_REF)
|
|
747 self.temp_wnd.Bind(wx.EVT_LEFT_DCLICK, self.on_ldclick)
|
|
748 self.temp_wnd.load_tree(settings.get("gametree"))
|
|
749 self.do_tree.Show()
|
|
750
|
|
751 def on_ldclick(self, evt):
|
|
752 self.rename_flag = 0
|
|
753 pt = evt.GetPosition()
|
|
754 (item, flag) = self.temp_wnd.HitTest(pt)
|
|
755 if item.IsOk():
|
|
756 obj = self.temp_wnd.GetPyData(item)
|
|
757 self.temp_wnd.SelectItem(item)
|
|
758 start = self.handler.xml.get('map').split('::')
|
|
759 end = obj.xml.get('map').split('::')
|
|
760 x = 0
|
|
761 if start[x] == end[x]:
|
|
762 try:
|
|
763 while start[x] == end[x]:
|
|
764 del end[x], start[x]
|
|
765 x += 1
|
|
766 except:
|
|
767 complete = "!!"
|
|
768 for e in end: complete += e +'::'
|
|
769 complete = complete + obj.xml.get('name') + '!!'
|
|
770 self.value_entry.SetValue(complete); self.reload_options()
|
|
771 self.do_tree.Destroy()
|
|
772 ##### #####
|
|
773
|
|
774 def on_edit_ok(self, evt):
|
|
775 self.handler.edit_caption(self.index, self.caption_entry.GetValue())
|
|
776 self.handler.edit_option(self.index, self.value_entry.GetValue())
|
|
777 self.reload_options()
|
|
778 self.dlg.Destroy()
|
|
779 component.add('tree', component.get('tree_back')) ## Backup
|
|
780 return
|
|
781
|
|
782 def on_edit_cancel(self, evt):
|
|
783 self.dlg.Destroy()
|
|
784 component.add('tree', component.get('tree_back')) ## Backup
|
|
785 return
|
155
|
786
|
|
787 def on_remove(self,evt):
|
|
788 index = self.listbox.GetSelection()
|
|
789 if index >= 0:
|
|
790 self.handler.remove_option(index)
|
|
791 self.reload_options()
|
|
792
|
|
793 def on_edit(self,evt):
|
173
|
794 self.index = self.listbox.GetFocusedItem()
|
|
795 if self.index >= 0:
|
|
796 self.dlg = wx.Frame(self, -1, 'Text', size=(300,150))
|
|
797 edit_panel = wx.Panel(self.dlg, -1)
|
|
798 sizer = wx.GridBagSizer(1, 2)
|
|
799 edit_panel.SetSizer(sizer)
|
|
800 caption_text = wx.StaticText(edit_panel, -1, 'Caption')
|
|
801 self.caption_entry = wx.TextCtrl(edit_panel, -1, self.handler.get_caption(self.index))
|
|
802 value_text = wx.StaticText(edit_panel, -1, 'Value')
|
|
803 self.value_entry = wx.TextCtrl(edit_panel, -1, self.handler.get_option(self.index))
|
|
804 button_ok = wx.Button(edit_panel, wx.ID_OK)
|
|
805 button_cancel = wx.Button(edit_panel, wx.ID_CANCEL)
|
|
806 button_ref = wx.Button(edit_panel, BUT_REF, "Reference")
|
|
807 sizer.Add(caption_text, (0,0))
|
|
808 sizer.Add(self.caption_entry, (0,1), span=(1,3), flag=wx.EXPAND)
|
|
809 sizer.Add(value_text, (1,0))
|
|
810 sizer.Add(self.value_entry, (1,1), span=(1,3), flag=wx.EXPAND)
|
|
811 sizer.Add(button_ok, (3,0))
|
|
812 sizer.Add(button_cancel, (3,1))
|
|
813 sizer.Add(button_ref, (3,2), flag=wx.EXPAND)
|
|
814 self.Bind(wx.EVT_BUTTON, self.on_reference, id=BUT_REF)
|
|
815 self.Bind(wx.EVT_BUTTON, self.on_edit_ok, id=wx.ID_OK)
|
|
816 self.Bind(wx.EVT_BUTTON, self.on_edit_cancel, id=wx.ID_CANCEL)
|
|
817 self.dlg.Show()
|
155
|
818
|
|
819 def reload_options(self):
|
173
|
820 self.listbox.DeleteAllItems()
|
|
821 values = self.handler.get_options()
|
|
822 captions = self.handler.get_captions()
|
|
823 for index in range(len(values)):
|
|
824 self.listbox.Append((captions[index], values[index]))
|
155
|
825
|
|
826 def on_text(self,evt):
|
|
827 id = evt.GetId()
|
|
828 txt = self.text.GetValue()
|
|
829 if not len(txt): return
|
|
830 if id == P_TITLE:
|
|
831 self.handler.xml.set('name',txt)
|
|
832 self.handler.rename(txt)
|
|
833
|
|
834 def on_send_button(self,evt):
|
|
835 self.handler.list.set("send_button", str( bool2int(evt.Checked()) ))
|
|
836
|
|
837 def on_hide_button(self,evt):
|
141
|
838 self.handler.list.set("hide_title", str( bool2int(evt.Checked()) ))
|
|
839
|
155
|
840 def on_raw_button(self,evt):
|
|
841 self.handler.list.set("raw_mode",str(bool2int(evt.Checked())))
|
|
842
|
|
843
|
|
844 ###############################
|
|
845 ## link image handlers
|
|
846 ###############################
|
|
847
|
|
848 class link_handler(node_handler):
|
|
849 """ A nodehandler for URLs. Will open URL in a wxHTMLFrame
|
|
850 <nodehandler name='?' module='forms' class='link_handler' >
|
|
851 <link href='http//??.??' />
|
|
852 </nodehandler >
|
|
853 """
|
|
854 def __init__(self,xml,tree_node):
|
|
855 node_handler.__init__(self,xml,tree_node)
|
|
856 self.link = self.xml[0]
|
|
857
|
|
858 def on_use(self,evt):
|
|
859 href = self.link.get("href")
|
|
860 wb = webbrowser.get()
|
|
861 wb.open(href)
|
|
862
|
|
863 def get_design_panel(self,parent):
|
|
864 return link_edit_panel(parent,self)
|
|
865
|
|
866 def get_use_panel(self,parent):
|
|
867 return link_panel(parent,self)
|
|
868
|
|
869 def tohtml(self):
|
|
870 href = self.link.get("href")
|
|
871 title = self.xml.get("name")
|
|
872 return "<a href='"+href+"' >"+title+"</a>"
|
|
873
|
|
874 class link_panel(wx.StaticText):
|
|
875 def __init__(self,parent,handler):
|
|
876 self.handler = handler
|
|
877 label = handler.xml.get('name')
|
|
878 wx.StaticText.__init__(self,parent,-1,label)
|
|
879 self.SetForegroundColour(wx.BLUE)
|
|
880 self.Bind(wx.EVT_LEFT_DOWN, self.handler.on_use)
|
|
881
|
|
882 P_URL = wx.NewId()
|
|
883
|
|
884 class link_edit_panel(wx.Panel):
|
|
885 def __init__(self, parent, handler):
|
|
886 wx.Panel.__init__(self, parent, -1)
|
|
887 self.handler = handler
|
|
888 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Link Properties"), wx.VERTICAL)
|
|
889
|
|
890 self.text = {}
|
|
891 self.text[P_TITLE] = wx.TextCtrl(self, P_TITLE, handler.xml.get('name'))
|
|
892 self.text[P_URL] = wx.TextCtrl(self, P_URL, handler.link.get('href'))
|
|
893
|
|
894 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND)
|
|
895 sizer.Add(self.text[P_TITLE], 0, wx.EXPAND)
|
|
896 sizer.Add(wx.Size(10,10))
|
|
897 sizer.Add(wx.StaticText(self, -1, "URL:"), 0, wx.EXPAND)
|
|
898 sizer.Add(self.text[P_URL], 0, wx.EXPAND)
|
|
899 self.SetSizer(sizer)
|
|
900 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE)
|
|
901 self.Bind(wx.EVT_TEXT, self.on_text, id=P_URL)
|
|
902
|
|
903 def on_text(self,evt):
|
|
904 id = evt.GetId()
|
|
905 txt = self.text[id].GetValue()
|
|
906 if not len(txt): return
|
|
907 if id == P_TITLE:
|
|
908 self.handler.xml.set('name',txt)
|
|
909 self.handler.rename(txt)
|
|
910 elif id == P_URL: self.handler.link.set('href',txt)
|
|
911
|
|
912 ##########################
|
|
913 ## webimg node handler
|
|
914 ##########################
|
|
915 class webimg_handler(node_handler):
|
|
916 """ A nodehandler for URLs. Will open URL in a wxHTMLFrame
|
|
917 <nodehandler name='?' module='forms' class='webimg_handler' >
|
|
918 <link href='http//??.??' />
|
|
919 </nodehandler >
|
|
920 """
|
|
921 def __init__(self,xml,tree_node):
|
|
922 node_handler.__init__(self,xml,tree_node)
|
|
923 self.link = self.xml[0]
|
|
924
|
|
925 def get_design_panel(self,parent):
|
|
926 return link_edit_panel(parent,self)
|
|
927
|
|
928 def get_use_panel(self,parent):
|
|
929 img = img_helper().load_url(self.link.get("href"))
|
|
930 if not img is None: return wx.StaticBitmap(parent,-1,img,size= wx.Size(img.GetWidth(),img.GetHeight()))
|
|
931 return wx.EmptyBitmap(1, 1)
|
|
932
|
|
933 def tohtml(self):
|
|
934 href = self.link.get("href")
|
|
935 title = self.xml.get("name")
|
|
936 return "<img src='"+href+"' alt="+title+" >"
|