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: rpg_grid.py
|
|
21 # Author: Chris Davis
|
|
22 # Maintainer:
|
|
23 # Version:
|
|
24 # $Id: rpg_grid.py,v Traipse 'Ornery-Orc' prof.ebral Exp $
|
|
25 #
|
|
26 # Description: The file contains code for the grid nodehanlers
|
|
27 #
|
|
28
|
|
29 __version__ = "$Id: rpg_grid.py,v Traipse 'Ornery-Orc' prof.ebral Exp $"
|
|
30
|
|
31 from core import *
|
18
|
32 from forms import *
|
28
|
33 from orpg.tools.orpg_log import debug
|
|
34 from orpg.tools.InterParse import Parse
|
|
35
|
|
36 class rpg_grid_handler(node_handler):
|
|
37 """ Node handler for rpg grid tool
|
|
38 <nodehandler module='rpg_grid' class='rpg_grid_handler' name='sample'>
|
|
39 <grid border='' autosize='1' >
|
|
40 <row>
|
|
41 <cell size='?'></cell>
|
|
42 <cell></cell>
|
|
43 </row>
|
|
44 <row>
|
|
45 <cell></cell>
|
|
46 <cell></cell>
|
|
47 </row>
|
|
48 </grid>
|
|
49 <macros>
|
|
50 <macro name=''/>
|
|
51 </macros>
|
|
52 </nodehandler>
|
|
53 """
|
|
54 def __init__(self,xml,tree_node):
|
|
55 node_handler.__init__(self,xml,tree_node)
|
|
56 self.grid = self.xml.find('grid')
|
|
57 if self.grid.get("border") == "": self.grid.set("border","1")
|
|
58 if self.grid.get("autosize") == "": self.grid.set("autosize","1")
|
|
59 self.macros = self.xml.find('macros')
|
|
60 self.myeditor = None
|
|
61 self.refresh_rows()
|
|
62
|
|
63 def refresh_die_macros(self):
|
|
64 pass
|
|
65
|
|
66 def refresh_rows(self):
|
|
67 self.rows = {}
|
|
68 tree = self.tree
|
|
69 icons = self.tree.icons
|
|
70 tree.CollapseAndReset(self.mytree_node)
|
|
71 for row in self.grid.findall('row'):
|
|
72 first_cell = row.find('cell')
|
|
73 name = first_cell.text
|
|
74 if name == None or name == '': name = "Row"
|
|
75 new_tree_node = tree.AppendItem(self.mytree_node,name,icons['gear'],icons['gear'])
|
|
76 handler = grid_row_handler(row,new_tree_node,self)
|
|
77 tree.SetPyData(new_tree_node,handler)
|
|
78
|
|
79 def tohtml(self):
|
|
80 border = self.grid.get("border")
|
|
81 name = self.xml.get('name')
|
|
82 rows = self.grid.findall('row')
|
|
83 colspan = str(len(rows[0].findall('cell')))
|
|
84 html_str = "<table border=\""+border+"\" align=center><tr bgcolor=\""+TH_BG+"\" ><th colspan="+colspan+">"+name+"</th></tr>"
|
|
85 for r in rows:
|
|
86 cells = r.findall('cell')
|
|
87 html_str += "<tr>"
|
|
88 for c in cells:
|
|
89 html_str += "<td >"
|
|
90 text = c.text
|
|
91 if text == None or text == '': text = '<br />'
|
31
|
92 s = Parse.ParseLogic(text, self.xml)
|
28
|
93 s = Parse.Normalize(s)
|
|
94 try: text = str(eval(s))
|
|
95 except: text = s
|
|
96 html_str += text + "</td>"
|
|
97 html_str += "</tr>"
|
|
98 html_str += "</table>"
|
|
99 return html_str
|
|
100
|
|
101 def get_design_panel(self,parent):
|
|
102 return rpg_grid_edit_panel(parent, self)
|
|
103
|
|
104 def get_use_panel(self,parent):
|
|
105 return rpg_grid_panel(parent, self)
|
|
106
|
|
107 def get_size_constraint(self):
|
|
108 return 1
|
|
109
|
|
110 def is_autosized(self):
|
|
111 return self.grid.get("autosize")
|
|
112
|
|
113 def set_autosize(self,autosize=1):
|
|
114 self.grid.set("autosize",str(autosize))
|
|
115
|
|
116 class grid_row_handler(node_handler):
|
|
117 """ Node Handler grid row.
|
|
118 """
|
|
119 def __init__(self,xml,tree_node,parent):
|
|
120 node_handler.__init__(self,xml,tree_node)
|
|
121 self.drag = False
|
|
122
|
|
123 def on_drop(self,evt):
|
|
124 pass
|
|
125
|
|
126 def can_clone(self):
|
|
127 return 0;
|
|
128
|
|
129 def tohtml(self):
|
|
130 cells = self.xml.findall('cell')
|
|
131 html_str = "<table border=1 align=center><tr >"
|
|
132 for c in cells: # should loop over rows first, then cells
|
|
133 html_str += "<td >"
|
|
134 text = c.text
|
|
135 if text == '' or text is None: text = '<br />'
|
|
136 html_str += text + "</td>"
|
|
137 html_str += "</tr>"
|
|
138 html_str += "</table>"
|
|
139 return html_str
|
|
140
|
|
141 def get_value(self):
|
|
142 cells = self.xml.findall('cell')
|
|
143 if len(cells) == 2: return getText(cells[1])
|
|
144 else: return None
|
|
145
|
|
146 def set_value(self, new_value):
|
|
147 cells = self.xml.findall('cell')
|
|
148 if len(cells) == 2:
|
|
149 cells[1].text = new_value
|
|
150
|
|
151 class MyCellEditor(wx.grid.PyGridCellEditor):
|
|
152 """
|
|
153 This is a sample GridCellEditor that shows you how to make your own custom
|
|
154 grid editors. All the methods that can be overridden are show here. The
|
|
155 ones that must be overridden are marked with "*Must Override*" in the
|
|
156 docstring.
|
|
157
|
|
158 Notice that in order to call the base class version of these special
|
|
159 methods we use the method name preceded by "base_". This is because these
|
|
160 methods are "virtual" in C++ so if we try to call wxGridCellEditor.Create
|
|
161 for example, then when the wxPython extension module tries to call
|
|
162 ptr->Create(...) then it actually calls the derived class version which
|
|
163 looks up the method in this class and calls it, causing a recursion loop.
|
|
164 If you don't understand any of this, don't worry, just call the "base_"
|
|
165 version instead.
|
|
166
|
|
167 ----------------------------------------------------------------------------
|
|
168 This class is copied from the wxPython examples directory and was written by
|
|
169 Robin Dunn.
|
|
170
|
|
171 I have pasted it directly in and removed all references to "log"
|
|
172
|
|
173 -- Andrew
|
|
174
|
|
175 """
|
|
176 def __init__(self):
|
|
177 wx.grid.PyGridCellEditor.__init__(self)
|
|
178
|
|
179 def Create(self, parent, id, evtHandler):
|
|
180 """
|
|
181 Called to create the control, which must derive from wxControl.
|
|
182 *Must Override*
|
|
183 """
|
|
184 self._tc = wx.TextCtrl(parent, id, "", style=wx.TE_PROCESS_ENTER | wx.TE_PROCESS_TAB)
|
|
185 self._tc.SetInsertionPoint(0)
|
|
186 self.SetControl(self._tc)
|
|
187 if evtHandler: self._tc.PushEventHandler(evtHandler)
|
|
188
|
|
189 def SetSize(self, rect):
|
|
190 """
|
|
191 Called to position/size the edit control within the cell rectangle.
|
|
192 If you don't fill the cell (the rect) then be sure to override
|
|
193 PaintBackground and do something meaningful there.
|
|
194 """
|
|
195 self._tc.SetDimensions(rect.x+1, rect.y+1, rect.width+2, rect.height+2)
|
|
196
|
|
197 def BeginEdit(self, row, col, grid):
|
|
198 """
|
|
199 Fetch the value from the table and prepare the edit control
|
|
200 to begin editing. Set the focus to the edit control.
|
|
201 *Must Override*
|
|
202 """
|
|
203 #self.startValue = grid.GetTable().GetValue(row, col)
|
|
204 self.startValue = grid.get_value(row, col)
|
|
205 self._tc.SetValue(self.startValue)
|
|
206 self._tc.SetInsertionPointEnd()
|
|
207 self._tc.SetFocus()
|
|
208
|
|
209 # For this example, select the text
|
|
210 self._tc.SetSelection(0, self._tc.GetLastPosition())
|
|
211
|
|
212 def EndEdit(self, row, col, grid):
|
|
213 """
|
|
214 Complete the editing of the current cell. Returns True if the value
|
|
215 has changed. If necessary, the control may be destroyed.
|
|
216 *Must Override*
|
|
217 """
|
|
218 changed = False
|
|
219 val = self._tc.GetValue()
|
|
220 if val != self.startValue:
|
|
221 changed = True
|
|
222 grid.GetTable().SetValue(row, col, val) # update the table
|
|
223 self.startValue = ''
|
|
224 self._tc.SetValue('')
|
|
225 return changed
|
|
226
|
|
227 def Reset(self):
|
|
228 """
|
|
229 Reset the value in the control back to its starting value.
|
|
230 *Must Override*
|
|
231 """
|
|
232 self._tc.SetValue(self.startValue)
|
|
233 self._tc.SetInsertionPointEnd()
|
|
234
|
|
235 def IsAcceptedKey(self, evt):
|
|
236 """
|
|
237 Return True to allow the given key to start editing: the base class
|
|
238 version only checks that the event has no modifiers. F2 is special
|
|
239 and will always start the editor.
|
|
240 """
|
|
241 return (not (evt.ControlDown() or evt.AltDown()) and
|
|
242 evt.GetKeyCode() != wx.WXK_SHIFT)
|
|
243
|
|
244 def StartingKey(self, evt):
|
|
245 """
|
|
246 If the editor is enabled by pressing keys on the grid, this will be
|
|
247 called to let the editor do something about that first key if desired.
|
|
248 """
|
|
249 key = evt.GetKeyCode()
|
|
250 ch = None
|
|
251 if key in [wx.WXK_NUMPAD0, wx.WXK_NUMPAD1, wx.WXK_NUMPAD2, wx.WXK_NUMPAD3, wx.WXK_NUMPAD4,
|
|
252 wx.WXK_NUMPAD5, wx.WXK_NUMPAD6, wx.WXK_NUMPAD7, wx.WXK_NUMPAD8, wx.WXK_NUMPAD9]:
|
|
253 ch = ch = chr(ord('0') + key - wx.WXK_NUMPAD0)
|
|
254 elif key < 256 and key >= 0 and chr(key) in string.printable:
|
|
255 ch = chr(key)
|
|
256 if not evt.ShiftDown(): ch = string.lower(ch)
|
|
257 if ch is not None: self._tc.AppendText(ch)
|
|
258 else: evt.Skip()
|
|
259
|
|
260 def Destroy(self):
|
|
261 """final cleanup"""
|
|
262 self.base_Destroy()
|
|
263
|
|
264 def Clone(self):
|
|
265 """
|
|
266 Create a new object which is the copy of this one
|
|
267 *Must Override*
|
|
268 """
|
|
269 return MyCellEditor()
|
|
270
|
|
271
|
|
272 class rpg_grid(wx.grid.Grid):
|
|
273 """grid for attacks"""
|
|
274 def __init__(self, parent, handler, mode):
|
|
275 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
|
|
276 self.parent = parent
|
|
277 self.handler = handler
|
|
278 self.mode = mode
|
|
279 self.RegisterDataType(wx.grid.GRID_VALUE_STRING, wx.grid.GridCellStringRenderer(),MyCellEditor())
|
|
280
|
|
281 self.rows = handler.grid.findall('row')
|
|
282 rows = len(self.rows)
|
|
283 cols = len(self.rows[0].findall('cell'))
|
|
284 self.CreateGrid(rows,cols)
|
|
285 self.SetRowLabelSize(0)
|
|
286 self.SetColLabelSize(0)
|
|
287 self.set_col_widths()
|
|
288
|
|
289 for i in range(0,len(self.rows)): self.refresh_row(i)
|
|
290
|
|
291 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
|
|
292 self.Bind(wx.grid.EVT_GRID_COL_SIZE, self.on_col_size)
|
|
293 self.Bind(wx.grid.EVT_GRID_CELL_LEFT_DCLICK, self.on_leftdclick)
|
|
294
|
|
295 def on_leftdclick(self,evt):
|
|
296 if self.CanEnableCellControl(): self.EnableCellEditControl()
|
|
297
|
|
298 def on_col_size(self, evt):
|
|
299 col = evt.GetRowOrCol()
|
|
300 cells = self.rows[0].findall('cell')
|
|
301 size = self.GetColSize(col)
|
|
302 cells[col].set('size',str(size))
|
|
303 evt.Skip()
|
|
304
|
|
305 def on_cell_change(self,evt):
|
|
306 row = evt.GetRow()
|
|
307 col = evt.GetCol()
|
|
308 value = self.GetCellValue(row,col)
|
|
309 cells = self.rows[row].findall('cell')
|
|
310 cells[col].text = value
|
|
311 if col == 0: self.handler.refresh_rows()
|
|
312 for i in range(0,len(self.rows)): self.refresh_row(i)
|
|
313
|
|
314 def set_col_widths(self):
|
|
315 cells = self.rows[0].findall('cell')
|
|
316 for i in range(0,len(cells)):
|
|
317 try:
|
|
318 size = int(cells[i].get('size'))
|
|
319 self.SetColSize(i,size)
|
|
320 except: continue
|
|
321
|
|
322 def refresh_row(self, rowi):
|
|
323 cells = self.rows[rowi].findall('cell')
|
|
324 for i in range(0,len(cells)):
|
|
325 text = cells[i].text
|
|
326 if text == None or text == '':
|
|
327 text = ''
|
|
328 cells[i].text = text
|
|
329 if self.mode == 0:
|
31
|
330 s = Parse.ParseLogic(text, self.handler.xml)
|
28
|
331 try: text = str(eval(s))
|
|
332 except: text = s
|
|
333 self.SetCellValue(rowi,i,text)
|
|
334
|
|
335 def add_row(self,evt=None):
|
|
336 cols = self.GetNumberCols()
|
|
337 row = Element('row')
|
|
338 for i in range(0,cols):
|
|
339 cell = Element('cell')
|
|
340 cell.text = ''
|
|
341 row.append(cell)
|
|
342 self.handler.grid.append(row)
|
|
343 self.AppendRows(1)
|
|
344 self.rows = self.handler.grid.findall('row')
|
|
345 self.handler.refresh_rows()
|
|
346
|
|
347 def add_col(self,evt=None):
|
|
348 for r in self.rows:
|
|
349 cell = Element('cell')
|
|
350 cell.text = ''
|
|
351 r.append(cell)
|
|
352 self.AppendCols(1)
|
|
353 self.set_col_widths()
|
|
354
|
|
355 def del_row(self,evt=None):
|
|
356 num = self.GetNumberRows()
|
|
357 if num == 1: return
|
|
358 self.handler.grid.remove(self.handler.grid[num-1])# always remove last row -- nasty
|
|
359 self.DeleteRows(num-1,1)
|
|
360 self.rows = self.handler.grid.findall('row')
|
|
361 self.handler.refresh_rows()
|
|
362
|
|
363 def del_col(self,evt=None):
|
|
364 num = self.GetNumberCols()
|
|
365 if num == 1: return
|
|
366 for r in self.rows:
|
|
367 cells = r.findall('cell')
|
|
368 r.remove(r[num-1]) # always remove the last column -- nasty
|
|
369 self.DeleteCols(num-1,1)
|
|
370 self.set_col_widths()
|
|
371
|
|
372 def get_value(self, row, col):
|
|
373 cells = self.rows[row].findall('cell')
|
|
374 return cells[col].text
|
|
375
|
|
376
|
|
377 G_TITLE = wx.NewId()
|
|
378 GRID_BOR = wx.NewId()
|
|
379 class rpg_grid_panel(wx.Panel):
|
|
380 def __init__(self, parent, handler):
|
|
381 wx.Panel.__init__(self, parent, -1)
|
|
382 self.handler = handler
|
|
383 self.grid = rpg_grid(self, handler, mode=0)
|
|
384 label = handler.xml.get('name')
|
|
385 self.main_sizer = wx.BoxSizer(wx.VERTICAL)
|
|
386 self.main_sizer.Add(wx.StaticText(self, -1, label+": "), 0, wx.EXPAND)
|
|
387 self.main_sizer.Add(self.grid,1,wx.EXPAND)
|
|
388 self.SetSizer(self.main_sizer)
|
|
389 self.SetAutoLayout(True)
|
|
390 self.Fit()
|
|
391 parent.SetSize(self.GetBestSize())
|
|
392
|
|
393 G_AUTO_SIZE = wx.NewId()
|
|
394 G_ADD_ROW = wx.NewId()
|
|
395 G_ADD_COL = wx.NewId()
|
|
396 G_DEL_ROW = wx.NewId()
|
|
397 G_DEL_COL = wx.NewId()
|
|
398 G_BUT_REF = wx.NewId()
|
|
399
|
|
400 class rpg_grid_edit_panel(wx.Panel):
|
|
401 def __init__(self, parent, handler):
|
|
402 wx.Panel.__init__(self, parent, -1)
|
|
403 self.handler = handler
|
|
404 self.parent = parent
|
|
405 self.grid = rpg_grid(self,handler, mode=1)
|
|
406 self.main_sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Grid"), wx.VERTICAL)
|
|
407
|
|
408 self.title = wx.TextCtrl(self, G_TITLE, handler.xml.get('name'))
|
|
409
|
|
410 radio_b = wx.RadioBox(self, GRID_BOR, "Border (HTML)", choices=["no","yes"])
|
|
411 border = handler.grid.get("border")
|
|
412 radio_b.SetSelection(int(border))
|
|
413
|
|
414 self.auto_size = wx.CheckBox(self, G_AUTO_SIZE, "Auto Size")
|
|
415 if handler.is_autosized() == '1': self.auto_size.SetValue(True)
|
|
416 else: self.auto_size.SetValue(False)
|
|
417
|
|
418 sizer = wx.BoxSizer(wx.HORIZONTAL)
|
|
419 sizer.Add(wx.Button(self, G_ADD_ROW, "Add Row"), 1, wx.EXPAND)
|
|
420 sizer.Add(wx.Size(10,10))
|
|
421 sizer.Add(wx.Button(self, G_DEL_ROW, "Remove Row"), 1, wx.EXPAND)
|
|
422 sizer.Add(wx.Size(10,10))
|
|
423 sizer.Add(wx.Button(self, G_ADD_COL, "Add Column"), 1, wx.EXPAND)
|
|
424 sizer.Add(wx.Size(10,10))
|
|
425 sizer.Add(wx.Button(self, G_DEL_COL, "Remove Column"), 1, wx.EXPAND)
|
|
426 sizer.Add(wx.Size(10,10))
|
|
427 sizer.Add(wx.Button(self, G_BUT_REF, "Reference"), 1)
|
|
428
|
|
429 self.main_sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND)
|
|
430 self.main_sizer.Add(self.title, 0, wx.EXPAND)
|
|
431 self.main_sizer.Add(radio_b, 0, 0)
|
|
432 self.main_sizer.Add(self.auto_size, 0, 0)
|
|
433 self.main_sizer.Add(self.grid,1,wx.EXPAND)
|
|
434 self.main_sizer.Add(sizer,0,wx.EXPAND)
|
|
435
|
|
436 self.SetSizer(self.main_sizer)
|
|
437 self.SetAutoLayout(True)
|
|
438 self.Fit()
|
|
439
|
|
440 self.Bind(wx.EVT_TEXT, self.on_text, id=G_TITLE)
|
|
441 self.Bind(wx.EVT_BUTTON, self.grid.add_row, id=G_ADD_ROW)
|
|
442 self.Bind(wx.EVT_BUTTON, self.grid.del_row, id=G_DEL_ROW)
|
|
443 self.Bind(wx.EVT_BUTTON, self.grid.add_col, id=G_ADD_COL)
|
|
444 self.Bind(wx.EVT_BUTTON, self.grid.del_col, id=G_DEL_COL)
|
|
445 self.Bind(wx.EVT_RADIOBOX, self.on_radio_box, id=GRID_BOR)
|
|
446 self.Bind(wx.EVT_CHECKBOX, self.on_auto_size, id=G_AUTO_SIZE)
|
|
447 self.Bind(wx.EVT_BUTTON, self.on_reference, id=G_BUT_REF)
|
|
448 self.parent.Bind(wx.EVT_CLOSE, self.tree_failsafe)
|
|
449
|
|
450 ## EZ_Tree Core TaS - Prof.Ebral ##
|
|
451 def on_reference(self, evt, car=None):
|
|
452 self.do_tree = wx.Frame(self, -1, 'EZ Tree')
|
|
453 self.ez_tree = orpg.gametree.gametree
|
|
454 self.temp_wnd = self.ez_tree.game_tree(self.do_tree, self.ez_tree.EZ_REF)
|
|
455 self.temp_wnd.Bind(wx.EVT_LEFT_DCLICK, self.on_ldclick) ## Remove for Alpha ##
|
|
456 component.get('tree_fs').save_tree(settings.get("gametree"))
|
|
457 self.temp_wnd.load_tree(settings.get("gametree"))
|
|
458 self.do_tree.Show()
|
|
459
|
|
460 def tree_failsafe(self, evt):
|
|
461 self.parent.Destroy()
|
|
462 component.add('tree', component.get('tree_fs')) ## Backup
|
|
463
|
|
464 def get_grid_ref(self, obj, complete):
|
|
465 self.temp_wnd.Freeze()
|
|
466 self.grid_ref = complete
|
|
467 self.mini_grid = wx.Frame(self, -1, 'EZ Tree Mini Grid')
|
|
468 self.temp_grid = obj.get_use_panel(self.mini_grid)
|
|
469 self.temp_grid.grid.Bind(wx.grid.EVT_GRID_CELL_LEFT_DCLICK, self.on_grid_ldclick)
|
|
470 self.mini_grid.Show()
|
|
471
|
|
472 def on_grid_ldclick(self, evt):
|
|
473 complete = self.grid_ref
|
|
474 row = str(evt.GetRow()+1)
|
|
475 col = str(evt.GetCol()+1)
|
|
476 complete = complete[:len(complete)-2] + '::'+'('+row+','+col+')'+complete[len(complete)-2:]
|
|
477 col = self.grid.GetGridCursorCol()
|
|
478 row = self.grid.GetGridCursorRow()
|
|
479 temp_value = self.grid.GetCellValue(row, col)
|
|
480 complete = temp_value + complete
|
|
481 self.grid.SetCellValue(row, col, complete)
|
|
482 cells = self.grid.rows[row].findall('cell')
|
|
483 cells[col].text = complete
|
|
484 self.mini_grid.Destroy()
|
|
485
|
|
486 def on_ldclick(self, evt):
|
|
487 self.rename_flag = 0
|
|
488 pt = evt.GetPosition()
|
|
489 (item, flag) = self.temp_wnd.HitTest(pt)
|
|
490 if item.IsOk():
|
|
491 obj = self.temp_wnd.GetPyData(item)
|
|
492 self.temp_wnd.SelectItem(item)
|
|
493 start = self.handler.xml.get('map').split('::')
|
|
494 end = obj.xml.get('map').split('::')
|
|
495 if obj.xml.get('class') not in ['rpg_grid_handler', 'textctrl_handler']: do = 'None'
|
|
496 elif end[0] == '' or start[0] != end[0]: do = 'Root'
|
|
497 elif start == end: do = 'Child'
|
|
498 elif start != end: do = 'Parent'
|
|
499 if do == 'Root':
|
|
500 complete = "!@"
|
|
501 for e in end:
|
|
502 if e != '': complete += e +'::'
|
|
503 complete = complete + obj.xml.get('name') + '@!'
|
|
504 elif do == 'Parent':
|
|
505 while start[0] == end[0]:
|
|
506 del end[0], start[0]
|
|
507 if len(start) == 0 or len(end) == 0: break
|
|
508 complete = "!#"
|
|
509 for e in end: complete += e +'::'
|
|
510 complete = complete + obj.xml.get('name') + '#!'
|
|
511 elif do == 'Child':
|
|
512 while start[0] == end[0]:
|
|
513 del end[0], start[0]
|
|
514 if len(start) == 0 or len(end) == 0: break
|
|
515 complete = "!!"
|
|
516 for e in end: complete += e +'::'
|
|
517 complete = complete + obj.xml.get('name') + '!!'
|
|
518 if do != 'None':
|
|
519 if obj.xml.get('class') == 'rpg_grid_handler':
|
|
520 self.get_grid_ref(obj, complete)
|
|
521 else:
|
|
522 col = self.grid.GetGridCursorCol()
|
|
523 row = self.grid.GetGridCursorRow()
|
|
524 temp_value = self.grid.GetCellValue(row, col)
|
|
525 complete = temp_value + complete
|
|
526 self.grid.SetCellValue(row, col, complete)
|
|
527 cells = self.grid.rows[row].findall('cell')
|
|
528 cells[col].text = complete
|
|
529 self.do_tree.Destroy()
|
|
530 if do == 'None':
|
|
531 wx.MessageBox('Invalid Reference', 'Error')
|
|
532 ##### #####
|
|
533
|
|
534 def on_auto_size(self,evt):
|
|
535 self.handler.set_autosize(bool2int(evt.Checked()))
|
|
536
|
|
537 def on_radio_box(self,evt):
|
|
538 id = evt.GetId()
|
|
539 index = evt.GetInt()
|
|
540 if id == GRID_BOR:
|
|
541 self.handler.grid.set("border",str(index))
|
|
542
|
|
543 def on_text(self,evt):
|
|
544 txt = self.title.GetValue()
|
|
545 if txt != "":
|
36
|
546 #self.handler.xml.set('name',txt)
|
28
|
547 self.handler.rename(txt)
|
|
548
|
|
549 def refresh_row(self,rowi):
|
|
550 cells = self.rows[rowi].findall('cell')
|
|
551 for i in range(0,len(cells)):
|
|
552 text = cells[i].text
|
|
553 #s = component.get('chat').ParseMap(s, self.handler.xml)
|
|
554 #try: text = str(eval(s))
|
|
555 #except: text = s
|
|
556 if text == None or text == '':
|
|
557 text = ''
|
|
558 cells[i].text = text
|
|
559 self.SetCellValue(rowi,i,text)
|