Mercurial > traipse_dev
comparison orpg/gametree/nodehandlers/rpg_grid.py @ 118:217fb049bd00 alpha
Traipse Alpha 'OpenRPG' {091028-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:
Adds Bookmarks (Alpha) with cool Smiley Star and Plus Symbol images!
Changes made to the map for increased portability. SnowDog has changes planned in
Core, though.
Added an initial push to the BCG. Not much to see, just shows off how it is
re-writing Main code.
Fix to remote admin commands
Minor fix to texted based server, works in /System/ folder
Some Core changes to gametree to correctly disply Pretty Print, thanks David!
Fix to Splitter Nodes not being created.
Added images to Plugin Control panel for Autostart feature
Fix to massive amounts of images loading; from Core
fix to gsclient so with_statement imports
Added 'boot' command to remote admin
Prep work in Pass tool for remote admin rankings and different passwords, ei,
Server, Admin, Moderator, etc.
Remote Admin Commands more organized, more prep work.
Added Confirmation window for sent nodes.
Minor changes to allow for portability to an OpenSUSE linux OS (hopefully without
breaking)
{091028}
00:
Made changes to gametree to start working with Element Tree, mostly from Core
Minor changes to Map to start working with Element Tree, from Core
Preliminary changes to map efficiency, from FlexiRPG
Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG
Changes to main.py to start working with Element Tree
author | sirebral |
---|---|
date | Wed, 28 Oct 2009 14:24:54 -0500 |
parents | eb1b275699c4 |
children | d54e1328dbb1 |
comparison
equal
deleted
inserted
replaced
117:0f18d16f3fe7 | 118:217fb049bd00 |
---|---|
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 1.20 2006/11/15 12:11:24 digitalxero 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 | |
34 | 33 |
35 class rpg_grid_handler(node_handler): | 34 class rpg_grid_handler(node_handler): |
36 """ Node handler for rpg grid tool | 35 """ Node handler for rpg grid tool |
37 <nodehandler module='rpg_grid' class='rpg_grid_handler' name='sample'> | 36 <nodehandler module='rpg_grid' class='rpg_grid_handler' name='sample'> |
38 <grid border='' autosize='1' > | 37 <grid border='' autosize='1' > |
48 <macros> | 47 <macros> |
49 <macro name=''/> | 48 <macro name=''/> |
50 </macros> | 49 </macros> |
51 </nodehandler> | 50 </nodehandler> |
52 """ | 51 """ |
53 def __init__(self,xml_dom,tree_node): | 52 def __init__(self,xml,tree_node): |
54 node_handler.__init__(self,xml_dom,tree_node) | 53 node_handler.__init__(self,xml,tree_node) |
55 self.grid = self.master_dom.getElementsByTagName('grid')[0] | 54 self.grid = self.xml.find('grid') |
56 if self.grid.getAttribute("border") == "": | 55 if self.grid.get("border") == "": |
57 self.grid.setAttribute("border","1") | 56 self.grid.set("border","1") |
58 if self.grid.getAttribute("autosize") == "": | 57 if self.grid.get("autosize") == "": |
59 self.grid.setAttribute("autosize","1") | 58 self.grid.set("autosize","1") |
60 self.macros = self.master_dom.getElementsByTagName('macros')[0] | 59 self.macros = self.xml.find('macros') |
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 == '': |
76 if t_node == None: | |
77 name = "Row" | |
78 else: | |
79 name = t_node._get_nodeValue() | |
80 if name == "": | |
81 name = "Row" | 75 name = "Row" |
82 new_tree_node = tree.AppendItem(self.mytree_node,name,icons['gear'],icons['gear']) | 76 new_tree_node = tree.AppendItem(self.mytree_node,name,icons['gear'],icons['gear']) |
83 handler = grid_row_handler(n,new_tree_node,self) | 77 handler = grid_row_handler(row,new_tree_node,self) |
84 tree.SetPyData(new_tree_node,handler) | 78 tree.SetPyData(new_tree_node,handler) |
85 | 79 |
86 | |
87 def tohtml(self): | 80 def tohtml(self): |
88 border = self.grid.getAttribute("border") | 81 border = self.grid.get("border") |
89 name = self.master_dom.getAttribute('name') | 82 name = self.xml.get('name') |
90 rows = self.grid.getElementsByTagName('row') | 83 rows = self.grid.findall('row') |
91 colspan = str(len(rows[0].getElementsByTagName('cell'))) | 84 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>" | 85 html_str = "<table border=\""+border+"\" align=center><tr bgcolor=\""+TH_BG+"\" ><th colspan="+colspan+">"+name+"</th></tr>" |
93 for r in rows: | 86 for r in rows: |
94 cells = r.getElementsByTagName('cell') | 87 cells = r.findall('cell') |
95 html_str += "<tr>" | 88 html_str += "<tr>" |
96 for c in cells: | 89 for c in cells: |
97 #html_str += "<td width='"+c.getAttribute('size')+"' >" bug here | 90 #html_str += "<td width='"+c.get('size')+"' >" bug here |
98 html_str += "<td >" | 91 html_str += "<td >" |
99 t_node = c._get_firstChild() | 92 text = c.text |
100 if t_node == None: | 93 if text == None or text == '': |
101 html_str += "<br /></td>" | 94 text = '<br />' |
102 else: | 95 html_str += text + "</td>" |
103 html_str += t_node._get_nodeValue() + "</td>" | |
104 html_str += "</tr>" | 96 html_str += "</tr>" |
105 html_str += "</table>" | 97 html_str += "</table>" |
106 return html_str | 98 return html_str |
107 | 99 |
108 def get_design_panel(self,parent): | 100 def get_design_panel(self,parent): |
113 | 105 |
114 def get_size_constraint(self): | 106 def get_size_constraint(self): |
115 return 1 | 107 return 1 |
116 | 108 |
117 def is_autosized(self): | 109 def is_autosized(self): |
118 return self.grid.getAttribute("autosize") | 110 return self.grid.get("autosize") |
119 | 111 |
120 def set_autosize(self,autosize=1): | 112 def set_autosize(self,autosize=1): |
121 self.grid.setAttribute("autosize",str(autosize)) | 113 self.grid.set("autosize",str(autosize)) |
122 | 114 |
123 class grid_row_handler(node_handler): | 115 class grid_row_handler(node_handler): |
124 """ Node Handler grid row. | 116 """ Node Handler grid row. |
125 """ | 117 """ |
126 def __init__(self,xml_dom,tree_node,parent): | 118 def __init__(self,xml,tree_node,parent): |
127 node_handler.__init__(self,xml_dom,tree_node) | 119 node_handler.__init__(self,xml,tree_node) |
128 self.drag = False | 120 self.drag = False |
129 | 121 |
130 def on_drop(self,evt): | 122 def on_drop(self,evt): |
131 pass | 123 pass |
132 | 124 |
133 def can_clone(self): | 125 def can_clone(self): |
134 return 0; | 126 return 0; |
135 | 127 |
136 def tohtml(self): | 128 def tohtml(self): |
137 cells = self.master_dom.getElementsByTagName('cell') | 129 cells = self.xml.findall('cell') |
138 html_str = "<table border=1 align=center><tr >" | 130 html_str = "<table border=1 align=center><tr >" |
139 for c in cells: | 131 for c in cells: # should loop over rows first, then cells |
140 html_str += "<td >" | 132 html_str += "<td >" |
141 t_node = c._get_firstChild() | 133 text = c.text |
142 if t_node == None: | 134 if text == '' or text is None: |
143 html_str += "<br /></td>" | 135 text = '<br />' |
144 else: | 136 html_str += text + "</td>" |
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: | |
144 return getText(cells[1]) | |
145 else: | |
146 return None | |
147 | |
148 def set_value(self, new_value): | |
149 cells = self.xml.findall('cell') | |
150 if len(cells) == 2: | |
151 cells[1].text = new_value | |
149 | 152 |
150 class MyCellEditor(wx.grid.PyGridCellEditor): | 153 class MyCellEditor(wx.grid.PyGridCellEditor): |
151 """ | 154 """ |
152 This is a sample GridCellEditor that shows you how to make your own custom | 155 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 | 156 grid editors. All the methods that can be overridden are show here. The |
282 self._tc.AppendText(ch) | 285 self._tc.AppendText(ch) |
283 else: | 286 else: |
284 evt.Skip() | 287 evt.Skip() |
285 | 288 |
286 | 289 |
290 | |
287 def Destroy(self): | 291 def Destroy(self): |
288 """final cleanup""" | 292 """final cleanup""" |
289 self.base_Destroy() | 293 self.base_Destroy() |
290 | 294 |
291 | 295 |
306 self.handler = handler | 310 self.handler = handler |
307 | 311 |
308 # Registers a "custom" cell editor (really the example from Robin Dunn with minor mods | 312 # 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()) | 313 self.RegisterDataType(wx.grid.GRID_VALUE_STRING, wx.grid.GridCellStringRenderer(),MyCellEditor()) |
310 | 314 |
311 self.rows = handler.grid.getElementsByTagName('row') | 315 self.rows = handler.grid.findall('row') |
312 rows = len(self.rows) | 316 rows = len(self.rows) |
313 cols = len(self.rows[0].getElementsByTagName('cell')) | 317 cols = len(self.rows[0].findall('cell')) |
314 self.CreateGrid(rows,cols) | 318 self.CreateGrid(rows,cols) |
315 self.SetRowLabelSize(0) | 319 self.SetRowLabelSize(0) |
316 self.SetColLabelSize(0) | 320 self.SetColLabelSize(0) |
317 self.set_col_widths() | 321 self.set_col_widths() |
318 | 322 |
328 if self.CanEnableCellControl(): | 332 if self.CanEnableCellControl(): |
329 self.EnableCellEditControl() | 333 self.EnableCellEditControl() |
330 | 334 |
331 def on_col_size(self, evt): | 335 def on_col_size(self, evt): |
332 col = evt.GetRowOrCol() | 336 col = evt.GetRowOrCol() |
333 cells = self.rows[0].getElementsByTagName('cell') | 337 cells = self.rows[0].findall('cell') |
334 size = self.GetColSize(col) | 338 size = self.GetColSize(col) |
335 cells[col].setAttribute('size',str(size)) | 339 cells[col].set('size',str(size)) |
336 evt.Skip() | 340 evt.Skip() |
337 | 341 |
338 def on_cell_change(self,evt): | 342 def on_cell_change(self,evt): |
339 row = evt.GetRow() | 343 row = evt.GetRow() |
340 col = evt.GetCol() | 344 col = evt.GetCol() |
341 value = self.GetCellValue(row,col) | 345 value = self.GetCellValue(row,col) |
342 cells = self.rows[row].getElementsByTagName('cell') | 346 cells = self.rows[row].findall('cell') |
343 t_node = cells[col]._get_firstChild() | 347 cells[col].text = value |
344 t_node._set_nodeValue(value) | |
345 if col == 0: | 348 if col == 0: |
346 self.handler.refresh_rows() | 349 self.handler.refresh_rows() |
347 | 350 |
348 def set_col_widths(self): | 351 def set_col_widths(self): |
349 cells = self.rows[0].getElementsByTagName('cell') | 352 cells = self.rows[0].findall('cell') |
350 for i in range(0,len(cells)): | 353 for i in range(0,len(cells)): |
351 try: | 354 try: |
352 size = int(cells[i].getAttribute('size')) | 355 size = int(cells[i].get('size')) |
353 self.SetColSize(i,size) | 356 self.SetColSize(i,size) |
354 except: | 357 except: |
355 continue | 358 continue |
356 | 359 |
357 def refresh_row(self,rowi): | 360 def refresh_row(self,rowi): |
358 cells = self.rows[rowi].getElementsByTagName('cell') | 361 cells = self.rows[rowi].findall('cell') |
359 for i in range(0,len(cells)): | 362 for i in range(0,len(cells)): |
360 t_node = cells[i]._get_firstChild() | 363 text = cells[i].text |
361 if t_node == None: | 364 if text == None or text == '': |
362 #doc = cells[i].ownerDocument | 365 text = '' |
363 #t_node = doc.createTextNode("") | 366 cells[i].text = text |
364 t_node = Text("") | 367 self.SetCellValue(rowi,i,text) |
365 t_node = cells[i].appendChild(t_node) | |
366 self.SetCellValue(rowi,i,t_node._get_nodeValue()) | |
367 | 368 |
368 def add_row(self,evt=None): | 369 def add_row(self,evt=None): |
369 cols = self.GetNumberCols() | 370 cols = self.GetNumberCols() |
370 #doc = self.handler.grid.ownerDocument | 371 row = ET.Element('row') |
371 #row = doc.createElement('row') | |
372 row = Element('row') | |
373 for i in range(0,cols): | 372 for i in range(0,cols): |
374 #cell = doc.createElement('cell') | 373 cell = ET.Element('cell') |
375 cell = Element('cell') | 374 cell.text = '' |
376 #t_node = doc.createTextNode("") | 375 row.append(cell) |
377 t_node = Text("") | 376 self.handler.grid.append(row) |
378 t_node = cell.appendChild(t_node) | |
379 row.appendChild(cell) | |
380 self.handler.grid.appendChild(row) | |
381 self.AppendRows(1) | 377 self.AppendRows(1) |
382 self.rows = self.handler.grid.getElementsByTagName('row') | 378 self.rows = self.handler.grid.findall('row') |
383 self.handler.refresh_rows() | 379 self.handler.refresh_rows() |
384 | 380 |
385 def add_col(self,evt=None): | 381 def add_col(self,evt=None): |
386 #doc = self.handler.grid.ownerDocument | |
387 for r in self.rows: | 382 for r in self.rows: |
388 #cell = doc.createElement('cell') | 383 cell = ET.Element('cell') |
389 cell = Element('cell') | 384 cell.text = '' |
390 #t_node = doc.createTextNode("") | 385 r.append(cell) |
391 t_node = Text("") | |
392 t_node = cell.appendChild(t_node) | |
393 r.appendChild(cell) | |
394 self.AppendCols(1) | 386 self.AppendCols(1) |
395 #self.fit_cols()::Where did this go? TaS. | 387 self.set_col_widths() |
396 | 388 |
397 def del_row(self,evt=None): | 389 def del_row(self,evt=None): |
398 num = self.GetNumberRows() | 390 num = self.GetNumberRows() |
399 row = self.rows[num-1] | 391 if num == 1: |
400 self.handler.grid.removeChild(row) | 392 return |
393 self.handler.grid.remove(self.handler.grid[num-1])#always remove last row -- nasty | |
401 self.DeleteRows(num-1,1) | 394 self.DeleteRows(num-1,1) |
402 self.rows = self.handler.grid.getElementsByTagName('row') | 395 self.rows = self.handler.grid.findall('row') |
403 self.handler.refresh_rows() | 396 self.handler.refresh_rows() |
404 | 397 |
405 def del_col(self,evt=None): | 398 def del_col(self,evt=None): |
406 num = self.GetNumberCols() | 399 num = self.GetNumberCols() |
400 if num == 1: | |
401 return | |
407 for r in self.rows: | 402 for r in self.rows: |
408 cells = r.getElementsByTagName('cell') | 403 cells = r.findall('cell') |
409 r.removeChild(cells[num-1]) | 404 r.remove(r[num-1])# always remove the last column -- nasty |
410 self.DeleteCols(num-1,1) | 405 self.DeleteCols(num-1,1) |
411 #self.fit_cols()::Where did this go? TaS. | 406 self.set_col_widths() |
412 | 407 |
413 | 408 |
414 G_TITLE = wx.NewId() | 409 G_TITLE = wx.NewId() |
415 GRID_BOR = wx.NewId() | 410 GRID_BOR = wx.NewId() |
416 class rpg_grid_panel(wx.Panel): | 411 class rpg_grid_panel(wx.Panel): |
417 def __init__(self, parent, handler): | 412 def __init__(self, parent, handler): |
418 wx.Panel.__init__(self, parent, -1) | 413 wx.Panel.__init__(self, parent, -1) |
419 self.handler = handler | 414 self.handler = handler |
420 self.grid = rpg_grid(self,handler) | 415 self.grid = rpg_grid(self,handler) |
421 label = handler.master_dom.getAttribute('name') | 416 label = handler.xml.get('name') |
422 self.main_sizer = wx.BoxSizer(wx.VERTICAL) | 417 self.main_sizer = wx.BoxSizer(wx.VERTICAL) |
423 self.main_sizer.Add(wx.StaticText(self, -1, label+": "), 0, wx.EXPAND) | 418 self.main_sizer.Add(wx.StaticText(self, -1, label+": "), 0, wx.EXPAND) |
424 self.main_sizer.Add(self.grid,1,wx.EXPAND) | 419 self.main_sizer.Add(self.grid,1,wx.EXPAND) |
425 self.SetSizer(self.main_sizer) | 420 self.SetSizer(self.main_sizer) |
426 self.SetAutoLayout(True) | 421 self.SetAutoLayout(True) |
437 class rpg_grid_edit_panel(wx.Panel): | 432 class rpg_grid_edit_panel(wx.Panel): |
438 def __init__(self, parent, handler): | 433 def __init__(self, parent, handler): |
439 wx.Panel.__init__(self, parent, -1) | 434 wx.Panel.__init__(self, parent, -1) |
440 self.handler = handler | 435 self.handler = handler |
441 self.grid = rpg_grid(self,handler) | 436 self.grid = rpg_grid(self,handler) |
442 self.title = wx.TextCtrl(self, G_TITLE, handler.master_dom.getAttribute('name')) | 437 self.title = wx.TextCtrl(self, G_TITLE, handler.xml.get('name')) |
443 | 438 |
444 radio_b = wx.RadioBox(self, GRID_BOR, "Border (HTML)", choices=["no","yes"]) | 439 radio_b = wx.RadioBox(self, GRID_BOR, "Border (HTML)", choices=["no","yes"]) |
445 border = handler.grid.getAttribute("border") | 440 border = handler.grid.get("border") |
446 radio_b.SetSelection(int(border)) | 441 radio_b.SetSelection(int(border)) |
447 | 442 |
448 self.auto_size = wx.CheckBox(self, G_AUTO_SIZE, " Auto Size") | 443 self.auto_size = wx.CheckBox(self, G_AUTO_SIZE, " Auto Size") |
449 if handler.is_autosized() == '1': | 444 if handler.is_autosized() == '1': |
450 self.auto_size.SetValue(True) | 445 self.auto_size.SetValue(True) |
485 | 480 |
486 def on_radio_box(self,evt): | 481 def on_radio_box(self,evt): |
487 id = evt.GetId() | 482 id = evt.GetId() |
488 index = evt.GetInt() | 483 index = evt.GetInt() |
489 if id == GRID_BOR: | 484 if id == GRID_BOR: |
490 self.handler.grid.setAttribute("border",str(index)) | 485 self.handler.grid.set("border",str(index)) |
491 | 486 |
492 def on_text(self,evt): | 487 def on_text(self,evt): |
493 txt = self.title.GetValue() | 488 txt = self.title.GetValue() |
494 if txt != "": | 489 if txt != "": |
495 self.handler.master_dom.setAttribute('name',txt) | 490 self.handler.xml.set('name',txt) |
496 self.handler.rename(txt) | 491 self.handler.rename(txt) |