]> git.saurik.com Git - wxWidgets.git/blame - utils/wxPython/demo/Sizers.py
updated version number for DLL name
[wxWidgets.git] / utils / wxPython / demo / Sizers.py
CommitLineData
bb0054cd
RD
1#----------------------------------------------------------------------
2# sizer test code
3#----------------------------------------------------------------------
4
5from wxPython.wx import *
6from wxPython.lib.sizers import *
7
8#----------------------------------------------------------------------
9
10def makeSimpleBox1(win):
11 box = wxBoxSizer(wxHORIZONTAL)
12 box.Add(wxButton(win, 1010, "one"), 0)
13 box.Add(wxButton(win, 1010, "two"), 0)
14 box.Add(wxButton(win, 1010, "three"), 0)
15 box.Add(wxButton(win, 1010, "four"), 0)
16
17 return box
18
19#----------------------------------------------------------------------
20
21def makeSimpleBox2(win):
22 box = wxBoxSizer(wxVERTICAL)
23 box.Add(wxButton(win, 1010, "one"), 0)
24 box.Add(wxButton(win, 1010, "two"), 0)
25 box.Add(wxButton(win, 1010, "three"), 0)
26 box.Add(wxButton(win, 1010, "four"), 0)
27
28 return box
29
30#----------------------------------------------------------------------
31
32def makeSimpleBox3(win):
33 box = wxBoxSizer(wxHORIZONTAL)
34 box.Add(wxButton(win, 1010, "one"), 0)
35 box.Add(wxButton(win, 1010, "two"), 0)
36 box.Add(wxButton(win, 1010, "three"), 0)
37 box.Add(wxButton(win, 1010, "four"), 0)
38 box.Add(wxButton(win, 1010, "five"), 1)
39
40 return box
41
42#----------------------------------------------------------------------
43
44def makeSimpleBox4(win):
45 box = wxBoxSizer(wxHORIZONTAL)
46 box.Add(wxButton(win, 1010, "one"), 0)
47 box.Add(wxButton(win, 1010, "two"), 0)
48 box.Add(wxButton(win, 1010, "three"), 1)
49 box.Add(wxButton(win, 1010, "four"), 1)
50 box.Add(wxButton(win, 1010, "five"), 1)
51
52 return box
53
54#----------------------------------------------------------------------
55
56def makeSimpleBox5(win):
57 box = wxBoxSizer(wxHORIZONTAL)
58 box.Add(wxButton(win, 1010, "one"), 0)
59 box.Add(wxButton(win, 1010, "two"), 0)
60 box.Add(wxButton(win, 1010, "three"), 3)
61 box.Add(wxButton(win, 1010, "four"), 1)
62 box.Add(wxButton(win, 1010, "five"), 1)
63
64 return box
65
66#----------------------------------------------------------------------
67
68def makeSimpleBox6(win):
69 box = wxBoxSizer(wxHORIZONTAL, wxSize(250, 50))
70 box.Add(wxButton(win, 1010, "10"), 10)
71 box.Add(wxButton(win, 1010, "20"), 20)
72 box.Add(wxButton(win, 1010, "30"), 30)
73 box.Add(wxButton(win, 1010, "15"), 15)
74 box.Add(wxButton(win, 1010, "5"), 5)
75
76 return box
77
78#----------------------------------------------------------------------
79
80def makeSimpleBorder1(win):
81 bdr = wxBorderSizer(wxALL)
82 btn = wxButton(win, 1010, "border")
83 btn.SetSize(wxSize(80, 80))
84 bdr.Add(btn, 15)
85
86 return bdr
87
88#----------------------------------------------------------------------
89
90def makeSimpleBorder2(win):
91 bdr = wxBorderSizer(wxEAST | wxWEST)
92 btn = wxButton(win, 1010, "border")
93 btn.SetSize(wxSize(80, 80))
94 bdr.Add(btn, 15)
95
96 return bdr
97
98#----------------------------------------------------------------------
99
100def makeSimpleBorder3(win):
101 bdr = wxBorderSizer(wxNORTH | wxWEST)
102 btn = wxButton(win, 1010, "border")
103 btn.SetSize(wxSize(80, 80))
104 bdr.Add(btn, 15)
105
106 return bdr
107
108#----------------------------------------------------------------------
109#----------------------------------------------------------------------
110
111def makeBoxInBox(win):
112 box = wxBoxSizer(wxVERTICAL)
113
8bf5d46e 114 box.Add(wxButton(win, 1010, "one"))
bb0054cd
RD
115
116 box2 = wxBoxSizer(wxHORIZONTAL)
8bf5d46e
RD
117 box2.AddMany([ wxButton(win, 1010, "two"),
118 wxButton(win, 1010, "three"),
119 wxButton(win, 1010, "four"),
120 wxButton(win, 1010, "five"),
121 ])
bb0054cd
RD
122
123 box3 = wxBoxSizer(wxVERTICAL)
8bf5d46e 124 box3.AddMany([ (wxButton(win, 1010, "six"), 0),
bb0054cd
RD
125 (wxButton(win, 1010, "seven"), 2),
126 (wxButton(win, 1010, "eight"), 1),
127 (wxButton(win, 1010, "nine"), 1),
128 ])
129
130 box2.Add(box3, 1)
131 box.Add(box2, 1)
132
8bf5d46e 133 box.Add(wxButton(win, 1010, "ten"))
bb0054cd
RD
134
135 return box
136
137#----------------------------------------------------------------------
138
139def makeBoxInBorder(win):
140 bdr = wxBorderSizer(wxALL)
141 box = makeSimpleBox3(win)
142 bdr.Add(box, 15)
143
144 return bdr
145
146#----------------------------------------------------------------------
147
148def makeBorderInBox(win):
149 insideBox = wxBoxSizer(wxHORIZONTAL)
5662a243
RD
150
151 box2 = wxBoxSizer(wxHORIZONTAL)
8bf5d46e
RD
152 box2.AddMany([ wxButton(win, 1010, "one"),
153 wxButton(win, 1010, "two"),
154 wxButton(win, 1010, "three"),
155 wxButton(win, 1010, "four"),
156 wxButton(win, 1010, "five"),
5662a243
RD
157 ])
158
159 insideBox.Add(box2, 0)
bb0054cd
RD
160
161 bdr = wxBorderSizer(wxALL)
162 bdr.Add(wxButton(win, 1010, "border"), 20)
163 insideBox.Add(bdr, 1)
164
165 box3 = wxBoxSizer(wxVERTICAL)
8bf5d46e 166 box3.AddMany([ (wxButton(win, 1010, "six"), 0),
bb0054cd
RD
167 (wxButton(win, 1010, "seven"), 2),
168 (wxButton(win, 1010, "eight"), 1),
169 (wxButton(win, 1010, "nine"), 1),
5662a243 170 ])
bb0054cd
RD
171 insideBox.Add(box3, 1)
172
173 outsideBox = wxBoxSizer(wxVERTICAL)
174 outsideBox.Add(wxButton(win, 1010, "top"))
175 outsideBox.Add(insideBox, 1)
176 outsideBox.Add(wxButton(win, 1010, "bottom"))
177
178 return outsideBox
179
180
181#----------------------------------------------------------------------
182
183theTests = [
184 ("Simple horizontal boxes", makeSimpleBox1,
185 "This is a HORIZONTAL box sizer with four non-stretchable buttons held "
186 "within it. Notice that the buttons are added and aligned in the horizontal "
187 "dimension. Also notice that they are fixed size in the horizontal dimension, "
188 "but will stretch vertically."
189 ),
190
191 ("Simple vertical boxes", makeSimpleBox2,
192 "Exactly the same as the previous sample but using a VERTICAL box sizer "
193 "instead of a HORIZONTAL one."
194 ),
195
196 ("Add a stretchable", makeSimpleBox3,
197 "We've added one more button with the strechable flag turned on. Notice "
198 "how it grows to fill the extra space in the otherwise fixed dimension."
199 ),
200
201 ("More than one stretchable", makeSimpleBox4,
202 "Here there are several items that are stretchable, they all divide up the "
203 "extra space evenly."
204 ),
205
206 ("Weighting factor", makeSimpleBox5,
207 "This one shows more than one strechable, but one of them has a weighting "
208 "factor so it gets more of the free space."
209 ),
210
211# ("Percent Sizer", makeSimpleBox6,
212# "You can use the wxBoxSizer like a Percent Sizer. Just make sure that all "
213# "the weighting factors add up to 100!"
214# ),
215
216 ("", None, ""),
217
218 ("Simple border sizer", makeSimpleBorder1,
219 "The wxBorderSizer leaves empty space around its contents. This one "
220 "gives a border all the way around."
221 ),
222
223 ("East and West border", makeSimpleBorder2,
224 "You can pick and choose which sides have borders."
225 ),
226
227 ("North and West border", makeSimpleBorder3,
228 "You can pick and choose which sides have borders."
229 ),
230
231 ("", None, ""),
232
233 ("Boxes inside of boxes", makeBoxInBox,
234 "This one shows nesting of boxes within boxes within boxes, using both "
235 "orientations. Notice also that button seven has a greater weighting "
236 "factor than its siblings."
237 ),
238
239 ("Boxes inside a Border", makeBoxInBorder,
240 "Sizers of different types can be nested withing each other as well. "
241 "Here is a box sizer with several buttons embedded within a border sizer."
242 ),
243
244 ("Border in a Box", makeBorderInBox,
5662a243 245 "Another nesting example. This one has Boxes and a Border inside another Box."
bb0054cd
RD
246 ),
247
248 ]
249#----------------------------------------------------------------------
250
251class TestFrame(wxFrame):
252 def __init__(self, parent, title, sizerFunc):
253 wxFrame.__init__(self, parent, -1, title)
254 EVT_BUTTON(self, 1010, self.OnButton)
255
256 self.sizer = sizerFunc(self)
257 self.CreateStatusBar()
a08cbc01 258 self.SetStatusText("Resize this frame to see how the sizers respond...")
bb0054cd
RD
259 self.sizer.FitWindow(self)
260
261
bb0054cd
RD
262 def OnSize(self, event):
263 size = self.GetClientSize()
264 self.sizer.Layout(size)
265
266 def OnCloseWindow(self, event):
267 self.MakeModal(false)
268 self.Destroy()
269
270 def OnButton(self, event):
271 self.Close(true)
272
273#----------------------------------------------------------------------
274
275
276
277class TestSelectionPanel(wxPanel):
278 def __init__(self, parent, frame):
279 wxPanel.__init__(self, parent, -1)
280 self.frame = frame
281
282 self.list = wxListBox(self, 401,
283 wxDLG_PNT(self, 10, 10), wxDLG_SZE(self, 100, 60),
284 [])
285 EVT_LISTBOX(self, 401, self.OnSelect)
286 EVT_LISTBOX_DCLICK(self, 401, self.OnDClick)
287
288 wxButton(self, 402, "Try it!", wxDLG_PNT(self, 120, 10)).SetDefault()
289 EVT_BUTTON(self, 402, self.OnDClick)
290
291 self.text = wxTextCtrl(self, -1, "",
292 wxDLG_PNT(self, 10, 80),
293 wxDLG_SZE(self, 200, 60),
294 wxTE_MULTILINE | wxTE_READONLY)
295
296 for item in theTests:
297 self.list.Append(item[0])
298
299
300
301 def OnSelect(self, event):
302 pos = self.list.GetSelection()
303 self.text.SetValue(theTests[pos][2])
304
305
306 def OnDClick(self, event):
307 pos = self.list.GetSelection()
308 title = theTests[pos][0]
309 func = theTests[pos][1]
310
311 if func:
312 win = TestFrame(self, title, func)
313 win.CentreOnParent(wxBOTH)
314 win.Show(true)
315 win.MakeModal(true)
316
317#----------------------------------------------------------------------
318
319def runTest(frame, nb, log):
320 win = TestSelectionPanel(nb, frame)
321 return win
322
323overview = wxSizer.__doc__ + '\n' + '-' * 80 + '\n' + \
324 wxBoxSizer.__doc__ + '\n' + '-' * 80 + '\n' + \
325 wxBorderSizer.__doc__
326
327#----------------------------------------------------------------------
328
329
330
331if __name__ == '__main__':
332
333 class MainFrame(wxFrame):
334 def __init__(self):
335 wxFrame.__init__(self, NULL, -1, "Testing...")
336
337 self.CreateStatusBar()
338 mainmenu = wxMenuBar()
339 menu = wxMenu()
340 menu.Append(200, 'E&xit', 'Get the heck outta here!')
341 mainmenu.Append(menu, "&File")
342 self.SetMenuBar(mainmenu)
343 EVT_MENU(self, 200, self.OnExit)
344 self.panel = TestSelectionPanel(self)
345 self.SetSize(wxSize(400, 380))
346
347 def OnCloseWindow(self, event):
348 self.Destroy()
349
350 def OnExit(self, event):
351 self.Close(true)
352
353
354 class TestApp(wxApp):
355 def OnInit(self):
356 frame = MainFrame()
357 frame.Show(true)
358 self.SetTopWindow(frame)
359 return true
360
361 app = TestApp(0)
362 app.MainLoop()
363
364
365#----------------------------------------------------------------------