4 from wxPython
.wx
import *
6 from xml
.parsers
import pyexpat
11 #----------------------------------------------------------------------
14 def runTest(frame
, nb
, log
):
15 dlg
= wxMessageDialog(frame
, 'This demo requires the XML package. See http://www.python.org/sigs/xml-sig/',
16 'Sorry', wxOK | wxICON_INFORMATION
)
22 class XMLTree(wxTreeCtrl
):
23 def __init__(self
, parent
, ID
):
24 wxTreeCtrl
.__init
__(self
, parent
, ID
)
25 self
.nodeStack
= [self
.AddRoot("Root")]
27 # Define a handler for start element events
28 def StartElement(self
, name
, attrs
):
29 self
.nodeStack
.append(self
.AppendItem(self
.nodeStack
[-1], name
))
31 def EndElement(self
, name
):
32 self
.nodeStack
= self
.nodeStack
[:-1]
34 def CharacterData(self
, data
):
35 if string
.strip(data
):
36 self
.AppendItem(self
.nodeStack
[-1], data
)
39 def LoadTree(self
, filename
):
41 Parser
= pyexpat
.ParserCreate()
43 # Tell the parser what the start element handler is
44 Parser
.StartElementHandler
= self
.StartElement
45 Parser
.EndElementHandler
= self
.EndElement
46 Parser
.CharacterDataHandler
= self
.CharacterData
49 ParserStatus
= Parser
.Parse(open(filename
,'r').read(), 1)
52 def runTest(frame
, nb
, log
):
54 win
.LoadTree("paper.xml")
57 #----------------------------------------------------------------------