]> git.saurik.com Git - wxWidgets.git/blame - utils/wxPython/demo/XMLtreeview.py
forgot to add the image with binary flags
[wxWidgets.git] / utils / wxPython / demo / XMLtreeview.py
CommitLineData
8bf5d46e
RD
1
2import string
3
4from wxPython.wx import *
5try:
6 from xml.parsers import pyexpat
7 haveXML = true
8except ImportError:
9 haveXML = false
10
11#----------------------------------------------------------------------
12
13if not haveXML:
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)
17 dlg.ShowModal()
18 dlg.Destroy()
19
20else:
21
22 class XMLTree(wxTreeCtrl):
23 def __init__(self, parent, ID):
24 wxTreeCtrl.__init__(self, parent, ID)
25 self.nodeStack = [self.AddRoot("Root")]
26
27 # Define a handler for start element events
28 def StartElement(self, name, attrs ):
9d8bd15f
RD
29 id = self.AppendItem(self.nodeStack[-1], name)
30 self.nodeStack.append(id)
8bf5d46e
RD
31
32 def EndElement(self, name ):
33 self.nodeStack = self.nodeStack[:-1]
34
35 def CharacterData(self, data ):
36 if string.strip(data):
37 self.AppendItem(self.nodeStack[-1], data)
38
39
40 def LoadTree(self, filename):
41 # Create a parser
42 Parser = pyexpat.ParserCreate()
43
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
48
49 # Parse the XML File
50 ParserStatus = Parser.Parse(open(filename,'r').read(), 1)
51
52
53 def runTest(frame, nb, log):
54 win = XMLTree(nb, -1)
55 win.LoadTree("paper.xml")
56 return win
57
58#----------------------------------------------------------------------
59
60
61
62
63
64
65overview = """\
66"""
67