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 id = self
.AppendItem(self
.nodeStack
[-1], name
)
30 self
.nodeStack
.append(id)
32 def EndElement(self
, name
):
33 self
.nodeStack
= self
.nodeStack
[:-1]
35 def CharacterData(self
, data
):
36 if string
.strip(data
):
37 self
.AppendItem(self
.nodeStack
[-1], data
)
40 def LoadTree(self
, filename
):
42 Parser
= pyexpat
.ParserCreate()
44 # Tell the parser what the start element handler is
45 Parser
.StartElementHandler
= self
.StartElement
46 Parser
.EndElementHandler
= self
.EndElement
47 Parser
.CharacterDataHandler
= self
.CharacterData
50 ParserStatus
= Parser
.Parse(open(filename
,'r').read(), 1)
53 def runTest(frame
, nb
, log
):
55 win
.LoadTree("paper.xml")
58 #----------------------------------------------------------------------