comparison orpg/gametree/nodehandlers/rpg_grid.py @ 195:b633f4c64aae alpha

Traipse Alpha 'OpenRPG' {100219-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 (Patch-2) New Features: New Namespace method with two new syntaxes Fixes: Fix to Server GUI startup errors Fix to Server GUI Rooms tab updating Fix to Chat and Settings if non existant die roller is picked Fix to Dieroller and .open() used with .vs(). Successes are correctly calculated Fix to Alias Lib's Export to Tree, Open, Save features Fix to alias node, now works properly Fix to Splitter node, minor GUI cleanup
author sirebral
date Sat, 24 Apr 2010 08:37:20 -0500
parents fa18af3e04b9
children
comparison
equal deleted inserted replaced
182:4b2884f29a72 195:b633f4c64aae
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.tools.orpg_log import debug
34 from orpg.tools.InterParse import Parse
33 35
34 class rpg_grid_handler(node_handler): 36 class rpg_grid_handler(node_handler):
35 """ Node handler for rpg grid tool 37 """ Node handler for rpg grid tool
36 <nodehandler module='rpg_grid' class='rpg_grid_handler' name='sample'> 38 <nodehandler module='rpg_grid' class='rpg_grid_handler' name='sample'>
37 <grid border='' autosize='1' > 39 <grid border='' autosize='1' >
85 html_str += "<tr>" 87 html_str += "<tr>"
86 for c in cells: 88 for c in cells:
87 html_str += "<td >" 89 html_str += "<td >"
88 text = c.text 90 text = c.text
89 if text == None or text == '': text = '<br />' 91 if text == None or text == '': text = '<br />'
92 s = Parse.ParseLogic(text, self.xml)
93 s = Parse.Normalize(s)
94 try: text = str(eval(s))
95 except: text = s
90 html_str += text + "</td>" 96 html_str += text + "</td>"
91 html_str += "</tr>" 97 html_str += "</tr>"
92 html_str += "</table>" 98 html_str += "</table>"
93 return html_str 99 return html_str
94 100
95 def get_design_panel(self,parent): 101 def get_design_panel(self,parent):
96 return rpg_grid_edit_panel(parent,self) 102 return rpg_grid_edit_panel(parent, self)
97 103
98 def get_use_panel(self,parent): 104 def get_use_panel(self,parent):
99 return rpg_grid_panel(parent,self) 105 return rpg_grid_panel(parent, self)
100 106
101 def get_size_constraint(self): 107 def get_size_constraint(self):
102 return 1 108 return 1
103 109
104 def is_autosized(self): 110 def is_autosized(self):
192 """ 198 """
193 Fetch the value from the table and prepare the edit control 199 Fetch the value from the table and prepare the edit control
194 to begin editing. Set the focus to the edit control. 200 to begin editing. Set the focus to the edit control.
195 *Must Override* 201 *Must Override*
196 """ 202 """
197 self.startValue = grid.GetTable().GetValue(row, col) 203 #self.startValue = grid.GetTable().GetValue(row, col)
204 self.startValue = grid.get_value(row, col)
198 self._tc.SetValue(self.startValue) 205 self._tc.SetValue(self.startValue)
199 self._tc.SetInsertionPointEnd() 206 self._tc.SetInsertionPointEnd()
200 self._tc.SetFocus() 207 self._tc.SetFocus()
201 208
202 # For this example, select the text 209 # For this example, select the text
211 changed = False 218 changed = False
212 val = self._tc.GetValue() 219 val = self._tc.GetValue()
213 if val != self.startValue: 220 if val != self.startValue:
214 changed = True 221 changed = True
215 grid.GetTable().SetValue(row, col, val) # update the table 222 grid.GetTable().SetValue(row, col, val) # update the table
216
217 self.startValue = '' 223 self.startValue = ''
218 self._tc.SetValue('') 224 self._tc.SetValue('')
219 return changed 225 return changed
220 226
221 def Reset(self): 227 def Reset(self):
263 return MyCellEditor() 269 return MyCellEditor()
264 270
265 271
266 class rpg_grid(wx.grid.Grid): 272 class rpg_grid(wx.grid.Grid):
267 """grid for attacks""" 273 """grid for attacks"""
268 def __init__(self, parent, handler): 274 def __init__(self, parent, handler, mode):
269 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)
270 self.parent = parent 276 self.parent = parent
271 self.handler = handler 277 self.handler = handler
272 278 self.mode = mode
273 self.RegisterDataType(wx.grid.GRID_VALUE_STRING, wx.grid.GridCellStringRenderer(),MyCellEditor()) 279 self.RegisterDataType(wx.grid.GRID_VALUE_STRING, wx.grid.GridCellStringRenderer(),MyCellEditor())
274 280
275 self.rows = handler.grid.findall('row') 281 self.rows = handler.grid.findall('row')
276 rows = len(self.rows) 282 rows = len(self.rows)
277 cols = len(self.rows[0].findall('cell')) 283 cols = len(self.rows[0].findall('cell'))
284 290
285 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)
286 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)
287 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)
288 294
289
290 def on_leftdclick(self,evt): 295 def on_leftdclick(self,evt):
291 if self.CanEnableCellControl(): self.EnableCellEditControl() 296 if self.CanEnableCellControl(): self.EnableCellEditControl()
292 297
293 def on_col_size(self, evt): 298 def on_col_size(self, evt):
294 col = evt.GetRowOrCol() 299 col = evt.GetRowOrCol()
302 col = evt.GetCol() 307 col = evt.GetCol()
303 value = self.GetCellValue(row,col) 308 value = self.GetCellValue(row,col)
304 cells = self.rows[row].findall('cell') 309 cells = self.rows[row].findall('cell')
305 cells[col].text = value 310 cells[col].text = value
306 if col == 0: self.handler.refresh_rows() 311 if col == 0: self.handler.refresh_rows()
312 for i in range(0,len(self.rows)): self.refresh_row(i)
307 313
308 def set_col_widths(self): 314 def set_col_widths(self):
309 cells = self.rows[0].findall('cell') 315 cells = self.rows[0].findall('cell')
310 for i in range(0,len(cells)): 316 for i in range(0,len(cells)):
311 try: 317 try:
312 size = int(cells[i].get('size')) 318 size = int(cells[i].get('size'))
313 self.SetColSize(i,size) 319 self.SetColSize(i,size)
314 except: continue 320 except: continue
315 321
316 def refresh_row(self,rowi): 322 def refresh_row(self, rowi):
317 cells = self.rows[rowi].findall('cell') 323 cells = self.rows[rowi].findall('cell')
318 for i in range(0,len(cells)): 324 for i in range(0,len(cells)):
319 text = cells[i].text 325 text = cells[i].text
320 if text == None or text == '': 326 if text == None or text == '':
321 text = '' 327 text = ''
322 cells[i].text = text 328 cells[i].text = text
329 if self.mode == 0:
330 s = Parse.ParseLogic(text, self.handler.xml)
331 try: text = str(eval(s))
332 except: text = s
323 self.SetCellValue(rowi,i,text) 333 self.SetCellValue(rowi,i,text)
324 334
325 def add_row(self,evt=None): 335 def add_row(self,evt=None):
326 cols = self.GetNumberCols() 336 cols = self.GetNumberCols()
327 row = Element('row') 337 row = Element('row')
357 cells = r.findall('cell') 367 cells = r.findall('cell')
358 r.remove(r[num-1]) # always remove the last column -- nasty 368 r.remove(r[num-1]) # always remove the last column -- nasty
359 self.DeleteCols(num-1,1) 369 self.DeleteCols(num-1,1)
360 self.set_col_widths() 370 self.set_col_widths()
361 371
372 def get_value(self, row, col):
373 cells = self.rows[row].findall('cell')
374 return cells[col].text
375
362 376
363 G_TITLE = wx.NewId() 377 G_TITLE = wx.NewId()
364 GRID_BOR = wx.NewId() 378 GRID_BOR = wx.NewId()
365 class rpg_grid_panel(wx.Panel): 379 class rpg_grid_panel(wx.Panel):
366 def __init__(self, parent, handler): 380 def __init__(self, parent, handler):
367 wx.Panel.__init__(self, parent, -1) 381 wx.Panel.__init__(self, parent, -1)
368 self.handler = handler 382 self.handler = handler
369 self.grid = rpg_grid(self, handler) 383 self.grid = rpg_grid(self, handler, mode=0)
370 label = handler.xml.get('name') 384 label = handler.xml.get('name')
371 self.main_sizer = wx.BoxSizer(wx.VERTICAL) 385 self.main_sizer = wx.BoxSizer(wx.VERTICAL)
372 self.main_sizer.Add(wx.StaticText(self, -1, label+": "), 0, wx.EXPAND) 386 self.main_sizer.Add(wx.StaticText(self, -1, label+": "), 0, wx.EXPAND)
373 self.main_sizer.Add(self.grid,1,wx.EXPAND) 387 self.main_sizer.Add(self.grid,1,wx.EXPAND)
374 self.SetSizer(self.main_sizer) 388 self.SetSizer(self.main_sizer)
386 class rpg_grid_edit_panel(wx.Panel): 400 class rpg_grid_edit_panel(wx.Panel):
387 def __init__(self, parent, handler): 401 def __init__(self, parent, handler):
388 wx.Panel.__init__(self, parent, -1) 402 wx.Panel.__init__(self, parent, -1)
389 self.handler = handler 403 self.handler = handler
390 self.parent = parent 404 self.parent = parent
391 self.grid = rpg_grid(self,handler) 405 self.grid = rpg_grid(self,handler, mode=1)
392 self.main_sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Grid"), wx.VERTICAL) 406 self.main_sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Grid"), wx.VERTICAL)
393 407
394 self.title = wx.TextCtrl(self, G_TITLE, handler.xml.get('name')) 408 self.title = wx.TextCtrl(self, G_TITLE, handler.xml.get('name'))
395 409
396 radio_b = wx.RadioBox(self, GRID_BOR, "Border (HTML)", choices=["no","yes"]) 410 radio_b = wx.RadioBox(self, GRID_BOR, "Border (HTML)", choices=["no","yes"])
460 row = str(evt.GetRow()+1) 474 row = str(evt.GetRow()+1)
461 col = str(evt.GetCol()+1) 475 col = str(evt.GetCol()+1)
462 complete = complete[:len(complete)-2] + '::'+'('+row+','+col+')'+complete[len(complete)-2:] 476 complete = complete[:len(complete)-2] + '::'+'('+row+','+col+')'+complete[len(complete)-2:]
463 col = self.grid.GetGridCursorCol() 477 col = self.grid.GetGridCursorCol()
464 row = self.grid.GetGridCursorRow() 478 row = self.grid.GetGridCursorRow()
479 temp_value = self.grid.GetCellValue(row, col)
480 complete = temp_value + complete
465 self.grid.SetCellValue(row, col, complete) 481 self.grid.SetCellValue(row, col, complete)
466 cells = self.grid.rows[row].findall('cell') 482 cells = self.grid.rows[row].findall('cell')
467 cells[col].text = complete 483 cells[col].text = complete
468 self.mini_grid.Destroy() 484 self.mini_grid.Destroy()
469 485
503 if obj.xml.get('class') == 'rpg_grid_handler': 519 if obj.xml.get('class') == 'rpg_grid_handler':
504 self.get_grid_ref(obj, complete) 520 self.get_grid_ref(obj, complete)
505 else: 521 else:
506 col = self.grid.GetGridCursorCol() 522 col = self.grid.GetGridCursorCol()
507 row = self.grid.GetGridCursorRow() 523 row = self.grid.GetGridCursorRow()
524 temp_value = self.grid.GetCellValue(row, col)
525 complete = temp_value + complete
508 self.grid.SetCellValue(row, col, complete) 526 self.grid.SetCellValue(row, col, complete)
509 cells = self.grid.rows[row].findall('cell') 527 cells = self.grid.rows[row].findall('cell')
510 cells[col].text = complete 528 cells[col].text = complete
511 self.do_tree.Destroy() 529 self.do_tree.Destroy()
512 if do == 'None': 530 if do == 'None':
525 def on_text(self,evt): 543 def on_text(self,evt):
526 txt = self.title.GetValue() 544 txt = self.title.GetValue()
527 if txt != "": 545 if txt != "":
528 self.handler.xml.set('name',txt) 546 self.handler.xml.set('name',txt)
529 self.handler.rename(txt) 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)