]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxXmlResourceSubclass.py
1 # 11/22/2003 - Jeff Grimmett (grimmtooth@softhome.net)
3 # o Updated for wx namespace
9 #----------------------------------------------------------------------
11 resourceText
= r
'''<?xml version="1.0"?>
14 <!-- Notice that the class IS a standard wx class, and a custom
15 subclass is specified as "moduleName.ClassName" Try changing
16 the classname to one that does not exist and see what happens -->
18 <object class="wxPanel" subclass="wxXmlResourceSubclass.MyBluePanel" name="MyPanel">
20 <object class="wxStaticText" name="label1">
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>
29 #----------------------------------------------------------------------
31 class MyBluePanel(wx
.Panel
):
36 self
.Bind(wx
.EVT_WINDOW_CREATE
, self
.OnCreate
)
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")
46 #----------------------------------------------------------------------
49 class TestPanel(wx
.Panel
):
50 def __init__(self
, parent
, log
):
52 wx
.Panel
.__init
__(self
, parent
, -1)
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
))
58 text
= wx
.TextCtrl(self
, -1, resourceText
,
59 style
=wx
.TE_READONLY|wx
.TE_MULTILINE
)
60 text
.SetInsertionPoint(0)
62 line
= wx
.StaticLine(self
, -1)
65 res
= xrc
.EmptyXmlResource()
66 res
.LoadFromString(resourceText
)
68 # Now create a panel from the resource data
69 panel
= res
.LoadPanel(self
, "MyPanel")
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)
79 self
.SetAutoLayout(True)
82 #----------------------------------------------------------------------
84 def runTest(frame
, nb
, log
):
85 win
= TestPanel(nb
, log
)
88 #----------------------------------------------------------------------
92 overview
= """<html><body>
93 <h2><center>wxXmlResourceSubclass</center></h2>
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
104 if __name__
== '__main__':
107 run
.main(['', os
.path
.basename(sys
.argv
[0])])