]> git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/demo/XMLtreeview.py
Cleaned up paint DC cache in ~wxPaintDC to avoid spurious memory warning
[wxWidgets.git] / utils / wxPython / demo / XMLtreeview.py
1
2 import string
3
4 from wxPython.wx import *
5 try:
6 from xml.parsers import pyexpat
7 haveXML = true
8 except ImportError:
9 haveXML = false
10
11 #----------------------------------------------------------------------
12
13 if 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
20 else:
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 id = self.AppendItem(self.nodeStack[-1], name)
30 self.nodeStack.append(id)
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
65 overview = """\
66 """
67