1 #----------------------------------------------------------------------
3 #----------------------------------------------------------------------
5 from wxPython
.wx
import *
6 from wxPython
.lib
.sizers
import *
8 #----------------------------------------------------------------------
10 def makeSimpleBox1(win
):
11 box
= wxBoxSizer(wxHORIZONTAL
)
12 box
.Add(wxButton(win
, 1010, "one"), 0)
13 box
.Add(wxButton(win
, 1010, "two"), 0)
14 box
.Add(wxButton(win
, 1010, "three"), 0)
15 box
.Add(wxButton(win
, 1010, "four"), 0)
19 #----------------------------------------------------------------------
21 def makeSimpleBox2(win
):
22 box
= wxBoxSizer(wxVERTICAL
)
23 box
.Add(wxButton(win
, 1010, "one"), 0)
24 box
.Add(wxButton(win
, 1010, "two"), 0)
25 box
.Add(wxButton(win
, 1010, "three"), 0)
26 box
.Add(wxButton(win
, 1010, "four"), 0)
30 #----------------------------------------------------------------------
32 def makeSimpleBox3(win
):
33 box
= wxBoxSizer(wxHORIZONTAL
)
34 box
.Add(wxButton(win
, 1010, "one"), 0)
35 box
.Add(wxButton(win
, 1010, "two"), 0)
36 box
.Add(wxButton(win
, 1010, "three"), 0)
37 box
.Add(wxButton(win
, 1010, "four"), 0)
38 box
.Add(wxButton(win
, 1010, "five"), 1)
42 #----------------------------------------------------------------------
44 def makeSimpleBox4(win
):
45 box
= wxBoxSizer(wxHORIZONTAL
)
46 box
.Add(wxButton(win
, 1010, "one"), 0)
47 box
.Add(wxButton(win
, 1010, "two"), 0)
48 box
.Add(wxButton(win
, 1010, "three"), 1)
49 box
.Add(wxButton(win
, 1010, "four"), 1)
50 box
.Add(wxButton(win
, 1010, "five"), 1)
54 #----------------------------------------------------------------------
56 def makeSimpleBox5(win
):
57 box
= wxBoxSizer(wxHORIZONTAL
)
58 box
.Add(wxButton(win
, 1010, "one"), 0)
59 box
.Add(wxButton(win
, 1010, "two"), 0)
60 box
.Add(wxButton(win
, 1010, "three"), 3)
61 box
.Add(wxButton(win
, 1010, "four"), 1)
62 box
.Add(wxButton(win
, 1010, "five"), 1)
66 #----------------------------------------------------------------------
68 def makeSimpleBox6(win
):
69 box
= wxBoxSizer(wxHORIZONTAL
, wxSize(250, 50))
70 box
.Add(wxButton(win
, 1010, "10"), 10)
71 box
.Add(wxButton(win
, 1010, "20"), 20)
72 box
.Add(wxButton(win
, 1010, "30"), 30)
73 box
.Add(wxButton(win
, 1010, "15"), 15)
74 box
.Add(wxButton(win
, 1010, "5"), 5)
78 #----------------------------------------------------------------------
80 def makeSimpleBorder1(win
):
81 bdr
= wxBorderSizer(wxALL
)
82 btn
= wxButton(win
, 1010, "border")
83 btn
.SetSize(wxSize(80, 80))
88 #----------------------------------------------------------------------
90 def makeSimpleBorder2(win
):
91 bdr
= wxBorderSizer(wxEAST | wxWEST
)
92 btn
= wxButton(win
, 1010, "border")
93 btn
.SetSize(wxSize(80, 80))
98 #----------------------------------------------------------------------
100 def makeSimpleBorder3(win
):
101 bdr
= wxBorderSizer(wxNORTH | wxWEST
)
102 btn
= wxButton(win
, 1010, "border")
103 btn
.SetSize(wxSize(80, 80))
108 #----------------------------------------------------------------------
111 box
=wxBoxSizer(wxVERTICAL
)
112 box
.Add(wxStaticLine(win
, -1), 0)
114 (wxANCHOR_NW
, "NorthWest"),
115 (wxANCHOR_NORTH
, "North"),
116 (wxANCHOR_NE
, "NorthEast")
118 (wxANCHOR_WEST
, "West"),
119 (wxANCHOR_NONE
, "Center"),
120 (wxANCHOR_EAST
, "East")
122 (wxANCHOR_SW
, "SouthWest"),
123 (wxANCHOR_SOUTH
, "South"),
124 (wxANCHOR_SE
, "SouthEast")
126 linebox
=wxBoxSizer(wxHORIZONTAL
)
127 linebox
.Add(wxStaticLine(win
, -1, style
=wxVERTICAL
), 0)
128 for (anchor
, label
) in line
:
129 sizer
=wxShapeSizer(anchor
)
130 sizer
.Add(wxButton(win
, -1, label
, size
=wxSize(100, 50)))
131 linebox
.Add(sizer
, 1)
132 linebox
.Add(wxStaticLine(win
, -1, style
=wxVERTICAL
), 0)
134 box
.Add(wxStaticLine(win
, -1), 0)
137 #----------------------------------------------------------------------
139 def makeBoxInBox(win
):
140 box
= wxBoxSizer(wxVERTICAL
)
142 box
.Add(wxButton(win
, 1010, "one"))
144 box2
= wxBoxSizer(wxHORIZONTAL
)
145 box2
.AddMany([ wxButton(win
, 1010, "two"),
146 wxButton(win
, 1010, "three"),
147 wxButton(win
, 1010, "four"),
148 wxButton(win
, 1010, "five"),
151 box3
= wxBoxSizer(wxVERTICAL
)
152 box3
.AddMany([ (wxButton(win
, 1010, "six"), 0),
153 (wxButton(win
, 1010, "seven"), 2),
154 (wxButton(win
, 1010, "eight"), 1),
155 (wxButton(win
, 1010, "nine"), 1),
161 box
.Add(wxButton(win
, 1010, "ten"))
165 #----------------------------------------------------------------------
167 def makeBoxInBorder(win
):
168 bdr
= wxBorderSizer(wxALL
)
169 box
= makeSimpleBox3(win
)
174 #----------------------------------------------------------------------
176 def makeBorderInBox(win
):
177 insideBox
= wxBoxSizer(wxHORIZONTAL
)
179 box2
= wxBoxSizer(wxHORIZONTAL
)
180 box2
.AddMany([ wxButton(win
, 1010, "one"),
181 wxButton(win
, 1010, "two"),
182 wxButton(win
, 1010, "three"),
183 wxButton(win
, 1010, "four"),
184 wxButton(win
, 1010, "five"),
187 insideBox
.Add(box2
, 0)
189 bdr
= wxBorderSizer(wxALL
)
190 bdr
.Add(wxButton(win
, 1010, "border"), 20)
191 insideBox
.Add(bdr
, 1)
193 box3
= wxBoxSizer(wxVERTICAL
)
194 box3
.AddMany([ (wxButton(win
, 1010, "six"), 0),
195 (wxButton(win
, 1010, "seven"), 2),
196 (wxButton(win
, 1010, "eight"), 1),
197 (wxButton(win
, 1010, "nine"), 1),
199 insideBox
.Add(box3
, 1)
201 outsideBox
= wxBoxSizer(wxVERTICAL
)
202 outsideBox
.Add(wxButton(win
, 1010, "top"))
203 outsideBox
.Add(insideBox
, 1)
204 outsideBox
.Add(wxButton(win
, 1010, "bottom"))
209 #----------------------------------------------------------------------
212 ("Simple horizontal boxes", makeSimpleBox1
,
213 "This is a HORIZONTAL box sizer with four non-stretchable buttons held "
214 "within it. Notice that the buttons are added and aligned in the horizontal "
215 "dimension. Also notice that they are fixed size in the horizontal dimension, "
216 "but will stretch vertically."
219 ("Simple vertical boxes", makeSimpleBox2
,
220 "Exactly the same as the previous sample but using a VERTICAL box sizer "
221 "instead of a HORIZONTAL one."
224 ("Add a stretchable", makeSimpleBox3
,
225 "We've added one more button with the strechable flag turned on. Notice "
226 "how it grows to fill the extra space in the otherwise fixed dimension."
229 ("More than one stretchable", makeSimpleBox4
,
230 "Here there are several items that are stretchable, they all divide up the "
231 "extra space evenly."
234 ("Weighting factor", makeSimpleBox5
,
235 "This one shows more than one strechable, but one of them has a weighting "
236 "factor so it gets more of the free space."
239 # ("Percent Sizer", makeSimpleBox6,
240 # "You can use the wxBoxSizer like a Percent Sizer. Just make sure that all "
241 # "the weighting factors add up to 100!"
246 ("Simple border sizer", makeSimpleBorder1
,
247 "The wxBorderSizer leaves empty space around its contents. This one "
248 "gives a border all the way around."
251 ("East and West border", makeSimpleBorder2
,
252 "You can pick and choose which sides have borders."
255 ("North and West border", makeSimpleBorder3
,
256 "You can pick and choose which sides have borders."
262 ("Proportional resize", makeShapes
,
263 "The wxShapeSizer preserves the original proportions of the window."
268 ("Boxes inside of boxes", makeBoxInBox
,
269 "This one shows nesting of boxes within boxes within boxes, using both "
270 "orientations. Notice also that button seven has a greater weighting "
271 "factor than its siblings."
274 ("Boxes inside a Border", makeBoxInBorder
,
275 "Sizers of different types can be nested withing each other as well. "
276 "Here is a box sizer with several buttons embedded within a border sizer."
279 ("Border in a Box", makeBorderInBox
,
280 "Another nesting example. This one has Boxes and a Border inside another Box."
284 #----------------------------------------------------------------------
286 class TestFrame(wxFrame
):
287 def __init__(self
, parent
, title
, sizerFunc
):
288 wxFrame
.__init
__(self
, parent
, -1, title
)
289 EVT_BUTTON(self
, 1010, self
.OnButton
)
291 self
.sizer
= sizerFunc(self
)
292 self
.CreateStatusBar()
293 self
.SetStatusText("Resize this frame to see how the sizers respond...")
294 self
.sizer
.FitWindow(self
)
297 def OnSize(self
, event
):
298 size
= self
.GetClientSize()
299 self
.sizer
.Layout(size
)
301 def OnCloseWindow(self
, event
):
302 self
.MakeModal(false
)
305 def OnButton(self
, event
):
308 #----------------------------------------------------------------------
312 class TestSelectionPanel(wxPanel
):
313 def __init__(self
, parent
, frame
=NULL
):
314 wxPanel
.__init
__(self
, parent
, -1)
317 self
.list = wxListBox(self
, 401,
318 wxDLG_PNT(self
, 10, 10), wxDLG_SZE(self
, 100, 60),
320 EVT_LISTBOX(self
, 401, self
.OnSelect
)
321 EVT_LISTBOX_DCLICK(self
, 401, self
.OnDClick
)
323 wxButton(self
, 402, "Try it!", wxDLG_PNT(self
, 120, 10)).SetDefault()
324 EVT_BUTTON(self
, 402, self
.OnDClick
)
326 self
.text
= wxTextCtrl(self
, -1, "",
327 wxDLG_PNT(self
, 10, 80),
328 wxDLG_SZE(self
, 200, 60),
329 wxTE_MULTILINE | wxTE_READONLY
)
331 for item
in theTests
:
332 self
.list.Append(item
[0])
336 def OnSelect(self
, event
):
337 pos
= self
.list.GetSelection()
338 self
.text
.SetValue(theTests
[pos
][2])
341 def OnDClick(self
, event
):
342 pos
= self
.list.GetSelection()
343 title
= theTests
[pos
][0]
344 func
= theTests
[pos
][1]
347 win
= TestFrame(self
, title
, func
)
348 win
.CentreOnParent(wxBOTH
)
352 #----------------------------------------------------------------------
354 def runTest(frame
, nb
, log
):
355 win
= TestSelectionPanel(nb
, frame
)
358 overview
= wxSizer
.__doc
__ + '\n' + '-' * 80 + '\n' + \
359 wxBoxSizer
.__doc
__ + '\n' + '-' * 80 + '\n' + \
360 wxBorderSizer
.__doc
__
362 #----------------------------------------------------------------------
366 if __name__
== '__main__':
368 class MainFrame(wxFrame
):
370 wxFrame
.__init
__(self
, NULL
, -1, "Testing...")
372 self
.CreateStatusBar()
373 mainmenu
= wxMenuBar()
375 menu
.Append(200, 'E&xit', 'Get the heck outta here!')
376 mainmenu
.Append(menu
, "&File")
377 self
.SetMenuBar(mainmenu
)
378 EVT_MENU(self
, 200, self
.OnExit
)
379 self
.panel
= TestSelectionPanel(self
, self
)
380 self
.SetSize(wxSize(400, 380))
382 def OnCloseWindow(self
, event
):
385 def OnExit(self
, event
):
389 class TestApp(wxApp
):
393 self
.SetTopWindow(frame
)
400 #----------------------------------------------------------------------