diff 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
line wrap: on
line diff
--- a/orpg/gametree/nodehandlers/rpg_grid.py	Mon Oct 12 23:24:10 2009 -0500
+++ b/orpg/gametree/nodehandlers/rpg_grid.py	Wed Oct 28 14:24:54 2009 -0500
@@ -29,8 +29,7 @@
 __version__ = "$Id: rpg_grid.py,v 1.20 2006/11/15 12:11:24 digitalxero Exp $"
 
 from core import *
-from forms import *
-from orpg.minidom import Element, Text
+from forms import *
 
 class rpg_grid_handler(node_handler):
     """ Node handler for rpg grid tool
@@ -50,14 +49,14 @@
   </macros>
 </nodehandler>
     """
-    def __init__(self,xml_dom,tree_node):
-        node_handler.__init__(self,xml_dom,tree_node)
-        self.grid = self.master_dom.getElementsByTagName('grid')[0]
-        if self.grid.getAttribute("border") == "":
-            self.grid.setAttribute("border","1")
-        if self.grid.getAttribute("autosize") == "":
-            self.grid.setAttribute("autosize","1")
-        self.macros = self.master_dom.getElementsByTagName('macros')[0]
+    def __init__(self,xml,tree_node):
+        node_handler.__init__(self,xml,tree_node)
+        self.grid = self.xml.find('grid')
+        if self.grid.get("border") == "":
+            self.grid.set("border","1")
+        if self.grid.get("autosize") == "":
+            self.grid.set("autosize","1")
+        self.macros = self.xml.find('macros')
         self.myeditor = None
         self.refresh_rows()
 
@@ -69,38 +68,31 @@
         tree = self.tree
         icons = self.tree.icons
         tree.CollapseAndReset(self.mytree_node)
-        node_list = self.master_dom.getElementsByTagName('row')
-        for n in node_list:
-            cells = n.getElementsByTagName('cell')
-            t_node = cells[0]._get_firstChild()
-            if t_node == None:
-                name = "Row"
-            else:
-                name = t_node._get_nodeValue()
-            if name == "":
+        for row in self.grid.findall('row'):
+            first_cell = row.find('cell')
+            name = first_cell.text
+            if name == None or name == '':
                 name = "Row"
             new_tree_node = tree.AppendItem(self.mytree_node,name,icons['gear'],icons['gear'])
-            handler = grid_row_handler(n,new_tree_node,self)
+            handler = grid_row_handler(row,new_tree_node,self)
             tree.SetPyData(new_tree_node,handler)
 
-
     def tohtml(self):
-        border = self.grid.getAttribute("border")
-        name = self.master_dom.getAttribute('name')
-        rows = self.grid.getElementsByTagName('row')
-        colspan = str(len(rows[0].getElementsByTagName('cell')))
+        border = self.grid.get("border")
+        name = self.xml.get('name')
+        rows = self.grid.findall('row')
+        colspan = str(len(rows[0].findall('cell')))
         html_str = "<table border=\""+border+"\" align=center><tr bgcolor=\""+TH_BG+"\" ><th colspan="+colspan+">"+name+"</th></tr>"
         for r in rows:
-            cells = r.getElementsByTagName('cell')
+            cells = r.findall('cell')
             html_str += "<tr>"
             for c in cells:
-                #html_str += "<td width='"+c.getAttribute('size')+"' >" bug here
+                #html_str += "<td width='"+c.get('size')+"' >" bug here
                 html_str += "<td >"
-                t_node = c._get_firstChild()
-                if t_node == None:
-                    html_str += "<br /></td>"
-                else:
-                    html_str += t_node._get_nodeValue() + "</td>"
+                text = c.text
+                if text == None or text == '':
+                    text = '<br />'
+                html_str += text + "</td>"
             html_str += "</tr>"
         html_str += "</table>"
         return html_str
@@ -115,16 +107,16 @@
         return 1
 
     def is_autosized(self):
-        return self.grid.getAttribute("autosize")
+        return self.grid.get("autosize")
 
     def set_autosize(self,autosize=1):
-        self.grid.setAttribute("autosize",str(autosize))
+        self.grid.set("autosize",str(autosize))
 
 class grid_row_handler(node_handler):
     """ Node Handler grid row.
     """
-    def __init__(self,xml_dom,tree_node,parent):
-        node_handler.__init__(self,xml_dom,tree_node)
+    def __init__(self,xml,tree_node,parent):
+        node_handler.__init__(self,xml,tree_node)
         self.drag = False
 
     def on_drop(self,evt):
@@ -134,19 +126,30 @@
         return 0;
 
     def tohtml(self):
-        cells = self.master_dom.getElementsByTagName('cell')
+        cells = self.xml.findall('cell')
         html_str = "<table border=1 align=center><tr >"
-        for c in cells:
+        for c in cells: # should loop over rows first, then cells
             html_str += "<td >"
-            t_node = c._get_firstChild()
-            if t_node == None:
-                html_str += "<br /></td>"
-            else:
-                html_str += t_node._get_nodeValue() + "</td>"
+            text = c.text
+            if text == '' or text is None:
+                text = '<br />'
+            html_str += text + "</td>"
             html_str += "</tr>"
         html_str += "</table>"
         return html_str
 
+    def get_value(self):
+        cells = self.xml.findall('cell')
+        if len(cells) == 2:
+            return getText(cells[1])
+        else:
+            return None
+
+    def set_value(self, new_value):
+        cells = self.xml.findall('cell')
+        if len(cells) == 2:
+            cells[1].text = new_value
+
 class MyCellEditor(wx.grid.PyGridCellEditor):
     """
     This is a sample GridCellEditor that shows you how to make your own custom
@@ -284,6 +287,7 @@
             evt.Skip()
 
 
+
     def Destroy(self):
         """final cleanup"""
         self.base_Destroy()
@@ -308,9 +312,9 @@
         #  Registers a "custom" cell editor (really the example from Robin Dunn with minor mods
         self.RegisterDataType(wx.grid.GRID_VALUE_STRING, wx.grid.GridCellStringRenderer(),MyCellEditor())
 
-        self.rows = handler.grid.getElementsByTagName('row')
+        self.rows = handler.grid.findall('row')
         rows = len(self.rows)
-        cols = len(self.rows[0].getElementsByTagName('cell'))
+        cols = len(self.rows[0].findall('cell'))
         self.CreateGrid(rows,cols)
         self.SetRowLabelSize(0)
         self.SetColLabelSize(0)
@@ -330,85 +334,76 @@
 
     def on_col_size(self, evt):
         col = evt.GetRowOrCol()
-        cells = self.rows[0].getElementsByTagName('cell')
+        cells = self.rows[0].findall('cell')
         size = self.GetColSize(col)
-        cells[col].setAttribute('size',str(size))
+        cells[col].set('size',str(size))
         evt.Skip()
 
     def on_cell_change(self,evt):
         row = evt.GetRow()
         col = evt.GetCol()
         value = self.GetCellValue(row,col)
-        cells = self.rows[row].getElementsByTagName('cell')
-        t_node = cells[col]._get_firstChild()
-        t_node._set_nodeValue(value)
+        cells = self.rows[row].findall('cell')
+        cells[col].text = value
         if col == 0:
             self.handler.refresh_rows()
 
     def set_col_widths(self):
-        cells = self.rows[0].getElementsByTagName('cell')
+        cells = self.rows[0].findall('cell')
         for i in range(0,len(cells)):
             try:
-                size = int(cells[i].getAttribute('size'))
+                size = int(cells[i].get('size'))
                 self.SetColSize(i,size)
             except:
                 continue
 
     def refresh_row(self,rowi):
-        cells = self.rows[rowi].getElementsByTagName('cell')
+        cells = self.rows[rowi].findall('cell')
         for i in range(0,len(cells)):
-            t_node = cells[i]._get_firstChild()
-            if t_node == None:
-                #doc = cells[i].ownerDocument
-                #t_node = doc.createTextNode("")
-                t_node = Text("")
-                t_node = cells[i].appendChild(t_node)
-            self.SetCellValue(rowi,i,t_node._get_nodeValue())
+            text = cells[i].text
+            if text == None or text == '':
+                text = ''
+                cells[i].text = text
+            self.SetCellValue(rowi,i,text)
 
     def add_row(self,evt=None):
         cols = self.GetNumberCols()
-        #doc = self.handler.grid.ownerDocument
-        #row = doc.createElement('row')
-        row = Element('row')
+        row = ET.Element('row')
         for i in range(0,cols):
-            #cell = doc.createElement('cell')
-            cell = Element('cell')
-            #t_node = doc.createTextNode("")
-            t_node = Text("")
-            t_node = cell.appendChild(t_node)
-            row.appendChild(cell)
-        self.handler.grid.appendChild(row)
+            cell = ET.Element('cell')
+            cell.text = ''
+            row.append(cell)
+        self.handler.grid.append(row)
         self.AppendRows(1)
-        self.rows = self.handler.grid.getElementsByTagName('row')
+        self.rows = self.handler.grid.findall('row')
         self.handler.refresh_rows()
 
     def add_col(self,evt=None):
-        #doc = self.handler.grid.ownerDocument
         for r in self.rows:
-            #cell = doc.createElement('cell')
-            cell = Element('cell')
-            #t_node = doc.createTextNode("")
-            t_node = Text("")
-            t_node = cell.appendChild(t_node)
-            r.appendChild(cell)
+            cell = ET.Element('cell')
+            cell.text = ''
+            r.append(cell)
         self.AppendCols(1)
-        #self.fit_cols()::Where did this go? TaS.
+        self.set_col_widths()
 
     def del_row(self,evt=None):
         num = self.GetNumberRows()
-        row = self.rows[num-1]
-        self.handler.grid.removeChild(row)
+        if num == 1:
+            return
+        self.handler.grid.remove(self.handler.grid[num-1])#always remove last row -- nasty
         self.DeleteRows(num-1,1)
-        self.rows = self.handler.grid.getElementsByTagName('row')
+        self.rows = self.handler.grid.findall('row')
         self.handler.refresh_rows()
 
     def del_col(self,evt=None):
         num = self.GetNumberCols()
+        if num == 1:
+            return
         for r in self.rows:
-            cells = r.getElementsByTagName('cell')
-            r.removeChild(cells[num-1])
+            cells = r.findall('cell')
+            r.remove(r[num-1])# always remove the last column -- nasty
         self.DeleteCols(num-1,1)
-        #self.fit_cols()::Where did this go? TaS.
+        self.set_col_widths()
 
 
 G_TITLE = wx.NewId()
@@ -418,7 +413,7 @@
         wx.Panel.__init__(self, parent, -1)
         self.handler = handler
         self.grid = rpg_grid(self,handler)
-        label = handler.master_dom.getAttribute('name')
+        label = handler.xml.get('name')
         self.main_sizer = wx.BoxSizer(wx.VERTICAL)
         self.main_sizer.Add(wx.StaticText(self, -1, label+": "), 0, wx.EXPAND)
         self.main_sizer.Add(self.grid,1,wx.EXPAND)
@@ -439,10 +434,10 @@
         wx.Panel.__init__(self, parent, -1)
         self.handler = handler
         self.grid = rpg_grid(self,handler)
-        self.title = wx.TextCtrl(self, G_TITLE, handler.master_dom.getAttribute('name'))
+        self.title = wx.TextCtrl(self, G_TITLE, handler.xml.get('name'))
 
         radio_b = wx.RadioBox(self, GRID_BOR, "Border (HTML)", choices=["no","yes"])
-        border = handler.grid.getAttribute("border")
+        border = handler.grid.get("border")
         radio_b.SetSelection(int(border))
 
         self.auto_size = wx.CheckBox(self, G_AUTO_SIZE, " Auto Size")
@@ -487,10 +482,10 @@
         id = evt.GetId()
         index = evt.GetInt()
         if id == GRID_BOR:
-            self.handler.grid.setAttribute("border",str(index))
+            self.handler.grid.set("border",str(index))
 
     def on_text(self,evt):
         txt = self.title.GetValue()
         if txt != "":
-            self.handler.master_dom.setAttribute('name',txt)
+            self.handler.xml.set('name',txt)
             self.handler.rename(txt)