How to use sizers - Part 2 (Phoenix)
Keywords : Sizers.
Demonstrating :
Tested py3.x, wx4.x and Win10.
Are you ready to use some samples ?
Test, modify, correct, complete, improve and share your discoveries !
1 # -*- coding: iso-8859-1 -*-
2
3 # Name : LearnSizers3.py
4 # Purpose : A demo app to learn sizers
5 # Author : Jean-Michel Fauth, Switzerland
6 # Copyright : (c) 2005 Jean-Michel Fauth
7 # Licence : GPL
8
9 # os dev : windows 98/10/11
10 # py dev : Python 2.4.1/Python 3.11.6
11 # wx dev : wxPython 2.6.1/wxPython 4.2.2
12 # Revision : 27 June 2005
13
14 # Contributor and minor fixes : Marcelo Barbero, Argentina
15 # Revision : 02 May 2006 (Marcelo Barbero)
16 # Revision : 25 November 2023 (Ecco)
17
18 # LearnSizer*.py is a small application aimed to learn the sizers and
19 # their usage.
20 # This application is a collection of panels. Each panel contains
21 # a few widgets laid out with sizers. The panels are numbered
22 # MyPanel_0 to MyPanel_n. The panel 0 is the simpliest case. The
23 # order of the panels follows an increasing complexity in the
24 # layout. It is warmly recommended to start with MyPanel_0.
25 #
26 # Do not forget :
27 # - the wxPython doc
28 # - the wiki page http://wiki.wxpython.org/index.cgi/UsingSizers
29 # - dir(<instance of a sizer>) for a list of methods
30 # - print sizer.method.__doc__
31
32
33 import os
34 import sys
35 import wx
36
37 #-------------------------------------------------------------------
38
39 # - a wx.Window with a coloured background
40 # - pos and size == (-1, -1) since sizers are used
41 class ColWin(wx.Window):
42
43 def __init__(self, parent, id, BackColour):
44 wx.Window.__init__(self, parent, id, (-1, -1), (-1, -1), wx.SIMPLE_BORDER)
45 self.SetBackgroundColour(BackColour)
46
47 #-------------------------------------------------------------------
48
49
50 class MyPanel_0(wx.Panel):
51 """
52 - the simplest sizer, a ColWin
53 - use of named arguments
54 """
55
56 def __init__(self, parent):
57 wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
58
59 wgreen = ColWin(self, wx.NewIdRef(), wx.GREEN)
60
61 b = 20
62 vsizer1 = wx.BoxSizer(orient=wx.VERTICAL)
63 # or
64 # vsizer1 = wx.BoxSizer(orient=wx.HORIZONTAL)
65 # vsizer1.Add(item=wgreen, proportion=1, flag=wx.EXPAND | wx.ALL, border=b)
66 vsizer1.Add(window=wgreen, proportion=1, flag=wx.EXPAND | wx.ALL, border=b)
67 self.SetSizer(vsizer1)
68
69 #-------------------------------------------------------------------
70
71 class MyPanel_1(wx.Panel):
72 """
73 - two ColWins, vertically
74 """
75
76 def __init__(self, parent):
77 wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
78
79 wred = ColWin(self, wx.NewIdRef(), wx.RED)
80 wblue = ColWin(self, wx.NewIdRef(), wx.BLUE)
81
82 b = 5
83 vsizer1 = wx.BoxSizer(wx.VERTICAL)
84 vsizer1.Add(wred, 1, wx.EXPAND | wx.ALL, b)
85 vsizer1.Add(wblue, 1, wx.EXPAND | wx.ALL, b)
86 self.SetSizer(vsizer1)
87
88 #-------------------------------------------------------------------
89
90 class MyPanel_2(wx.Panel):
91 """
92 - three ColWins, horizontally
93 """
94
95 def __init__(self, parent):
96 wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
97
98 wred = ColWin(self, wx.NewIdRef(), wx.RED)
99 wblue = ColWin(self, wx.NewIdRef(), wx.BLUE)
100 wgreen = ColWin(self, wx.NewIdRef(), wx.GREEN)
101
102 b = 5
103 hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
104 hsizer1.Add(wred, 1, wx.EXPAND | wx.ALL, b)
105 hsizer1.Add(wblue, 1, wx.EXPAND | wx.ALL, b)
106 hsizer1.Add(wgreen, 1, wx.EXPAND | wx.ALL, b)
107 self.SetSizer(hsizer1)
108
109 #-------------------------------------------------------------------
110
111 class MyPanel_3(wx.Panel):
112 """
113 - three ColWins, horizontally, height ratio 1:2:3
114 """
115
116 def __init__(self, parent):
117 wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
118
119 wred = ColWin(self, wx.NewIdRef(), wx.RED)
120 wblue = ColWin(self, wx.NewIdRef(), wx.BLUE)
121 wgreen = ColWin(self, wx.NewIdRef(), wx.GREEN)
122
123 b = 5
124 hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
125 hsizer1.Add(wred, 1, wx.EXPAND | wx.ALL, b)
126 hsizer1.Add(wblue, 2, wx.EXPAND | wx.ALL, b)
127 hsizer1.Add(wgreen, 3, wx.EXPAND | wx.ALL, b)
128 self.SetSizer(hsizer1)
129
130 #-------------------------------------------------------------------
131
132 class MyPanel_4(wx.Panel):
133 """
134 - two ColWins, vertically, a fixed width of 50 pixels between the two items
135 """
136
137 def __init__(self, parent):
138 wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
139
140 wred = ColWin(self, wx.NewIdRef(), wx.RED)
141 wblue = ColWin(self, wx.NewIdRef(), wx.BLUE)
142
143 b = 5
144 vsizer1 = wx.BoxSizer(wx.VERTICAL)
145 vsizer1.Add(wred, 1, wx.EXPAND | wx.ALL, b)
146 vsizer1.Add((-1, 50), 0, wx.ALL, b)
147 vsizer1.Add(wblue, 1, wx.EXPAND | wx.ALL, b)
148 self.SetSizer(vsizer1)
149
150 #-------------------------------------------------------------------
151
152 class MyPanel_5(wx.Panel):
153 """
154 - two items, a ColWin and a Button, vertically
155 - the Button is either left/right aligned or centered
156 - comment / uncomment for testing the Button alignment
157 - wx.ALIGN_LEFT is the default value
158 """
159
160 def __init__(self, parent):
161 wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
162
163 wred = ColWin(self, wx.NewIdRef(), wx.RED)
164 b1 = wx.Button(self, wx.NewIdRef(), 'button1', (-1, -1), wx.DefaultSize)
165
166 b = 5
167 vsizer1 = wx.BoxSizer(wx.VERTICAL)
168 vsizer1.Add(wred, 1, wx.EXPAND | wx.ALL, b)
169
170 #~ vsizer1.Add(b1, 0, wx.ALIGN_LEFT | wx.ALL, b)
171 #~ vsizer1.Add(b1, 0, wx.ALIGN_RIGHT | wx.ALL, b)
172 vsizer1.Add(b1, 0, wx.ALIGN_CENTER | wx.ALL, b)
173 self.SetSizer(vsizer1)
174
175 #-------------------------------------------------------------------
176
177 class MyPanel_6(wx.Panel):
178 """
179 - three items, a ColWin and two Buttons
180 - the Buttons are either left/right aligned or centered
181 """
182
183 def __init__(self, parent):
184 wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
185
186 wred = ColWin(self, wx.NewIdRef(), wx.RED)
187 b1 = wx.Button(self, wx.NewIdRef(), '&OK', (-1, -1), wx.DefaultSize)
188 b2 = wx.Button(self, wx.NewIdRef(), '&Cancel', (-1, -1), wx.DefaultSize)
189
190 b = 10
191 hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
192 hsizer1.Add(b1, 0)
193 hsizer1.Add(b2, 0, wx.LEFT, b)
194
195 b = 5
196 vsizer1 = wx.BoxSizer(wx.VERTICAL)
197 vsizer1.Add(wred, 1, wx.EXPAND | wx.ALL, b)
198 vsizer1.Add(hsizer1, 0, wx.ALIGN_RIGHT | wx.ALL, b)
199 #~ vsizer1.Add(hsizer1, 0, wx.ALIGN_CENTER | wx.ALL, b)
200 #~ vsizer1.Add(hsizer1, 0, wx.ALIGN_LEFT | wx.ALL, b)
201 self.SetSizer(vsizer1)
202
203 #-------------------------------------------------------------------
204
205 class MyPanel_7(wx.Panel):
206 """
207 - four items, a ColWin, two Buttons, and a StaticLine
208 - the Buttons are either left/right aligned or centered
209 - the height of the static line == 2, the wx.GROW flag specifies an
210 horizontal expansion, since the StaticLine is in a vertical sizer
211 """
212 def __init__(self, parent):
213 wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
214
215 wred = ColWin(self, wx.NewIdRef(), wx.RED)
216 b1 = wx.Button(self, wx.NewIdRef(), '&OK', (-1, -1), wx.DefaultSize)
217 b2 = wx.Button(self, wx.NewIdRef(), '&Cancel', (-1, -1), wx.DefaultSize)
218 staline = wx.StaticLine(self, wx.NewIdRef(), (-1, -1), (-1, 2), wx.LI_HORIZONTAL)
219
220 b = 5
221 hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
222 hsizer1.Add(b1, 0)
223 hsizer1.Add(b2, 0, wx.LEFT, b)
224
225 vsizer1 = wx.BoxSizer(wx.VERTICAL)
226 vsizer1.Add(wred, 1, wx.EXPAND | wx.ALL, b)
227 vsizer1.Add(staline, 0, wx.GROW | wx.ALL, b)
228 vsizer1.Add(hsizer1, 0, wx.ALIGN_RIGHT | wx.ALL, b)
229 self.SetSizer(vsizer1)
230
231 #-------------------------------------------------------------------
232
233 class MyPanel_8(wx.Panel):
234 """
235 - 7 items, 2 ColWins and 5 Buttons
236 - ColWins: one is sizable, the others not
237 - Buttons at the right of the frame
238 - something like a toolbar at the right
239 """
240
241 def __init__(self, parent):
242 wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
243
244 wred = ColWin(self, wx.NewIdRef(), wx.RED)
245 wwhite = ColWin(self, wx.NewIdRef(), wx.WHITE)
246
247 b1 = wx.Button(self, wx.NewIdRef(), '1', (-1, -1), wx.DefaultSize)
248 b2 = wx.Button(self, wx.NewIdRef(), '2', (-1, -1), wx.DefaultSize)
249 b3 = wx.Button(self, wx.NewIdRef(), '3', (-1, -1), wx.DefaultSize)
250 b4 = wx.Button(self, wx.NewIdRef(), '4', (-1, -1), wx.DefaultSize)
251 b5 = wx.Button(self, wx.NewIdRef(), '5', (-1, -1), wx.DefaultSize)
252
253 vsizer1 = wx.BoxSizer(wx.VERTICAL)
254 b = 3
255 vsizer1.Add(wred, 1, wx.EXPAND | wx.BOTTOM, b)
256 vsizer1.Add(wwhite, 0, wx.EXPAND, b)
257
258 vsizer2 = wx.BoxSizer(wx.VERTICAL)
259 b = 5
260 vsizer2.Add(b1, 0, wx.BOTTOM, b)
261 vsizer2.Add(b2, 0, wx.BOTTOM, b)
262 vsizer2.Add(b3, 0, wx.BOTTOM, b)
263 vsizer2.Add(b4, 0, wx.BOTTOM, b)
264 vsizer2.Add(b5, 0, wx.BOTTOM, b)
265
266 hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
267 b = 10
268 hsizer1.Add(vsizer1, 1, wx.EXPAND | wx.LEFT | wx.TOP | wx.BOTTOM, b)
269 hsizer1.Add(vsizer2, 0, wx.EXPAND| wx.ALL, b)
270
271 self.SetSizer(hsizer1)
272
273 #-------------------------------------------------------------------
274
275 class MyPanel_9(wx.Panel):
276 """
277 - 7 items, 2 ColWins and 5 Buttons
278 - the ColWins are sizable
279 - the Buttons have a fixed height and a default width
280 - something like a toolbar at the top
281 """
282 def __init__(self, parent):
283 wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
284
285 wred = ColWin(self, wx.NewIdRef(), wx.RED)
286 wwhite = ColWin(self, wx.NewIdRef(), wx.WHITE)
287
288 h = 40
289 b1 = wx.Button(self, wx.NewIdRef(), '1', (-1, -1), (-1, h))
290 b2 = wx.Button(self, wx.NewIdRef(), '2', (-1, -1), (-1, h))
291 b3 = wx.Button(self, wx.NewIdRef(), '3', (-1, -1), (-1, h))
292 b4 = wx.Button(self, wx.NewIdRef(), '4', (-1, -1), (-1, h))
293 b5 = wx.Button(self, wx.NewIdRef(), '5', (-1, -1), (-1, h))
294
295 hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
296 hsizer1.Add(b1, 0)
297 hsizer1.Add(b2, 0)
298 hsizer1.Add(b3, 0)
299 hsizer1.Add(b4, 0)
300 hsizer1.Add(b5, 0)
301
302 b = 2
303 hsizer2 = wx.BoxSizer(wx.HORIZONTAL)
304 hsizer2.Add(wred, 1, wx.EXPAND | wx.RIGHT, b)
305 hsizer2.Add(wwhite, 1, wx.EXPAND | wx.LEFT, b)
306
307 b = 5
308 vsizer1 = wx.BoxSizer(wx.VERTICAL)
309 vsizer1.Add(hsizer1, 0, wx.EXPAND, b)
310 vsizer1.Add(hsizer2, 1, wx.ALL | wx.EXPAND, b)
311
312 self.SetSizer(vsizer1)
313
314 #-------------------------------------------------------------------
315
316 class MyPanel_10(wx.Panel):
317 """
318 - three ColWins in a StaticBoxSizer, vertically
319 """
320
321 def __init__(self, parent):
322 wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
323
324 wred = ColWin(self, wx.NewIdRef(), wx.RED)
325 wblue = ColWin(self, wx.NewIdRef(), wx.BLUE)
326 wgreen = ColWin(self, wx.NewIdRef(), wx.GREEN)
327
328 b = 10 #inside the staticbox
329 vsbsizer1 = wx.StaticBoxSizer(wx.StaticBox(self, wx.NewIdRef(), 'StaticboxSizer with a caption'), wx.VERTICAL)
330 vsbsizer1.Add(wred, 1, wx.EXPAND | wx.ALL, b)
331 vsbsizer1.Add(wblue, 1, wx.EXPAND | wx.ALL, b)
332 vsbsizer1.Add(wgreen, 1, wx.EXPAND | wx.ALL, b)
333 self.SetSizer(vsbsizer1)
334
335 #-------------------------------------------------------------------
336
337 class MyPanel_11(wx.Panel):
338 """
339 - three ColWins in a StaticBoxSizer, vertically
340 - the StaticBoxSizer is in a sizer to enable a border
341 """
342
343 def __init__(self, parent):
344 wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
345
346 wred = ColWin(self, wx.NewIdRef(), wx.RED)
347 wblue = ColWin(self, wx.NewIdRef(), wx.BLUE)
348 wgreen = ColWin(self, wx.NewIdRef(), wx.GREEN)
349
350 b = 10 #inside the staticbox
351 vsbsizer1 = wx.StaticBoxSizer(wx.StaticBox(self, wx.NewIdRef(), 'StaticboxSizer with a caption'), wx.VERTICAL)
352 vsbsizer1.Add(wred, 1, wx.EXPAND | wx.ALL, b)
353 vsbsizer1.Add(wblue, 1, wx.EXPAND | wx.ALL, b)
354 vsbsizer1.Add(wgreen, 1, wx.EXPAND | wx.ALL, b)
355
356 b = 20
357 hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
358 hsizer1.Add(vsbsizer1, 1, wx.EXPAND | wx.ALL, b)
359
360 self.SetSizer(hsizer1)
361
362 #-------------------------------------------------------------------
363
364 class MyPanel_12(wx.Panel):
365 """
366 - 5 ColWins, vertically
367 - the ColWins 2 and 4 are in StaticBoxSizers
368 """
369 def __init__(self, parent):
370 wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
371
372 wred = ColWin(self, wx.NewIdRef(), wx.RED)
373 wblue = ColWin(self, wx.NewIdRef(), wx.BLUE)
374 wgreen = ColWin(self, wx.NewIdRef(), wx.GREEN)
375 wwhite = ColWin(self, wx.NewIdRef(), wx.WHITE)
376 wyellow = ColWin(self, wx.NewIdRef(), wx.Colour('yellow'))
377
378 b = 10
379 vsbsizer1 = wx.StaticBoxSizer(wx.StaticBox(self, wx.NewIdRef(), 'blue'), wx.VERTICAL)
380 vsbsizer1.Add(wblue, 1, wx.EXPAND | wx.ALL, b)
381
382 vsbsizer2 = wx.StaticBoxSizer(wx.StaticBox(self, wx.NewIdRef(), 'white'), wx.VERTICAL)
383 vsbsizer2.Add(wwhite, 1, wx.EXPAND | wx.ALL, b)
384
385 b = 5
386 vsizer1 = wx.BoxSizer(wx.VERTICAL)
387 vsizer1.Add(wred, 1, wx.EXPAND | wx.ALL, b)
388 vsizer1.Add(vsbsizer1, 1, wx.EXPAND | wx.ALL, b)
389 vsizer1.Add(wgreen, 1, wx.EXPAND | wx.ALL, b)
390 vsizer1.Add(vsbsizer2, 1, wx.EXPAND | wx.ALL, b)
391 vsizer1.Add(wyellow, 1, wx.EXPAND | wx.ALL, b)
392
393 self.SetSizer(vsizer1)
394
395 #-------------------------------------------------------------------
396
397 class MyPanel_13(wx.Panel):
398 """
399 - 3 StaticBoxSizers with each a ColWin
400 - the StaticBoxSizers are arranged vertically
401 """
402
403 def __init__(self, parent):
404 wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
405
406 wred = ColWin(self, wx.NewIdRef(), wx.Colour('green'))
407 wgreen = ColWin(self, wx.NewIdRef(), wx.Colour('red'))
408 wblue = ColWin(self, wx.NewIdRef(), wx.Colour('blue'))
409
410 b = 10
411 sizer1 = wx.StaticBoxSizer(wx.StaticBox(self, wx.NewIdRef(), 'Staticbox'), wx.VERTICAL)
412 sizer1.Add(wred, 1, wx.EXPAND | wx.ALL, b)
413
414 sizer2 = wx.StaticBoxSizer(wx.StaticBox(self, wx.NewIdRef(), 'Staticbox'), wx.VERTICAL)
415 sizer2.Add(wgreen, 1, wx.EXPAND | wx.ALL, b)
416
417 sizer4 = wx.StaticBoxSizer(wx.StaticBox(self, wx.NewIdRef(), 'Staticbox'), wx.VERTICAL)
418 sizer4.Add(wblue, 1, wx.EXPAND | wx.ALL, b)
419
420 #tricky: the 2nd and 3rd staticbox sizer are shifted one pixel to the
421 #left, try with b2 = 0
422 b1, b2 = 0, -1
423 sizer3 = wx.BoxSizer(wx.HORIZONTAL)
424 sizer3.Add(sizer1, 1, wx.EXPAND, b1)
425 sizer3.Add(sizer2, 1, wx.EXPAND | wx.LEFT, b2)
426 sizer3.Add(sizer4, 1, wx.EXPAND | wx.LEFT, b2)
427
428 self.SetSizer(sizer3)
429
430 #-------------------------------------------------------------------
431
432 class MyPanel_14(wx.Panel):
433 """
434 - 3 ColWins, horizontally, 2 spacers with a fixed height
435 """
436 def __init__(self, parent):
437 wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
438
439 wred = ColWin(self, wx.NewIdRef(), wx.RED)
440 wblue = ColWin(self, wx.NewIdRef(), wx.BLUE)
441 wgreen = ColWin(self, wx.NewIdRef(), wx.GREEN)
442
443 b = 0
444 h = 20
445 hsizer1 = wx.BoxSizer(wx.VERTICAL)
446 hsizer1.Add(wred, 1, wx.EXPAND | wx.ALL, b)
447 hsizer1.Add((-1, h))
448 hsizer1.Add(wblue, 1, wx.EXPAND | wx.ALL, b)
449 hsizer1.Add((-1, h))
450 hsizer1.Add(wgreen, 1, wx.EXPAND | wx.ALL, b)
451 self.SetSizer(hsizer1)
452
453 #-------------------------------------------------------------------
454
455 class MyPanel_15(wx.Panel):
456 """
457 - 4 items, a ColWin, 3 Buttons
458 - Buttons 1 and 3 are left/right aligned, Button 2 is centered
459 - use of spacers to set a gap between the Buttons.
460 - better way?
461 """
462
463 def __init__(self, parent):
464 wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
465
466 wgreen = ColWin(self, wx.NewIdRef(), wx.Colour('green'))
467 b1 = wx.Button(self, wx.NewIdRef(), 'button1', (-1, -1), wx.DefaultSize)
468 b2 = wx.Button(self, wx.NewIdRef(), 'button2', (-1, -1), wx.DefaultSize)
469 b3 = wx.Button(self, wx.NewIdRef(), 'button3', (-1, -1), wx.DefaultSize)
470
471 b = 0
472 hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
473 hsizer1.Add(b1, 0, wx.ALL, b)
474 hsizer1.Add((-1, -1), 1)
475 hsizer1.Add(b2, 0, wx.ALL, b)
476 hsizer1.Add((-1, -1), 1)
477 hsizer1.Add(b3, 0, wx.ALL, b)
478
479 #tip: this does not work
480 #~ b = 0
481 #~ hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
482 #~ hsizer1.Add(b1, 0, wx.ALIGN_LEFT, b)
483 #~ hsizer1.Add(b2, 0, wx.ALIGN_CENTER, b)
484 #~ hsizer1.Add(b3, 0, wx.ALIGN_RIGHT, b)
485
486 b = 5
487 vsizer2 = wx.BoxSizer(wx.VERTICAL)
488 vsizer2.Add(wgreen, 1, wx.EXPAND | wx.ALL, b)
489 vsizer2.Add(hsizer1, 0, wx.EXPAND | wx.ALL, b)
490 self.SetSizer(vsizer2)
491
492 #-------------------------------------------------------------------
493
494 class MyPanel_16(wx.Panel):
495 """
496 - 4 items, a ColWin, 3 Buttons
497 - Buttons 1 and 3 are top/bottom aligned, Button 2 is centered
498 - use of spacers to set a gap between the Buttons
499 - better way?
500 """
501
502 def __init__(self, parent):
503 wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
504
505 wgreen = ColWin(self, wx.NewIdRef(), wx.Colour('green'))
506 b1 = wx.Button(self, wx.NewIdRef(), 'button1', (-1, -1), wx.DefaultSize)
507 b2 = wx.Button(self, wx.NewIdRef(), 'button2', (-1, -1), wx.DefaultSize)
508 b3 = wx.Button(self, wx.NewIdRef(), 'button3', (-1, -1), wx.DefaultSize)
509
510 b = 0
511 vsizer1 = wx.BoxSizer(wx.VERTICAL)
512 vsizer1.Add(b1, 0, wx.ALL, b)
513 vsizer1.Add((-1, -1), 1)
514 vsizer1.Add(b2, 0, wx.ALL, b)
515 vsizer1.Add((-1, -1), 1)
516 vsizer1.Add(b3, 0, wx.ALL, b)
517
518 b = 5
519 hsizer2 = wx.BoxSizer(wx.HORIZONTAL)
520 hsizer2.Add(vsizer1, 0, wx.EXPAND | wx.ALL, b)
521 hsizer2.Add(wgreen, 1, wx.EXPAND | wx.ALL, b)
522 self.SetSizer(hsizer2)
523
524 #-------------------------------------------------------------------
525
526 class MyPanel_17(wx.Panel):
527 """
528 - an input box
529 """
530
531 def __init__(self, parent):
532 wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
533 self.parent = parent
534
535 s = 'abc' + os.linesep + 'def' + os.linesep + 'ghi'
536 statxt = wx.StaticText(self, -1, s, (-1, -1), (-1, -1))
537 txt = wx.TextCtrl(self, wx.NewIdRef(), 'input', (-1, -1), (-1, -1))
538 staline = wx.StaticLine(self, -1, (-1, -1), (-1, -1), wx.LI_HORIZONTAL)
539
540 b1 = wx.Button(self, wx.NewIdRef(), "&OK", (-1, -1), wx.DefaultSize)
541 b2 = wx.Button(self, wx.NewIdRef(), "&Cancel", (-1, -1), wx.DefaultSize)
542
543 b = 10
544 hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
545 hsizer1.Add(b1, 0)
546 hsizer1.Add(b2, 0, wx.LEFT, b)
547
548 b = 5
549 vsizer1 = wx.BoxSizer(wx.VERTICAL)
550 vsizer1.Add(statxt, 0, wx.GROW | wx.ALL, b)
551 vsizer1.Add(txt, 0, wx.GROW | wx.ALL, b)
552 vsizer1.Add(staline, 0, wx.GROW | wx.ALL, b)
553 vsizer1.Add(hsizer1, 0, wx.ALIGN_RIGHT | wx.ALL, b)
554 vsizer1.SetMinSize((300, -1))
555 self.SetSizerAndFit(vsizer1)
556
557 #the items are not sizable, once set, pass the fitted size to
558 #the parent
559 self.parent.SetClientSize(vsizer1.GetSize())
560
561 #-------------------------------------------------------------------
562
563 class MyPanel_18(wx.Panel):
564 """
565 - a message box
566 """
567
568 def __init__(self, parent):
569 wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
570 self.parent = parent
571
572 s = 'This is a rather long message with.'
573 s += (os.linesep + 'a lot of lines...')*20
574
575 statxt = wx.StaticText(self, -1, s, (-1, -1), (-1, -1))
576 staline = wx.StaticLine(self, -1, (-1, -1), (-1, -1), wx.LI_HORIZONTAL)
577 b1 = wx.Button(self, wx.NewIdRef(), "&OK", (-1, -1), wx.DefaultSize)
578
579 b = 5
580 vsizer1 = wx.BoxSizer(wx.VERTICAL)
581 vsizer1.Add(statxt, 1, wx.EXPAND | wx.ALL, b)
582 vsizer1.Add(staline, 0, wx.GROW | wx.ALL, b)
583 vsizer1.Add(b1, 0, wx.ALIGN_CENTER | wx.ALL, b)
584 vsizer1.SetMinSize((200, -1))
585 self.SetSizerAndFit(vsizer1)
586
587 self.parent.SetClientSize(vsizer1.GetSize())
588
589 #-------------------------------------------------------------------
590
591 class MyPanel_19(wx.Panel):
592 """
593 - a serie of couples, StaticText-TextCtrl
594 - Buttons ok and cancel
595 """
596
597 def __init__(self, parent):
598 wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
599 self.parent = parent
600
601 lab1 = wx.StaticText(self, -1, 'hydrogen :', (-1, -1), (-1, -1), wx.ALIGN_RIGHT)
602 lab2 = wx.StaticText(self, -1, 'tin :', (-1, -1), (-1, -1), wx.ALIGN_RIGHT)
603 lab3 = wx.StaticText(self, -1, 'mendelevium :', (-1, -1), (-1, -1), wx.ALIGN_RIGHT)
604 lab4 = wx.StaticText(self, -1, 'carbon :', (-1, -1), (-1, -1), wx.ALIGN_RIGHT)
605 txt1 = wx.TextCtrl(self, -1, '', (-1, -1), (-1, -1))
606 txt2 = wx.TextCtrl(self, -1, '', (-1, -1), (-1, -1))
607 txt3 = wx.TextCtrl(self, -1, '', (-1, -1), (-1, -1))
608 txt4 = wx.TextCtrl(self, -1, '', (-1, -1), (-1, -1))
609 b1 = wx.Button(self, wx.NewIdRef(), '&OK', (-1, -1), wx.DefaultSize)
610 b2 = wx.Button(self, wx.NewIdRef(), '&Cancel', (-1, -1), wx.DefaultSize)
611 staline = wx.StaticLine(self, wx.NewIdRef(), (-1, -1), (-1, 2), wx.LI_HORIZONTAL)
612
613 b = 5
614 w = 100
615 hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
616 hsizer1.Add(lab1, 0, wx.RIGHT, b)
617 hsizer1.Add(txt1, 1, wx.GROW, b)
618 hsizer1.SetItemMinSize(lab1, (w, -1))
619
620 hsizer2 = wx.BoxSizer(wx.HORIZONTAL)
621 hsizer2.Add(lab2, 0, wx.RIGHT, b)
622 hsizer2.Add(txt2, 1, wx.GROW, b)
623 hsizer2.SetItemMinSize(lab2, (w, -1))
624
625 hsizer3 = wx.BoxSizer(wx.HORIZONTAL)
626 hsizer3.Add(lab3, 0, wx.RIGHT, b)
627 hsizer3.Add(txt3, 1, wx.GROW, b)
628 hsizer3.SetItemMinSize(lab3, (w, -1))
629
630 hsizer4 = wx.BoxSizer(wx.HORIZONTAL)
631 hsizer4.Add(lab4, 0, wx.RIGHT, b)
632 hsizer4.Add(txt4, 1, wx.GROW, b)
633 hsizer4.SetItemMinSize(lab4, (w, -1))
634
635 hsizer5 = wx.BoxSizer(wx.HORIZONTAL)
636 hsizer5.Add(b1, 0)
637 hsizer5.Add(b2, 0, wx.LEFT, 10)
638
639 b = 5
640 vsizer1 = wx.BoxSizer(wx.VERTICAL)
641 vsizer1.Add(hsizer1, 0, wx.EXPAND | wx.ALL, b)
642 vsizer1.Add(hsizer2, 0, wx.EXPAND | wx.ALL, b)
643 vsizer1.Add(hsizer3, 0, wx.EXPAND | wx.ALL, b)
644 vsizer1.Add(hsizer4, 0, wx.EXPAND | wx.ALL, b)
645 vsizer1.Add(staline, 0, wx.GROW | wx.ALL, b)
646 vsizer1.Add(hsizer5, 0, wx.ALIGN_RIGHT | wx.ALL, b)
647
648 self.SetSizerAndFit(vsizer1)
649 self.parent.SetClientSize(vsizer1.GetSize())
650
651 #-------------------------------------------------------------------
652
653 class MyPanel_20(wx.Panel):
654 """
655 - a FlexGridSizer
656 - 4 ColWins as cells, all sizeable
657 """
658
659 def __init__(self, parent):
660 wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
661
662 wred = ColWin(self, -1, wx.RED)
663 wblue = ColWin(self, -1, wx.BLUE)
664 wwhite = ColWin(self, -1, wx.WHITE)
665 wcyan = ColWin(self, -1, wx.CYAN)
666
667 hgap, vgap = 0, 0
668 nrows, ncols = 2, 2
669 fgs = wx.FlexGridSizer(nrows, ncols, hgap, vgap)
670
671 b = 5
672 fgs.AddMany([(wred, 1, wx.EXPAND | wx.ALL, b),
673 (wblue, 1, wx.EXPAND | wx.ALL, b),
674 (wwhite, 1, wx.EXPAND | wx.ALL, b),
675 (wcyan, 1, wx.EXPAND | wx.ALL, b),
676 ])
677
678 # or
679 #~ fgs.Add(wred, 1, wx.EXPAND | wx.ALL, b)
680 #~ fgs.Add(wblue, 1, wx.EXPAND | wx.ALL, b)
681 #~ fgs.Add(wwhite, 1, wx.EXPAND | wx.ALL, b)
682 #~ fgs.Add(wcyan, 1, wx.EXPAND | wx.ALL, b)
683
684 #set all rows and cols sizable, try to comment / uncomment
685 fgs.AddGrowableRow(0)
686 fgs.AddGrowableRow(1)
687 fgs.AddGrowableCol(0)
688 fgs.AddGrowableCol(1)
689
690 self.SetSizer(fgs)
691
692 #-------------------------------------------------------------------
693
694 class MyPanel_21(wx.Panel):
695 """
696 - a FlexgridSizer with 4 cells
697 - cell (0, 0) is a column of 3 Buttons
698 - cell (0, 1) is a ColWin
699 - cell (1, 0) is empty
700 - cell (1, 1) is a row of 3 Buttons
701 """
702
703 def __init__(self, parent):
704 wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
705
706 wwhite = ColWin(self, -1, wx.WHITE)
707 b1 = wx.Button(self, -1, 'button1', (-1, -1), wx.DefaultSize)
708 b2 = wx.Button(self, -1, 'button2', (-1, -1), wx.DefaultSize)
709 b3 = wx.Button(self, -1, 'button3', (-1, -1), wx.DefaultSize)
710 b4 = wx.Button(self, -1, 'button4', (-1, -1), wx.DefaultSize)
711 b5 = wx.Button(self, -1, 'button5', (-1, -1), wx.DefaultSize)
712 b6 = wx.Button(self, -1, 'button6', (-1, -1), wx.DefaultSize)
713
714 b = 0
715 hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
716 hsizer1.Add(b1, 0, wx.ALL, b)
717 hsizer1.Add((-1, -1), 1)
718 hsizer1.Add(b2, 0, wx.ALL, b)
719 hsizer1.Add((-1, -1), 1)
720 hsizer1.Add(b3, 0, wx.ALL, b)
721
722 b = 0
723 vsizer1 = wx.BoxSizer(wx.VERTICAL)
724 vsizer1.Add(b4, 0, wx.ALL, b)
725 vsizer1.Add((-1, -1), 1)
726 vsizer1.Add(b5, 0, wx.ALL, b)
727 vsizer1.Add((-1, -1), 1)
728 vsizer1.Add(b6, 0, wx.ALL, b)
729
730 hgap, vgap = 0, 0
731 nrows, ncols = 2, 2
732 fgs = wx.FlexGridSizer(nrows, ncols, hgap, vgap)
733
734 b = 5
735 fgs.AddMany([(vsizer1, 1, wx.EXPAND | wx.ALL, b),
736 (wwhite, 1, wx.EXPAND | wx.ALL, b),
737 ((-1, -1), 1, wx.EXPAND | wx.ALL, b),
738 (hsizer1, 1, wx.EXPAND | wx.ALL, b),
739 ])
740
741 #really tricky ;-)
742 fgs.AddGrowableRow(0)
743 fgs.AddGrowableCol(1)
744
745 self.SetSizer(fgs)
746
747 #-------------------------------------------------------------------
748
749 class MyPanel_22(wx.Panel):
750 """
751 - a FlexGridSizer of 9 cells (3x3) with 5 ColWins in cells and 4 empty cells
752 """
753
754 def __init__(self, parent):
755 wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
756
757 wwhite = ColWin(self, -1, wx.WHITE)
758 wblue = ColWin(self, -1, wx.BLUE)
759 wgreen = ColWin(self, -1, wx.GREEN)
760 wcyan = ColWin(self, -1, wx.CYAN)
761 wred = ColWin(self, -1, wx.RED)
762
763 hgap, vgap = 0, 0
764 nrows, ncols = 3, 3
765 fgs = wx.FlexGridSizer(nrows, ncols, hgap, vgap)
766
767 b = 5
768 fgs.AddMany([(wwhite, 1, wx.EXPAND | wx.ALL, b),
769 ((-1, -1), 1, wx.EXPAND | wx.ALL, b),
770 (wblue, 1, wx.EXPAND | wx.ALL, b),
771
772 ((-1, -1), 1, wx.EXPAND | wx.ALL, b),
773 (wgreen, 1, wx.EXPAND | wx.ALL, b),
774 ((-1, -1), 1, wx.EXPAND | wx.ALL, b),
775
776 (wred, 1, wx.EXPAND | wx.ALL, b),
777 ((-1, -1), 1, wx.EXPAND | wx.ALL, b),
778 (wcyan, 1, wx.EXPAND | wx.ALL, b),
779 ])
780
781 fgs.AddGrowableRow(0)
782 fgs.AddGrowableRow(1)
783 fgs.AddGrowableRow(2)
784
785 fgs.AddGrowableCol(0)
786 fgs.AddGrowableCol(1)
787 fgs.AddGrowableCol(2)
788
789 self.SetSizer(fgs)
790
791 #-------------------------------------------------------------------
792
793 class MyPanel_23(wx.Panel):
794 """
795 - a FlexGridSizer of 9 cells (3x3) with 4 ColWins in cells and 5 empty cells
796 - rows 1 and 3 have a fixed size
797 """
798
799 def __init__(self, parent):
800 wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
801
802 h = 40
803 wwhite = wx.Window(self, -1, (-1, -1), (-1, h), wx.SIMPLE_BORDER)
804 wwhite.SetBackgroundColour(wx.WHITE)
805 wblue = ColWin(self, -1, wx.BLUE)
806 wgreen = ColWin(self, -1, wx.GREEN)
807 wred = wx.Window(self, -1, (-1, -1), (-1, h), wx.SIMPLE_BORDER)
808 wred.SetBackgroundColour(wx.RED)
809
810 hgap, vgap = 0, 0
811 nrows, ncols = 3, 3
812 fgs = wx.FlexGridSizer(nrows, ncols, hgap, vgap)
813
814 b = 5
815 fgs.AddMany([((-1, -1), 1, wx.EXPAND | wx.ALL, b),
816 (wwhite, 1, wx.EXPAND | wx.ALL, b),
817 ((-1, -1), 1, wx.EXPAND | wx.ALL, b),
818
819 (wblue, 1, wx.EXPAND | wx.ALL, b),
820 ((-1, -1), 1, wx.EXPAND | wx.ALL, b),
821 (wgreen, 1, wx.EXPAND | wx.ALL, b),
822
823 ((-1, -1), 1, wx.EXPAND | wx.ALL, b),
824 (wred, 1, wx.EXPAND | wx.ALL, b),
825 ((-1, -1), 1, wx.EXPAND | wx.ALL, b),
826 ])
827
828 fgs.AddGrowableRow(1)
829
830 fgs.AddGrowableCol(0)
831 fgs.AddGrowableCol(1)
832 fgs.AddGrowableCol(2)
833
834 self.SetSizer(fgs)
835
836 #-------------------------------------------------------------------
837
838 class MyPanel_24(wx.Panel):
839 """
840 - this exemple is coming from one of my applications
841 - in the real app, the white window is a drawing area and
842 the five lower windows are StaticTexts with a defined
843 font size. This is why I force a fixed height.
844 """
845
846 def __init__(self, parent):
847 wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
848 self.parent = parent
849
850 #a menu for the beauty of the demo
851 menu1 = wx.Menu()
852 menu1.Append(101, '&aaa')
853 menuBar = wx.MenuBar()
854 menuBar.Append(menu1, '&File')
855 self.parent.SetMenuBar(menuBar)
856
857 wwhite = ColWin(self, -1, wx.WHITE)
858 wblue = ColWin(self, -1, wx.BLUE)
859 wgreen = ColWin(self, -1, wx.GREEN)
860 wcyan = ColWin(self, -1, wx.CYAN)
861 wred = ColWin(self, -1, wx.RED)
862 wcoral = ColWin(self, -1, wx.Colour('coral'))
863 staline = wx.StaticLine(self, -1, (-1, -1), (-1, 2), wx.LI_HORIZONTAL)
864
865 vsizer1 = wx.BoxSizer(wx.VERTICAL)
866 b = 5
867 vsizer1.Add(wblue, 1, wx.EXPAND | wx.BOTTOM, b)
868 vsizer1.Add(wgreen, 1, wx.EXPAND)
869
870 hsizer2 = wx.BoxSizer(wx.HORIZONTAL)
871 b = 5
872 minhe = 100
873 hsizer2.Add(wcoral, 2, wx.EXPAND | wx.RIGHT, b)
874 hsizer2.Add(wcyan, 3, wx.EXPAND | wx.RIGHT, b)
875 hsizer2.Add(wred, 3, wx.EXPAND | wx.RIGHT, b)
876 hsizer2.Add(vsizer1, 2, wx.EXPAND, border=b)
877 hsizer2.SetItemMinSize(wcoral, (-1, minhe))
878 hsizer2.SetItemMinSize(wcyan, (-1, minhe))
879 hsizer2.SetItemMinSize(wred, (-1, minhe))
880 hsizer2.SetItemMinSize(vsizer1, (-1, minhe))
881
882 vsizer3 = wx.BoxSizer(wx.VERTICAL)
883 b = 5
884 vsizer3.Add(staline, 0, wx.GROW | wx.ALL, 0)
885 vsizer3.Add(wwhite, 1, wx.EXPAND | wx.TOP | wx.LEFT | wx.RIGHT, b)
886 vsizer3.Add(hsizer2, 0, wx.EXPAND | wx.ALL, b)
887
888 self.SetSizerAndFit(vsizer3)
889
890 #-------------------------------------------------------------------
891
892 class MyPanel_25(wx.Panel):
893 """
894 - this shows the relaton between the font size and the size of the
895 widgets when sizers are used
896 """
897
898 def __init__(self, parent):
899 wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
900 self.parent = parent
901
902 fs = 20
903 self.SetFont(wx.Font(fs, wx.DEFAULT, wx.NORMAL, wx.NORMAL, False))
904
905 statxt1 = wx.StaticText(self, -1, 'one, two, three', (-1, -1), (-1, -1))
906 statxt1.SetBackgroundColour(wx.WHITE)
907 statxt2 = wx.StaticText(self, -1, 'eins, zwei, drei', (-1, -1), (-1, -1))
908 statxt3 = wx.StaticText(self, -1, 'un, deux, trois', (-1, -1), (-1, -1))
909 b1 = wx.Button(self, wx.NewIdRef(), 'button1', (-1, -1), (-1, -1))
910 b2 = wx.Button(self, wx.NewIdRef(), 'button2', (-1, -1), (-1, -1))
911
912 b = 5
913 hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
914 hsizer1.Add(b1, 1, wx.EXPAND | wx.ALL, b)
915 hsizer1.Add(b2, 1, wx.EXPAND | wx.ALL, b)
916
917 vsizer1 = wx.BoxSizer(wx.VERTICAL)
918 vsizer1.Add(statxt1, 0, wx.ALL, b)
919 vsizer1.Add(statxt2, 0, wx.ALL, b)
920 vsizer1.Add(statxt3, 0, wx.ALL, b)
921 vsizer1.Add(hsizer1, 0, wx.ALL, b)
922
923 self.SetSizerAndFit(vsizer1)
924 self.parent.SetClientSize(vsizer1.GetSize())
925
926 #-------------------------------------------------------------------
927
928 class MyPanel_26(wx.Panel):
929 """
930 - a GridBagSizer of 4 cells (2x2)
931 - Note: cell spanning is always specified
932 - gbs.Add.__doc__ : Add(self, item, GBPosition pos,
933 GBSpan span=DefaultSpan, int flag=0,
934 int border=0, userData=None) -> wx.GBSizerItem
935 """
936
937 def __init__(self, parent):
938 wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
939
940 wwhite = ColWin(self, -1, wx.WHITE)
941 wblue = ColWin(self, -1, wx.BLUE)
942 wgreen = ColWin(self, -1, wx.GREEN)
943 wred = ColWin(self, -1, wx.RED)
944
945 vgap, hgap = 10, 20
946 gbs = wx.GridBagSizer(vgap, hgap)
947
948 b = 0
949 gbs.Add(wwhite, (0, 0), (1, 1), wx.EXPAND | wx.ALL, b)
950 gbs.Add(wblue, (0, 1), (1, 1), wx.EXPAND | wx.ALL, b)
951 gbs.Add(wgreen, (1, 0), (1, 1), wx.EXPAND | wx.ALL, b)
952 gbs.Add(wred, (1, 1), (1, 1), wx.EXPAND | wx.ALL, b)
953
954 gbs.AddGrowableRow(0)
955 gbs.AddGrowableRow(1)
956 gbs.AddGrowableCol(0)
957 gbs.AddGrowableCol(1)
958
959 self.SetSizer(gbs)
960
961 #-------------------------------------------------------------------
962
963 class MyPanel_27(wx.Panel):
964 """
965 - a GridBagSizer of 9 cells (3x3)
966 - Note: cell spanning is always specified
967 - vgap and hgap define the space between the cells and not
968 between the cells and the border of the panel/frame.
969 This example creates a constant spacing for all cells.
970
971 """
972
973 def __init__(self, parent):
974 wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
975
976 wwhite = ColWin(self, -1, wx.WHITE)
977 wblue = ColWin(self, -1, wx.BLUE)
978 wgreen = ColWin(self, -1, wx.GREEN)
979 wred = ColWin(self, -1, wx.RED)
980 wblack = ColWin(self, -1, wx.BLACK)
981 wpink = ColWin(self, -1, wx.Colour('pink'))
982 wyellow = ColWin(self, -1, wx.Colour('yellow'))
983 wcyan = ColWin(self, -1, wx.Colour('cyan'))
984 worange = ColWin(self, -1, wx.Colour('orange'))
985
986 vgap = hgap = 10
987 gbs = wx.GridBagSizer(vgap, hgap)
988
989 b = vgap
990 gbs.Add(wwhite, (0, 0), (1, 1), wx.EXPAND | wx.LEFT | wx.TOP, b)
991 gbs.Add(wblue, (0, 1), (1, 1), wx.EXPAND | wx.TOP, b)
992 gbs.Add(wgreen, (0, 2), (1, 1), wx.EXPAND | wx.RIGHT | wx.TOP, b)
993
994 gbs.Add(wred, (1, 0), (1, 1), wx.EXPAND | wx.LEFT, b)
995 gbs.Add(wblack, (1, 1), (1, 1), wx.EXPAND)
996 gbs.Add(wpink, (1, 2), (1, 1), wx.EXPAND | wx.RIGHT, b)
997
998 gbs.Add(wyellow, (2, 0), (1, 1), wx.EXPAND | wx.LEFT | wx.BOTTOM, b)
999 gbs.Add(wcyan, (2, 1), (1, 1), wx.EXPAND | wx.BOTTOM, b)
1000 gbs.Add(worange, (2, 2), (1, 1), wx.EXPAND | wx.RIGHT | wx.BOTTOM, b)
1001
1002 gbs.AddGrowableRow(0)
1003 gbs.AddGrowableRow(1)
1004 gbs.AddGrowableRow(2)
1005 gbs.AddGrowableCol(0)
1006 gbs.AddGrowableCol(1)
1007 gbs.AddGrowableCol(2)
1008
1009 self.SetSizer(gbs)
1010
1011 #-------------------------------------------------------------------
1012
1013 class MyPanel_28(wx.Panel):
1014 """
1015 - a GridBagSizer of 9 cells (3x3)
1016 - Layout like MyPanel_27, uses a secondary sizer to get a border
1017 """
1018
1019 def __init__(self, parent):
1020 wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
1021
1022 wwhite = ColWin(self, -1, wx.WHITE)
1023 wblue = ColWin(self, -1, wx.BLUE)
1024 wgreen = ColWin(self, -1, wx.GREEN)
1025 wred = ColWin(self, -1, wx.RED)
1026 wblack = ColWin(self, -1, wx.BLACK)
1027 wpink = ColWin(self, -1, wx.Colour('pink'))
1028 wyellow = ColWin(self, -1, wx.Colour('yellow'))
1029 wcyan = ColWin(self, -1, wx.Colour('cyan'))
1030 worange = ColWin(self, -1, wx.Colour('orange'))
1031
1032 vgap = hgap = 10
1033 gbs = wx.GridBagSizer(vgap, hgap)
1034
1035 b = 0
1036 gbs.Add(wwhite, (0, 0), (1, 1), wx.EXPAND, b)
1037 gbs.Add(wblue, (0, 1), (1, 1), wx.EXPAND, b)
1038 gbs.Add(wgreen, (0, 2), (1, 1), wx.EXPAND, b)
1039
1040 gbs.Add(wred, (1, 0), (1, 1), wx.EXPAND, b)
1041 gbs.Add(wblack, (1, 1), (1, 1), wx.EXPAND)
1042 gbs.Add(wpink, (1, 2), (1, 1), wx.EXPAND, b)
1043
1044 gbs.Add(wyellow, (2, 0), (1, 1), wx.EXPAND, b)
1045 gbs.Add(wcyan, (2, 1), (1, 1), wx.EXPAND, b)
1046 gbs.Add(worange, (2, 2), (1, 1), wx.EXPAND, b)
1047
1048 gbs.AddGrowableRow(0)
1049 gbs.AddGrowableRow(1)
1050 gbs.AddGrowableRow(2)
1051 gbs.AddGrowableCol(0)
1052 gbs.AddGrowableCol(1)
1053 gbs.AddGrowableCol(2)
1054
1055 b = vgap
1056 vsizer1 = wx.BoxSizer(wx.VERTICAL)
1057 vsizer1.Add(gbs, 1, wx.EXPAND | wx.ALL, b)
1058 self.SetSizer(vsizer1)
1059
1060 #-------------------------------------------------------------------
1061
1062 class MyPanel_29(wx.Panel):
1063 """
1064 - a GridBagSizer of 25 cells (5x5)
1065 - spanning
1066 - cell (1, 1) is empty
1067 - when spanning, cells ovelapping raises an error. This explains
1068 the commented lines for unused coloured windows.
1069 """
1070
1071 def __init__(self, parent):
1072 wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
1073
1074 wwhite = ColWin(self, -1, wx.WHITE)
1075 #~ wblue = ColWin(self, -1, wx.BLUE)
1076 #~ wgreen = ColWin(self, -1, wx.GREEN)
1077 wred = ColWin(self, -1, wx.RED)
1078 wblack = ColWin(self, -1, wx.BLACK)
1079
1080 wpink = ColWin(self, -1, wx.Colour('pink'))
1081 #~ wyellow = ColWin(self, -1, wx.Colour('yellow'))
1082 wcyan = ColWin(self, -1, wx.Colour('cyan'))
1083 worange = ColWin(self, -1, wx.Colour('orange'))
1084 wgold = ColWin(self, -1, wx.Colour('gold'))
1085
1086 wtan = ColWin(self, -1, wx.Colour('tan'))
1087 wcoral = ColWin(self, -1, wx.Colour('coral'))
1088 #~ wplum = ColWin(self, -1, wx.Colour('plum'))
1089 wspringgreen = ColWin(self, -1, wx.Colour('spring green'))
1090 #~ wbrown = ColWin(self, -1, wx.Colour('brown'))
1091
1092 wwheat = ColWin(self, -1, wx.Colour('wheat'))
1093 #~ wvioletred = ColWin(self, -1, wx.Colour('violet red'))
1094 #~ wgoldenrod = ColWin(self, -1, wx.Colour('goldenrod'))
1095 wpalegreen = ColWin(self, -1, wx.Colour('pale green'))
1096 #~ wyellowgreen = ColWin(self, -1, wx.Colour('yellow green'))
1097
1098 wnavy = ColWin(self, -1, wx.Colour('navy'))
1099 wskyblue = ColWin(self, -1, wx.Colour('sky blue'))
1100 wmagenta = ColWin(self, -1, wx.Colour('magenta'))
1101 wkhaki = ColWin(self, -1, wx.Colour('khaki'))
1102 #~ wslateblue = ColWin(self, -1, wx.Colour('slate blue'))
1103
1104 vgap = hgap = 10
1105 gbs = wx.GridBagSizer(vgap, hgap)
1106
1107 b = 0
1108 gbs.Add(wwhite, (0, 0), (1, 3), wx.EXPAND | wx.ALL, b)
1109 #~ gbs.Add(wblue, (0, 1), (1, 1), wx.EXPAND | wx.ALL, b)
1110 #~ gbs.Add(wgreen, (0, 2), (1, 1), wx.EXPAND | wx.ALL, b)
1111 gbs.Add(wred, (0, 3), (1, 1), wx.EXPAND | wx.ALL, b)
1112 gbs.Add(wblack, (0, 4), (1, 1), wx.EXPAND | wx.ALL, b)
1113
1114 gbs.Add(wpink, (1, 0), (1, 1), wx.EXPAND | wx.ALL, b)
1115 #~ gbs.Add(wyellow, (1, 1), (1, 1), wx.EXPAND | wx.ALL, b)
1116 gbs.Add(wcyan, (1, 2), (1, 1), wx.EXPAND | wx.ALL, b)
1117 gbs.Add(worange, (1, 3), (1, 1), wx.EXPAND | wx.ALL, b)
1118 gbs.Add(wgold, (1, 4), (4, 1), wx.EXPAND | wx.ALL, b)
1119
1120 gbs.Add(wtan, (2, 0), (1, 1), wx.EXPAND | wx.ALL, b)
1121 gbs.Add(wcoral, (2, 1), (2, 2), wx.EXPAND | wx.ALL, b)
1122 #~ gbs.Add(wplum, (2, 2), (1, 1), wx.EXPAND | wx.ALL, b)
1123 gbs.Add(wspringgreen, (2, 3), (1, 1), wx.EXPAND | wx.ALL, b)
1124 #~ gbs.Add(wbrown, (2, 4), (1, 1), wx.EXPAND | wx.ALL, b)
1125
1126 gbs.Add(wwheat, (3, 0), (1, 1), wx.EXPAND | wx.ALL, b)
1127 #~ gbs.Add(wvioletred, (3, 1), (1, 1), wx.EXPAND | wx.ALL, b)
1128 #~ gbs.Add(wgoldenrod, (3, 2), (1, 1), wx.EXPAND | wx.ALL, b)
1129 gbs.Add(wpalegreen, (3, 3), (1, 1), wx.EXPAND | wx.ALL, b)
1130 #~ gbs.Add(wyellowgreen, (3, 4), (1, 1), wx.EXPAND | wx.ALL, b)
1131
1132 gbs.Add(wnavy, (4, 0), (1, 1), wx.EXPAND | wx.ALL, b)
1133 gbs.Add(wskyblue, (4, 1), (1, 1), wx.EXPAND | wx.ALL, b)
1134 gbs.Add(wmagenta, (4, 2), (1, 1), wx.EXPAND | wx.ALL, b)
1135 gbs.Add(wkhaki, (4, 3), (1, 1), wx.EXPAND | wx.ALL, b)
1136 #~ gbs.Add(wslateblue, (4, 4), (1, 1), wx.EXPAND | wx.ALL, b)
1137
1138 gbs.AddGrowableRow(0)
1139 gbs.AddGrowableRow(1)
1140 gbs.AddGrowableRow(2)
1141 gbs.AddGrowableRow(3)
1142 gbs.AddGrowableRow(4)
1143 gbs.AddGrowableCol(0)
1144 gbs.AddGrowableCol(1)
1145 gbs.AddGrowableCol(2)
1146 gbs.AddGrowableCol(3)
1147 gbs.AddGrowableCol(4)
1148
1149 self.SetSizer(gbs)
1150
1151 #-------------------------------------------------------------------
1152
1153 class MyPanel_30(wx.Panel):
1154 """
1155 - a GridBagSizer of 16 cells (4x4)
1156 """
1157
1158 def __init__(self, parent):
1159 wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
1160
1161 wwhite = ColWin(self, -1, wx.WHITE)
1162 wblue = ColWin(self, -1, wx.BLUE)
1163 wgreen = ColWin(self, -1, wx.GREEN)
1164 wred = ColWin(self, -1, wx.RED)
1165
1166 wpink = ColWin(self, -1, wx.Colour('pink'))
1167 wyellow = ColWin(self, -1, wx.Colour('yellow'))
1168 wcyan = ColWin(self, -1, wx.Colour('cyan'))
1169 worange = ColWin(self, -1, wx.Colour('orange'))
1170
1171 wtan = ColWin(self, -1, wx.Colour('tan'))
1172 wcoral = ColWin(self, -1, wx.Colour('coral'))
1173 wplum = ColWin(self, -1, wx.Colour('plum'))
1174 wspringgreen = ColWin(self, -1, wx.Colour('spring green'))
1175
1176 wwheat = ColWin(self, -1, wx.Colour('wheat'))
1177 wvioletred = ColWin(self, -1, wx.Colour('violet red'))
1178 wgoldenrod = ColWin(self, -1, wx.Colour('goldenrod'))
1179 wpalegreen = ColWin(self, -1, wx.Colour('pale green'))
1180
1181 vgap = hgap = 10
1182 gbs = wx.GridBagSizer(vgap, hgap)
1183
1184 b = 0
1185 gbs.Add(wwhite, (0, 0), (1, 1), wx.EXPAND | wx.ALL, b)
1186 gbs.Add(wblue, (0, 1), (1, 1), wx.EXPAND | wx.ALL, b)
1187 gbs.Add(wgreen, (0, 2), (1, 1), wx.EXPAND | wx.ALL, b)
1188 gbs.Add(wred, (0, 3), (1, 1), wx.EXPAND | wx.ALL, b)
1189
1190 gbs.Add(wpink, (1, 0), (1, 1), wx.EXPAND | wx.ALL, b)
1191 gbs.Add(wyellow, (1, 1), (1, 1), wx.EXPAND | wx.ALL, b)
1192 gbs.Add(wcyan, (1, 2), (1, 1), wx.EXPAND | wx.ALL, b)
1193 gbs.Add(worange, (1, 3), (1, 1), wx.EXPAND | wx.ALL, b)
1194
1195 gbs.Add(wtan, (2, 0), (1, 1), wx.EXPAND | wx.ALL, b)
1196 gbs.Add(wcoral, (2, 1), (1, 1), wx.EXPAND | wx.ALL, b)
1197 gbs.Add(wplum, (2, 2), (1, 1), wx.EXPAND | wx.ALL, b)
1198 gbs.Add(wspringgreen, (2, 3), (1, 1), wx.EXPAND | wx.ALL, b)
1199
1200 gbs.Add(wwheat, (3, 0), (1, 1), wx.EXPAND | wx.ALL, b)
1201 gbs.Add(wvioletred, (3, 1), (1, 1), wx.EXPAND | wx.ALL, b)
1202 gbs.Add(wgoldenrod, (3, 2), (1, 1), wx.EXPAND | wx.ALL, b)
1203 gbs.Add(wpalegreen, (3, 3), (1, 1), wx.EXPAND | wx.ALL, b)
1204
1205 gbs.AddGrowableRow(0)
1206 gbs.AddGrowableRow(1)
1207 #~ gbs.AddGrowableRow(2)
1208 gbs.AddGrowableRow(3)
1209 gbs.AddGrowableCol(0)
1210 gbs.AddGrowableCol(1)
1211 #~ gbs.AddGrowableCol(2)
1212 gbs.AddGrowableCol(3)
1213
1214 self.SetSizer(gbs)
1215
1216 #~ for e in dir(gbs):
1217 #~ print e
1218 print(gbs.SetDimension.__doc__)
1219
1220 #-------------------------------------------------------------------
1221
1222 class MyPanel_31(wx.Panel):
1223 """
1224 - based on MyPanel_15 where the central button has been replaced by
1225 an horizontal sizer conaining two buttons.
1226 """
1227
1228 def __init__(self, parent):
1229 wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
1230
1231 wgreen = ColWin(self, wx.NewIdRef(), wx.Colour('green'))
1232 b1 = wx.Button(self, wx.NewIdRef(), 'button1', (-1, -1), wx.DefaultSize)
1233 b2 = wx.Button(self, wx.NewIdRef(), 'button2', (-1, -1), wx.DefaultSize)
1234 b3 = wx.Button(self, wx.NewIdRef(), 'button3', (-1, -1), wx.DefaultSize)
1235 b4 = wx.Button(self, wx.NewIdRef(), 'button4', (-1, -1), wx.DefaultSize)
1236
1237 b = 0
1238 hsizer1a = wx.BoxSizer(wx.HORIZONTAL)
1239 hsizer1a.Add(b2, 0, wx.ALL, b)
1240 hsizer1a.Add(b3, 0, wx.ALL, b)
1241
1242 b = 0
1243 hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
1244 hsizer1.Add(b1, 0, wx.ALL, b)
1245 hsizer1.Add((-1, -1), 1)
1246 hsizer1.Add(hsizer1a, 0, wx.ALL, b)
1247 hsizer1.Add((-1, -1), 1)
1248 hsizer1.Add(b4, 0, wx.ALL, b)
1249
1250 b = 0
1251 hsizer1b = wx.BoxSizer(wx.HORIZONTAL)
1252 hsizer1b.Add((-1, -1), 1)
1253 hsizer1b.Add(wgreen, 1, wx.EXPAND | wx.ALL, b)
1254 hsizer1b.Add((-1, -1), 1)
1255
1256 b = 5
1257 vsizer2 = wx.BoxSizer(wx.VERTICAL)
1258 vsizer2.Add(hsizer1, 0, wx.EXPAND | wx.ALL, b)
1259 #~ vsizer2.Add(wgreen, 1, wx.EXPAND | wx.ALL, b)
1260 vsizer2.Add(hsizer1b, 1, wx.EXPAND | wx.ALL, b)
1261 self.SetSizer(vsizer2)
1262
1263 #-------------------------------------------------------------------
1264
1265 class TestComboBox(wx.Panel):
1266 def __init__(self, parent, id):
1267 wx.Panel.__init__(self, parent, id)
1268
1269 sampleList = []
1270 for i in range(0, 32):
1271 sampleList.append('MyPanel_' + str(i))
1272
1273 self.st = wx.StaticText(self, -1, "Select the example you want to see."
1274 "Then click the View button.", (-1, -1))
1275
1276 self.doctxt = wx.StaticText(self, -1, "")
1277 self.doctxt.SetLabel(MyPanel_0.__doc__)
1278
1279 # This combobox is created with a preset list of values.
1280 self.cb = wx.ComboBox(self, -1, "MyPanel_0", (-1, -1),
1281 (-1, -1), sampleList, wx.CB_DROPDOWN | wx.CB_READONLY
1282 )
1283
1284 self.stline = wx.StaticLine(self, -1, (-1, -1), (-1, 2), wx.LI_HORIZONTAL)
1285
1286 btnView = wx.Button(self, -1, "&View")
1287 self.Bind(wx.EVT_BUTTON, self.OnClickView, btnView)
1288
1289 btnExit = wx.Button(self, -1, "E&xit")
1290 self.Bind(wx.EVT_BUTTON, self.OnClickExit, btnExit)
1291
1292 b = 5
1293 vsizer1 = wx.BoxSizer(wx.VERTICAL)
1294 vsizer1.Add(self.st, 0, wx.EXPAND | wx.ALL, b)
1295 vsizer1.Add(self.cb, 0, wx.EXPAND | wx.ALL, 0)
1296 vsizer1.Add(self.doctxt, 0, wx.EXPAND | wx.ALL, b)
1297
1298 hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
1299 hsizer1.Add(btnView, 0)
1300 hsizer1.Add(btnExit, 0, wx.LEFT, b)
1301
1302 vsizer2 = wx.BoxSizer(wx.VERTICAL)
1303 vsizer2.Add(vsizer1, 5, wx.EXPAND | wx.ALL, 0)
1304 vsizer2.Add(self.stline, 0, wx.GROW | wx.ALL, b)
1305 vsizer2.Add(hsizer1, 1, wx.ALIGN_RIGHT | wx.ALL, b)
1306 self.SetSizer(vsizer2)
1307
1308 self.Bind(wx.EVT_COMBOBOX, self.OnEvtComboBox, self.cb)
1309
1310 #~ Based on Tim Roberts' proposal
1311 #~ Tim Roberts, timr@probo.com
1312 # When the user selects something, we go here.
1313 def OnEvtComboBox(self, evt):
1314 self.doctxt.SetLabel(eval('%s.__doc__' % evt.GetString()))
1315
1316 def OnClickView(self, evt):
1317 win = wx.Frame(self, -1, self.cb.GetValue(), size=(500, 300),
1318 style = wx.DEFAULT_FRAME_STYLE)
1319 eval('%s(win)' % self.cb.GetValue())
1320
1321 win.CenterOnScreen()
1322 win.Show(True)
1323
1324 def OnClickExit(self, evt):
1325 sys.exit()
1326
1327 #-------------------------------------------------------------------
1328
1329 class MyApp(wx.App):
1330
1331 def OnInit(self):
1332 frame = wx.Frame(None, -1, __file__, (0, 0), (450, 300))
1333 frame.panel = TestComboBox(frame, -1)
1334 frame.Show(True)
1335 self.SetTopWindow(frame)
1336 return True
1337
1338 #-------------------------------------------------------------------
1339
1340 def main():
1341 app = MyApp(False)
1342 app.MainLoop()
1343
1344 #-------------------------------------------------------------------
1345
1346 if __name__ == "__main__" :
1347 main()
Additional Information
Link :
- - - - -
https://wiki.wxpython.org/TitleIndex
Thanks to
Jean-Michel Fauth, the wxPython community...
About this page
Date(d/m/y) Person (bot) Comments :
27/06/05 - Jean-Michel Fauth (Created page).
26/11/23 - Ecco (Updated page and code for wxPython Phoenix).
Comments
- blah, blah, blah