]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/XmlResource.py
wxGTK_CONV -> wxGTK_CONV_SYS
[wxWidgets.git] / wxPython / demo / XmlResource.py
1
2 import wx
3 import wx.xrc as xrc
4
5 from Main import opj
6
7 #----------------------------------------------------------------------
8
9 RESFILE = opj("data/resource_wdr.xrc")
10
11 class TestPanel(wx.Panel):
12 def __init__(self, parent, log):
13 wx.Panel.__init__(self, parent, -1)
14 self.log = log
15
16 # make the components
17 label = wx.StaticText(self, -1, "The lower panel was built from this XML:")
18 label.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD))
19
20 resourceText = open(RESFILE).read()
21 text = wx.TextCtrl(self, -1, resourceText,
22 style=wx.TE_READONLY|wx.TE_MULTILINE)
23 text.SetInsertionPoint(0)
24
25 line = wx.StaticLine(self, -1)
26
27 # This shows a few different ways to load XML Resources
28 if 0:
29 # XML Resources can be loaded from a file like this:
30 res = xrc.XmlResource(RESFILE)
31
32 elif 1:
33 # or from a Virtual FileSystem:
34 wx.FileSystem_AddHandler(wx.MemoryFSHandler())
35 wx.MemoryFSHandler_AddFile("XRC_Resources/data_file", resourceText)
36 res = xrc.XmlResource("memory:XRC_Resources/data_file")
37
38 else:
39 # or from a string, like this:
40 res = xrc.EmptyXmlResource()
41 res.LoadFromString(resourceText)
42
43
44 # Now create a panel from the resource data
45 panel = res.LoadPanel(self, "MyPanel")
46
47 # and do the layout
48 sizer = wx.BoxSizer(wx.VERTICAL)
49 sizer.Add(label, 0, wx.EXPAND|wx.TOP|wx.LEFT, 5)
50 sizer.Add(text, 1, wx.EXPAND|wx.ALL, 5)
51 sizer.Add(line, 0, wx.EXPAND)
52 sizer.Add(panel, 1, wx.EXPAND|wx.ALL, 5)
53
54 self.SetSizer(sizer)
55 self.SetAutoLayout(True)
56
57
58 #----------------------------------------------------------------------
59
60 def runTest(frame, nb, log):
61 win = TestPanel(nb, log)
62 return win
63
64 #----------------------------------------------------------------------
65
66
67
68 overview = """
69 """
70
71
72 if __name__ == '__main__':
73 import sys,os
74 import run
75 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
76