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: rpg_grid.py
|
|
21 # Author: Chris Davis
|
|
22 # Maintainer:
|
|
23 # Version:
|
184
|
24 # $Id: rpg_grid.py,v Traipse 'Ornery-Orc' prof.ebral Exp $
|
156
|
25 #
|
|
26 # Description: The file contains code for the grid nodehanlers
|
|
27 #
|
|
28
|
184
|
29 __version__ = "$Id: rpg_grid.py,v Traipse 'Ornery-Orc' prof.ebral Exp $"
|
156
|
30
|
|
31 from core import *
|
140
|
32 from forms import *
|
189
|
33 from orpg.tools.orpg_log import debug
|
191
|
34 from orpg.tools.InterParse import Parse
|
156
|
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 />'
|
191
|
92 s = Parse.NodeMap(text, self.xml)
|
|
93 s = Parse.Normalize(s)
|
189
|
94 try: text = str(eval(s))
|
|
95 except: text = s
|
156
|
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):
|
189
|
102 return rpg_grid_edit_panel(parent, self)
|
156
|
103
|
|
104 def get_use_panel(self,parent):
|
189
|
105 return rpg_grid_panel(parent, self)
|
156
|
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 """
|
189
|
203 #self.startValue = grid.GetTable().GetValue(row, col)
|
|
204 self.startValue = grid.get_value(row, col)
|
156
|
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())
|
152
|
211
|
156
|
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"""
|
189
|
274 def __init__(self, parent, handler, mode):
|
156
|
275 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
|
|
276 self.parent = parent
|
|
277 self.handler = handler
|
189
|
278 self.mode = mode
|
156
|
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()
|
189
|
312 for i in range(0,len(self.rows)): self.refresh_row(i)
|
156
|
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
|
189
|
322 def refresh_row(self, rowi):
|
156
|
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
|
189
|
329 if self.mode == 0:
|
191
|
330 s = Parse.NodeMap(text, self.handler.xml)
|
|
331 s = Parse.NodeParent(s, self.handler.xml.get('map'))
|
189
|
332 try: text = str(eval(s))
|
|
333 except: text = s
|
156
|
334 self.SetCellValue(rowi,i,text)
|
|
335
|
|
336 def add_row(self,evt=None):
|
|
337 cols = self.GetNumberCols()
|
|
338 row = Element('row')
|
|
339 for i in range(0,cols):
|
|
340 cell = Element('cell')
|
|
341 cell.text = ''
|
|
342 row.append(cell)
|
|
343 self.handler.grid.append(row)
|
|
344 self.AppendRows(1)
|
|
345 self.rows = self.handler.grid.findall('row')
|
|
346 self.handler.refresh_rows()
|
|
347
|
|
348 def add_col(self,evt=None):
|
|
349 for r in self.rows:
|
|
350 cell = Element('cell')
|
|
351 cell.text = ''
|
|
352 r.append(cell)
|
|
353 self.AppendCols(1)
|
|
354 self.set_col_widths()
|
|
355
|
|
356 def del_row(self,evt=None):
|
|
357 num = self.GetNumberRows()
|
|
358 if num == 1: return
|
|
359 self.handler.grid.remove(self.handler.grid[num-1])# always remove last row -- nasty
|
|
360 self.DeleteRows(num-1,1)
|
|
361 self.rows = self.handler.grid.findall('row')
|
|
362 self.handler.refresh_rows()
|
|
363
|
|
364 def del_col(self,evt=None):
|
|
365 num = self.GetNumberCols()
|
|
366 if num == 1: return
|
|
367 for r in self.rows:
|
|
368 cells = r.findall('cell')
|
|
369 r.remove(r[num-1]) # always remove the last column -- nasty
|
|
370 self.DeleteCols(num-1,1)
|
|
371 self.set_col_widths()
|
|
372
|
189
|
373 def get_value(self, row, col):
|
|
374 cells = self.rows[row].findall('cell')
|
|
375 return cells[col].text
|
|
376
|
156
|
377
|
|
378 G_TITLE = wx.NewId()
|
|
379 GRID_BOR = wx.NewId()
|
|
380 class rpg_grid_panel(wx.Panel):
|
|
381 def __init__(self, parent, handler):
|
|
382 wx.Panel.__init__(self, parent, -1)
|
|
383 self.handler = handler
|
189
|
384 self.grid = rpg_grid(self, handler, mode=0)
|
156
|
385 label = handler.xml.get('name')
|
|
386 self.main_sizer = wx.BoxSizer(wx.VERTICAL)
|
|
387 self.main_sizer.Add(wx.StaticText(self, -1, label+": "), 0, wx.EXPAND)
|
|
388 self.main_sizer.Add(self.grid,1,wx.EXPAND)
|
|
389 self.SetSizer(self.main_sizer)
|
|
390 self.SetAutoLayout(True)
|
|
391 self.Fit()
|
|
392 parent.SetSize(self.GetBestSize())
|
|
393
|
|
394 G_AUTO_SIZE = wx.NewId()
|
|
395 G_ADD_ROW = wx.NewId()
|
|
396 G_ADD_COL = wx.NewId()
|
|
397 G_DEL_ROW = wx.NewId()
|
|
398 G_DEL_COL = wx.NewId()
|
183
|
399 G_BUT_REF = wx.NewId()
|
156
|
400
|
|
401 class rpg_grid_edit_panel(wx.Panel):
|
|
402 def __init__(self, parent, handler):
|
|
403 wx.Panel.__init__(self, parent, -1)
|
|
404 self.handler = handler
|
183
|
405 self.parent = parent
|
189
|
406 self.grid = rpg_grid(self,handler, mode=1)
|
140
|
407 self.main_sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Grid"), wx.VERTICAL)
|
|
408
|
156
|
409 self.title = wx.TextCtrl(self, G_TITLE, handler.xml.get('name'))
|
|
410
|
|
411 radio_b = wx.RadioBox(self, GRID_BOR, "Border (HTML)", choices=["no","yes"])
|
140
|
412 border = handler.grid.get("border")
|
156
|
413 radio_b.SetSelection(int(border))
|
|
414
|
|
415 self.auto_size = wx.CheckBox(self, G_AUTO_SIZE, "Auto Size")
|
|
416 if handler.is_autosized() == '1': self.auto_size.SetValue(True)
|
|
417 else: self.auto_size.SetValue(False)
|
|
418
|
140
|
419 sizer = wx.BoxSizer(wx.HORIZONTAL)
|
156
|
420 sizer.Add(wx.Button(self, G_ADD_ROW, "Add Row"), 1, wx.EXPAND)
|
|
421 sizer.Add(wx.Size(10,10))
|
|
422 sizer.Add(wx.Button(self, G_DEL_ROW, "Remove Row"), 1, wx.EXPAND)
|
|
423 sizer.Add(wx.Size(10,10))
|
|
424 sizer.Add(wx.Button(self, G_ADD_COL, "Add Column"), 1, wx.EXPAND)
|
|
425 sizer.Add(wx.Size(10,10))
|
140
|
426 sizer.Add(wx.Button(self, G_DEL_COL, "Remove Column"), 1, wx.EXPAND)
|
183
|
427 sizer.Add(wx.Size(10,10))
|
|
428 sizer.Add(wx.Button(self, G_BUT_REF, "Reference"), 1)
|
156
|
429
|
|
430 self.main_sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND)
|
|
431 self.main_sizer.Add(self.title, 0, wx.EXPAND)
|
|
432 self.main_sizer.Add(radio_b, 0, 0)
|
|
433 self.main_sizer.Add(self.auto_size, 0, 0)
|
|
434 self.main_sizer.Add(self.grid,1,wx.EXPAND)
|
140
|
435 self.main_sizer.Add(sizer,0,wx.EXPAND)
|
156
|
436
|
140
|
437 self.SetSizer(self.main_sizer)
|
156
|
438 self.SetAutoLayout(True)
|
|
439 self.Fit()
|
|
440
|
|
441 self.Bind(wx.EVT_TEXT, self.on_text, id=G_TITLE)
|
|
442 self.Bind(wx.EVT_BUTTON, self.grid.add_row, id=G_ADD_ROW)
|
|
443 self.Bind(wx.EVT_BUTTON, self.grid.del_row, id=G_DEL_ROW)
|
|
444 self.Bind(wx.EVT_BUTTON, self.grid.add_col, id=G_ADD_COL)
|
|
445 self.Bind(wx.EVT_BUTTON, self.grid.del_col, id=G_DEL_COL)
|
|
446 self.Bind(wx.EVT_RADIOBOX, self.on_radio_box, id=GRID_BOR)
|
|
447 self.Bind(wx.EVT_CHECKBOX, self.on_auto_size, id=G_AUTO_SIZE)
|
183
|
448 self.Bind(wx.EVT_BUTTON, self.on_reference, id=G_BUT_REF)
|
|
449 self.parent.Bind(wx.EVT_CLOSE, self.tree_failsafe)
|
|
450
|
|
451 ## EZ_Tree Core TaS - Prof.Ebral ##
|
|
452 def on_reference(self, evt, car=None):
|
|
453 self.do_tree = wx.Frame(self, -1, 'EZ Tree')
|
|
454 self.ez_tree = orpg.gametree.gametree
|
|
455 self.temp_wnd = self.ez_tree.game_tree(self.do_tree, self.ez_tree.EZ_REF)
|
|
456 self.temp_wnd.Bind(wx.EVT_LEFT_DCLICK, self.on_ldclick) ## Remove for Alpha ##
|
|
457 component.get('tree_fs').save_tree(settings.get("gametree"))
|
|
458 self.temp_wnd.load_tree(settings.get("gametree"))
|
|
459 self.do_tree.Show()
|
|
460
|
|
461 def tree_failsafe(self, evt):
|
|
462 self.parent.Destroy()
|
|
463 component.add('tree', component.get('tree_fs')) ## Backup
|
|
464
|
|
465 def get_grid_ref(self, obj, complete):
|
|
466 self.temp_wnd.Freeze()
|
|
467 self.grid_ref = complete
|
|
468 self.mini_grid = wx.Frame(self, -1, 'EZ Tree Mini Grid')
|
|
469 self.temp_grid = obj.get_use_panel(self.mini_grid)
|
|
470 self.temp_grid.grid.Bind(wx.grid.EVT_GRID_CELL_LEFT_DCLICK, self.on_grid_ldclick)
|
|
471 self.mini_grid.Show()
|
|
472
|
|
473 def on_grid_ldclick(self, evt):
|
|
474 complete = self.grid_ref
|
|
475 row = str(evt.GetRow()+1)
|
|
476 col = str(evt.GetCol()+1)
|
|
477 complete = complete[:len(complete)-2] + '::'+'('+row+','+col+')'+complete[len(complete)-2:]
|
|
478 col = self.grid.GetGridCursorCol()
|
|
479 row = self.grid.GetGridCursorRow()
|
189
|
480 temp_value = self.grid.GetCellValue(row, col)
|
|
481 complete = temp_value + complete
|
183
|
482 self.grid.SetCellValue(row, col, complete)
|
|
483 cells = self.grid.rows[row].findall('cell')
|
|
484 cells[col].text = complete
|
|
485 self.mini_grid.Destroy()
|
|
486
|
|
487 def on_ldclick(self, evt):
|
|
488 self.rename_flag = 0
|
|
489 pt = evt.GetPosition()
|
|
490 (item, flag) = self.temp_wnd.HitTest(pt)
|
|
491 if item.IsOk():
|
|
492 obj = self.temp_wnd.GetPyData(item)
|
|
493 self.temp_wnd.SelectItem(item)
|
|
494 start = self.handler.xml.get('map').split('::')
|
|
495 end = obj.xml.get('map').split('::')
|
|
496 if obj.xml.get('class') not in ['rpg_grid_handler', 'textctrl_handler']: do = 'None'
|
|
497 elif end[0] == '' or start[0] != end[0]: do = 'Root'
|
|
498 elif start == end: do = 'Child'
|
|
499 elif start != end: do = 'Parent'
|
|
500 if do == 'Root':
|
|
501 complete = "!@"
|
|
502 for e in end:
|
|
503 if e != '': complete += e +'::'
|
|
504 complete = complete + obj.xml.get('name') + '@!'
|
|
505 elif do == 'Parent':
|
|
506 while start[0] == end[0]:
|
|
507 del end[0], start[0]
|
|
508 if len(start) == 0 or len(end) == 0: break
|
|
509 complete = "!#"
|
|
510 for e in end: complete += e +'::'
|
|
511 complete = complete + obj.xml.get('name') + '#!'
|
|
512 elif do == 'Child':
|
|
513 while start[0] == end[0]:
|
|
514 del end[0], start[0]
|
|
515 if len(start) == 0 or len(end) == 0: break
|
|
516 complete = "!!"
|
|
517 for e in end: complete += e +'::'
|
|
518 complete = complete + obj.xml.get('name') + '!!'
|
|
519 if do != 'None':
|
|
520 if obj.xml.get('class') == 'rpg_grid_handler':
|
|
521 self.get_grid_ref(obj, complete)
|
|
522 else:
|
|
523 col = self.grid.GetGridCursorCol()
|
|
524 row = self.grid.GetGridCursorRow()
|
189
|
525 temp_value = self.grid.GetCellValue(row, col)
|
|
526 complete = temp_value + complete
|
183
|
527 self.grid.SetCellValue(row, col, complete)
|
|
528 cells = self.grid.rows[row].findall('cell')
|
|
529 cells[col].text = complete
|
|
530 self.do_tree.Destroy()
|
|
531 if do == 'None':
|
|
532 wx.MessageBox('Invalid Reference', 'Error')
|
|
533 ##### #####
|
156
|
534
|
|
535 def on_auto_size(self,evt):
|
|
536 self.handler.set_autosize(bool2int(evt.Checked()))
|
|
537
|
|
538 def on_radio_box(self,evt):
|
|
539 id = evt.GetId()
|
|
540 index = evt.GetInt()
|
|
541 if id == GRID_BOR:
|
|
542 self.handler.grid.set("border",str(index))
|
|
543
|
|
544 def on_text(self,evt):
|
|
545 txt = self.title.GetValue()
|
|
546 if txt != "":
|
|
547 self.handler.xml.set('name',txt)
|
|
548 self.handler.rename(txt)
|
189
|
549
|
|
550 def refresh_row(self,rowi):
|
|
551 cells = self.rows[rowi].findall('cell')
|
|
552 for i in range(0,len(cells)):
|
|
553 text = cells[i].text
|
|
554 #s = component.get('chat').ParseMap(s, self.handler.xml)
|
|
555 #try: text = str(eval(s))
|
|
556 #except: text = s
|
|
557 if text == None or text == '':
|
|
558 text = ''
|
|
559 cells[i].text = text
|
|
560 self.SetCellValue(rowi,i,text)
|