]>
Commit | Line | Data |
---|---|---|
8fa876ca RD |
1 | # 11/22/2003 - Jeff Grimmett (grimmtooth@softhome.net) |
2 | # | |
3 | # o Updated for wx namespace | |
4 | # | |
6fa68946 | 5 | |
8fa876ca RD |
6 | import wx |
7 | import wx.xrc as xrc | |
6fa68946 RD |
8 | |
9 | #---------------------------------------------------------------------- | |
10 | ||
11 | resourceText = r'''<?xml version="1.0"?> | |
12 | <resource> | |
13 | ||
14 | <!-- Notice that the class IS a standard wx class, and a custom | |
d14a1e28 RD |
15 | subclass is specified as "moduleName.ClassName" Try changing |
16 | the classname to one that does not exist and see what happens --> | |
6fa68946 RD |
17 | |
18 | <object class="wxPanel" subclass="wxXmlResourceSubclass.MyBluePanel" name="MyPanel"> | |
19 | <size>200,100</size> | |
d14a1e28 | 20 | <object class="wxStaticText" name="label1"> |
6fa68946 RD |
21 | <label>This blue panel is a class derived from wxPanel |
22 | and is loaded by a using a subclass attribute of the object tag.</label> | |
23 | <pos>10,10</pos> | |
24 | </object> | |
25 | </object> | |
26 | </resource> | |
27 | ''' | |
28 | ||
29 | #---------------------------------------------------------------------- | |
30 | ||
8fa876ca | 31 | class MyBluePanel(wx.Panel): |
6fa68946 | 32 | def __init__(self): |
8fa876ca | 33 | p = wx.PrePanel() |
d14a1e28 | 34 | self.PostCreate(p) |
6fa68946 | 35 | |
8fa876ca | 36 | self.Bind(wx.EVT_WINDOW_CREATE, self.OnCreate) |
6fa68946 RD |
37 | |
38 | def OnCreate(self, evt): | |
39 | # This is the little bit of customization that we do for this | |
40 | # silly example. It could just as easily have been done in | |
41 | # the resource. We do it in the EVT_WINDOW_CREATE handler | |
42 | # because the window doesn't really exist yet in the __init__. | |
43 | self.SetBackgroundColour("BLUE") | |
44 | self.SetForegroundColour("WHITE") | |
45 | ||
46 | #---------------------------------------------------------------------- | |
47 | ||
48 | ||
8fa876ca | 49 | class TestPanel(wx.Panel): |
6fa68946 RD |
50 | def __init__(self, parent, log): |
51 | self.log = log | |
8fa876ca | 52 | wx.Panel.__init__(self, parent, -1) |
6fa68946 RD |
53 | |
54 | # make the components | |
8fa876ca RD |
55 | label = wx.StaticText(self, -1, "The lower panel was built from this XML:") |
56 | label.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD)) | |
6fa68946 | 57 | |
8fa876ca RD |
58 | text = wx.TextCtrl(self, -1, resourceText, |
59 | style=wx.TE_READONLY|wx.TE_MULTILINE) | |
6fa68946 RD |
60 | text.SetInsertionPoint(0) |
61 | ||
8fa876ca | 62 | line = wx.StaticLine(self, -1) |
6fa68946 RD |
63 | |
64 | # Load the resource | |
8fa876ca | 65 | res = xrc.EmptyXmlResource() |
6fa68946 RD |
66 | res.LoadFromString(resourceText) |
67 | ||
68 | # Now create a panel from the resource data | |
69 | panel = res.LoadPanel(self, "MyPanel") | |
70 | ||
71 | # and do the layout | |
8fa876ca RD |
72 | sizer = wx.BoxSizer(wx.VERTICAL) |
73 | sizer.Add(label, 0, wx.EXPAND|wx.TOP|wx.LEFT, 5) | |
74 | sizer.Add(text, 1, wx.EXPAND|wx.ALL, 5) | |
75 | sizer.Add(line, 0, wx.EXPAND) | |
76 | sizer.Add(panel, 1, wx.EXPAND|wx.ALL, 5) | |
6fa68946 RD |
77 | |
78 | self.SetSizer(sizer) | |
79 | self.SetAutoLayout(True) | |
80 | ||
81 | ||
82 | #---------------------------------------------------------------------- | |
83 | ||
84 | def runTest(frame, nb, log): | |
85 | win = TestPanel(nb, log) | |
86 | return win | |
87 | ||
88 | #---------------------------------------------------------------------- | |
89 | ||
90 | ||
91 | ||
92 | overview = """<html><body> | |
93 | <h2><center>wxXmlResourceSubclass</center></h2> | |
94 | ||
95 | Sometimes it is necessary to use custom classes, but you still want | |
96 | them to be created from XRC. The subclass XRC attribute allows you to | |
97 | do that. | |
98 | ||
99 | </body></html> | |
100 | """ | |
101 | ||
102 | ||
103 | ||
104 | if __name__ == '__main__': | |
105 | import sys,os | |
106 | import run | |
107 | run.main(['', os.path.basename(sys.argv[0])]) | |
108 |