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" -->
13 <object class="wxPanel" subclass="wxXmlResourceSubclass.MyBluePanel" name="MyPanel">
15 <object class="wxStaticText" name="label1" subclass="wxPython.wx.wxPreStaticText">
16 <label>This blue panel is a class derived from wxPanel
17 and is loaded by a using a subclass attribute of the object tag.</label>
24 #----------------------------------------------------------------------
26 class MyBluePanel(wxPanel
):
28 #print "MyBluePanel.__init__"
31 self
.thisown
= p
.thisown
32 self
._setOORInfo
(self
)
34 EVT_WINDOW_CREATE(self
, self
.OnCreate
)
36 def OnCreate(self
, evt
):
37 # This is the little bit of customization that we do for this
38 # silly example. It could just as easily have been done in
39 # the resource. We do it in the EVT_WINDOW_CREATE handler
40 # because the window doesn't really exist yet in the __init__.
41 self
.SetBackgroundColour("BLUE")
42 self
.SetForegroundColour("WHITE")
44 #----------------------------------------------------------------------
47 class TestPanel(wxPanel
):
48 def __init__(self
, parent
, log
):
50 wxPanel
.__init
__(self
, parent
, -1)
53 label
= wxStaticText(self
, -1, "The lower panel was built from this XML:")
54 label
.SetFont(wxFont(12, wxSWISS
, wxNORMAL
, wxBOLD
))
56 text
= wxTextCtrl(self
, -1, resourceText
,
57 style
=wxTE_READONLY|wxTE_MULTILINE
)
58 text
.SetInsertionPoint(0)
60 line
= wxStaticLine(self
, -1)
63 res
= wxEmptyXmlResource()
64 res
.LoadFromString(resourceText
)
66 # Now create a panel from the resource data
67 panel
= res
.LoadPanel(self
, "MyPanel")
70 sizer
= wxBoxSizer(wxVERTICAL
)
71 sizer
.Add(label
, 0, wxEXPAND|wxTOP|wxLEFT
, 5)
72 sizer
.Add(text
, 1, wxEXPAND|wxALL
, 5)
73 sizer
.Add(line
, 0, wxEXPAND
)
74 sizer
.Add(panel
, 1, wxEXPAND|wxALL
, 5)
77 self
.SetAutoLayout(True)
80 #----------------------------------------------------------------------
82 def runTest(frame
, nb
, log
):
83 win
= TestPanel(nb
, log
)
86 #----------------------------------------------------------------------
90 overview
= """<html><body>
91 <h2><center>wxXmlResourceSubclass</center></h2>
93 Sometimes it is necessary to use custom classes, but you still want
94 them to be created from XRC. The subclass XRC attribute allows you to
102 if __name__
== '__main__':
105 run
.main(['', os
.path
.basename(sys
.argv
[0])])