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