]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/Sizers.py
#include "wx/settings.h" for wxSystemSettings
[wxWidgets.git] / wxPython / demo / Sizers.py
CommitLineData
8fa876ca
RD
1# 11/26/2003 - Jeff Grimmett (grimmtooth@softhome.net)
2#
3# o Had to do a bit of rework for the demo; there was no panel attached
4# to the demo window, so all buttons were showing as dark gray on
5# dark gray. I have no idea why this didn't break before. Robin,
6# please examine my changes to ensure you approve. It's rather
7# hackish looking.
8#
9
bb0054cd
RD
10#----------------------------------------------------------------------
11# sizer test code
12#----------------------------------------------------------------------
13
8fa876ca 14import wx
bb0054cd
RD
15
16#----------------------------------------------------------------------
17
18def makeSimpleBox1(win):
8fa876ca
RD
19 box = wx.BoxSizer(wx.HORIZONTAL)
20 box.Add(wx.Button(win, -1, "one"), 0, wx.EXPAND)
21 box.Add(wx.Button(win, -1, "two"), 0, wx.EXPAND)
22 box.Add(wx.Button(win, -1, "three"), 0, wx.EXPAND)
23 box.Add(wx.Button(win, -1, "four"), 0, wx.EXPAND)
bb0054cd
RD
24
25 return box
26
27#----------------------------------------------------------------------
28
29def makeSimpleBox2(win):
8fa876ca
RD
30 box = wx.BoxSizer(wx.VERTICAL)
31 box.Add(wx.Button(win, -1, "one"), 0, wx.EXPAND)
32 box.Add(wx.Button(win, -1, "two"), 0, wx.EXPAND)
33 box.Add(wx.Button(win, -1, "three"), 0, wx.EXPAND)
34 box.Add(wx.Button(win, -1, "four"), 0, wx.EXPAND)
bb0054cd
RD
35
36 return box
37
38#----------------------------------------------------------------------
39
40def makeSimpleBox3(win):
8fa876ca
RD
41 box = wx.BoxSizer(wx.HORIZONTAL)
42 box.Add(wx.Button(win, -1, "one"), 0, wx.EXPAND)
43 box.Add(wx.Button(win, -1, "two"), 0, wx.EXPAND)
44 box.Add(wx.Button(win, -1, "three"), 0, wx.EXPAND)
45 box.Add(wx.Button(win, -1, "four"), 0, wx.EXPAND)
46 box.Add(wx.Button(win, -1, "five"), 1, wx.EXPAND)
bb0054cd
RD
47
48 return box
49
50#----------------------------------------------------------------------
51
52def makeSimpleBox4(win):
8fa876ca
RD
53 box = wx.BoxSizer(wx.HORIZONTAL)
54 box.Add(wx.Button(win, -1, "one"), 0, wx.EXPAND)
55 box.Add(wx.Button(win, -1, "two"), 0, wx.EXPAND)
56 box.Add(wx.Button(win, -1, "three"), 1, wx.EXPAND)
57 box.Add(wx.Button(win, -1, "four"), 1, wx.EXPAND)
58 box.Add(wx.Button(win, -1, "five"), 1, wx.EXPAND)
bb0054cd
RD
59
60 return box
61
62#----------------------------------------------------------------------
63
64def makeSimpleBox5(win):
8fa876ca
RD
65 box = wx.BoxSizer(wx.HORIZONTAL)
66 box.Add(wx.Button(win, -1, "one"), 0, wx.EXPAND)
67 box.Add(wx.Button(win, -1, "two"), 0, wx.EXPAND)
68 box.Add(wx.Button(win, -1, "three"), 3, wx.EXPAND)
69 box.Add(wx.Button(win, -1, "four"), 1, wx.EXPAND)
70 box.Add(wx.Button(win, -1, "five"), 1, wx.EXPAND)
bb0054cd
RD
71
72 return box
73
74#----------------------------------------------------------------------
75
76def makeSimpleBox6(win):
8fa876ca
RD
77 box = wx.BoxSizer(wx.HORIZONTAL)
78 box.Add(wx.Button(win, -1, "one"), 1, wx.ALIGN_TOP)
79 box.Add(wx.Button(win, -1, "two"), 1, wx.EXPAND)
80 box.Add(wx.Button(win, -1, "three"), 1, wx.ALIGN_CENTER)
81 box.Add(wx.Button(win, -1, "four"), 1, wx.EXPAND)
82 box.Add(wx.Button(win, -1, "five"), 1, wx.ALIGN_BOTTOM)
2f90df85
RD
83
84 return box
85
86#----------------------------------------------------------------------
87
88def makeSimpleBox7(win):
8bba1492
RD
89 box = wx.BoxSizer(wx.HORIZONTAL)
90 box.Add(wx.Button(win, 1010, "one"), 0, wx.EXPAND)
91 box.Add(wx.Button(win, 1010, "two"), 0, wx.EXPAND)
92 box.Add(wx.Button(win, 1010, "three"), 0, wx.EXPAND)
93 box.Add((60, 20), 0, wx.EXPAND)
94 box.Add(wx.Button(win, 1010, "five"), 1, wx.EXPAND)
bb0054cd
RD
95
96 return box
97
9d8bd15f
RD
98#----------------------------------------------------------------------
99
100def makeSimpleBox8(win):
317d1550
RD
101 box = wx.BoxSizer(wx.VERTICAL)
102 box.Add(wx.Button(win, 1010, "one"), 0, wx.EXPAND)
fd3f2efe 103 box.Add((0,0), 1)
8bba1492 104 box.Add(wx.Button(win, 1010, "two"), 0, wx.ALIGN_CENTER)
fd3f2efe 105 box.Add((0,0), 1)
8bba1492
RD
106 box.Add(wx.Button(win, 1010, "three"), 0, wx.EXPAND)
107 box.Add(wx.Button(win, 1010, "four"), 0, wx.EXPAND)
108# box.Add(wx.Button(win, 1010, "five"), 1, wx.EXPAND)
9d8bd15f
RD
109
110 return box
111
bb0054cd 112#----------------------------------------------------------------------
2f90df85 113#----------------------------------------------------------------------
bb0054cd
RD
114
115def makeSimpleBorder1(win):
8fa876ca
RD
116 bdr = wx.BoxSizer(wx.HORIZONTAL)
117 btn = wx.Button(win, -1, "border")
118 btn.SetSize((80, 80))
119 bdr.Add(btn, 1, wx.EXPAND|wx.ALL, 15)
bb0054cd
RD
120
121 return bdr
122
123#----------------------------------------------------------------------
124
125def makeSimpleBorder2(win):
8fa876ca
RD
126 bdr = wx.BoxSizer(wx.HORIZONTAL)
127 btn = wx.Button(win, -1, "border")
128 btn.SetSize((80, 80))
129 bdr.Add(btn, 1, wx.EXPAND | wx.EAST | wx.WEST, 15)
bb0054cd
RD
130
131 return bdr
132
133#----------------------------------------------------------------------
134
135def makeSimpleBorder3(win):
8fa876ca
RD
136 bdr = wx.BoxSizer(wx.HORIZONTAL)
137 btn = wx.Button(win, -1, "border")
138 btn.SetSize((80, 80))
139 bdr.Add(btn, 1, wx.EXPAND | wx.NORTH | wx.WEST, 15)
bb0054cd
RD
140
141 return bdr
142
143#----------------------------------------------------------------------
144#----------------------------------------------------------------------
145
146def makeBoxInBox(win):
8fa876ca
RD
147 box = wx.BoxSizer(wx.VERTICAL)
148
149 box.Add(wx.Button(win, -1, "one"), 0, wx.EXPAND)
150
151 box2 = wx.BoxSizer(wx.HORIZONTAL)
152 box2.Add(wx.Button(win, -1, "two"), 0, wx.EXPAND)
153 btn3 = wx.Button(win, -1, "three")
154 box2.Add(btn3, 0, wx.EXPAND)
155 box2.Add(wx.Button(win, -1, "four"), 0, wx.EXPAND)
156 box2.Add(wx.Button(win, -1, "five"), 0, wx.EXPAND)
157
158 box3 = wx.BoxSizer(wx.VERTICAL)
159 box3.AddMany([ (wx.Button(win, -1, "six"), 0, wx.EXPAND),
160 (wx.Button(win, -1, "seven"), 2, wx.EXPAND),
161 (wx.Button(win, -1, "eight"), 1, wx.EXPAND),
162 (wx.Button(win, -1, "nine"), 1, wx.EXPAND),
bb0054cd
RD
163 ])
164
8fa876ca
RD
165 box2.Add(box3, 1, wx.EXPAND)
166 box.Add(box2, 1, wx.EXPAND)
bb0054cd 167
8fa876ca 168 box.Add(wx.Button(win, -1, "ten"), 0, wx.EXPAND)
bb0054cd 169
1fded56b
RD
170 ##box.Hide(btn3)
171
bb0054cd
RD
172 return box
173
174#----------------------------------------------------------------------
175
176def makeBoxInBorder(win):
8fa876ca 177 bdr = wx.BoxSizer(wx.HORIZONTAL)
bb0054cd 178 box = makeSimpleBox3(win)
8fa876ca 179 bdr.Add(box, 1, wx.EXPAND | wx.ALL, 15)
bb0054cd
RD
180
181 return bdr
182
183#----------------------------------------------------------------------
184
185def makeBorderInBox(win):
8fa876ca
RD
186 insideBox = wx.BoxSizer(wx.HORIZONTAL)
187
188 box2 = wx.BoxSizer(wx.HORIZONTAL)
189 box2.AddMany([ (wx.Button(win, -1, "one"), 0, wx.EXPAND),
190 (wx.Button(win, -1, "two"), 0, wx.EXPAND),
191 (wx.Button(win, -1, "three"), 0, wx.EXPAND),
192 (wx.Button(win, -1, "four"), 0, wx.EXPAND),
193 (wx.Button(win, -1, "five"), 0, wx.EXPAND),
5662a243
RD
194 ])
195
8fa876ca 196 insideBox.Add(box2, 0, wx.EXPAND)
bb0054cd 197
8fa876ca
RD
198 bdr = wx.BoxSizer(wx.HORIZONTAL)
199 bdr.Add(wx.Button(win, -1, "border"), 1, wx.EXPAND | wx.ALL)
200 insideBox.Add(bdr, 1, wx.EXPAND | wx.ALL, 20)
bb0054cd 201
8fa876ca
RD
202 box3 = wx.BoxSizer(wx.VERTICAL)
203 box3.AddMany([ (wx.Button(win, -1, "six"), 0, wx.EXPAND),
204 (wx.Button(win, -1, "seven"), 2, wx.EXPAND),
205 (wx.Button(win, -1, "eight"), 1, wx.EXPAND),
206 (wx.Button(win, -1, "nine"), 1, wx.EXPAND),
5662a243 207 ])
8fa876ca 208 insideBox.Add(box3, 1, wx.EXPAND)
bb0054cd 209
8fa876ca
RD
210 outsideBox = wx.BoxSizer(wx.VERTICAL)
211 outsideBox.Add(wx.Button(win, -1, "top"), 0, wx.EXPAND)
212 outsideBox.Add(insideBox, 1, wx.EXPAND)
213 outsideBox.Add(wx.Button(win, -1, "bottom"), 0, wx.EXPAND)
bb0054cd
RD
214
215 return outsideBox
216
217
218#----------------------------------------------------------------------
219
2f90df85 220def makeGrid1(win):
8fa876ca 221 gs = wx.GridSizer(3, 3, 2, 2) # rows, cols, hgap, vgap
2f90df85 222
8fa876ca
RD
223 gs.AddMany([ (wx.Button(win, -1, 'one'), 0, wx.EXPAND),
224 (wx.Button(win, -1, 'two'), 0, wx.EXPAND),
225 (wx.Button(win, -1, 'three'), 0, wx.EXPAND),
226 (wx.Button(win, -1, 'four'), 0, wx.EXPAND),
227 (wx.Button(win, -1, 'five'), 0, wx.EXPAND),
2f90df85 228 #(75, 50),
8fa876ca
RD
229 (wx.Button(win, -1, 'six'), 0, wx.EXPAND),
230 (wx.Button(win, -1, 'seven'), 0, wx.EXPAND),
231 (wx.Button(win, -1, 'eight'), 0, wx.EXPAND),
232 (wx.Button(win, -1, 'nine'), 0, wx.EXPAND),
2f90df85
RD
233 ])
234
235 return gs
236
237#----------------------------------------------------------------------
238
239def makeGrid2(win):
8fa876ca
RD
240 gs = wx.GridSizer(3, 3) # rows, cols, hgap, vgap
241
242 box = wx.BoxSizer(wx.VERTICAL)
243 box.Add(wx.Button(win, -1, 'A'), 0, wx.EXPAND)
244 box.Add(wx.Button(win, -1, 'B'), 1, wx.EXPAND)
245
246 gs2 = wx.GridSizer(2,2, 4, 4)
247 gs2.AddMany([ (wx.Button(win, -1, 'C'), 0, wx.EXPAND),
248 (wx.Button(win, -1, 'E'), 0, wx.EXPAND),
249 (wx.Button(win, -1, 'F'), 0, wx.EXPAND),
250 (wx.Button(win, -1, 'G'), 0, wx.EXPAND)])
251
252 gs.AddMany([ (wx.Button(win, -1, 'one'), 0, wx.ALIGN_RIGHT | wx.ALIGN_BOTTOM),
253 (wx.Button(win, -1, 'two'), 0, wx.EXPAND),
254 (wx.Button(win, -1, 'three'), 0, wx.ALIGN_LEFT | wx.ALIGN_BOTTOM),
255 (wx.Button(win, -1, 'four'), 0, wx.EXPAND),
256 (wx.Button(win, -1, 'five'), 0, wx.ALIGN_CENTER),
257 (wx.Button(win, -1, 'six'), 0, wx.EXPAND),
258 (box, 0, wx.EXPAND | wx.ALL, 10),
259 (wx.Button(win, -1, 'eight'), 0, wx.EXPAND),
260 (gs2, 0, wx.EXPAND | wx.ALL, 4),
2f90df85
RD
261 ])
262
263 return gs
264
265#----------------------------------------------------------------------
266
267def makeGrid3(win):
8fa876ca 268 gs = wx.FlexGridSizer(3, 3, 2, 2) # rows, cols, hgap, vgap
2f90df85 269
8fa876ca
RD
270 gs.AddMany([ (wx.Button(win, -1, 'one'), 0, wx.EXPAND),
271 (wx.Button(win, -1, 'two'), 0, wx.EXPAND),
272 (wx.Button(win, -1, 'three'), 0, wx.EXPAND),
273 (wx.Button(win, -1, 'four'), 0, wx.EXPAND),
317d1550 274 #(wx.Button(win, 1010, 'five'), 0, wx.EXPAND),
8fa876ca
RD
275 ((175, 50)),
276 (wx.Button(win, -1, 'six'), 0, wx.EXPAND),
277 (wx.Button(win, -1, 'seven'), 0, wx.EXPAND),
278 (wx.Button(win, -1, 'eight'), 0, wx.EXPAND),
279 (wx.Button(win, -1, 'nine'), 0, wx.EXPAND),
2f90df85
RD
280 ])
281
282 gs.AddGrowableRow(0)
283 gs.AddGrowableRow(2)
284 gs.AddGrowableCol(1)
285 return gs
286
287#----------------------------------------------------------------------
288
be2577e4 289def makeGrid4(win):
8fa876ca
RD
290 bpos = wx.DefaultPosition
291 bsize = wx.Size(100, 50)
292 gs = wx.GridSizer(3, 3, 2, 2) # rows, cols, hgap, vgap
293
294 gs.AddMany([ (wx.Button(win, -1, 'one', bpos, bsize),
295 0, wx.ALIGN_TOP | wx.ALIGN_LEFT ),
296 (wx.Button(win, -1, 'two', bpos, bsize),
297 0, wx.ALIGN_TOP | wx.ALIGN_CENTER_HORIZONTAL ),
298 (wx.Button(win, -1, 'three', bpos, bsize),
299 0, wx.ALIGN_TOP | wx.ALIGN_RIGHT ),
300 (wx.Button(win, -1, 'four', bpos, bsize),
301 0, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT ),
302 (wx.Button(win, -1, 'five', bpos, bsize),
303 0, wx.ALIGN_CENTER ),
304 (wx.Button(win, -1, 'six', bpos, bsize),
305 0, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT ),
306 (wx.Button(win, -1, 'seven', bpos, bsize),
307 0, wx.ALIGN_BOTTOM | wx.ALIGN_LEFT ),
308 (wx.Button(win, -1, 'eight', bpos, bsize),
309 0, wx.ALIGN_BOTTOM | wx.ALIGN_CENTER_HORIZONTAL ),
310 (wx.Button(win, -1, 'nine', bpos, bsize),
311 0, wx.ALIGN_BOTTOM | wx.ALIGN_RIGHT ),
be2577e4
RD
312 ])
313
314 return gs
315
316#----------------------------------------------------------------------
317
318def makeShapes(win):
8fa876ca
RD
319 bpos = wx.DefaultPosition
320 bsize = wx.Size(100, 50)
321 gs = wx.GridSizer(3, 3, 2, 2) # rows, cols, hgap, vgap
322
323 gs.AddMany([ (wx.Button(win, -1, 'one', bpos, bsize),
324 0, wx.SHAPED | wx.ALIGN_TOP | wx.ALIGN_LEFT ),
325 (wx.Button(win, -1, 'two', bpos, bsize),
326 0, wx.SHAPED | wx.ALIGN_TOP | wx.ALIGN_CENTER_HORIZONTAL ),
327 (wx.Button(win, -1, 'three', bpos, bsize),
328 0, wx.SHAPED | wx.ALIGN_TOP | wx.ALIGN_RIGHT ),
329 (wx.Button(win, -1, 'four', bpos, bsize),
330 0, wx.SHAPED | wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT ),
331 (wx.Button(win, -1, 'five', bpos, bsize),
332 0, wx.SHAPED | wx.ALIGN_CENTER ),
333 (wx.Button(win, -1, 'six', bpos, bsize),
334 0, wx.SHAPED | wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT ),
335 (wx.Button(win, -1, 'seven', bpos, bsize),
336 0, wx.SHAPED | wx.ALIGN_BOTTOM | wx.ALIGN_LEFT ),
337 (wx.Button(win, -1, 'eight', bpos, bsize),
338 0, wx.SHAPED | wx.ALIGN_BOTTOM | wx.ALIGN_CENTER_HORIZONTAL ),
339 (wx.Button(win, -1, 'nine', bpos, bsize),
340 0, wx.SHAPED | wx.ALIGN_BOTTOM | wx.ALIGN_RIGHT ),
be2577e4
RD
341 ])
342
343 return gs
344
345#----------------------------------------------------------------------
346
347def makeSimpleBoxShaped(win):
8fa876ca
RD
348 box = wx.BoxSizer(wx.HORIZONTAL)
349 box.Add(wx.Button(win, -1, "one"), 0, wx.EXPAND)
350 box.Add(wx.Button(win, -1, "two"), 0, wx.EXPAND)
351 box.Add(wx.Button(win, -1, "three"), 0, wx.EXPAND)
352 box.Add(wx.Button(win, -1, "four"), 0, wx.EXPAND)
353 box.Add(wx.Button(win, -1, "five"), 1, wx.SHAPED)
be2577e4
RD
354
355 return box
356
357#----------------------------------------------------------------------
358
bb0054cd
RD
359theTests = [
360 ("Simple horizontal boxes", makeSimpleBox1,
361 "This is a HORIZONTAL box sizer with four non-stretchable buttons held "
362 "within it. Notice that the buttons are added and aligned in the horizontal "
363 "dimension. Also notice that they are fixed size in the horizontal dimension, "
364 "but will stretch vertically."
365 ),
366
367 ("Simple vertical boxes", makeSimpleBox2,
368 "Exactly the same as the previous sample but using a VERTICAL box sizer "
369 "instead of a HORIZONTAL one."
370 ),
371
372 ("Add a stretchable", makeSimpleBox3,
8b9a4190 373 "We've added one more button with the stretchable flag turned on. Notice "
bb0054cd
RD
374 "how it grows to fill the extra space in the otherwise fixed dimension."
375 ),
376
377 ("More than one stretchable", makeSimpleBox4,
378 "Here there are several items that are stretchable, they all divide up the "
379 "extra space evenly."
380 ),
381
382 ("Weighting factor", makeSimpleBox5,
8b9a4190 383 "This one shows more than one stretchable, but one of them has a weighting "
bb0054cd
RD
384 "factor so it gets more of the free space."
385 ),
386
2f90df85
RD
387 ("Edge Affinity", makeSimpleBox6,
388 "For items that don't completly fill their allotted space, and don't "
389 "stretch, you can specify which side (or the center) they should stay "
390 "attached to."
391 ),
392
393 ("Spacer", makeSimpleBox7,
394 "You can add empty space to be managed by a Sizer just as if it were a "
395 "window or another Sizer."
396 ),
397
9d8bd15f
RD
398 ("Centering in available space", makeSimpleBox8,
399 "This one shows an item that does not expand to fill it's space, but rather"
400 "stays centered within it."
401 ),
402
bb0054cd 403# ("Percent Sizer", makeSimpleBox6,
8fa876ca 404# "You can use the wx.BoxSizer like a Percent Sizer. Just make sure that all "
bb0054cd
RD
405# "the weighting factors add up to 100!"
406# ),
407
408 ("", None, ""),
409
410 ("Simple border sizer", makeSimpleBorder1,
8fa876ca 411 "The wx.BoxSizer can leave empty space around its contents. This one "
bb0054cd
RD
412 "gives a border all the way around."
413 ),
414
415 ("East and West border", makeSimpleBorder2,
416 "You can pick and choose which sides have borders."
417 ),
418
419 ("North and West border", makeSimpleBorder3,
420 "You can pick and choose which sides have borders."
421 ),
422
423 ("", None, ""),
424
425 ("Boxes inside of boxes", makeBoxInBox,
426 "This one shows nesting of boxes within boxes within boxes, using both "
427 "orientations. Notice also that button seven has a greater weighting "
428 "factor than its siblings."
429 ),
430
431 ("Boxes inside a Border", makeBoxInBorder,
8b9a4190 432 "Sizers of different types can be nested within each other as well. "
bb0054cd
RD
433 "Here is a box sizer with several buttons embedded within a border sizer."
434 ),
435
436 ("Border in a Box", makeBorderInBox,
5662a243 437 "Another nesting example. This one has Boxes and a Border inside another Box."
bb0054cd
RD
438 ),
439
2f90df85
RD
440 ("", None, ""),
441
442 ("Simple Grid", makeGrid1,
317d1550 443 "This is an example of the wx.GridSizer. In this case all row heights "
2f90df85 444 "and column widths are kept the same as all the others and all items "
8b9a4190 445 "fill their available space. The horizontal and vertical gaps are set to "
2f90df85
RD
446 "2 pixels each."
447 ),
448
449 ("More Grid Features", makeGrid2,
317d1550 450 "This is another example of the wx.GridSizer. This one has no gaps in the grid, "
2f90df85
RD
451 "but various cells are given different alignment options and some of them "
452 "hold nested sizers."
453 ),
454
455 ("Flexible Grid", makeGrid3,
456 "This grid allows the rows to have different heights and the columns to have "
457 "different widths. You can also specify rows and columns that are growable, "
458 "which we have done for the first and last row and the middle column for "
459 "this example.\n"
460 "\nThere is also a spacer in the middle cell instead of an actual window."
461 ),
462
be2577e4
RD
463 ("Grid with Alignment", makeGrid4,
464 "New alignment flags allow for the positioning of items in any corner or centered "
465 "position."
466 ),
467
468 ("", None, ""),
469
470 ("Proportional resize", makeSimpleBoxShaped,
471 "Managed items can preserve their original aspect ratio. The last item has the "
317d1550 472 "wx.SHAPED flag set and will resize proportional to its original size."
be2577e4
RD
473 ),
474
475 ("Proportional resize with Alignments", makeShapes,
476 "This one shows various alignments as well as proportional resizing for all items."
477 ),
478
bb0054cd
RD
479 ]
480#----------------------------------------------------------------------
481
8fa876ca 482class TestFrame(wx.Frame):
bb0054cd 483 def __init__(self, parent, title, sizerFunc):
8fa876ca
RD
484 wx.Frame.__init__(self, parent, -1, title)
485 self.Bind(wx.EVT_BUTTON, self.OnButton)
486
487 p = wx.Panel(self, -1)
bb0054cd 488
8fa876ca 489 self.sizer = sizerFunc(p)
bb0054cd 490 self.CreateStatusBar()
a08cbc01 491 self.SetStatusText("Resize this frame to see how the sizers respond...")
8fa876ca 492 self.sizer.Fit(p)
bb0054cd 493
8fa876ca
RD
494 p.SetAutoLayout(True)
495 p.SetSizer(self.sizer)
496 self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
497 self.Fit()
bb0054cd
RD
498
499 def OnCloseWindow(self, event):
1e4a197e 500 self.MakeModal(False)
bb0054cd
RD
501 self.Destroy()
502
503 def OnButton(self, event):
1e4a197e 504 self.Close(True)
bb0054cd
RD
505
506#----------------------------------------------------------------------
507
508
509
8fa876ca 510class TestSelectionPanel(wx.Panel):
bb0054cd 511 def __init__(self, parent, frame):
8fa876ca 512 wx.Panel.__init__(self, parent, -1)
bb0054cd
RD
513 self.frame = frame
514
8fa876ca
RD
515 self.list = wx.ListBox(self, -1,
516 wx.DLG_PNT(self, 10, 10), wx.DLG_SZE(self, 100, 100),
bb0054cd 517 [])
8fa876ca
RD
518 self.Bind(wx.EVT_LISTBOX, self.OnSelect, id=self.list.GetId())
519 self.Bind(wx.EVT_LISTBOX_DCLICK, self.OnDClick, id=self.list.GetId())
bb0054cd 520
8fa876ca
RD
521 self.btn = wx.Button(self, -1, "Try it!", wx.DLG_PNT(self, 120, 10)).SetDefault()
522 self.Bind(wx.EVT_BUTTON, self.OnDClick)
bb0054cd 523
8fa876ca
RD
524 self.text = wx.TextCtrl(self, -1, "",
525 wx.DLG_PNT(self, 10, 115),
526 wx.DLG_SZE(self, 200, 50),
527 wx.TE_MULTILINE | wx.TE_READONLY)
bb0054cd
RD
528
529 for item in theTests:
530 self.list.Append(item[0])
531
532
bb0054cd
RD
533 def OnSelect(self, event):
534 pos = self.list.GetSelection()
535 self.text.SetValue(theTests[pos][2])
536
537
538 def OnDClick(self, event):
539 pos = self.list.GetSelection()
540 title = theTests[pos][0]
541 func = theTests[pos][1]
542
543 if func:
544 win = TestFrame(self, title, func)
8fa876ca 545 win.CentreOnParent(wx.BOTH)
1e4a197e
RD
546 win.Show(True)
547 win.MakeModal(True)
bb0054cd
RD
548
549#----------------------------------------------------------------------
550
551def runTest(frame, nb, log):
552 win = TestSelectionPanel(nb, frame)
553 return win
554
2f90df85 555overview = ""
bb0054cd
RD
556
557#----------------------------------------------------------------------
558
bb0054cd
RD
559if __name__ == '__main__':
560
8fa876ca 561 class MainFrame(wx.Frame):
bb0054cd 562 def __init__(self):
8fa876ca 563 wx.Frame.__init__(self, None, -1, "Testing...")
bb0054cd 564
1e4a197e 565 self.CreateStatusBar()
8fa876ca
RD
566 mainmenu = wx.MenuBar()
567 menu = wx.Menu()
1e4a197e
RD
568 menu.Append(200, 'E&xit', 'Get the heck outta here!')
569 mainmenu.Append(menu, "&File")
570 self.SetMenuBar(mainmenu)
8fa876ca 571 self.Bind(wx.EVT_MENU, self.OnExit, id=200)
2f90df85 572 self.panel = TestSelectionPanel(self, self)
8fa876ca
RD
573 self.SetSize((400, 380))
574 self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
bb0054cd
RD
575
576 def OnCloseWindow(self, event):
577 self.Destroy()
578
579 def OnExit(self, event):
1e4a197e 580 self.Close(True)
bb0054cd
RD
581
582
8fa876ca 583 class TestApp(wx.App):
bb0054cd
RD
584 def OnInit(self):
585 frame = MainFrame()
1e4a197e 586 frame.Show(True)
bb0054cd 587 self.SetTopWindow(frame)
1e4a197e 588 return True
bb0054cd 589
8fa876ca 590 app = TestApp(False)
bb0054cd
RD
591 app.MainLoop()
592
593
594#----------------------------------------------------------------------