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