]> git.saurik.com Git - wxWidgets.git/blame - utils/wxPython/demo/XMLtreeview.py
The beginings of wxHtmlWindow support in the wxPython demo
[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 ):
29 self.nodeStack.append(self.AppendItem(self.nodeStack[-1], name))
30
31 def EndElement(self, name ):
32 self.nodeStack = self.nodeStack[:-1]
33
34 def CharacterData(self, data ):
35 if string.strip(data):
36 self.AppendItem(self.nodeStack[-1], data)
37
38
39 def LoadTree(self, filename):
40 # Create a parser
41 Parser = pyexpat.ParserCreate()
42
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
47
48 # Parse the XML File
49 ParserStatus = Parser.Parse(open(filename,'r').read(), 1)
50
51
52 def runTest(frame, nb, log):
53 win = XMLTree(nb, -1)
54 win.LoadTree("paper.xml")
55 return win
56
57#----------------------------------------------------------------------
58
59
60
61
62
63
64overview = """\
65"""
66