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