]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/XmlResourceSubclass.py
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="XmlResourceSubclass.MyCustomPanel" name="MyPanel">
16 <object class="wxStaticText" name="label1">
17 <label>This blue panel is a class derived from wx.Panel
18 and is loaded by a using a subclass attribute of the object tag.</label>
25 #----------------------------------------------------------------------
27 class MyCustomPanel(wx
.Panel
):
30 # the Create step is done by XRC.
32 self
.Bind(wx
.EVT_WINDOW_CREATE
, self
.OnCreate
)
33 self
.Bind(wx
.EVT_SIZE
, self
.OnSize
)
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 t
= wx
.StaticText(self
, -1, "MyCustomPanel")
44 f
.SetPointSize(f
.GetPointSize()+2)
48 def OnSize(self
, evt
):
50 w
, h
= self
.t
.GetTextExtent(self
.t
.GetLabel())
51 self
.t
.SetPosition(((sz
.width
-w
)/2, (sz
.height
-h
)/2))
53 #----------------------------------------------------------------------
56 class TestPanel(wx
.Panel
):
57 def __init__(self
, parent
, log
):
59 wx
.Panel
.__init
__(self
, parent
, -1)
62 label
= wx
.StaticText(self
, -1, "The lower panel was built from this XML:")
63 label
.SetFont(wx
.Font(12, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
))
65 text
= wx
.TextCtrl(self
, -1, resourceText
,
66 style
=wx
.TE_READONLY|wx
.TE_MULTILINE
)
67 text
.SetInsertionPoint(0)
69 line
= wx
.StaticLine(self
, -1)
72 res
= xrc
.EmptyXmlResource()
73 res
.LoadFromString(resourceText
)
75 # Now create a panel from the resource data
76 panel
= res
.LoadPanel(self
, "MyPanel")
79 sizer
= wx
.BoxSizer(wx
.VERTICAL
)
80 sizer
.Add(label
, 0, wx
.EXPAND|wx
.TOP|wx
.LEFT
, 5)
81 sizer
.Add(text
, 1, wx
.EXPAND|wx
.ALL
, 5)
82 sizer
.Add(line
, 0, wx
.EXPAND
)
83 sizer
.Add(panel
, 1, wx
.EXPAND|wx
.ALL
, 5)
86 self
.SetAutoLayout(True)
89 #----------------------------------------------------------------------
91 def runTest(frame
, nb
, log
):
92 win
= TestPanel(nb
, log
)
95 #----------------------------------------------------------------------
99 overview
= """<html><body>
100 <h2><center>wx.XmlResourceSubclass</center></h2>
102 Sometimes it is necessary to use custom classes, but you still want
103 them to be created from XRC. The subclass XRC attribute allows you to
111 if __name__
== '__main__':
114 run
.main(['', os
.path
.basename(sys
.argv
[0])] + sys
.argv
[1:])