2 from wxPython
.wx
import *
3 from wxPython
.xrc
import *
5 #----------------------------------------------------------------------
7 resourceText
= r
'''<?xml version="1.0"?>
10 <!-- Notice that the class IS a standard wx class, and a custom
11 subclass is specified as "moduleName.ClassName" Try changing
12 the classname to one that does not exist and see what happens -->
14 <object class="wxPanel" subclass="wxXmlResourceSubclass.MyBluePanel" name="MyPanel">
16 <object class="wxStaticText" name="label1">
17 <label>This blue panel is a class derived from wxPanel
18 and is loaded by a using a subclass attribute of the object tag.</label>
25 #----------------------------------------------------------------------
27 class MyBluePanel(wxPanel
):
32 EVT_WINDOW_CREATE(self
, self
.OnCreate
)
34 def OnCreate(self
, evt
):
35 # This is the little bit of customization that we do for this
36 # silly example. It could just as easily have been done in
37 # the resource. We do it in the EVT_WINDOW_CREATE handler
38 # because the window doesn't really exist yet in the __init__.
39 self
.SetBackgroundColour("BLUE")
40 self
.SetForegroundColour("WHITE")
42 #----------------------------------------------------------------------
45 class TestPanel(wxPanel
):
46 def __init__(self
, parent
, log
):
48 wxPanel
.__init
__(self
, parent
, -1)
51 label
= wxStaticText(self
, -1, "The lower panel was built from this XML:")
52 label
.SetFont(wxFont(12, wxSWISS
, wxNORMAL
, wxBOLD
))
54 text
= wxTextCtrl(self
, -1, resourceText
,
55 style
=wxTE_READONLY|wxTE_MULTILINE
)
56 text
.SetInsertionPoint(0)
58 line
= wxStaticLine(self
, -1)
61 res
= wxEmptyXmlResource()
62 res
.LoadFromString(resourceText
)
64 # Now create a panel from the resource data
65 panel
= res
.LoadPanel(self
, "MyPanel")
68 sizer
= wxBoxSizer(wxVERTICAL
)
69 sizer
.Add(label
, 0, wxEXPAND|wxTOP|wxLEFT
, 5)
70 sizer
.Add(text
, 1, wxEXPAND|wxALL
, 5)
71 sizer
.Add(line
, 0, wxEXPAND
)
72 sizer
.Add(panel
, 1, wxEXPAND|wxALL
, 5)
75 self
.SetAutoLayout(True)
78 #----------------------------------------------------------------------
80 def runTest(frame
, nb
, log
):
81 win
= TestPanel(nb
, log
)
84 #----------------------------------------------------------------------
88 overview
= """<html><body>
89 <h2><center>wxXmlResourceSubclass</center></h2>
91 Sometimes it is necessary to use custom classes, but you still want
92 them to be created from XRC. The subclass XRC attribute allows you to
100 if __name__
== '__main__':
103 run
.main(['', os
.path
.basename(sys
.argv
[0])])