comparison orpg/gametree/nodehandlers/rpg_grid.py @ 152:6081bdc2b8d5 beta

Traipse Beta 'OpenRPG' {091125-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 (Beta) Added Bookmarks Fix to Remote Admin Commands Minor fix to text based Server Fix to Pretty Print, from Core Fix to Splitter Nodes not being created Fix to massive amounts of images loading, from Core Added 'boot' command to remote admin Added confirmation window for sent nodes Minor changes to allow for portability to an OpenSUSE linux OS Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG Zoom Mouse plugin added Images added to Plugin UI Switching to Element Tree Map efficiency, from FlexiRPG Added Status Bar to Update Manager default_manifest.xml renamed to default_upmana.xml Cleaner clode for saved repositories New TrueDebug Class in orpg_log (See documentation for usage) Mercurial's hgweb folder is ported to upmana Pretty important update that can help remove thousands of dead children from your gametree. Children, <forms />, <group_atts />, <horizontal />, <cols />, <rows />, <height />, etc... are all tags now. Check your gametree and look for dead children!! New Gametree Recursion method, mapping, and context sensitivity. !Infinite Loops return error instead of freezing the software! New Syntax added for custom PC sheets Tip of the Day added, from Core and community Fixed Whiteboard ID to prevent random line or text deleting. Modified ID's to prevent non updated clients from ruining the fix.
author sirebral
date Wed, 25 Nov 2009 06:16:35 -0600
parents e842a5f1b775
children 3b6888bb53b5
comparison
equal deleted inserted replaced
150:6c5f46a5924b 152:6081bdc2b8d5
50 </nodehandler> 50 </nodehandler>
51 """ 51 """
52 def __init__(self,xml,tree_node): 52 def __init__(self,xml,tree_node):
53 node_handler.__init__(self,xml,tree_node) 53 node_handler.__init__(self,xml,tree_node)
54 self.grid = self.xml.find('grid') 54 self.grid = self.xml.find('grid')
55 if self.grid.get("border") == "": 55 if self.grid.get("border") == "": self.grid.set("border","1")
56 self.grid.set("border","1") 56 if self.grid.get("autosize") == "": self.grid.set("autosize","1")
57 if self.grid.get("autosize") == "":
58 self.grid.set("autosize","1")
59 self.macros = self.xml.find('macros') 57 self.macros = self.xml.find('macros')
60 self.myeditor = None 58 self.myeditor = None
61 self.refresh_rows() 59 self.refresh_rows()
62 60
63 def refresh_die_macros(self): 61 def refresh_die_macros(self):
69 icons = self.tree.icons 67 icons = self.tree.icons
70 tree.CollapseAndReset(self.mytree_node) 68 tree.CollapseAndReset(self.mytree_node)
71 for row in self.grid.findall('row'): 69 for row in self.grid.findall('row'):
72 first_cell = row.find('cell') 70 first_cell = row.find('cell')
73 name = first_cell.text 71 name = first_cell.text
74 if name == None or name == '': 72 if name == None or name == '': name = "Row"
75 name = "Row"
76 new_tree_node = tree.AppendItem(self.mytree_node,name,icons['gear'],icons['gear']) 73 new_tree_node = tree.AppendItem(self.mytree_node,name,icons['gear'],icons['gear'])
77 handler = grid_row_handler(row,new_tree_node,self) 74 handler = grid_row_handler(row,new_tree_node,self)
78 tree.SetPyData(new_tree_node,handler) 75 tree.SetPyData(new_tree_node,handler)
79 76
80 def tohtml(self): 77 def tohtml(self):
85 html_str = "<table border=\""+border+"\" align=center><tr bgcolor=\""+TH_BG+"\" ><th colspan="+colspan+">"+name+"</th></tr>" 82 html_str = "<table border=\""+border+"\" align=center><tr bgcolor=\""+TH_BG+"\" ><th colspan="+colspan+">"+name+"</th></tr>"
86 for r in rows: 83 for r in rows:
87 cells = r.findall('cell') 84 cells = r.findall('cell')
88 html_str += "<tr>" 85 html_str += "<tr>"
89 for c in cells: 86 for c in cells:
90 #html_str += "<td width='"+c.get('size')+"' >" bug here
91 html_str += "<td >" 87 html_str += "<td >"
92 text = c.text 88 text = c.text
93 if text == None or text == '': 89 if text == None or text == '': text = '<br />'
94 text = '<br />'
95 html_str += text + "</td>" 90 html_str += text + "</td>"
96 html_str += "</tr>" 91 html_str += "</tr>"
97 html_str += "</table>" 92 html_str += "</table>"
98 return html_str 93 return html_str
99 94
129 cells = self.xml.findall('cell') 124 cells = self.xml.findall('cell')
130 html_str = "<table border=1 align=center><tr >" 125 html_str = "<table border=1 align=center><tr >"
131 for c in cells: # should loop over rows first, then cells 126 for c in cells: # should loop over rows first, then cells
132 html_str += "<td >" 127 html_str += "<td >"
133 text = c.text 128 text = c.text
134 if text == '' or text is None: 129 if text == '' or text is None: text = '<br />'
135 text = '<br />'
136 html_str += text + "</td>" 130 html_str += text + "</td>"
137 html_str += "</tr>" 131 html_str += "</tr>"
138 html_str += "</table>" 132 html_str += "</table>"
139 return html_str 133 return html_str
140 134
141 def get_value(self): 135 def get_value(self):
142 cells = self.xml.findall('cell') 136 cells = self.xml.findall('cell')
143 if len(cells) == 2: 137 if len(cells) == 2: return getText(cells[1])
144 return getText(cells[1]) 138 else: return None
145 else:
146 return None
147 139
148 def set_value(self, new_value): 140 def set_value(self, new_value):
149 cells = self.xml.findall('cell') 141 cells = self.xml.findall('cell')
150 if len(cells) == 2: 142 if len(cells) == 2:
151 cells[1].text = new_value 143 cells[1].text = new_value
176 168
177 """ 169 """
178 def __init__(self): 170 def __init__(self):
179 wx.grid.PyGridCellEditor.__init__(self) 171 wx.grid.PyGridCellEditor.__init__(self)
180 172
181
182 def Create(self, parent, id, evtHandler): 173 def Create(self, parent, id, evtHandler):
183 """ 174 """
184 Called to create the control, which must derive from wxControl. 175 Called to create the control, which must derive from wxControl.
185 *Must Override* 176 *Must Override*
186 """ 177 """
187 self._tc = wx.TextCtrl(parent, id, "", style=wx.TE_PROCESS_ENTER | wx.TE_PROCESS_TAB) 178 self._tc = wx.TextCtrl(parent, id, "", style=wx.TE_PROCESS_ENTER | wx.TE_PROCESS_TAB)
188 self._tc.SetInsertionPoint(0) 179 self._tc.SetInsertionPoint(0)
189 self.SetControl(self._tc) 180 self.SetControl(self._tc)
190 if evtHandler: 181 if evtHandler: self._tc.PushEventHandler(evtHandler)
191 self._tc.PushEventHandler(evtHandler)
192
193 182
194 def SetSize(self, rect): 183 def SetSize(self, rect):
195 """ 184 """
196 Called to position/size the edit control within the cell rectangle. 185 Called to position/size the edit control within the cell rectangle.
197 If you don't fill the cell (the rect) then be sure to override 186 If you don't fill the cell (the rect) then be sure to override
198 PaintBackground and do something meaningful there. 187 PaintBackground and do something meaningful there.
199 """ 188 """
200 self._tc.SetDimensions(rect.x+1, rect.y+1, rect.width+2, rect.height+2) 189 self._tc.SetDimensions(rect.x+1, rect.y+1, rect.width+2, rect.height+2)
201
202
203 #def Show(self, show, attr): #deprecated DeprecationWarning: Please use PyGridCellEditor.Show instead.
204 # """
205 # Show or hide the edit control. You can use the attr (if not None)
206 # to set colours or fonts for the control.
207 # """
208 # self.base_Show(show, attr) # Removed to prevent recursive error type.
209
210 190
211 def BeginEdit(self, row, col, grid): 191 def BeginEdit(self, row, col, grid):
212 """ 192 """
213 Fetch the value from the table and prepare the edit control 193 Fetch the value from the table and prepare the edit control
214 to begin editing. Set the focus to the edit control. 194 to begin editing. Set the focus to the edit control.
220 self._tc.SetFocus() 200 self._tc.SetFocus()
221 201
222 # For this example, select the text 202 # For this example, select the text
223 self._tc.SetSelection(0, self._tc.GetLastPosition()) 203 self._tc.SetSelection(0, self._tc.GetLastPosition())
224 204
225
226 def EndEdit(self, row, col, grid): 205 def EndEdit(self, row, col, grid):
227 """ 206 """
228 Complete the editing of the current cell. Returns True if the value 207 Complete the editing of the current cell. Returns True if the value
229 has changed. If necessary, the control may be destroyed. 208 has changed. If necessary, the control may be destroyed.
230 *Must Override* 209 *Must Override*
231 """ 210 """
232 changed = False 211 changed = False
233
234 val = self._tc.GetValue() 212 val = self._tc.GetValue()
235 if val != self.startValue: 213 if val != self.startValue:
236 changed = True 214 changed = True
237 grid.GetTable().SetValue(row, col, val) # update the table 215 grid.GetTable().SetValue(row, col, val) # update the table
238 216
239 self.startValue = '' 217 self.startValue = ''
240 self._tc.SetValue('') 218 self._tc.SetValue('')
241 return changed 219 return changed
242 220
243
244 def Reset(self): 221 def Reset(self):
245 """ 222 """
246 Reset the value in the control back to its starting value. 223 Reset the value in the control back to its starting value.
247 *Must Override* 224 *Must Override*
248 """ 225 """
249 self._tc.SetValue(self.startValue) 226 self._tc.SetValue(self.startValue)
250 self._tc.SetInsertionPointEnd() 227 self._tc.SetInsertionPointEnd()
251
252 228
253 def IsAcceptedKey(self, evt): 229 def IsAcceptedKey(self, evt):
254 """ 230 """
255 Return True to allow the given key to start editing: the base class 231 Return True to allow the given key to start editing: the base class
256 version only checks that the event has no modifiers. F2 is special 232 version only checks that the event has no modifiers. F2 is special
257 and will always start the editor. 233 and will always start the editor.
258 """ 234 """
259
260 ## Oops, there's a bug here, we'll have to do it ourself..
261 ##return self.base_IsAcceptedKey(evt)
262
263 return (not (evt.ControlDown() or evt.AltDown()) and 235 return (not (evt.ControlDown() or evt.AltDown()) and
264 evt.GetKeyCode() != wx.WXK_SHIFT) 236 evt.GetKeyCode() != wx.WXK_SHIFT)
265
266 237
267 def StartingKey(self, evt): 238 def StartingKey(self, evt):
268 """ 239 """
269 If the editor is enabled by pressing keys on the grid, this will be 240 If the editor is enabled by pressing keys on the grid, this will be
270 called to let the editor do something about that first key if desired. 241 called to let the editor do something about that first key if desired.
272 key = evt.GetKeyCode() 243 key = evt.GetKeyCode()
273 ch = None 244 ch = None
274 if key in [wx.WXK_NUMPAD0, wx.WXK_NUMPAD1, wx.WXK_NUMPAD2, wx.WXK_NUMPAD3, wx.WXK_NUMPAD4, 245 if key in [wx.WXK_NUMPAD0, wx.WXK_NUMPAD1, wx.WXK_NUMPAD2, wx.WXK_NUMPAD3, wx.WXK_NUMPAD4,
275 wx.WXK_NUMPAD5, wx.WXK_NUMPAD6, wx.WXK_NUMPAD7, wx.WXK_NUMPAD8, wx.WXK_NUMPAD9]: 246 wx.WXK_NUMPAD5, wx.WXK_NUMPAD6, wx.WXK_NUMPAD7, wx.WXK_NUMPAD8, wx.WXK_NUMPAD9]:
276 ch = ch = chr(ord('0') + key - wx.WXK_NUMPAD0) 247 ch = ch = chr(ord('0') + key - wx.WXK_NUMPAD0)
277
278 elif key < 256 and key >= 0 and chr(key) in string.printable: 248 elif key < 256 and key >= 0 and chr(key) in string.printable:
279 ch = chr(key) 249 ch = chr(key)
280 if not evt.ShiftDown(): 250 if not evt.ShiftDown(): ch = string.lower(ch)
281 ch = string.lower(ch) 251 if ch is not None: self._tc.AppendText(ch)
282 252 else: evt.Skip()
283 if ch is not None:
284 # For this example, replace the text. Normally we would append it.
285 self._tc.AppendText(ch)
286 else:
287 evt.Skip()
288
289
290 253
291 def Destroy(self): 254 def Destroy(self):
292 """final cleanup""" 255 """final cleanup"""
293 self.base_Destroy() 256 self.base_Destroy()
294 257
295
296 def Clone(self): 258 def Clone(self):
297 """ 259 """
298 Create a new object which is the copy of this one 260 Create a new object which is the copy of this one
299 *Must Override* 261 *Must Override*
300 """ 262 """
301 return MyCellEditor() 263 return MyCellEditor()
302
303 264
304 265
305 class rpg_grid(wx.grid.Grid): 266 class rpg_grid(wx.grid.Grid):
306 """grid for attacks""" 267 """grid for attacks"""
307 def __init__(self, parent, handler): 268 def __init__(self, parent, handler):
308 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS) 269 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
309 self.parent = parent 270 self.parent = parent
310 self.handler = handler 271 self.handler = handler
311 272
312 # Registers a "custom" cell editor (really the example from Robin Dunn with minor mods
313 self.RegisterDataType(wx.grid.GRID_VALUE_STRING, wx.grid.GridCellStringRenderer(),MyCellEditor()) 273 self.RegisterDataType(wx.grid.GRID_VALUE_STRING, wx.grid.GridCellStringRenderer(),MyCellEditor())
314 274
315 self.rows = handler.grid.findall('row') 275 self.rows = handler.grid.findall('row')
316 rows = len(self.rows) 276 rows = len(self.rows)
317 cols = len(self.rows[0].findall('cell')) 277 cols = len(self.rows[0].findall('cell'))
318 self.CreateGrid(rows,cols) 278 self.CreateGrid(rows,cols)
319 self.SetRowLabelSize(0) 279 self.SetRowLabelSize(0)
320 self.SetColLabelSize(0) 280 self.SetColLabelSize(0)
321 self.set_col_widths() 281 self.set_col_widths()
322 282
323 for i in range(0,len(self.rows)): 283 for i in range(0,len(self.rows)): self.refresh_row(i)
324 self.refresh_row(i)
325 284
326 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change) 285 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
327 self.Bind(wx.grid.EVT_GRID_COL_SIZE, self.on_col_size) 286 self.Bind(wx.grid.EVT_GRID_COL_SIZE, self.on_col_size)
328 self.Bind(wx.grid.EVT_GRID_CELL_LEFT_DCLICK, self.on_leftdclick) 287 self.Bind(wx.grid.EVT_GRID_CELL_LEFT_DCLICK, self.on_leftdclick)
329 288
330 289
331 def on_leftdclick(self,evt): 290 def on_leftdclick(self,evt):
332 if self.CanEnableCellControl(): 291 if self.CanEnableCellControl(): self.EnableCellEditControl()
333 self.EnableCellEditControl()
334 292
335 def on_col_size(self, evt): 293 def on_col_size(self, evt):
336 col = evt.GetRowOrCol() 294 col = evt.GetRowOrCol()
337 cells = self.rows[0].findall('cell') 295 cells = self.rows[0].findall('cell')
338 size = self.GetColSize(col) 296 size = self.GetColSize(col)
343 row = evt.GetRow() 301 row = evt.GetRow()
344 col = evt.GetCol() 302 col = evt.GetCol()
345 value = self.GetCellValue(row,col) 303 value = self.GetCellValue(row,col)
346 cells = self.rows[row].findall('cell') 304 cells = self.rows[row].findall('cell')
347 cells[col].text = value 305 cells[col].text = value
348 if col == 0: 306 if col == 0: self.handler.refresh_rows()
349 self.handler.refresh_rows()
350 307
351 def set_col_widths(self): 308 def set_col_widths(self):
352 cells = self.rows[0].findall('cell') 309 cells = self.rows[0].findall('cell')
353 for i in range(0,len(cells)): 310 for i in range(0,len(cells)):
354 try: 311 try:
355 size = int(cells[i].get('size')) 312 size = int(cells[i].get('size'))
356 self.SetColSize(i,size) 313 self.SetColSize(i,size)
357 except: 314 except: continue
358 continue
359 315
360 def refresh_row(self,rowi): 316 def refresh_row(self,rowi):
361 cells = self.rows[rowi].findall('cell') 317 cells = self.rows[rowi].findall('cell')
362 for i in range(0,len(cells)): 318 for i in range(0,len(cells)):
363 text = cells[i].text 319 text = cells[i].text
386 self.AppendCols(1) 342 self.AppendCols(1)
387 self.set_col_widths() 343 self.set_col_widths()
388 344
389 def del_row(self,evt=None): 345 def del_row(self,evt=None):
390 num = self.GetNumberRows() 346 num = self.GetNumberRows()
391 if num == 1: 347 if num == 1: return
392 return
393 self.handler.grid.remove(self.handler.grid[num-1])# always remove last row -- nasty 348 self.handler.grid.remove(self.handler.grid[num-1])# always remove last row -- nasty
394 self.DeleteRows(num-1,1) 349 self.DeleteRows(num-1,1)
395 self.rows = self.handler.grid.findall('row') 350 self.rows = self.handler.grid.findall('row')
396 self.handler.refresh_rows() 351 self.handler.refresh_rows()
397 352
398 def del_col(self,evt=None): 353 def del_col(self,evt=None):
399 num = self.GetNumberCols() 354 num = self.GetNumberCols()
400 if num == 1: 355 if num == 1: return
401 return
402 for r in self.rows: 356 for r in self.rows:
403 cells = r.findall('cell') 357 cells = r.findall('cell')
404 r.remove(r[num-1]) # always remove the last column -- nasty 358 r.remove(r[num-1]) # always remove the last column -- nasty
405 self.DeleteCols(num-1,1) 359 self.DeleteCols(num-1,1)
406 self.set_col_widths() 360 self.set_col_widths()
420 self.SetSizer(self.main_sizer) 374 self.SetSizer(self.main_sizer)
421 self.SetAutoLayout(True) 375 self.SetAutoLayout(True)
422 self.Fit() 376 self.Fit()
423 parent.SetSize(self.GetBestSize()) 377 parent.SetSize(self.GetBestSize())
424 378
425
426 G_AUTO_SIZE = wx.NewId() 379 G_AUTO_SIZE = wx.NewId()
427 G_ADD_ROW = wx.NewId() 380 G_ADD_ROW = wx.NewId()
428 G_ADD_COL = wx.NewId() 381 G_ADD_COL = wx.NewId()
429 G_DEL_ROW = wx.NewId() 382 G_DEL_ROW = wx.NewId()
430 G_DEL_COL = wx.NewId() 383 G_DEL_COL = wx.NewId()