1 #----------------------------------------------------------------------
3 #----------------------------------------------------------------------
5 from wxPython
.wx
import *
6 from wxPython
.lib
.sizers
import *
8 #----------------------------------------------------------------------
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)
19 #----------------------------------------------------------------------
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)
30 #----------------------------------------------------------------------
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)
42 #----------------------------------------------------------------------
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)
54 #----------------------------------------------------------------------
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)
66 #----------------------------------------------------------------------
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)
78 #----------------------------------------------------------------------
80 def makeSimpleBorder1(win
):
81 bdr
= wxBorderSizer(wxALL
)
82 btn
= wxButton(win
, 1010, "border")
83 btn
.SetSize(wxSize(80, 80))
88 #----------------------------------------------------------------------
90 def makeSimpleBorder2(win
):
91 bdr
= wxBorderSizer(wxEAST | wxWEST
)
92 btn
= wxButton(win
, 1010, "border")
93 btn
.SetSize(wxSize(80, 80))
98 #----------------------------------------------------------------------
100 def makeSimpleBorder3(win
):
101 bdr
= wxBorderSizer(wxNORTH | wxWEST
)
102 btn
= wxButton(win
, 1010, "border")
103 btn
.SetSize(wxSize(80, 80))
108 #----------------------------------------------------------------------
109 #----------------------------------------------------------------------
111 def makeBoxInBox(win
):
112 box
= wxBoxSizer(wxVERTICAL
)
114 btn
= wxButton(win
, 1010, "one")
117 box2
= wxBoxSizer(wxHORIZONTAL
)
118 btn
= wxButton(win
, 1010, "two")
120 btn
= wxButton(win
, 1010, "three")
122 btn
= wxButton(win
, 1010, "four")
124 btn
= wxButton(win
, 1010, "five")
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),
137 btn
= wxButton(win
, 1010, "ten")
142 #----------------------------------------------------------------------
144 def makeBoxInBorder(win
):
145 bdr
= wxBorderSizer(wxALL
)
146 box
= makeSimpleBox3(win
)
151 #----------------------------------------------------------------------
153 def makeBorderInBox(win
):
154 insideBox
= wxBoxSizer(wxHORIZONTAL
)
155 insideBox
.Add(makeSimpleBox3(win
), 1)
157 bdr
= wxBorderSizer(wxALL
)
158 bdr
.Add(wxButton(win
, 1010, "border"), 20)
159 insideBox
.Add(bdr
, 1)
161 box3
= wxBoxSizer(wxVERTICAL
)
162 box3
.AddMany([ (wxButton(win
, 1010, "six"), 1),
163 (wxButton(win
, 1010, "seven"), 2),
164 (wxButton(win
, 1010, "eight"), 1),
165 (wxButton(win
, 1010, "nine"), 1),
167 insideBox
.Add(box3
, 1)
169 outsideBox
= wxBoxSizer(wxVERTICAL
)
170 outsideBox
.Add(wxButton(win
, 1010, "top"))
171 outsideBox
.Add(insideBox
, 1)
172 outsideBox
.Add(wxButton(win
, 1010, "bottom"))
177 #----------------------------------------------------------------------
180 ("Simple horizontal boxes", makeSimpleBox1
,
181 "This is a HORIZONTAL box sizer with four non-stretchable buttons held "
182 "within it. Notice that the buttons are added and aligned in the horizontal "
183 "dimension. Also notice that they are fixed size in the horizontal dimension, "
184 "but will stretch vertically."
187 ("Simple vertical boxes", makeSimpleBox2
,
188 "Exactly the same as the previous sample but using a VERTICAL box sizer "
189 "instead of a HORIZONTAL one."
192 ("Add a stretchable", makeSimpleBox3
,
193 "We've added one more button with the strechable flag turned on. Notice "
194 "how it grows to fill the extra space in the otherwise fixed dimension."
197 ("More than one stretchable", makeSimpleBox4
,
198 "Here there are several items that are stretchable, they all divide up the "
199 "extra space evenly."
202 ("Weighting factor", makeSimpleBox5
,
203 "This one shows more than one strechable, but one of them has a weighting "
204 "factor so it gets more of the free space."
207 # ("Percent Sizer", makeSimpleBox6,
208 # "You can use the wxBoxSizer like a Percent Sizer. Just make sure that all "
209 # "the weighting factors add up to 100!"
214 ("Simple border sizer", makeSimpleBorder1
,
215 "The wxBorderSizer leaves empty space around its contents. This one "
216 "gives a border all the way around."
219 ("East and West border", makeSimpleBorder2
,
220 "You can pick and choose which sides have borders."
223 ("North and West border", makeSimpleBorder3
,
224 "You can pick and choose which sides have borders."
229 ("Boxes inside of boxes", makeBoxInBox
,
230 "This one shows nesting of boxes within boxes within boxes, using both "
231 "orientations. Notice also that button seven has a greater weighting "
232 "factor than its siblings."
235 ("Boxes inside a Border", makeBoxInBorder
,
236 "Sizers of different types can be nested withing each other as well. "
237 "Here is a box sizer with several buttons embedded within a border sizer."
240 ("Border in a Box", makeBorderInBox
,
245 #----------------------------------------------------------------------
247 class TestFrame(wxFrame
):
248 def __init__(self
, parent
, title
, sizerFunc
):
249 wxFrame
.__init
__(self
, parent
, -1, title
)
250 EVT_BUTTON(self
, 1010, self
.OnButton
)
252 self
.sizer
= sizerFunc(self
)
253 self
.CreateStatusBar()
255 self
.sizer
.FitWindow(self
)
259 def OnSize(self
, event
):
260 size
= self
.GetClientSize()
261 self
.sizer
.Layout(size
)
263 def OnCloseWindow(self
, event
):
264 self
.MakeModal(false
)
267 def OnButton(self
, event
):
270 #----------------------------------------------------------------------
274 class TestSelectionPanel(wxPanel
):
275 def __init__(self
, parent
, frame
):
276 wxPanel
.__init
__(self
, parent
, -1)
279 self
.list = wxListBox(self
, 401,
280 wxDLG_PNT(self
, 10, 10), wxDLG_SZE(self
, 100, 60),
282 EVT_LISTBOX(self
, 401, self
.OnSelect
)
283 EVT_LISTBOX_DCLICK(self
, 401, self
.OnDClick
)
285 wxButton(self
, 402, "Try it!", wxDLG_PNT(self
, 120, 10)).SetDefault()
286 EVT_BUTTON(self
, 402, self
.OnDClick
)
288 self
.text
= wxTextCtrl(self
, -1, "",
289 wxDLG_PNT(self
, 10, 80),
290 wxDLG_SZE(self
, 200, 60),
291 wxTE_MULTILINE | wxTE_READONLY
)
293 for item
in theTests
:
294 self
.list.Append(item
[0])
298 def OnSelect(self
, event
):
299 pos
= self
.list.GetSelection()
300 self
.text
.SetValue(theTests
[pos
][2])
303 def OnDClick(self
, event
):
304 pos
= self
.list.GetSelection()
305 title
= theTests
[pos
][0]
306 func
= theTests
[pos
][1]
309 win
= TestFrame(self
, title
, func
)
310 win
.CentreOnParent(wxBOTH
)
314 #----------------------------------------------------------------------
316 def runTest(frame
, nb
, log
):
317 win
= TestSelectionPanel(nb
, frame
)
320 overview
= wxSizer
.__doc
__ + '\n' + '-' * 80 + '\n' + \
321 wxBoxSizer
.__doc
__ + '\n' + '-' * 80 + '\n' + \
322 wxBorderSizer
.__doc
__
324 #----------------------------------------------------------------------
328 if __name__
== '__main__':
330 class MainFrame(wxFrame
):
332 wxFrame
.__init
__(self
, NULL
, -1, "Testing...")
334 self
.CreateStatusBar()
335 mainmenu
= wxMenuBar()
337 menu
.Append(200, 'E&xit', 'Get the heck outta here!')
338 mainmenu
.Append(menu
, "&File")
339 self
.SetMenuBar(mainmenu
)
340 EVT_MENU(self
, 200, self
.OnExit
)
341 self
.panel
= TestSelectionPanel(self
)
342 self
.SetSize(wxSize(400, 380))
344 def OnCloseWindow(self
, event
):
347 def OnExit(self
, event
):
351 class TestApp(wxApp
):
355 self
.SetTopWindow(frame
)
362 #----------------------------------------------------------------------