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