1 #----------------------------------------------------------------------
3 #----------------------------------------------------------------------
5 from wxPython
.wx
import *
6 from wxPython
.lib
.grids
import wxGridSizer
, wxFlexGridSizer
8 #----------------------------------------------------------------------
10 def makeSimpleBox1(win
):
11 box
= wxBoxSizer(wxHORIZONTAL
)
12 box
.Add(wxButton(win
, 1010, "one"), 0, wxEXPAND
)
13 box
.Add(wxButton(win
, 1010, "two"), 0, wxEXPAND
)
14 box
.Add(wxButton(win
, 1010, "three"), 0, wxEXPAND
)
15 box
.Add(wxButton(win
, 1010, "four"), 0, wxEXPAND
)
19 #----------------------------------------------------------------------
21 def makeSimpleBox2(win
):
22 box
= wxBoxSizer(wxVERTICAL
)
23 box
.Add(wxButton(win
, 1010, "one"), 0, wxEXPAND
)
24 box
.Add(wxButton(win
, 1010, "two"), 0, wxEXPAND
)
25 box
.Add(wxButton(win
, 1010, "three"), 0, wxEXPAND
)
26 box
.Add(wxButton(win
, 1010, "four"), 0, wxEXPAND
)
30 #----------------------------------------------------------------------
32 def makeSimpleBox3(win
):
33 box
= wxBoxSizer(wxHORIZONTAL
)
34 box
.Add(wxButton(win
, 1010, "one"), 0, wxEXPAND
)
35 box
.Add(wxButton(win
, 1010, "two"), 0, wxEXPAND
)
36 box
.Add(wxButton(win
, 1010, "three"), 0, wxEXPAND
)
37 box
.Add(wxButton(win
, 1010, "four"), 0, wxEXPAND
)
38 box
.Add(wxButton(win
, 1010, "five"), 1, wxEXPAND
)
42 #----------------------------------------------------------------------
44 def makeSimpleBox4(win
):
45 box
= wxBoxSizer(wxHORIZONTAL
)
46 box
.Add(wxButton(win
, 1010, "one"), 0, wxEXPAND
)
47 box
.Add(wxButton(win
, 1010, "two"), 0, wxEXPAND
)
48 box
.Add(wxButton(win
, 1010, "three"), 1, wxEXPAND
)
49 box
.Add(wxButton(win
, 1010, "four"), 1, wxEXPAND
)
50 box
.Add(wxButton(win
, 1010, "five"), 1, wxEXPAND
)
54 #----------------------------------------------------------------------
56 def makeSimpleBox5(win
):
57 box
= wxBoxSizer(wxHORIZONTAL
)
58 box
.Add(wxButton(win
, 1010, "one"), 0, wxEXPAND
)
59 box
.Add(wxButton(win
, 1010, "two"), 0, wxEXPAND
)
60 box
.Add(wxButton(win
, 1010, "three"), 3, wxEXPAND
)
61 box
.Add(wxButton(win
, 1010, "four"), 1, wxEXPAND
)
62 box
.Add(wxButton(win
, 1010, "five"), 1, wxEXPAND
)
66 #----------------------------------------------------------------------
68 def makeSimpleBox6(win
):
69 box
= wxBoxSizer(wxHORIZONTAL
)
70 box
.Add(wxButton(win
, 1010, "one"), 1, wxALIGN_TOP
)
71 box
.Add(wxButton(win
, 1010, "two"), 1, wxEXPAND
)
72 box
.Add(wxButton(win
, 1010, "three"), 1, wxCENTER
)
73 box
.Add(wxButton(win
, 1010, "four"), 1, wxEXPAND
)
74 box
.Add(wxButton(win
, 1010, "five"), 1, wxALIGN_BOTTOM
)
78 #----------------------------------------------------------------------
80 def makeSimpleBox7(win
):
81 box
= wxBoxSizer(wxHORIZONTAL
)
82 box
.Add(wxButton(win
, 1010, "one"), 0, wxEXPAND
)
83 box
.Add(wxButton(win
, 1010, "two"), 0, wxEXPAND
)
84 box
.Add(wxButton(win
, 1010, "three"), 0, wxEXPAND
)
85 box
.Add(60, 20, 0, wxEXPAND
)
86 box
.Add(wxButton(win
, 1010, "five"), 1, wxEXPAND
)
90 #----------------------------------------------------------------------
91 #----------------------------------------------------------------------
93 def makeSimpleBorder1(win
):
94 bdr
= wxBoxSizer(wxHORIZONTAL
)
95 btn
= wxButton(win
, 1010, "border")
96 btn
.SetSize(wxSize(80, 80))
97 bdr
.Add(btn
, 1, wxEXPAND|wxALL
, 15)
101 #----------------------------------------------------------------------
103 def makeSimpleBorder2(win
):
104 bdr
= wxBoxSizer(wxHORIZONTAL
)
105 btn
= wxButton(win
, 1010, "border")
106 btn
.SetSize(wxSize(80, 80))
107 bdr
.Add(btn
, 1, wxEXPAND | wxEAST | wxWEST
, 15)
111 #----------------------------------------------------------------------
113 def makeSimpleBorder3(win
):
114 bdr
= wxBoxSizer(wxHORIZONTAL
)
115 btn
= wxButton(win
, 1010, "border")
116 btn
.SetSize(wxSize(80, 80))
117 bdr
.Add(btn
, 1, wxEXPAND | wxNORTH | wxWEST
, 15)
121 #----------------------------------------------------------------------
122 #----------------------------------------------------------------------
124 def makeBoxInBox(win
):
125 box
= wxBoxSizer(wxVERTICAL
)
127 box
.Add(wxButton(win
, 1010, "one"), 0, wxEXPAND
)
129 box2
= wxBoxSizer(wxHORIZONTAL
)
130 box2
.AddMany([ (wxButton(win
, 1010, "two"), 0, wxEXPAND
),
131 (wxButton(win
, 1010, "three"), 0, wxEXPAND
),
132 (wxButton(win
, 1010, "four"), 0, wxEXPAND
),
133 (wxButton(win
, 1010, "five"), 0, wxEXPAND
),
136 box3
= wxBoxSizer(wxVERTICAL
)
137 box3
.AddMany([ (wxButton(win
, 1010, "six"), 0, wxEXPAND
),
138 (wxButton(win
, 1010, "seven"), 2, wxEXPAND
),
139 (wxButton(win
, 1010, "eight"), 1, wxEXPAND
),
140 (wxButton(win
, 1010, "nine"), 1, wxEXPAND
),
143 box2
.Add(box3
, 1, wxEXPAND
)
144 box
.Add(box2
, 1, wxEXPAND
)
146 box
.Add(wxButton(win
, 1010, "ten"), 0, wxEXPAND
)
150 #----------------------------------------------------------------------
152 def makeBoxInBorder(win
):
153 bdr
= wxBoxSizer(wxHORIZONTAL
)
154 box
= makeSimpleBox3(win
)
155 bdr
.Add(box
, 1, wxEXPAND | wxALL
, 15)
159 #----------------------------------------------------------------------
161 def makeBorderInBox(win
):
162 insideBox
= wxBoxSizer(wxHORIZONTAL
)
164 box2
= wxBoxSizer(wxHORIZONTAL
)
165 box2
.AddMany([ (wxButton(win
, 1010, "one"), 0, wxEXPAND
),
166 (wxButton(win
, 1010, "two"), 0, wxEXPAND
),
167 (wxButton(win
, 1010, "three"), 0, wxEXPAND
),
168 (wxButton(win
, 1010, "four"), 0, wxEXPAND
),
169 (wxButton(win
, 1010, "five"), 0, wxEXPAND
),
172 insideBox
.Add(box2
, 0, wxEXPAND
)
174 bdr
= wxBoxSizer(wxHORIZONTAL
)
175 bdr
.Add(wxButton(win
, 1010, "border"), 1, wxEXPAND | wxALL
)
176 insideBox
.Add(bdr
, 1, wxEXPAND | wxALL
, 20)
178 box3
= wxBoxSizer(wxVERTICAL
)
179 box3
.AddMany([ (wxButton(win
, 1010, "six"), 0, wxEXPAND
),
180 (wxButton(win
, 1010, "seven"), 2, wxEXPAND
),
181 (wxButton(win
, 1010, "eight"), 1, wxEXPAND
),
182 (wxButton(win
, 1010, "nine"), 1, wxEXPAND
),
184 insideBox
.Add(box3
, 1, wxEXPAND
)
186 outsideBox
= wxBoxSizer(wxVERTICAL
)
187 outsideBox
.Add(wxButton(win
, 1010, "top"), 0, wxEXPAND
)
188 outsideBox
.Add(insideBox
, 1, wxEXPAND
)
189 outsideBox
.Add(wxButton(win
, 1010, "bottom"), 0, wxEXPAND
)
194 #----------------------------------------------------------------------
197 gs
= wxGridSizer(3, 3, 2, 2) # rows, cols, hgap, vgap
199 gs
.AddMany([ (wxButton(win
, 1010, 'one'), 0, wxEXPAND
),
200 (wxButton(win
, 1010, 'two'), 0, wxEXPAND
),
201 (wxButton(win
, 1010, 'three'), 0, wxEXPAND
),
202 (wxButton(win
, 1010, 'four'), 0, wxEXPAND
),
203 (wxButton(win
, 1010, 'five'), 0, wxEXPAND
),
205 (wxButton(win
, 1010, 'six'), 0, wxEXPAND
),
206 (wxButton(win
, 1010, 'seven'), 0, wxEXPAND
),
207 (wxButton(win
, 1010, 'eight'), 0, wxEXPAND
),
208 (wxButton(win
, 1010, 'nine'), 0, wxEXPAND
),
213 #----------------------------------------------------------------------
216 gs
= wxGridSizer(3, 3) # rows, cols, hgap, vgap
218 box
= wxBoxSizer(wxVERTICAL
)
219 box
.Add(wxButton(win
, 1010, 'A'), 0, wxEXPAND
)
220 box
.Add(wxButton(win
, 1010, 'B'), 1, wxEXPAND
)
222 gs2
= wxGridSizer(2,2, 4, 4)
223 gs2
.AddMany([ (wxButton(win
, 1010, 'C'), 0, wxEXPAND
),
224 (wxButton(win
, 1010, 'E'), 0, wxEXPAND
),
225 (wxButton(win
, 1010, 'F'), 0, wxEXPAND
),
226 (wxButton(win
, 1010, 'G'), 0, wxEXPAND
)])
228 gs
.AddMany([ (wxButton(win
, 1010, 'one'), 0, wxALIGN_RIGHT | wxALIGN_BOTTOM
),
229 (wxButton(win
, 1010, 'two'), 0, wxEXPAND
),
230 (wxButton(win
, 1010, 'three'), 0, wxALIGN_LEFT | wxALIGN_BOTTOM
),
231 (wxButton(win
, 1010, 'four'), 0, wxEXPAND
),
232 (wxButton(win
, 1010, 'five'), 0, wxCENTER
),
233 (wxButton(win
, 1010, 'six'), 0, wxEXPAND
),
234 (box
, 0, wxEXPAND | wxALL
, 10),
235 (wxButton(win
, 1010, 'eight'), 0, wxEXPAND
),
236 (gs2
, 0, wxEXPAND | wxALL
, 4),
241 #----------------------------------------------------------------------
244 gs
= wxFlexGridSizer(3, 3, 2, 2) # rows, cols, hgap, vgap
246 gs
.AddMany([ (wxButton(win
, 1010, 'one'), 0, wxEXPAND
),
247 (wxButton(win
, 1010, 'two'), 0, wxEXPAND
),
248 (wxButton(win
, 1010, 'three'), 0, wxEXPAND
),
249 (wxButton(win
, 1010, 'four'), 0, wxEXPAND
),
250 #(wxButton(win, 1010, 'five'), 0, wxEXPAND),
252 (wxButton(win
, 1010, 'six'), 0, wxEXPAND
),
253 (wxButton(win
, 1010, 'seven'), 0, wxEXPAND
),
254 (wxButton(win
, 1010, 'eight'), 0, wxEXPAND
),
255 (wxButton(win
, 1010, 'nine'), 0, wxEXPAND
),
263 #----------------------------------------------------------------------
266 ("Simple horizontal boxes", makeSimpleBox1
,
267 "This is a HORIZONTAL box sizer with four non-stretchable buttons held "
268 "within it. Notice that the buttons are added and aligned in the horizontal "
269 "dimension. Also notice that they are fixed size in the horizontal dimension, "
270 "but will stretch vertically."
273 ("Simple vertical boxes", makeSimpleBox2
,
274 "Exactly the same as the previous sample but using a VERTICAL box sizer "
275 "instead of a HORIZONTAL one."
278 ("Add a stretchable", makeSimpleBox3
,
279 "We've added one more button with the strechable flag turned on. Notice "
280 "how it grows to fill the extra space in the otherwise fixed dimension."
283 ("More than one stretchable", makeSimpleBox4
,
284 "Here there are several items that are stretchable, they all divide up the "
285 "extra space evenly."
288 ("Weighting factor", makeSimpleBox5
,
289 "This one shows more than one strechable, but one of them has a weighting "
290 "factor so it gets more of the free space."
293 ("Edge Affinity", makeSimpleBox6
,
294 "For items that don't completly fill their allotted space, and don't "
295 "stretch, you can specify which side (or the center) they should stay "
299 ("Spacer", makeSimpleBox7
,
300 "You can add empty space to be managed by a Sizer just as if it were a "
301 "window or another Sizer."
304 # ("Percent Sizer", makeSimpleBox6,
305 # "You can use the wxBoxSizer like a Percent Sizer. Just make sure that all "
306 # "the weighting factors add up to 100!"
311 ("Simple border sizer", makeSimpleBorder1
,
312 "The wxBorderSizer leaves empty space around its contents. This one "
313 "gives a border all the way around."
316 ("East and West border", makeSimpleBorder2
,
317 "You can pick and choose which sides have borders."
320 ("North and West border", makeSimpleBorder3
,
321 "You can pick and choose which sides have borders."
326 ("Boxes inside of boxes", makeBoxInBox
,
327 "This one shows nesting of boxes within boxes within boxes, using both "
328 "orientations. Notice also that button seven has a greater weighting "
329 "factor than its siblings."
332 ("Boxes inside a Border", makeBoxInBorder
,
333 "Sizers of different types can be nested withing each other as well. "
334 "Here is a box sizer with several buttons embedded within a border sizer."
337 ("Border in a Box", makeBorderInBox
,
338 "Another nesting example. This one has Boxes and a Border inside another Box."
343 ("Simple Grid", makeGrid1
,
344 "This is an example of the wxGridSizer. In this case all row heights "
345 "and column widths are kept the same as all the others and all items "
346 "fill their available space. The horzontal and vertical gaps are set to "
350 ("More Grid Features", makeGrid2
,
351 "This is another example of the wxGridSizer. This one has no gaps in the grid, "
352 "but various cells are given different alignment options and some of them "
353 "hold nested sizers."
356 ("Flexible Grid", makeGrid3
,
357 "This grid allows the rows to have different heights and the columns to have "
358 "different widths. You can also specify rows and columns that are growable, "
359 "which we have done for the first and last row and the middle column for "
361 "\nThere is also a spacer in the middle cell instead of an actual window."
365 #----------------------------------------------------------------------
367 class TestFrame(wxFrame
):
368 def __init__(self
, parent
, title
, sizerFunc
):
369 wxFrame
.__init
__(self
, parent
, -1, title
)
370 EVT_BUTTON(self
, 1010, self
.OnButton
)
372 self
.sizer
= sizerFunc(self
)
373 self
.CreateStatusBar()
374 self
.SetStatusText("Resize this frame to see how the sizers respond...")
377 self
.SetAutoLayout(true
)
378 self
.SetSizer(self
.sizer
)
380 def OnCloseWindow(self
, event
):
381 self
.MakeModal(false
)
384 def OnButton(self
, event
):
387 #----------------------------------------------------------------------
391 class TestSelectionPanel(wxPanel
):
392 def __init__(self
, parent
, frame
):
393 wxPanel
.__init
__(self
, parent
, -1)
396 self
.list = wxListBox(self
, 401,
397 wxDLG_PNT(self
, 10, 10), wxDLG_SZE(self
, 100, 100),
399 EVT_LISTBOX(self
, 401, self
.OnSelect
)
400 EVT_LISTBOX_DCLICK(self
, 401, self
.OnDClick
)
402 self
.btn
= wxButton(self
, 402, "Try it!", wxDLG_PNT(self
, 120, 10)).SetDefault()
403 EVT_BUTTON(self
, 402, self
.OnDClick
)
405 self
.text
= wxTextCtrl(self
, -1, "",
406 wxDLG_PNT(self
, 10, 115),
407 wxDLG_SZE(self
, 200, 50),
408 wxTE_MULTILINE | wxTE_READONLY
)
410 for item
in theTests
:
411 self
.list.Append(item
[0])
415 def OnSelect(self
, event
):
416 pos
= self
.list.GetSelection()
417 self
.text
.SetValue(theTests
[pos
][2])
420 def OnDClick(self
, event
):
421 pos
= self
.list.GetSelection()
422 title
= theTests
[pos
][0]
423 func
= theTests
[pos
][1]
426 win
= TestFrame(self
, title
, func
)
427 win
.CentreOnParent(wxBOTH
)
431 #----------------------------------------------------------------------
433 def runTest(frame
, nb
, log
):
434 win
= TestSelectionPanel(nb
, frame
)
438 #wxSizer.__doc__ + '\n' + '-' * 80 + '\n' + \
439 #wxBoxSizer.__doc__ + '\n' + '-' * 80 + '\n' + \
440 #wxBorderSizer.__doc__
442 #----------------------------------------------------------------------
446 if __name__
== '__main__':
448 class MainFrame(wxFrame
):
450 wxFrame
.__init
__(self
, NULL
, -1, "Testing...")
452 self
.CreateStatusBar()
453 mainmenu
= wxMenuBar()
455 menu
.Append(200, 'E&xit', 'Get the heck outta here!')
456 mainmenu
.Append(menu
, "&File")
457 self
.SetMenuBar(mainmenu
)
458 EVT_MENU(self
, 200, self
.OnExit
)
459 self
.panel
= TestSelectionPanel(self
, self
)
460 self
.SetSize(wxSize(400, 380))
462 def OnCloseWindow(self
, event
):
465 def OnExit(self
, event
):
469 class TestApp(wxApp
):
473 self
.SetTopWindow(frame
)
480 #----------------------------------------------------------------------