comparison orpg/gametree/nodehandlers/rpg_grid.py @ 28:ff154cf3350c ornery-orc

Traipse 'OpenRPG' {100203-00} Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for developers to work on code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to the code. 'Ornery-Orc's main goal is to offer more advanced features and enhance the productivity of the user. Update Summary (Stable) New Features: New Bookmarks Feature New 'boot' command to remote admin New confirmation window for sent nodes Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG New Zoom Mouse plugin added New Images added to Plugin UI Switching to Element Tree New Map efficiency, from FlexiRPG New Status Bar to Update Manager New TrueDebug Class in orpg_log (See documentation for usage) New Portable Mercurial New Tip of the Day, from Core and community New Reference Syntax added for custom PC sheets New Child Reference for gametree New Parent Reference for gametree New Gametree Recursion method, mapping, context sensitivity, and effeciency.. New Features node with bonus nodes and Node Referencing help added New Dieroller structure from Core New DieRoller portability for odd Dice New 7th Sea die roller; ie [7k3] = [7d10.takeHighest(3).open(10)] New 'Mythos' System die roller added New vs. die roller method for WoD; ie [3v3] = [3d10.vs(3)]. Included for Mythos roller also New Warhammer FRPG Die Roller (Special thanks to Puu-san for the support) New EZ_Tree Reference system. Push a button, Traipse the tree, get a reference (Beta!) New Grids act more like Spreadsheets in Use mode, with Auto Calc Fixes: Fix to allow for portability to an OpenSUSE linux OS Fix to mplay_client for Fedora and OpenSUSE Fix to Text based Server Fix to Remote Admin Commands Fix to Pretty Print, from Core Fix to Splitter Nodes not being created Fix to massive amounts of images loading, from Core Fix to Map from gametree not showing to all clients Fix to gametree about menus Fix to Password Manager check on startup Fix to PC Sheets from tool nodes. They now use the tabber_panel Fix to Whiteboard ID to prevent random line or text deleting. Fixes to Server, Remote Server, and Server GUI Fix to Update Manager; cleaner clode for saved repositories Fixes made to Settings Panel and now reactive settings when Ok is pressed Fixes to Alternity roller's attack roll. Uses a simple Tuple instead of a Splice Fix to Use panel of Forms and Tabbers. Now longer enters design mode Fix made Image Fetching. New fetching image and new failed image Fix to whiteboard ID's to prevent non updated clients from ruining the fix. default_manifest.xml renamed to default_upmana.xml
author sirebral
date Wed, 03 Feb 2010 22:16:49 -0600
parents 51428d30c59e
children fc48380f0c9f
comparison
equal deleted inserted replaced
27:51428d30c59e 28:ff154cf3350c
19 # 19 #
20 # File: rpg_grid.py 20 # File: rpg_grid.py
21 # Author: Chris Davis 21 # Author: Chris Davis
22 # Maintainer: 22 # Maintainer:
23 # Version: 23 # Version:
24 # $Id: rpg_grid.py,v 1.20 2006/11/15 12:11:24 digitalxero Exp $ 24 # $Id: rpg_grid.py,v Traipse 'Ornery-Orc' prof.ebral Exp $
25 # 25 #
26 # Description: The file contains code for the grid nodehanlers 26 # Description: The file contains code for the grid nodehanlers
27 # 27 #
28 28
29 __version__ = "$Id: rpg_grid.py,v 1.20 2006/11/15 12:11:24 digitalxero Exp $" 29 __version__ = "$Id: rpg_grid.py,v Traipse 'Ornery-Orc' prof.ebral Exp $"
30 30
31 from core import * 31 from core import *
32 from forms import * 32 from forms import *
33 from orpg.minidom import Element, Text 33 from orpg.tools.orpg_log import debug
34 from orpg.tools.InterParse import Parse
34 35
35 class rpg_grid_handler(node_handler): 36 class rpg_grid_handler(node_handler):
36 """ Node handler for rpg grid tool 37 """ Node handler for rpg grid tool
37 <nodehandler module='rpg_grid' class='rpg_grid_handler' name='sample'> 38 <nodehandler module='rpg_grid' class='rpg_grid_handler' name='sample'>
38 <grid border='' autosize='1' > 39 <grid border='' autosize='1' >
48 <macros> 49 <macros>
49 <macro name=''/> 50 <macro name=''/>
50 </macros> 51 </macros>
51 </nodehandler> 52 </nodehandler>
52 """ 53 """
53 def __init__(self,xml_dom,tree_node): 54 def __init__(self,xml,tree_node):
54 node_handler.__init__(self,xml_dom,tree_node) 55 node_handler.__init__(self,xml,tree_node)
55 self.grid = self.master_dom.getElementsByTagName('grid')[0] 56 self.grid = self.xml.find('grid')
56 if self.grid.getAttribute("border") == "": 57 if self.grid.get("border") == "": self.grid.set("border","1")
57 self.grid.setAttribute("border","1") 58 if self.grid.get("autosize") == "": self.grid.set("autosize","1")
58 if self.grid.getAttribute("autosize") == "": 59 self.macros = self.xml.find('macros')
59 self.grid.setAttribute("autosize","1")
60 self.macros = self.master_dom.getElementsByTagName('macros')[0]
61 self.myeditor = None 60 self.myeditor = None
62 self.refresh_rows() 61 self.refresh_rows()
63 62
64 def refresh_die_macros(self): 63 def refresh_die_macros(self):
65 pass 64 pass
67 def refresh_rows(self): 66 def refresh_rows(self):
68 self.rows = {} 67 self.rows = {}
69 tree = self.tree 68 tree = self.tree
70 icons = self.tree.icons 69 icons = self.tree.icons
71 tree.CollapseAndReset(self.mytree_node) 70 tree.CollapseAndReset(self.mytree_node)
72 node_list = self.master_dom.getElementsByTagName('row') 71 for row in self.grid.findall('row'):
73 for n in node_list: 72 first_cell = row.find('cell')
74 cells = n.getElementsByTagName('cell') 73 name = first_cell.text
75 t_node = cells[0]._get_firstChild() 74 if name == None or name == '': name = "Row"
76 if t_node == None:
77 name = "Row"
78 else:
79 name = t_node._get_nodeValue()
80 if name == "":
81 name = "Row"
82 new_tree_node = tree.AppendItem(self.mytree_node,name,icons['gear'],icons['gear']) 75 new_tree_node = tree.AppendItem(self.mytree_node,name,icons['gear'],icons['gear'])
83 handler = grid_row_handler(n,new_tree_node,self) 76 handler = grid_row_handler(row,new_tree_node,self)
84 tree.SetPyData(new_tree_node,handler) 77 tree.SetPyData(new_tree_node,handler)
85 78
86
87 def tohtml(self): 79 def tohtml(self):
88 border = self.grid.getAttribute("border") 80 border = self.grid.get("border")
89 name = self.master_dom.getAttribute('name') 81 name = self.xml.get('name')
90 rows = self.grid.getElementsByTagName('row') 82 rows = self.grid.findall('row')
91 colspan = str(len(rows[0].getElementsByTagName('cell'))) 83 colspan = str(len(rows[0].findall('cell')))
92 html_str = "<table border=\""+border+"\" align=center><tr bgcolor=\""+TH_BG+"\" ><th colspan="+colspan+">"+name+"</th></tr>" 84 html_str = "<table border=\""+border+"\" align=center><tr bgcolor=\""+TH_BG+"\" ><th colspan="+colspan+">"+name+"</th></tr>"
93 for r in rows: 85 for r in rows:
94 cells = r.getElementsByTagName('cell') 86 cells = r.findall('cell')
95 html_str += "<tr>" 87 html_str += "<tr>"
96 for c in cells: 88 for c in cells:
97 #html_str += "<td width='"+c.getAttribute('size')+"' >" bug here
98 html_str += "<td >" 89 html_str += "<td >"
99 t_node = c._get_firstChild() 90 text = c.text
100 if t_node == None: 91 if text == None or text == '': text = '<br />'
101 html_str += "<br /></td>" 92 s = Parse.NodeMap(text, self.xml)
102 else: 93 s = Parse.Normalize(s)
103 html_str += t_node._get_nodeValue() + "</td>" 94 try: text = str(eval(s))
95 except: text = s
96 html_str += text + "</td>"
104 html_str += "</tr>" 97 html_str += "</tr>"
105 html_str += "</table>" 98 html_str += "</table>"
106 return html_str 99 return html_str
107 100
108 def get_design_panel(self,parent): 101 def get_design_panel(self,parent):
109 return rpg_grid_edit_panel(parent,self) 102 return rpg_grid_edit_panel(parent, self)
110 103
111 def get_use_panel(self,parent): 104 def get_use_panel(self,parent):
112 return rpg_grid_panel(parent,self) 105 return rpg_grid_panel(parent, self)
113 106
114 def get_size_constraint(self): 107 def get_size_constraint(self):
115 return 1 108 return 1
116 109
117 def is_autosized(self): 110 def is_autosized(self):
118 return self.grid.getAttribute("autosize") 111 return self.grid.get("autosize")
119 112
120 def set_autosize(self,autosize=1): 113 def set_autosize(self,autosize=1):
121 self.grid.setAttribute("autosize",str(autosize)) 114 self.grid.set("autosize",str(autosize))
122 115
123 class grid_row_handler(node_handler): 116 class grid_row_handler(node_handler):
124 """ Node Handler grid row. 117 """ Node Handler grid row.
125 """ 118 """
126 def __init__(self,xml_dom,tree_node,parent): 119 def __init__(self,xml,tree_node,parent):
127 node_handler.__init__(self,xml_dom,tree_node) 120 node_handler.__init__(self,xml,tree_node)
128 self.drag = False 121 self.drag = False
129 122
130 def on_drop(self,evt): 123 def on_drop(self,evt):
131 pass 124 pass
132 125
133 def can_clone(self): 126 def can_clone(self):
134 return 0; 127 return 0;
135 128
136 def tohtml(self): 129 def tohtml(self):
137 cells = self.master_dom.getElementsByTagName('cell') 130 cells = self.xml.findall('cell')
138 html_str = "<table border=1 align=center><tr >" 131 html_str = "<table border=1 align=center><tr >"
139 for c in cells: 132 for c in cells: # should loop over rows first, then cells
140 html_str += "<td >" 133 html_str += "<td >"
141 t_node = c._get_firstChild() 134 text = c.text
142 if t_node == None: 135 if text == '' or text is None: text = '<br />'
143 html_str += "<br /></td>" 136 html_str += text + "</td>"
144 else:
145 html_str += t_node._get_nodeValue() + "</td>"
146 html_str += "</tr>" 137 html_str += "</tr>"
147 html_str += "</table>" 138 html_str += "</table>"
148 return html_str 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
149 150
150 class MyCellEditor(wx.grid.PyGridCellEditor): 151 class MyCellEditor(wx.grid.PyGridCellEditor):
151 """ 152 """
152 This is a sample GridCellEditor that shows you how to make your own custom 153 This is a sample GridCellEditor that shows you how to make your own custom
153 grid editors. All the methods that can be overridden are show here. The 154 grid editors. All the methods that can be overridden are show here. The
173 174
174 """ 175 """
175 def __init__(self): 176 def __init__(self):
176 wx.grid.PyGridCellEditor.__init__(self) 177 wx.grid.PyGridCellEditor.__init__(self)
177 178
178
179 def Create(self, parent, id, evtHandler): 179 def Create(self, parent, id, evtHandler):
180 """ 180 """
181 Called to create the control, which must derive from wxControl. 181 Called to create the control, which must derive from wxControl.
182 *Must Override* 182 *Must Override*
183 """ 183 """
184 self._tc = wx.TextCtrl(parent, id, "", style=wx.TE_PROCESS_ENTER | wx.TE_PROCESS_TAB) 184 self._tc = wx.TextCtrl(parent, id, "", style=wx.TE_PROCESS_ENTER | wx.TE_PROCESS_TAB)
185 self._tc.SetInsertionPoint(0) 185 self._tc.SetInsertionPoint(0)
186 self.SetControl(self._tc) 186 self.SetControl(self._tc)
187 if evtHandler: 187 if evtHandler: self._tc.PushEventHandler(evtHandler)
188 self._tc.PushEventHandler(evtHandler)
189
190 188
191 def SetSize(self, rect): 189 def SetSize(self, rect):
192 """ 190 """
193 Called to position/size the edit control within the cell rectangle. 191 Called to position/size the edit control within the cell rectangle.
194 If you don't fill the cell (the rect) then be sure to override 192 If you don't fill the cell (the rect) then be sure to override
195 PaintBackground and do something meaningful there. 193 PaintBackground and do something meaningful there.
196 """ 194 """
197 self._tc.SetDimensions(rect.x+1, rect.y+1, rect.width+2, rect.height+2) 195 self._tc.SetDimensions(rect.x+1, rect.y+1, rect.width+2, rect.height+2)
198 196
199
200 #def Show(self, show, attr): #deprecated DeprecationWarning: Please use PyGridCellEditor.Show instead.
201 # """
202 # Show or hide the edit control. You can use the attr (if not None)
203 # to set colours or fonts for the control.
204 # """
205 # self.base_Show(show, attr) # Removed to prevent recursive error type.
206
207
208 def BeginEdit(self, row, col, grid): 197 def BeginEdit(self, row, col, grid):
209 """ 198 """
210 Fetch the value from the table and prepare the edit control 199 Fetch the value from the table and prepare the edit control
211 to begin editing. Set the focus to the edit control. 200 to begin editing. Set the focus to the edit control.
212 *Must Override* 201 *Must Override*
213 """ 202 """
214 self.startValue = grid.GetTable().GetValue(row, col) 203 #self.startValue = grid.GetTable().GetValue(row, col)
204 self.startValue = grid.get_value(row, col)
215 self._tc.SetValue(self.startValue) 205 self._tc.SetValue(self.startValue)
216 self._tc.SetInsertionPointEnd() 206 self._tc.SetInsertionPointEnd()
217 self._tc.SetFocus() 207 self._tc.SetFocus()
218 208
219 # For this example, select the text 209 # For this example, select the text
220 self._tc.SetSelection(0, self._tc.GetLastPosition()) 210 self._tc.SetSelection(0, self._tc.GetLastPosition())
221 211
222
223 def EndEdit(self, row, col, grid): 212 def EndEdit(self, row, col, grid):
224 """ 213 """
225 Complete the editing of the current cell. Returns True if the value 214 Complete the editing of the current cell. Returns True if the value
226 has changed. If necessary, the control may be destroyed. 215 has changed. If necessary, the control may be destroyed.
227 *Must Override* 216 *Must Override*
228 """ 217 """
229 changed = False 218 changed = False
230
231 val = self._tc.GetValue() 219 val = self._tc.GetValue()
232 if val != self.startValue: 220 if val != self.startValue:
233 changed = True 221 changed = True
234 grid.GetTable().SetValue(row, col, val) # update the table 222 grid.GetTable().SetValue(row, col, val) # update the table
235
236 self.startValue = '' 223 self.startValue = ''
237 self._tc.SetValue('') 224 self._tc.SetValue('')
238 return changed 225 return changed
239 226
240
241 def Reset(self): 227 def Reset(self):
242 """ 228 """
243 Reset the value in the control back to its starting value. 229 Reset the value in the control back to its starting value.
244 *Must Override* 230 *Must Override*
245 """ 231 """
246 self._tc.SetValue(self.startValue) 232 self._tc.SetValue(self.startValue)
247 self._tc.SetInsertionPointEnd() 233 self._tc.SetInsertionPointEnd()
248
249 234
250 def IsAcceptedKey(self, evt): 235 def IsAcceptedKey(self, evt):
251 """ 236 """
252 Return True to allow the given key to start editing: the base class 237 Return True to allow the given key to start editing: the base class
253 version only checks that the event has no modifiers. F2 is special 238 version only checks that the event has no modifiers. F2 is special
254 and will always start the editor. 239 and will always start the editor.
255 """ 240 """
256
257 ## Oops, there's a bug here, we'll have to do it ourself..
258 ##return self.base_IsAcceptedKey(evt)
259
260 return (not (evt.ControlDown() or evt.AltDown()) and 241 return (not (evt.ControlDown() or evt.AltDown()) and
261 evt.GetKeyCode() != wx.WXK_SHIFT) 242 evt.GetKeyCode() != wx.WXK_SHIFT)
262
263 243
264 def StartingKey(self, evt): 244 def StartingKey(self, evt):
265 """ 245 """
266 If the editor is enabled by pressing keys on the grid, this will be 246 If the editor is enabled by pressing keys on the grid, this will be
267 called to let the editor do something about that first key if desired. 247 called to let the editor do something about that first key if desired.
269 key = evt.GetKeyCode() 249 key = evt.GetKeyCode()
270 ch = None 250 ch = None
271 if key in [wx.WXK_NUMPAD0, wx.WXK_NUMPAD1, wx.WXK_NUMPAD2, wx.WXK_NUMPAD3, wx.WXK_NUMPAD4, 251 if key in [wx.WXK_NUMPAD0, wx.WXK_NUMPAD1, wx.WXK_NUMPAD2, wx.WXK_NUMPAD3, wx.WXK_NUMPAD4,
272 wx.WXK_NUMPAD5, wx.WXK_NUMPAD6, wx.WXK_NUMPAD7, wx.WXK_NUMPAD8, wx.WXK_NUMPAD9]: 252 wx.WXK_NUMPAD5, wx.WXK_NUMPAD6, wx.WXK_NUMPAD7, wx.WXK_NUMPAD8, wx.WXK_NUMPAD9]:
273 ch = ch = chr(ord('0') + key - wx.WXK_NUMPAD0) 253 ch = ch = chr(ord('0') + key - wx.WXK_NUMPAD0)
274
275 elif key < 256 and key >= 0 and chr(key) in string.printable: 254 elif key < 256 and key >= 0 and chr(key) in string.printable:
276 ch = chr(key) 255 ch = chr(key)
277 if not evt.ShiftDown(): 256 if not evt.ShiftDown(): ch = string.lower(ch)
278 ch = string.lower(ch) 257 if ch is not None: self._tc.AppendText(ch)
279 258 else: evt.Skip()
280 if ch is not None:
281 # For this example, replace the text. Normally we would append it.
282 self._tc.AppendText(ch)
283 else:
284 evt.Skip()
285
286 259
287 def Destroy(self): 260 def Destroy(self):
288 """final cleanup""" 261 """final cleanup"""
289 self.base_Destroy() 262 self.base_Destroy()
290 263
291
292 def Clone(self): 264 def Clone(self):
293 """ 265 """
294 Create a new object which is the copy of this one 266 Create a new object which is the copy of this one
295 *Must Override* 267 *Must Override*
296 """ 268 """
297 return MyCellEditor() 269 return MyCellEditor()
298 270
299 271
300
301 class rpg_grid(wx.grid.Grid): 272 class rpg_grid(wx.grid.Grid):
302 """grid for attacks""" 273 """grid for attacks"""
303 def __init__(self, parent, handler): 274 def __init__(self, parent, handler, mode):
304 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS) 275 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
305 self.parent = parent 276 self.parent = parent
306 self.handler = handler 277 self.handler = handler
307 278 self.mode = mode
308 # Registers a "custom" cell editor (really the example from Robin Dunn with minor mods
309 self.RegisterDataType(wx.grid.GRID_VALUE_STRING, wx.grid.GridCellStringRenderer(),MyCellEditor()) 279 self.RegisterDataType(wx.grid.GRID_VALUE_STRING, wx.grid.GridCellStringRenderer(),MyCellEditor())
310 280
311 self.rows = handler.grid.getElementsByTagName('row') 281 self.rows = handler.grid.findall('row')
312 rows = len(self.rows) 282 rows = len(self.rows)
313 cols = len(self.rows[0].getElementsByTagName('cell')) 283 cols = len(self.rows[0].findall('cell'))
314 self.CreateGrid(rows,cols) 284 self.CreateGrid(rows,cols)
315 self.SetRowLabelSize(0) 285 self.SetRowLabelSize(0)
316 self.SetColLabelSize(0) 286 self.SetColLabelSize(0)
317 self.set_col_widths() 287 self.set_col_widths()
318 288
319 for i in range(0,len(self.rows)): 289 for i in range(0,len(self.rows)): self.refresh_row(i)
320 self.refresh_row(i)
321 290
322 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change) 291 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
323 self.Bind(wx.grid.EVT_GRID_COL_SIZE, self.on_col_size) 292 self.Bind(wx.grid.EVT_GRID_COL_SIZE, self.on_col_size)
324 self.Bind(wx.grid.EVT_GRID_CELL_LEFT_DCLICK, self.on_leftdclick) 293 self.Bind(wx.grid.EVT_GRID_CELL_LEFT_DCLICK, self.on_leftdclick)
325 294
326
327 def on_leftdclick(self,evt): 295 def on_leftdclick(self,evt):
328 if self.CanEnableCellControl(): 296 if self.CanEnableCellControl(): self.EnableCellEditControl()
329 self.EnableCellEditControl()
330 297
331 def on_col_size(self, evt): 298 def on_col_size(self, evt):
332 col = evt.GetRowOrCol() 299 col = evt.GetRowOrCol()
333 cells = self.rows[0].getElementsByTagName('cell') 300 cells = self.rows[0].findall('cell')
334 size = self.GetColSize(col) 301 size = self.GetColSize(col)
335 cells[col].setAttribute('size',str(size)) 302 cells[col].set('size',str(size))
336 evt.Skip() 303 evt.Skip()
337 304
338 def on_cell_change(self,evt): 305 def on_cell_change(self,evt):
339 row = evt.GetRow() 306 row = evt.GetRow()
340 col = evt.GetCol() 307 col = evt.GetCol()
341 value = self.GetCellValue(row,col) 308 value = self.GetCellValue(row,col)
342 cells = self.rows[row].getElementsByTagName('cell') 309 cells = self.rows[row].findall('cell')
343 t_node = cells[col]._get_firstChild() 310 cells[col].text = value
344 t_node._set_nodeValue(value) 311 if col == 0: self.handler.refresh_rows()
345 if col == 0: 312 for i in range(0,len(self.rows)): self.refresh_row(i)
346 self.handler.refresh_rows()
347 313
348 def set_col_widths(self): 314 def set_col_widths(self):
349 cells = self.rows[0].getElementsByTagName('cell') 315 cells = self.rows[0].findall('cell')
350 for i in range(0,len(cells)): 316 for i in range(0,len(cells)):
351 try: 317 try:
352 size = int(cells[i].getAttribute('size')) 318 size = int(cells[i].get('size'))
353 self.SetColSize(i,size) 319 self.SetColSize(i,size)
354 except: 320 except: continue
355 continue 321
356 322 def refresh_row(self, rowi):
357 def refresh_row(self,rowi): 323 cells = self.rows[rowi].findall('cell')
358 cells = self.rows[rowi].getElementsByTagName('cell')
359 for i in range(0,len(cells)): 324 for i in range(0,len(cells)):
360 t_node = cells[i]._get_firstChild() 325 text = cells[i].text
361 if t_node == None: 326 if text == None or text == '':
362 #doc = cells[i].ownerDocument 327 text = ''
363 #t_node = doc.createTextNode("") 328 cells[i].text = text
364 t_node = Text("") 329 if self.mode == 0:
365 t_node = cells[i].appendChild(t_node) 330 s = Parse.NodeMap(text, self.handler.xml)
366 self.SetCellValue(rowi,i,t_node._get_nodeValue()) 331 s = Parse.NodeParent(s, self.handler.xml.get('map'))
332 try: text = str(eval(s))
333 except: text = s
334 self.SetCellValue(rowi,i,text)
367 335
368 def add_row(self,evt=None): 336 def add_row(self,evt=None):
369 cols = self.GetNumberCols() 337 cols = self.GetNumberCols()
370 #doc = self.handler.grid.ownerDocument
371 #row = doc.createElement('row')
372 row = Element('row') 338 row = Element('row')
373 for i in range(0,cols): 339 for i in range(0,cols):
374 #cell = doc.createElement('cell')
375 cell = Element('cell') 340 cell = Element('cell')
376 #t_node = doc.createTextNode("") 341 cell.text = ''
377 t_node = Text("") 342 row.append(cell)
378 t_node = cell.appendChild(t_node) 343 self.handler.grid.append(row)
379 row.appendChild(cell)
380 self.handler.grid.appendChild(row)
381 self.AppendRows(1) 344 self.AppendRows(1)
382 self.rows = self.handler.grid.getElementsByTagName('row') 345 self.rows = self.handler.grid.findall('row')
383 self.handler.refresh_rows() 346 self.handler.refresh_rows()
384 347
385 def add_col(self,evt=None): 348 def add_col(self,evt=None):
386 #doc = self.handler.grid.ownerDocument
387 for r in self.rows: 349 for r in self.rows:
388 #cell = doc.createElement('cell')
389 cell = Element('cell') 350 cell = Element('cell')
390 #t_node = doc.createTextNode("") 351 cell.text = ''
391 t_node = Text("") 352 r.append(cell)
392 t_node = cell.appendChild(t_node)
393 r.appendChild(cell)
394 self.AppendCols(1) 353 self.AppendCols(1)
395 #self.fit_cols()::Where did this go? TaS. 354 self.set_col_widths()
396 355
397 def del_row(self,evt=None): 356 def del_row(self,evt=None):
398 num = self.GetNumberRows() 357 num = self.GetNumberRows()
399 row = self.rows[num-1] 358 if num == 1: return
400 self.handler.grid.removeChild(row) 359 self.handler.grid.remove(self.handler.grid[num-1])# always remove last row -- nasty
401 self.DeleteRows(num-1,1) 360 self.DeleteRows(num-1,1)
402 self.rows = self.handler.grid.getElementsByTagName('row') 361 self.rows = self.handler.grid.findall('row')
403 self.handler.refresh_rows() 362 self.handler.refresh_rows()
404 363
405 def del_col(self,evt=None): 364 def del_col(self,evt=None):
406 num = self.GetNumberCols() 365 num = self.GetNumberCols()
366 if num == 1: return
407 for r in self.rows: 367 for r in self.rows:
408 cells = r.getElementsByTagName('cell') 368 cells = r.findall('cell')
409 r.removeChild(cells[num-1]) 369 r.remove(r[num-1]) # always remove the last column -- nasty
410 self.DeleteCols(num-1,1) 370 self.DeleteCols(num-1,1)
411 #self.fit_cols()::Where did this go? TaS. 371 self.set_col_widths()
372
373 def get_value(self, row, col):
374 cells = self.rows[row].findall('cell')
375 return cells[col].text
412 376
413 377
414 G_TITLE = wx.NewId() 378 G_TITLE = wx.NewId()
415 GRID_BOR = wx.NewId() 379 GRID_BOR = wx.NewId()
416 class rpg_grid_panel(wx.Panel): 380 class rpg_grid_panel(wx.Panel):
417 def __init__(self, parent, handler): 381 def __init__(self, parent, handler):
418 wx.Panel.__init__(self, parent, -1) 382 wx.Panel.__init__(self, parent, -1)
419 self.handler = handler 383 self.handler = handler
420 self.grid = rpg_grid(self,handler) 384 self.grid = rpg_grid(self, handler, mode=0)
421 label = handler.master_dom.getAttribute('name') 385 label = handler.xml.get('name')
422 self.main_sizer = wx.BoxSizer(wx.VERTICAL) 386 self.main_sizer = wx.BoxSizer(wx.VERTICAL)
423 self.main_sizer.Add(wx.StaticText(self, -1, label+": "), 0, wx.EXPAND) 387 self.main_sizer.Add(wx.StaticText(self, -1, label+": "), 0, wx.EXPAND)
424 self.main_sizer.Add(self.grid,1,wx.EXPAND) 388 self.main_sizer.Add(self.grid,1,wx.EXPAND)
425 self.SetSizer(self.main_sizer) 389 self.SetSizer(self.main_sizer)
426 self.SetAutoLayout(True) 390 self.SetAutoLayout(True)
427 self.Fit() 391 self.Fit()
428 parent.SetSize(self.GetBestSize()) 392 parent.SetSize(self.GetBestSize())
429 393
430
431 G_AUTO_SIZE = wx.NewId() 394 G_AUTO_SIZE = wx.NewId()
432 G_ADD_ROW = wx.NewId() 395 G_ADD_ROW = wx.NewId()
433 G_ADD_COL = wx.NewId() 396 G_ADD_COL = wx.NewId()
434 G_DEL_ROW = wx.NewId() 397 G_DEL_ROW = wx.NewId()
435 G_DEL_COL = wx.NewId() 398 G_DEL_COL = wx.NewId()
399 G_BUT_REF = wx.NewId()
436 400
437 class rpg_grid_edit_panel(wx.Panel): 401 class rpg_grid_edit_panel(wx.Panel):
438 def __init__(self, parent, handler): 402 def __init__(self, parent, handler):
439 wx.Panel.__init__(self, parent, -1) 403 wx.Panel.__init__(self, parent, -1)
440 self.handler = handler 404 self.handler = handler
441 self.grid = rpg_grid(self,handler) 405 self.parent = parent
442 self.title = wx.TextCtrl(self, G_TITLE, handler.master_dom.getAttribute('name')) 406 self.grid = rpg_grid(self,handler, mode=1)
407 self.main_sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Grid"), wx.VERTICAL)
408
409 self.title = wx.TextCtrl(self, G_TITLE, handler.xml.get('name'))
443 410
444 radio_b = wx.RadioBox(self, GRID_BOR, "Border (HTML)", choices=["no","yes"]) 411 radio_b = wx.RadioBox(self, GRID_BOR, "Border (HTML)", choices=["no","yes"])
445 border = handler.grid.getAttribute("border") 412 border = handler.grid.get("border")
446 radio_b.SetSelection(int(border)) 413 radio_b.SetSelection(int(border))
447 414
448 self.auto_size = wx.CheckBox(self, G_AUTO_SIZE, " Auto Size") 415 self.auto_size = wx.CheckBox(self, G_AUTO_SIZE, "Auto Size")
449 if handler.is_autosized() == '1': 416 if handler.is_autosized() == '1': self.auto_size.SetValue(True)
450 self.auto_size.SetValue(True) 417 else: self.auto_size.SetValue(False)
451 else:
452 self.auto_size.SetValue(False)
453 418
454 sizer = wx.BoxSizer(wx.HORIZONTAL) 419 sizer = wx.BoxSizer(wx.HORIZONTAL)
455 sizer.Add(wx.Button(self, G_ADD_ROW, "Add Row"), 1, wx.EXPAND) 420 sizer.Add(wx.Button(self, G_ADD_ROW, "Add Row"), 1, wx.EXPAND)
456 sizer.Add(wx.Size(10,10)) 421 sizer.Add(wx.Size(10,10))
457 sizer.Add(wx.Button(self, G_DEL_ROW, "Remove Row"), 1, wx.EXPAND) 422 sizer.Add(wx.Button(self, G_DEL_ROW, "Remove Row"), 1, wx.EXPAND)
458 sizer.Add(wx.Size(10,10)) 423 sizer.Add(wx.Size(10,10))
459 sizer.Add(wx.Button(self, G_ADD_COL, "Add Column"), 1, wx.EXPAND) 424 sizer.Add(wx.Button(self, G_ADD_COL, "Add Column"), 1, wx.EXPAND)
460 sizer.Add(wx.Size(10,10)) 425 sizer.Add(wx.Size(10,10))
461 sizer.Add(wx.Button(self, G_DEL_COL, "Remove Column"), 1, wx.EXPAND) 426 sizer.Add(wx.Button(self, G_DEL_COL, "Remove Column"), 1, wx.EXPAND)
462 427 sizer.Add(wx.Size(10,10))
463 self.main_sizer = wx.StaticBoxSizer(wx.StaticBox(self,-1,"Grid"), wx.VERTICAL) 428 sizer.Add(wx.Button(self, G_BUT_REF, "Reference"), 1)
429
464 self.main_sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND) 430 self.main_sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND)
465 self.main_sizer.Add(self.title, 0, wx.EXPAND) 431 self.main_sizer.Add(self.title, 0, wx.EXPAND)
466 self.main_sizer.Add(radio_b, 0, 0) 432 self.main_sizer.Add(radio_b, 0, 0)
467 self.main_sizer.Add(self.auto_size, 0, 0) 433 self.main_sizer.Add(self.auto_size, 0, 0)
468 self.main_sizer.Add(self.grid,1,wx.EXPAND) 434 self.main_sizer.Add(self.grid,1,wx.EXPAND)
477 self.Bind(wx.EVT_BUTTON, self.grid.del_row, id=G_DEL_ROW) 443 self.Bind(wx.EVT_BUTTON, self.grid.del_row, id=G_DEL_ROW)
478 self.Bind(wx.EVT_BUTTON, self.grid.add_col, id=G_ADD_COL) 444 self.Bind(wx.EVT_BUTTON, self.grid.add_col, id=G_ADD_COL)
479 self.Bind(wx.EVT_BUTTON, self.grid.del_col, id=G_DEL_COL) 445 self.Bind(wx.EVT_BUTTON, self.grid.del_col, id=G_DEL_COL)
480 self.Bind(wx.EVT_RADIOBOX, self.on_radio_box, id=GRID_BOR) 446 self.Bind(wx.EVT_RADIOBOX, self.on_radio_box, id=GRID_BOR)
481 self.Bind(wx.EVT_CHECKBOX, self.on_auto_size, id=G_AUTO_SIZE) 447 self.Bind(wx.EVT_CHECKBOX, self.on_auto_size, id=G_AUTO_SIZE)
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()
480 temp_value = self.grid.GetCellValue(row, col)
481 complete = temp_value + complete
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()
525 temp_value = self.grid.GetCellValue(row, col)
526 complete = temp_value + complete
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 ##### #####
482 534
483 def on_auto_size(self,evt): 535 def on_auto_size(self,evt):
484 self.handler.set_autosize(bool2int(evt.Checked())) 536 self.handler.set_autosize(bool2int(evt.Checked()))
485 537
486 def on_radio_box(self,evt): 538 def on_radio_box(self,evt):
487 id = evt.GetId() 539 id = evt.GetId()
488 index = evt.GetInt() 540 index = evt.GetInt()
489 if id == GRID_BOR: 541 if id == GRID_BOR:
490 self.handler.grid.setAttribute("border",str(index)) 542 self.handler.grid.set("border",str(index))
491 543
492 def on_text(self,evt): 544 def on_text(self,evt):
493 txt = self.title.GetValue() 545 txt = self.title.GetValue()
494 if txt != "": 546 if txt != "":
495 self.handler.master_dom.setAttribute('name',txt) 547 self.handler.xml.set('name',txt)
496 self.handler.rename(txt) 548 self.handler.rename(txt)
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)