import sys import urllib from xml.dom.minidom import parse from wxPython.wx import * def word_wrap(str, width=72): result = [] line = '' sp = '' for word in str.split(): if len(line) + len(sp) + len(word) <= width: line = line + sp + word sp = ' ' else: if len(line): result.append(line) line = word sp = ' ' if len(line): result.append(line) return result def node_to_wx_tree(d, tree, ID = None): string = d.getAttribute('text') if string == '': string = d.tagName string = string.encode('ascii', 'replace') if ID == None: chID = tree.AddRoot(string) else: chID = tree.AppendItem(ID, string) for node in d.childNodes: if node.nodeType == node.ELEMENT_NODE: node_to_wx_tree (node, tree, chID) if ID == None: tree.Expand(chID) class TestApplication (wxPySimpleApp): def OnInit(self): frame =wxFrame (NULL, -1, "test", size = (300,300)) panel = wxPanel(frame, -1 ) sizer = wxBoxSizer( wxVERTICAL) self.tree = wxTreeCtrl(panel) sizer.Add( self.tree, 1, wxEXPAND ) panel.SetSizer(sizer) panel.SetAutoLayout(true) frame.Show (1) self.SetTopWindow(frame) return 1 if __name__ == '__main__': url = sys.argv[1] f = urllib.urlopen(url) d = parse(f) root = d.childNodes[0] app = TestApplication() body = root.getElementsByTagName('body')[0] node_to_wx_tree(body, app.tree) app.MainLoop()