Relying on a global attribute in 'Grid' being an actual wx.Grid object
is not a good idea.
import sys, string
from xml.dom import minidom, Node
import Grid
class Parser:
def __init__(self, grid):
self.grid = grid #just pass the grid you want to use
def walk(self,parent,level):
for node in parent.childNodes:
if node.nodeType==Node.ELEMENT_NODE:
#print "\nElement: %s" %node.nodeName
attrs=node.attributes
tableAttr=('chain','policy')
ruleAttr=('num', 'protocol', 'option', 'source', 'destination','target')
if node.nodeName=='table':
attrNode=attrs.get('chain')
chainValue=attrNode.nodeValue
attrNode=attrs.get('policy')
policyValue=attrNode.nodeValue
#print "\nChain: %s --- Policy: %s" %(chainValue,policyValue)
if node.nodeName=='rule':
attrNode=attrs.get('num')
numValue=attrNode.nodeValue
attrNode=attrs.get('protocol')
protocolValue=attrNode.nodeValue
attrNode=attrs.get('option')
optionValue=attrNode.nodeValue
attrNode=attrs.get('source')
sourceValue=attrNode.nodeValue
attrNode=attrs.get('destination')
destinationValue=attrNode.nodeValue
attrNode=attrs.get('target')
targetValue=attrNode.nodeValue
self.createRow(chainValue,policyValue,numValue,protocolValue,optionValue,sourceValue,destinationValue,targetValue)
self.walk(node, level+1)
def run (self):
doc=minidom.parse("iptResponse.xml")
rootNode=doc.documentElement
level=0
self.walk(rootNode,level)
def creteRow (self,chainValue,policyValue,numValue,protocolValue,optionValue,sourceValue,destinationValue,targetValue):
self.grid.AppendRows(1)
self.grid.GetNumberRows()-1
self.grid.SetRowLabelValue(row,"")
self.grid.SetCellValue(row,0,chainValue)
self.grid.SetCellValue(row,1,policyValue)
self.grid.SetCellValue(row,2,numValue)
self.grid.SetCellValue(row,3,protocolValue)
self.grid.SetCellValue(row,4,optionValue)
self.grid.SetCellValue(row,5,sourceValue)
self.grid.SetCellValue(row,6,destinationValue)
self.grid.SetCellValue(row,7,targetValue)
if __name__=="__main__":
parser=Parser()
parser.run()
Unless you are creating a grid object inside of Grid, createRow won't
work, and even if you are, you aren't creating a wx.App() object, and
you aren't calling the app's .mainloop() method anywhere.
If you want to create a "dialog", you can use a wx.Dialog object instead
of a wx.Frame object as the parent to your panels, grids, etc., and you
can .Show() or .ShowModal() to show them. Read the documentation for
what they do and how to use them.
- Josiah
···
Sbaush <sbaush@gmail.com> wrote: