]>
Commit | Line | Data |
---|---|---|
d14a1e28 RD |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: _sizers.i | |
3 | // Purpose: SWIG interface defs for the Sizers | |
4 | // | |
5 | // Author: Robin Dunn | |
6 | // | |
7 | // Created: 18-Sept-1999 | |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) 2003 by Total Control Software | |
10 | // Licence: wxWindows license | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
13 | // Not a %module | |
14 | ||
15 | ||
16 | //--------------------------------------------------------------------------- | |
17 | ||
18 | %{ | |
19 | %} | |
20 | ||
21 | //--------------------------------------------------------------------------- | |
22 | %newgroup; | |
23 | ||
cbfc9df6 RD |
24 | DocStr(wxSizerFlags, |
25 | "Normally, when you add an item to a sizer via `wx.Sizer.Add`, you have | |
26 | to specify a lot of flags and parameters which can be unwieldy. This | |
27 | is where wx.SizerFlags comes in: it allows you to specify all | |
28 | parameters using the named methods instead. For example, instead of:: | |
29 | ||
30 | sizer.Add(ctrl, 0, wx.EXPAND | wx.ALL, 10) | |
31 | ||
32 | you can now write:: | |
33 | ||
34 | sizer.AddF(ctrl, wx.SizerFlags().Expand().Border(wx.ALL, 10)) | |
35 | ||
36 | This is more readable and also allows you to create wx.SizerFlags | |
37 | objects which can be reused for several sizer items.:: | |
38 | ||
39 | flagsExpand = wx.SizerFlags(1) | |
40 | flagsExpand.Expand().Border(wx.ALL, 10) | |
41 | sizer.AddF(ctrl1, flagsExpand) | |
42 | sizer.AddF(ctrl2, flagsExpand) | |
43 | ||
44 | Note that by specification, all methods of wx.SizerFlags return the | |
45 | wx.SizerFlags object itself allowing chaining multiple method calls | |
46 | like in the examples above.", ""); | |
47 | ||
48 | class wxSizerFlags | |
49 | { | |
50 | public: | |
51 | // construct the flags object initialized with the given proportion (0 by | |
52 | // default) | |
53 | DocCtorStr( | |
54 | wxSizerFlags(int proportion = 0), | |
55 | "Constructs the flags object with the specified proportion.", ""); | |
56 | ||
57 | ~wxSizerFlags(); | |
58 | ||
59 | // This typemap ensures that the returned object is the same | |
60 | // Python instance as what was passed in as `self`, instead of | |
61 | // creating a new proxy as SWIG would normally do. | |
62 | %typemap(out) wxSizerFlags& { $result = $self; Py_INCREF($result); } | |
63 | ||
64 | DocDeclStr( | |
65 | wxSizerFlags& , Proportion(int proportion), | |
66 | "Sets the item's proportion value.", ""); | |
67 | ||
68 | DocDeclStr( | |
69 | wxSizerFlags& , Align(int alignment), | |
70 | "Sets the item's alignment", ""); | |
71 | ||
72 | DocDeclStr( | |
73 | wxSizerFlags& , Expand(), | |
74 | "Sets the wx.EXPAND flag, which will cause the item to be expanded to | |
75 | fill as much space as it is given by the sizer.", ""); | |
76 | ||
77 | DocDeclStr( | |
78 | wxSizerFlags& , Centre(), | |
79 | "Same as `Center` for those with an alternate dialect of English.", ""); | |
80 | ||
81 | DocDeclStr( | |
82 | wxSizerFlags& , Center(), | |
83 | "Sets the centering alignment flags.", ""); | |
84 | ||
85 | DocDeclStr( | |
86 | wxSizerFlags& , Left(), | |
87 | "Aligns the object to the left, a shortcut for calling | |
88 | Align(wx.ALIGN_LEFT)", ""); | |
89 | ||
90 | DocDeclStr( | |
91 | wxSizerFlags& , Right(), | |
92 | "Aligns the object to the right, a shortcut for calling | |
93 | Align(wx.ALIGN_RIGHT)", ""); | |
94 | ||
95 | DocDeclStr( | |
96 | wxSizerFlags& , Top(), | |
97 | "Aligns the object to the top of the available space, a shortcut for | |
98 | calling Align(wx.ALIGN_TOP)", ""); | |
99 | ||
100 | DocDeclStr( | |
101 | wxSizerFlags& , Bottom(), | |
102 | "Aligns the object to the bottom of the available space, a shortcut for | |
103 | calling Align(wx.ALIGN_BOTTOM)", ""); | |
104 | ||
105 | DocDeclStr( | |
106 | wxSizerFlags& , Shaped(), | |
107 | "Sets the wx.SHAPED flag.", ""); | |
108 | ||
109 | DocDeclStr( | |
110 | wxSizerFlags& , FixedMinSize(), | |
111 | "Sets the wx.FIXED_MINSIZE flag.", ""); | |
112 | ||
113 | ||
114 | ||
115 | %extend { | |
116 | DocDeclStr( | |
117 | wxSizerFlags& , Border(int direction=wxALL, int borderInPixels=-1), | |
118 | "Sets the border of the item in the direction(s) or sides given by the | |
119 | direction parameter. If the borderInPixels value is not given then | |
120 | the default border size (see `GetDefaultBorder`) will be used.", "") | |
121 | { | |
122 | if (borderInPixels == -1) | |
123 | return self->Border(direction); | |
124 | else | |
125 | return self->Border(direction, borderInPixels); | |
126 | } | |
127 | } | |
128 | ||
129 | DocDeclStr( | |
130 | wxSizerFlags& , DoubleBorder(int direction = wxALL), | |
131 | "Sets the border in the given direction to twice the default border | |
132 | size.", ""); | |
133 | ||
134 | DocDeclStr( | |
135 | wxSizerFlags& , TripleBorder(int direction = wxALL), | |
136 | "Sets the border in the given direction to three times the default | |
137 | border size.", ""); | |
138 | ||
139 | DocDeclStr( | |
140 | wxSizerFlags& , HorzBorder(), | |
141 | "Sets the left and right borders to the default border size.", ""); | |
142 | ||
143 | DocDeclStr( | |
144 | wxSizerFlags& , DoubleHorzBorder(), | |
145 | "Sets the left and right borders to twice the default border size.", ""); | |
146 | ||
147 | ||
148 | // Clear the typemap | |
149 | %typemap(out) wxSizerFlags& ; | |
150 | ||
151 | ||
152 | ||
153 | DocDeclStr( | |
154 | static int , GetDefaultBorder(), | |
155 | "Returns the default border size used by the other border methods", ""); | |
156 | ||
157 | ||
158 | DocDeclStr( | |
159 | int , GetProportion() const, | |
160 | "Returns the proportion value to be used in the sizer item.", ""); | |
161 | ||
162 | DocDeclStr( | |
163 | int , GetFlags() const, | |
164 | "Returns the flags value to be used in the sizer item.", ""); | |
165 | ||
166 | DocDeclStr( | |
167 | int , GetBorderInPixels() const, | |
168 | "Returns the border value in pixels to be used in the sizer item.", ""); | |
169 | }; | |
170 | ||
171 | //--------------------------------------------------------------------------- | |
172 | ||
3ea6e0ec RD |
173 | DocStr(wxSizerItem, |
174 | "The wx.SizerItem class is used to track the position, size and other | |
4ba3af91 RD |
175 | attributes of each item managed by a `wx.Sizer`. It is not usually |
176 | necessary to use this class because the sizer elements can also be | |
177 | identified by their positions or window or sizer references but | |
178 | sometimes it may be more convenient to use wx.SizerItem directly. | |
179 | Also, custom classes derived from `wx.PySizer` will probably need to | |
180 | use the collection of wx.SizerItems held by wx.Sizer when calculating | |
181 | layout. | |
3ea6e0ec RD |
182 | |
183 | :see: `wx.Sizer`, `wx.GBSizerItem`", ""); | |
d14a1e28 RD |
184 | |
185 | class wxSizerItem : public wxObject { | |
186 | public: | |
3ea6e0ec RD |
187 | DocCtorStr( |
188 | wxSizerItem(), | |
189 | "Constructs an empty wx.SizerItem. Either a window, sizer or spacer | |
190 | size will need to be set before this item can be used in a Sizer. | |
191 | ||
192 | You will probably never need to create a wx.SizerItem directly as they | |
193 | are created automatically when the sizer's Add, Insert or Prepend | |
194 | methods are called. | |
195 | ||
196 | :see: `wx.SizerItemSpacer`, `wx.SizerItemWindow`, `wx.SizerItemSizer`", ""); | |
197 | ||
214c4fbe RD |
198 | |
199 | ~wxSizerItem(); | |
3ea6e0ec | 200 | |
7e8f0df9 | 201 | |
3ea6e0ec RD |
202 | %extend { |
203 | DocStr( | |
204 | wxSizerItem( wxWindow *window, int proportion, int flag, | |
205 | int border, PyObject* userData=NULL ), | |
7e8f0df9 RD |
206 | "Constructs a `wx.SizerItem` for tracking a window.", ""); |
207 | ||
1b8c7ba6 RD |
208 | %RenameCtor(SizerItemWindow, wxSizerItem( wxWindow *window, int proportion, int flag, |
209 | int border, PyObject* userData=NULL )) | |
210 | { | |
3ea6e0ec RD |
211 | wxPyUserData* data = NULL; |
212 | if ( userData ) { | |
6e6b3557 | 213 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); |
3ea6e0ec RD |
214 | data = new wxPyUserData(userData); |
215 | wxPyEndBlockThreads(blocked); | |
216 | } | |
217 | return new wxSizerItem(window, proportion, flag, border, data); | |
218 | } | |
219 | ||
7e8f0df9 | 220 | |
3ea6e0ec RD |
221 | DocStr( |
222 | wxSizerItem( int width, int height, int proportion, int flag, | |
223 | int border, PyObject* userData=NULL), | |
224 | "Constructs a `wx.SizerItem` for tracking a spacer.", ""); | |
7e8f0df9 | 225 | |
1b8c7ba6 RD |
226 | %RenameCtor(SizerItemSpacer, wxSizerItem( int width, int height, int proportion, int flag, |
227 | int border, PyObject* userData=NULL)) | |
228 | { | |
3ea6e0ec RD |
229 | wxPyUserData* data = NULL; |
230 | if ( userData ) { | |
6e6b3557 | 231 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); |
3ea6e0ec RD |
232 | data = new wxPyUserData(userData); |
233 | wxPyEndBlockThreads(blocked); | |
234 | } | |
235 | return new wxSizerItem(width, height, proportion, flag, border, data); | |
236 | } | |
7e8f0df9 | 237 | |
3ea6e0ec RD |
238 | DocStr( |
239 | wxSizerItem( wxSizer *sizer, int proportion, int flag, | |
240 | int border, PyObject* userData=NULL ), | |
1b8c7ba6 | 241 | "Constructs a `wx.SizerItem` for tracking a subsizer", ""); |
7e8f0df9 | 242 | |
214c4fbe | 243 | %disownarg( wxSizer *sizer ); |
1b8c7ba6 RD |
244 | %RenameCtor(SizerItemSizer, wxSizerItem( wxSizer *sizer, int proportion, int flag, |
245 | int border, PyObject* userData=NULL )) | |
246 | { | |
3ea6e0ec RD |
247 | wxPyUserData* data = NULL; |
248 | if ( userData ) { | |
6e6b3557 | 249 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); |
3ea6e0ec RD |
250 | data = new wxPyUserData(userData); |
251 | wxPyEndBlockThreads(blocked); | |
252 | } | |
253 | return new wxSizerItem(sizer, proportion, flag, border, data); | |
254 | } | |
214c4fbe | 255 | %cleardisown( wxSizer *sizer ); |
3ea6e0ec | 256 | } |
d14a1e28 | 257 | |
d14a1e28 | 258 | |
7e8f0df9 | 259 | |
3ea6e0ec RD |
260 | DocDeclStr( |
261 | void , DeleteWindows(), | |
262 | "Destroy the window or the windows in a subsizer, depending on the type | |
263 | of item.", ""); | |
7e8f0df9 | 264 | |
3ea6e0ec RD |
265 | DocDeclStr( |
266 | void , DetachSizer(), | |
267 | "Enable deleting the SizerItem without destroying the contained sizer.", ""); | |
7e8f0df9 | 268 | |
d14a1e28 | 269 | |
3ea6e0ec RD |
270 | DocDeclStr( |
271 | wxSize , GetSize(), | |
272 | "Get the current size of the item, as set in the last Layout.", ""); | |
7e8f0df9 | 273 | |
3ea6e0ec RD |
274 | DocDeclStr( |
275 | wxSize , CalcMin(), | |
276 | "Calculates the minimum desired size for the item, including any space | |
277 | needed by borders.", ""); | |
7e8f0df9 | 278 | |
3ea6e0ec | 279 | DocDeclStr( |
b6222be9 | 280 | void , SetDimension( const wxPoint& pos, const wxSize& size ), |
3ea6e0ec RD |
281 | "Set the position and size of the space allocated for this item by the |
282 | sizer, and adjust the position and size of the item (window or | |
283 | subsizer) to be within that space taking alignment and borders into | |
284 | account.", ""); | |
7e8f0df9 | 285 | |
3ea6e0ec RD |
286 | |
287 | DocDeclStr( | |
288 | wxSize , GetMinSize(), | |
289 | "Get the minimum size needed for the item.", ""); | |
7e8f0df9 | 290 | |
329b045c RD |
291 | DocDeclStr( |
292 | wxSize , GetMinSizeWithBorder() const, | |
293 | "Get the minimum size needed for the item with space for the borders | |
294 | added, if needed.", ""); | |
295 | ||
3ea6e0ec RD |
296 | DocDeclStr( |
297 | void , SetInitSize( int x, int y ), | |
298 | "", ""); | |
7e8f0df9 | 299 | |
d14a1e28 | 300 | |
3ea6e0ec RD |
301 | DocStr(SetRatio, |
302 | "Set the ratio item attribute.", ""); | |
1b8c7ba6 | 303 | %Rename(SetRatioWH, void, SetRatio( int width, int height )); |
f1e759d7 | 304 | %Rename(SetRatioSize, void, SetRatio( const wxSize& size )); |
d14a1e28 | 305 | void SetRatio( float ratio ); |
7e8f0df9 | 306 | |
3ea6e0ec RD |
307 | DocDeclStr( |
308 | float , GetRatio(), | |
309 | "Set the ratio item attribute.", ""); | |
7aada1e0 RD |
310 | |
311 | DocDeclStr( | |
312 | wxRect , GetRect(), | |
313 | "Returns the rectangle that the sizer item should occupy", ""); | |
7e8f0df9 | 314 | |
d14a1e28 | 315 | |
3ea6e0ec RD |
316 | DocDeclStr( |
317 | bool , IsWindow(), | |
318 | "Is this sizer item a window?", ""); | |
7e8f0df9 | 319 | |
3ea6e0ec RD |
320 | DocDeclStr( |
321 | bool , IsSizer(), | |
322 | "Is this sizer item a subsizer?", ""); | |
7e8f0df9 | 323 | |
3ea6e0ec RD |
324 | DocDeclStr( |
325 | bool , IsSpacer(), | |
326 | "Is this sizer item a spacer?", ""); | |
7e8f0df9 | 327 | |
d14a1e28 | 328 | |
3ea6e0ec RD |
329 | DocDeclStr( |
330 | void , SetProportion( int proportion ), | |
331 | "Set the proportion value for this item.", ""); | |
7e8f0df9 | 332 | |
3ea6e0ec RD |
333 | DocDeclStr( |
334 | int , GetProportion(), | |
335 | "Get the proportion value for this item.", ""); | |
7e8f0df9 | 336 | |
3ea6e0ec RD |
337 | %pythoncode { SetOption = wx._deprecated(SetProportion, "Please use `SetProportion` instead.") } |
338 | %pythoncode { GetOption = wx._deprecated(GetProportion, "Please use `GetProportion` instead.") } | |
d14a1e28 | 339 | |
7e8f0df9 | 340 | |
3ea6e0ec RD |
341 | DocDeclStr( |
342 | void , SetFlag( int flag ), | |
343 | "Set the flag value for this item.", ""); | |
7e8f0df9 | 344 | |
3ea6e0ec RD |
345 | DocDeclStr( |
346 | int , GetFlag(), | |
347 | "Get the flag value for this item.", ""); | |
7e8f0df9 RD |
348 | |
349 | ||
3ea6e0ec RD |
350 | DocDeclStr( |
351 | void , SetBorder( int border ), | |
352 | "Set the border value for this item.", ""); | |
7e8f0df9 | 353 | |
3ea6e0ec RD |
354 | DocDeclStr( |
355 | int , GetBorder(), | |
356 | "Get the border value for this item.", ""); | |
d14a1e28 | 357 | |
7e8f0df9 RD |
358 | |
359 | ||
3ea6e0ec RD |
360 | DocDeclStr( |
361 | wxWindow *, GetWindow(), | |
362 | "Get the window (if any) that is managed by this sizer item.", ""); | |
7e8f0df9 | 363 | |
7e8f0df9 | 364 | |
3ea6e0ec RD |
365 | DocDeclStr( |
366 | wxSizer *, GetSizer(), | |
367 | "Get the subsizer (if any) that is managed by this sizer item.", ""); | |
7e8f0df9 | 368 | |
10f9d5a2 RD |
369 | DocDeclStr( |
370 | wxSize , GetSpacer(), | |
371 | "Get the size of the spacer managed by this sizer item.", ""); | |
372 | ||
373 | ||
374 | ||
375 | ||
376 | DocDeclStr( | |
377 | void , SetWindow( wxWindow *window ), | |
378 | "Set the window to be managed by this sizer item.", ""); | |
379 | ||
214c4fbe | 380 | %disownarg( wxSizer *sizer ); |
3ea6e0ec RD |
381 | DocDeclStr( |
382 | void , SetSizer( wxSizer *sizer ), | |
383 | "Set the subsizer to be managed by this sizer item.", ""); | |
214c4fbe | 384 | %cleardisown( wxSizer *sizer ); |
7e8f0df9 | 385 | |
3ea6e0ec | 386 | DocDeclStr( |
10f9d5a2 RD |
387 | void , SetSpacer( const wxSize &size ), |
388 | "Set the size of the spacer to be managed by this sizer item.", ""); | |
389 | ||
390 | %pythoncode { | |
391 | SetWindow = wx._deprecated(SetWindow, "Use `AssignWindow` instead.") | |
392 | SetSizer = wx._deprecated(SetSizer, "Use `AssignSizer` instead.") | |
393 | SetSpacer = wx._deprecated(SetSpacer, "Use `AssignSpacer` instead.") | |
394 | } | |
395 | ||
7e8f0df9 | 396 | |
10f9d5a2 | 397 | |
3ea6e0ec | 398 | DocDeclStr( |
10f9d5a2 RD |
399 | void , AssignWindow(wxWindow *window), |
400 | "Set the window to be managed by this sizer item.", ""); | |
401 | ||
402 | DocDeclStr( | |
403 | void , AssignSizer(wxSizer *sizer), | |
404 | "Set the subsizer to be managed by this sizer item.", ""); | |
405 | ||
406 | DocDeclStr( | |
407 | void , AssignSpacer(const wxSize& size), | |
3ea6e0ec | 408 | "Set the size of the spacer to be managed by this sizer item.", ""); |
10f9d5a2 | 409 | |
7e8f0df9 | 410 | |
10f9d5a2 | 411 | |
d14a1e28 | 412 | |
3ea6e0ec RD |
413 | DocDeclStr( |
414 | void , Show( bool show ), | |
415 | "Set the show item attribute, which sizers use to determine if the item | |
416 | is to be made part of the layout or not. If the item is tracking a | |
417 | window then it is shown or hidden as needed.", ""); | |
7e8f0df9 | 418 | |
3ea6e0ec RD |
419 | DocDeclStr( |
420 | bool , IsShown(), | |
421 | "Is the item to be shown in the layout?", ""); | |
7e8f0df9 | 422 | |
3ea6e0ec RD |
423 | |
424 | DocDeclStr( | |
425 | wxPoint , GetPosition(), | |
426 | "Returns the current position of the item, as set in the last Layout.", ""); | |
7e8f0df9 | 427 | |
d14a1e28 RD |
428 | |
429 | // wxObject* GetUserData(); | |
430 | %extend { | |
431 | // Assume that the user data is a wxPyUserData object and return the contents | |
3ea6e0ec RD |
432 | |
433 | DocStr(GetUserData, | |
434 | "Returns the userData associated with this sizer item, or None if there | |
435 | isn't any.", ""); | |
d14a1e28 RD |
436 | PyObject* GetUserData() { |
437 | wxPyUserData* data = (wxPyUserData*)self->GetUserData(); | |
438 | if (data) { | |
439 | Py_INCREF(data->m_obj); | |
440 | return data->m_obj; | |
441 | } else { | |
442 | Py_INCREF(Py_None); | |
443 | return Py_None; | |
444 | } | |
445 | } | |
095315e2 RD |
446 | |
447 | DocStr(SetUserData, | |
448 | "Associate a Python object with this sizer item.", ""); | |
449 | void SetUserData(PyObject* userData) { | |
450 | wxPyUserData* data = NULL; | |
451 | if ( userData ) { | |
452 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); | |
453 | data = new wxPyUserData(userData); | |
454 | wxPyEndBlockThreads(blocked); | |
455 | } | |
456 | self->SetUserData(data); | |
457 | } | |
d14a1e28 | 458 | } |
7012bb9f RD |
459 | |
460 | %property(Border, GetBorder, SetBorder, doc="See `GetBorder` and `SetBorder`"); | |
461 | %property(Flag, GetFlag, SetFlag, doc="See `GetFlag` and `SetFlag`"); | |
462 | %property(MinSize, GetMinSize, doc="See `GetMinSize`"); | |
463 | %property(MinSizeWithBorder, GetMinSizeWithBorder, doc="See `GetMinSizeWithBorder`"); | |
464 | %property(Position, GetPosition, doc="See `GetPosition`"); | |
465 | %property(Proportion, GetProportion, SetProportion, doc="See `GetProportion` and `SetProportion`"); | |
466 | %property(Ratio, GetRatio, SetRatio, doc="See `GetRatio` and `SetRatio`"); | |
467 | %property(Rect, GetRect, doc="See `GetRect`"); | |
468 | %property(Size, GetSize, doc="See `GetSize`"); | |
10f9d5a2 RD |
469 | %property(Sizer, GetSizer, AssignSizer, doc="See `GetSizer` and `AssignSizer`"); |
470 | %property(Spacer, GetSpacer, AssignSpacer, doc="See `GetSpacer` and `AssignSpacer`"); | |
7012bb9f | 471 | %property(UserData, GetUserData, SetUserData, doc="See `GetUserData` and `SetUserData`"); |
10f9d5a2 | 472 | %property(Window, GetWindow, AssignWindow, doc="See `GetWindow` and `AssignWindow`"); |
d14a1e28 RD |
473 | }; |
474 | ||
475 | ||
476 | //--------------------------------------------------------------------------- | |
477 | ||
478 | %{ | |
479 | // Figure out the type of the sizer item | |
480 | ||
481 | struct wxPySizerItemInfo { | |
482 | wxPySizerItemInfo() | |
a72f4631 RD |
483 | : window(NULL), sizer(NULL), gotSize(false), |
484 | size(wxDefaultSize), gotPos(false), pos(-1) | |
d14a1e28 | 485 | {} |
7e8f0df9 | 486 | |
d14a1e28 RD |
487 | wxWindow* window; |
488 | wxSizer* sizer; | |
489 | bool gotSize; | |
490 | wxSize size; | |
491 | bool gotPos; | |
492 | int pos; | |
493 | }; | |
7e8f0df9 | 494 | |
d14a1e28 RD |
495 | static wxPySizerItemInfo wxPySizerItemTypeHelper(PyObject* item, bool checkSize, bool checkIdx ) { |
496 | ||
497 | wxPySizerItemInfo info; | |
498 | wxSize size; | |
499 | wxSize* sizePtr = &size; | |
500 | ||
501 | // Find out what the type of the item is | |
502 | // try wxWindow | |
503 | if ( ! wxPyConvertSwigPtr(item, (void**)&info.window, wxT("wxWindow")) ) { | |
504 | PyErr_Clear(); | |
505 | info.window = NULL; | |
7e8f0df9 | 506 | |
d14a1e28 RD |
507 | // try wxSizer |
508 | if ( ! wxPyConvertSwigPtr(item, (void**)&info.sizer, wxT("wxSizer")) ) { | |
509 | PyErr_Clear(); | |
510 | info.sizer = NULL; | |
7e8f0df9 | 511 | |
d14a1e28 RD |
512 | // try wxSize or (w,h) |
513 | if ( checkSize && wxSize_helper(item, &sizePtr)) { | |
514 | info.size = *sizePtr; | |
a72f4631 | 515 | info.gotSize = true; |
d14a1e28 RD |
516 | } |
517 | ||
518 | // or a single int | |
519 | if (checkIdx && PyInt_Check(item)) { | |
520 | info.pos = PyInt_AsLong(item); | |
a72f4631 | 521 | info.gotPos = true; |
d14a1e28 RD |
522 | } |
523 | } | |
524 | } | |
525 | ||
526 | if ( !(info.window || info.sizer || (checkSize && info.gotSize) || (checkIdx && info.gotPos)) ) { | |
527 | // no expected type, figure out what kind of error message to generate | |
528 | if ( !checkSize && !checkIdx ) | |
02b800ce | 529 | PyErr_SetString(PyExc_TypeError, "wx.Window or wx.Sizer expected for item"); |
d14a1e28 | 530 | else if ( checkSize && !checkIdx ) |
02b800ce | 531 | PyErr_SetString(PyExc_TypeError, "wx.Window, wx.Sizer, wx.Size, or (w,h) expected for item"); |
d14a1e28 | 532 | else if ( !checkSize && checkIdx) |
02b800ce | 533 | PyErr_SetString(PyExc_TypeError, "wx.Window, wx.Sizer or int (position) expected for item"); |
d14a1e28 RD |
534 | else |
535 | // can this one happen? | |
02b800ce | 536 | PyErr_SetString(PyExc_TypeError, "wx.Window, wx.Sizer, wx.Size, or (w,h) or int (position) expected for item"); |
d14a1e28 RD |
537 | } |
538 | ||
539 | return info; | |
540 | } | |
541 | %} | |
542 | ||
543 | ||
544 | ||
545 | ||
3ea6e0ec RD |
546 | DocStr(wxSizer, |
547 | "wx.Sizer is the abstract base class used for laying out subwindows in | |
548 | a window. You cannot use wx.Sizer directly; instead, you will have to | |
549 | use one of the sizer classes derived from it such as `wx.BoxSizer`, | |
a2cccbc3 RD |
550 | `wx.StaticBoxSizer`, `wx.GridSizer`, `wx.FlexGridSizer` and |
551 | `wx.GridBagSizer`. | |
3ea6e0ec RD |
552 | |
553 | The concept implemented by sizers in wxWidgets is closely related to | |
554 | layout tools in other GUI toolkits, such as Java's AWT, the GTK | |
555 | toolkit or the Qt toolkit. It is based upon the idea of the individual | |
556 | subwindows reporting their minimal required size and their ability to | |
557 | get stretched if the size of the parent window has changed. This will | |
558 | most often mean that the programmer does not set the original size of | |
559 | a dialog in the beginning, rather the dialog will assigned a sizer and | |
560 | this sizer will be queried about the recommended size. The sizer in | |
561 | turn will query its children, which can be normal windows or contorls, | |
562 | empty space or other sizers, so that a hierarchy of sizers can be | |
563 | constructed. Note that wxSizer does not derive from wxWindow and thus | |
564 | do not interfere with tab ordering and requires very little resources | |
565 | compared to a real window on screen. | |
566 | ||
567 | What makes sizers so well fitted for use in wxWidgets is the fact that | |
568 | every control reports its own minimal size and the algorithm can | |
569 | handle differences in font sizes or different window (dialog item) | |
570 | sizes on different platforms without problems. If for example the | |
571 | standard font as well as the overall design of Mac widgets requires | |
572 | more space than on Windows, then the initial size of a dialog using a | |
573 | sizer will automatically be bigger on Mac than on Windows.", " | |
574 | ||
38260cce RD |
575 | Sizers may also be used to control the layout of custom drawn items on |
576 | the window. The `Add`, `Insert`, and `Prepend` functions return a | |
577 | pointer to the newly added `wx.SizerItem`. Just add empty space of the | |
578 | desired size and attributes, and then use the `wx.SizerItem.GetRect` | |
579 | method to determine where the drawing operations should take place. | |
580 | ||
3ea6e0ec RD |
581 | :note: If you wish to create a custom sizer class in wxPython you |
582 | should derive the class from `wx.PySizer` in order to get | |
583 | Python-aware capabilities for the various virtual methods. | |
584 | ||
585 | :see: `wx.SizerItem` | |
586 | ||
587 | :todo: More dscriptive text here along with some pictures... | |
588 | ||
589 | "); | |
590 | ||
d14a1e28 RD |
591 | class wxSizer : public wxObject { |
592 | public: | |
593 | // wxSizer(); **** abstract, can't instantiate | |
214c4fbe RD |
594 | |
595 | ~wxSizer(); | |
d14a1e28 RD |
596 | |
597 | %extend { | |
598 | void _setOORInfo(PyObject* _self) { | |
a77bf68f RD |
599 | if (!self->GetClientObject()) |
600 | self->SetClientObject(new wxPyOORClientData(_self)); | |
d14a1e28 RD |
601 | } |
602 | ||
3ea6e0ec RD |
603 | DocAStr(Add, |
604 | "Add(self, item, int proportion=0, int flag=0, int border=0, | |
7aada1e0 | 605 | PyObject userData=None) -> wx.SizerItem", |
3ea6e0ec RD |
606 | |
607 | "Appends a child item to the sizer.", " | |
608 | ||
609 | :param item: The item can be one of three kinds of objects: | |
610 | ||
611 | - **window**: A `wx.Window` to be managed by the sizer. Its | |
612 | minimal size (either set explicitly by the user or | |
613 | calculated internally when constructed with wx.DefaultSize) | |
614 | is interpreted as the minimal size to use when laying out | |
615 | item in the sizer. This is particularly useful in | |
616 | connection with `wx.Window.SetSizeHints`. | |
617 | ||
618 | - **sizer**: The (child-)sizer to be added to the sizer. This | |
619 | allows placing a child sizer in a sizer and thus to create | |
cbfc9df6 | 620 | hierarchies of sizers (for example a vertical box as the top |
3ea6e0ec RD |
621 | sizer and several horizontal boxes on the level beneath). |
622 | ||
623 | - **size**: A `wx.Size` or a 2-element sequence of integers | |
624 | that represents the width and height of a spacer to be added | |
625 | to the sizer. Adding spacers to sizers gives more | |
626 | flexibility in the design of dialogs; imagine for example a | |
627 | horizontal box with two buttons at the bottom of a dialog: | |
628 | you might want to insert a space between the two buttons and | |
629 | make that space stretchable using the *proportion* value and | |
630 | the result will be that the left button will be aligned with | |
631 | the left side of the dialog and the right button with the | |
632 | right side - the space in between will shrink and grow with | |
633 | the dialog. | |
634 | ||
635 | :param proportion: Although the meaning of this parameter is | |
636 | undefined in wx.Sizer, it is used in `wx.BoxSizer` to indicate | |
637 | if a child of a sizer can change its size in the main | |
638 | orientation of the wx.BoxSizer - where 0 stands for not | |
639 | changeable and a value of more than zero is interpreted | |
640 | relative (a proportion of the total) to the value of other | |
641 | children of the same wx.BoxSizer. For example, you might have | |
642 | a horizontal wx.BoxSizer with three children, two of which are | |
643 | supposed to change their size with the sizer. Then the two | |
644 | stretchable windows should each be given *proportion* value of | |
645 | 1 to make them grow and shrink equally with the sizer's | |
646 | horizontal dimension. But if one of them had a *proportion* | |
647 | value of 2 then it would get a double share of the space | |
648 | available after the fixed size items are positioned. | |
649 | ||
650 | :param flag: This parameter can be used to set a number of flags | |
651 | which can be combined using the binary OR operator ``|``. Two | |
652 | main behaviours are defined using these flags. One is the | |
653 | border around a window: the *border* parameter determines the | |
654 | border width whereas the flags given here determine which | |
655 | side(s) of the item that the border will be added. The other | |
656 | flags determine how the sizer item behaves when the space | |
657 | allotted to the sizer changes, and is somewhat dependent on | |
658 | the specific kind of sizer used. | |
659 | ||
660 | +----------------------------+------------------------------------------+ | |
661 | |- wx.TOP |These flags are used to specify | | |
662 | |- wx.BOTTOM |which side(s) of the sizer item that | | |
663 | |- wx.LEFT |the *border* width will apply to. | | |
664 | |- wx.RIGHT | | | |
665 | |- wx.ALL | | | |
666 | | | | | |
667 | +----------------------------+------------------------------------------+ | |
8b5895b0 | 668 | |- wx.EXPAND |The item will be expanded to fill | |
3ea6e0ec RD |
669 | | |the space allotted to the item. | |
670 | +----------------------------+------------------------------------------+ | |
671 | |- wx.SHAPED |The item will be expanded as much as | | |
672 | | |possible while also maintaining its | | |
673 | | |aspect ratio | | |
674 | +----------------------------+------------------------------------------+ | |
675 | |- wx.FIXED_MINSIZE |Normally wx.Sizers will use | | |
676 | | |`wx.Window.GetMinSize` or | | |
677 | | |`wx.Window.GetBestSize` to determine what | | |
678 | | |the minimal size of window items should | | |
679 | | |be, and will use that size to calculate | | |
680 | | |the layout. This allows layouts to adjust | | |
681 | | |when an item changes and it's best size | | |
682 | | |becomes different. If you would rather | | |
683 | | |have a window item stay the size it | | |
684 | | |started with then use wx.FIXED_MINSIZE. | | |
685 | +----------------------------+------------------------------------------+ | |
686 | |- wx.ALIGN_CENTER |The wx.ALIGN flags allow you to specify | | |
687 | |- wx.ALIGN_LEFT |the alignment of the item within the space| | |
688 | |- wx.ALIGN_RIGHT |allotted to it by the sizer, ajusted for | | |
689 | |- wx.ALIGN_TOP |the border if any. | | |
690 | |- wx.ALIGN_BOTTOM | | | |
691 | |- wx.ALIGN_CENTER_VERTICAL | | | |
692 | |- wx.ALIGN_CENTER_HORIZONTAL| | | |
693 | +----------------------------+------------------------------------------+ | |
694 | ||
695 | ||
696 | :param border: Determines the border width, if the *flag* | |
697 | parameter is set to include any border flag. | |
698 | ||
699 | :param userData: Allows an extra object to be attached to the | |
700 | sizer item, for use in derived classes when sizing information | |
701 | is more complex than the *proportion* and *flag* will allow for. | |
702 | "); | |
d14a1e28 | 703 | |
7aada1e0 RD |
704 | wxSizerItem* Add(PyObject* item, int proportion=0, int flag=0, int border=0, |
705 | PyObject* userData=NULL) { | |
7e8f0df9 | 706 | |
d14a1e28 | 707 | wxPyUserData* data = NULL; |
6e6b3557 | 708 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); |
a72f4631 | 709 | wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, true, false); |
d14a1e28 RD |
710 | if ( userData && (info.window || info.sizer || info.gotSize) ) |
711 | data = new wxPyUserData(userData); | |
214c4fbe RD |
712 | if ( info.sizer ) |
713 | PyObject_SetAttrString(item,"thisown",Py_False); | |
da32eb53 | 714 | wxPyEndBlockThreads(blocked); |
7e8f0df9 | 715 | |
d14a1e28 RD |
716 | // Now call the real Add method if a valid item type was found |
717 | if ( info.window ) | |
7aada1e0 | 718 | return self->Add(info.window, proportion, flag, border, data); |
d14a1e28 | 719 | else if ( info.sizer ) |
7aada1e0 | 720 | return self->Add(info.sizer, proportion, flag, border, data); |
d14a1e28 | 721 | else if (info.gotSize) |
7aada1e0 RD |
722 | return self->Add(info.size.GetWidth(), info.size.GetHeight(), |
723 | proportion, flag, border, data); | |
724 | else | |
725 | return NULL; | |
d14a1e28 RD |
726 | } |
727 | ||
cbfc9df6 RD |
728 | |
729 | DocAStr(AddF, | |
730 | "AddF(self, item, wx.SizerFlags flags) -> wx.SizerItem", | |
731 | "Similar to `Add` but uses the `wx.SizerFlags` convenience class for | |
732 | setting the various flags, options and borders.", ""); | |
733 | wxSizerItem* AddF(PyObject* item, wxSizerFlags& flags) { | |
734 | ||
735 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); | |
736 | wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, true, false); | |
737 | if ( info.sizer ) | |
738 | PyObject_SetAttrString(item,"thisown",Py_False); | |
739 | wxPyEndBlockThreads(blocked); | |
740 | ||
741 | // Now call the real Add method if a valid item type was found | |
742 | if ( info.window ) | |
743 | return self->Add(info.window, flags); | |
744 | else if ( info.sizer ) | |
745 | return self->Add(info.sizer, flags); | |
746 | else if (info.gotSize) | |
747 | return self->Add(info.size.GetWidth(), info.size.GetHeight(), | |
748 | flags.GetProportion(), | |
749 | flags.GetFlags(), | |
750 | flags.GetBorderInPixels()); | |
751 | else | |
752 | return NULL; | |
753 | } | |
754 | ||
755 | ||
d14a1e28 | 756 | |
3ea6e0ec RD |
757 | DocAStr(Insert, |
758 | "Insert(self, int before, item, int proportion=0, int flag=0, int border=0, | |
7aada1e0 | 759 | PyObject userData=None) -> wx.SizerItem", |
3ea6e0ec RD |
760 | |
761 | "Inserts a new item into the list of items managed by this sizer before | |
762 | the item at index *before*. See `Add` for a description of the parameters.", ""); | |
7aada1e0 RD |
763 | wxSizerItem* Insert(int before, PyObject* item, int proportion=0, int flag=0, |
764 | int border=0, PyObject* userData=NULL) { | |
d14a1e28 RD |
765 | |
766 | wxPyUserData* data = NULL; | |
6e6b3557 | 767 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); |
a72f4631 | 768 | wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, true, false); |
d14a1e28 RD |
769 | if ( userData && (info.window || info.sizer || info.gotSize) ) |
770 | data = new wxPyUserData(userData); | |
214c4fbe RD |
771 | if ( info.sizer ) |
772 | PyObject_SetAttrString(item,"thisown",Py_False); | |
da32eb53 | 773 | wxPyEndBlockThreads(blocked); |
7e8f0df9 | 774 | |
d14a1e28 RD |
775 | // Now call the real Insert method if a valid item type was found |
776 | if ( info.window ) | |
7aada1e0 | 777 | return self->Insert(before, info.window, proportion, flag, border, data); |
d14a1e28 | 778 | else if ( info.sizer ) |
7aada1e0 | 779 | return self->Insert(before, info.sizer, proportion, flag, border, data); |
d14a1e28 | 780 | else if (info.gotSize) |
7aada1e0 RD |
781 | return self->Insert(before, info.size.GetWidth(), info.size.GetHeight(), |
782 | proportion, flag, border, data); | |
783 | else | |
784 | return NULL; | |
d14a1e28 RD |
785 | } |
786 | ||
787 | ||
cbfc9df6 RD |
788 | |
789 | DocAStr(InsertF, | |
790 | "InsertF(self, int before, item, wx.SizerFlags flags) -> wx.SizerItem", | |
791 | "Similar to `Insert`, but uses the `wx.SizerFlags` convenience class | |
792 | for setting the various flags, options and borders.", ""); | |
793 | wxSizerItem* InsertF(int before, PyObject* item, wxSizerFlags& flags) { | |
794 | ||
795 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); | |
796 | wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, true, false); | |
797 | if ( info.sizer ) | |
798 | PyObject_SetAttrString(item,"thisown",Py_False); | |
799 | wxPyEndBlockThreads(blocked); | |
800 | ||
801 | // Now call the real Insert method if a valid item type was found | |
802 | if ( info.window ) | |
803 | return self->Insert(before, info.window, flags); | |
804 | else if ( info.sizer ) | |
805 | return self->Insert(before, info.sizer, flags); | |
806 | else if (info.gotSize) | |
807 | return self->Insert(before, info.size.GetWidth(), info.size.GetHeight(), | |
808 | flags.GetProportion(), | |
809 | flags.GetFlags(), | |
810 | flags.GetBorderInPixels()); | |
811 | else | |
812 | return NULL; | |
813 | } | |
814 | ||
815 | ||
816 | ||
7e8f0df9 | 817 | |
3ea6e0ec RD |
818 | DocAStr(Prepend, |
819 | "Prepend(self, item, int proportion=0, int flag=0, int border=0, | |
7aada1e0 | 820 | PyObject userData=None) -> wx.SizerItem", |
d14a1e28 | 821 | |
3ea6e0ec RD |
822 | "Adds a new item to the begining of the list of sizer items managed by |
823 | this sizer. See `Add` for a description of the parameters.", ""); | |
7aada1e0 RD |
824 | wxSizerItem* Prepend(PyObject* item, int proportion=0, int flag=0, int border=0, |
825 | PyObject* userData=NULL) { | |
d14a1e28 RD |
826 | |
827 | wxPyUserData* data = NULL; | |
6e6b3557 | 828 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); |
a72f4631 | 829 | wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, true, false); |
d14a1e28 RD |
830 | if ( userData && (info.window || info.sizer || info.gotSize) ) |
831 | data = new wxPyUserData(userData); | |
214c4fbe RD |
832 | if ( info.sizer ) |
833 | PyObject_SetAttrString(item,"thisown",Py_False); | |
da32eb53 | 834 | wxPyEndBlockThreads(blocked); |
7e8f0df9 | 835 | |
d14a1e28 RD |
836 | // Now call the real Prepend method if a valid item type was found |
837 | if ( info.window ) | |
7aada1e0 | 838 | return self->Prepend(info.window, proportion, flag, border, data); |
d14a1e28 | 839 | else if ( info.sizer ) |
7aada1e0 | 840 | return self->Prepend(info.sizer, proportion, flag, border, data); |
d14a1e28 | 841 | else if (info.gotSize) |
7aada1e0 RD |
842 | return self->Prepend(info.size.GetWidth(), info.size.GetHeight(), |
843 | proportion, flag, border, data); | |
844 | else | |
845 | return NULL; | |
d14a1e28 RD |
846 | } |
847 | ||
3ea6e0ec | 848 | |
e81b607b | 849 | |
cbfc9df6 RD |
850 | DocAStr(PrependF, |
851 | "PrependF(self, item, wx.SizerFlags flags) -> wx.SizerItem", | |
852 | "Similar to `Prepend` but uses the `wx.SizerFlags` convenience class | |
853 | for setting the various flags, options and borders.", ""); | |
854 | wxSizerItem* PrependF(PyObject* item, wxSizerFlags& flags) { | |
855 | ||
856 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); | |
857 | wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, true, false); | |
858 | if ( info.sizer ) | |
859 | PyObject_SetAttrString(item,"thisown",Py_False); | |
860 | wxPyEndBlockThreads(blocked); | |
861 | ||
862 | // Now call the real Add method if a valid item type was found | |
863 | if ( info.window ) | |
864 | return self->Prepend(info.window, flags); | |
865 | else if ( info.sizer ) | |
866 | return self->Prepend(info.sizer, flags); | |
867 | else if (info.gotSize) | |
868 | return self->Prepend(info.size.GetWidth(), info.size.GetHeight(), | |
869 | flags.GetProportion(), | |
870 | flags.GetFlags(), | |
871 | flags.GetBorderInPixels()); | |
872 | else | |
873 | return NULL; | |
874 | } | |
875 | ||
876 | ||
877 | ||
3ea6e0ec RD |
878 | DocAStr(Remove, |
879 | "Remove(self, item) -> bool", | |
880 | "Removes an item from the sizer and destroys it. This method does not | |
881 | cause any layout or resizing to take place, call `Layout` to update | |
882 | the layout on screen after removing a child from the sizer. The | |
883 | *item* parameter can be either a window, a sizer, or the zero-based | |
884 | index of an item to remove. Returns True if the child item was found | |
885 | and removed.", " | |
886 | ||
887 | :note: For historical reasons calling this method with a `wx.Window` | |
888 | parameter is depreacted, as it will not be able to destroy the | |
889 | window since it is owned by its parent. You should use `Detach` | |
890 | instead. | |
891 | "); | |
d14a1e28 | 892 | bool Remove(PyObject* item) { |
6e6b3557 | 893 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); |
a72f4631 | 894 | wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, false, true); |
da32eb53 | 895 | wxPyEndBlockThreads(blocked); |
d14a1e28 | 896 | if ( info.window ) |
cbfc9df6 | 897 | return false; //self->Remove(info.window); |
d14a1e28 RD |
898 | else if ( info.sizer ) |
899 | return self->Remove(info.sizer); | |
900 | else if ( info.gotPos ) | |
901 | return self->Remove(info.pos); | |
7e8f0df9 | 902 | else |
a72f4631 | 903 | return false; |
d14a1e28 RD |
904 | } |
905 | ||
3ea6e0ec RD |
906 | |
907 | DocAStr(Detach, | |
908 | "Detach(self, item) -> bool", | |
909 | "Detaches an item from the sizer without destroying it. This method | |
910 | does not cause any layout or resizing to take place, call `Layout` to | |
911 | do so. The *item* parameter can be either a window, a sizer, or the | |
912 | zero-based index of the item to be detached. Returns True if the child item | |
913 | was found and detached.", ""); | |
60a71c29 | 914 | bool Detach(PyObject* item) { |
6e6b3557 | 915 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); |
a72f4631 | 916 | wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, false, true); |
60a71c29 RD |
917 | wxPyEndBlockThreads(blocked); |
918 | if ( info.window ) | |
919 | return self->Detach(info.window); | |
920 | else if ( info.sizer ) | |
921 | return self->Detach(info.sizer); | |
922 | else if ( info.gotPos ) | |
923 | return self->Detach(info.pos); | |
7e8f0df9 | 924 | else |
a72f4631 | 925 | return false; |
60a71c29 RD |
926 | } |
927 | ||
7e8f0df9 | 928 | |
7aada1e0 | 929 | DocAStr(GetItem, |
cbfc9df6 | 930 | "GetItem(self, item, recursive=False) -> wx.SizerItem", |
7aada1e0 RD |
931 | "Returns the `wx.SizerItem` which holds the *item* given. The *item* |
932 | parameter can be either a window, a sizer, or the zero-based index of | |
aae5d34f | 933 | the item to be found.", ""); |
cbfc9df6 | 934 | wxSizerItem* GetItem(PyObject* item, bool recursive=false) { |
6e6b3557 | 935 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); |
7aada1e0 RD |
936 | wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, false, true); |
937 | wxPyEndBlockThreads(blocked); | |
938 | if ( info.window ) | |
cbfc9df6 | 939 | return self->GetItem(info.window, recursive); |
7aada1e0 | 940 | else if ( info.sizer ) |
cbfc9df6 | 941 | return self->GetItem(info.sizer, recursive); |
7aada1e0 RD |
942 | else if ( info.gotPos ) |
943 | return self->GetItem(info.pos); | |
944 | else | |
945 | return NULL; | |
946 | } | |
947 | ||
7e8f0df9 | 948 | |
dd9f7fea | 949 | void _SetItemMinSize(PyObject* item, const wxSize& size) { |
6e6b3557 | 950 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); |
a72f4631 | 951 | wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, false, true); |
da32eb53 | 952 | wxPyEndBlockThreads(blocked); |
d14a1e28 RD |
953 | if ( info.window ) |
954 | self->SetItemMinSize(info.window, size); | |
955 | else if ( info.sizer ) | |
956 | self->SetItemMinSize(info.sizer, size); | |
957 | else if ( info.gotPos ) | |
958 | self->SetItemMinSize(info.pos, size); | |
959 | } | |
960 | } | |
961 | ||
e81b607b RD |
962 | |
963 | %Rename(_ReplaceWin, | |
964 | bool, Replace( wxWindow *oldwin, wxWindow *newwin, bool recursive = false )); | |
965 | %Rename(_ReplaceSizer, | |
966 | bool, Replace( wxSizer *oldsz, wxSizer *newsz, bool recursive = false )); | |
967 | %Rename(_ReplaceItem, | |
968 | bool, Replace( size_t index, wxSizerItem *newitem )); | |
969 | %pythoncode { | |
970 | def Replace(self, olditem, item, recursive=False): | |
971 | """ | |
972 | Detaches the given ``olditem`` from the sizer and replaces it with | |
973 | ``item`` which can be a window, sizer, or `wx.SizerItem`. The | |
974 | detached child is destroyed only if it is not a window, (because | |
975 | windows are owned by their parent, not the sizer.) The | |
976 | ``recursive`` parameter can be used to search for the given | |
977 | element recursivly in subsizers. | |
978 | ||
979 | This method does not cause any layout or resizing to take place, | |
980 | call `Layout` to do so. | |
981 | ||
982 | Returns ``True`` if the child item was found and removed. | |
983 | """ | |
984 | if isinstance(olditem, wx.Window): | |
985 | return self._ReplaceWin(olditem, item, recursive) | |
cbfc9df6 | 986 | elif isinstance(olditem, wx.Sizer): |
e81b607b | 987 | return self._ReplaceSizer(olditem, item, recursive) |
cbfc9df6 | 988 | elif isinstance(olditem, int): |
e81b607b RD |
989 | return self._ReplaceItem(olditem, item) |
990 | else: | |
991 | raise TypeError("Expected Window, Sizer, or integer for first parameter.") | |
992 | } | |
993 | ||
994 | ||
995 | DocDeclStr( | |
996 | void , SetContainingWindow(wxWindow *window), | |
997 | "Set (or unset) the window this sizer is used in.", ""); | |
998 | ||
999 | DocDeclStr( | |
1000 | wxWindow *, GetContainingWindow() const, | |
1001 | "Get the window this sizer is used in.", ""); | |
1002 | ||
1003 | ||
3ea6e0ec RD |
1004 | %pythoncode { |
1005 | def SetItemMinSize(self, item, *args): | |
1006 | """ | |
1007 | SetItemMinSize(self, item, Size size) | |
1008 | ||
1009 | Sets the minimum size that will be allocated for an item in the sizer. | |
1010 | The *item* parameter can be either a window, a sizer, or the | |
1011 | zero-based index of the item. If a window or sizer is given then it | |
1012 | will be searched for recursivly in subsizers if neccessary. | |
1013 | """ | |
1014 | if len(args) == 2: | |
1015 | %# for backward compatibility accept separate width,height args too | |
1016 | return self._SetItemMinSize(item, args) | |
1017 | else: | |
1018 | return self._SetItemMinSize(item, args[0]) | |
1019 | } | |
7e8f0df9 | 1020 | |
214c4fbe RD |
1021 | |
1022 | %disownarg( wxSizerItem *item ); | |
1023 | ||
3ea6e0ec | 1024 | DocDeclAStrName( |
7aada1e0 | 1025 | wxSizerItem* , Add( wxSizerItem *item ), |
3ea6e0ec RD |
1026 | "AddItem(self, SizerItem item)", |
1027 | "Adds a `wx.SizerItem` to the sizer.", "", | |
1028 | AddItem); | |
7e8f0df9 | 1029 | |
3ea6e0ec | 1030 | DocDeclAStrName( |
7aada1e0 | 1031 | wxSizerItem* , Insert( size_t index, wxSizerItem *item ), |
3ea6e0ec RD |
1032 | "InsertItem(self, int index, SizerItem item)", |
1033 | "Inserts a `wx.SizerItem` to the sizer at the position given by *index*.", "", | |
1034 | InsertItem); | |
7e8f0df9 | 1035 | |
3ea6e0ec | 1036 | DocDeclAStrName( |
7aada1e0 | 1037 | wxSizerItem* , Prepend( wxSizerItem *item ), |
3ea6e0ec RD |
1038 | "PrependItem(self, SizerItem item)", |
1039 | "Prepends a `wx.SizerItem` to the sizer.", "", | |
1040 | PrependItem); | |
7e8f0df9 | 1041 | |
214c4fbe | 1042 | %cleardisown( wxSizerItem *item ); |
d14a1e28 RD |
1043 | |
1044 | ||
1045 | %pythoncode { | |
3ea6e0ec | 1046 | def AddMany(self, items): |
dce2bd22 RD |
1047 | """ |
1048 | AddMany is a convenience method for adding several items | |
1049 | to a sizer at one time. Simply pass it a list of tuples, | |
1050 | where each tuple consists of the parameters that you | |
1051 | would normally pass to the `Add` method. | |
1052 | """ | |
3ea6e0ec RD |
1053 | for item in items: |
1054 | if type(item) != type(()) or (len(item) == 2 and type(item[0]) == type(1)): | |
1055 | item = (item, ) | |
1056 | self.Add(*item) | |
d14a1e28 | 1057 | |
79032d2b RD |
1058 | def AddSpacer(self, *args, **kw): |
1059 | """AddSpacer(int size) --> SizerItem | |
1060 | ||
1061 | Add a spacer that is (size,size) pixels. | |
1062 | """ | |
1063 | if args and type(args[0]) == int: | |
1064 | return self.Add( (args[0],args[0] ), 0) | |
1065 | else: %# otherwise stay compatible with old AddSpacer | |
1066 | return self.Add(*args, **kw) | |
1067 | def PrependSpacer(self, *args, **kw): | |
1068 | """PrependSpacer(int size) --> SizerItem | |
1069 | ||
1070 | Prepend a spacer that is (size, size) pixels.""" | |
1071 | if args and type(args[0]) == int: | |
1072 | return self.Prepend( (args[0],args[0] ), 0) | |
1073 | else: %# otherwise stay compatible with old PrependSpacer | |
1074 | return self.Prepend(*args, **kw) | |
1075 | def InsertSpacer(self, index, *args, **kw): | |
1076 | """InsertSpacer(int index, int size) --> SizerItem | |
1077 | ||
1078 | Insert a spacer at position index that is (size, size) pixels.""" | |
1079 | if args and type(args[0]) == int: | |
1080 | return self.Insert( index, (args[0],args[0] ), 0) | |
1081 | else: %# otherwise stay compatible with old InsertSpacer | |
1082 | return self.Insert(index, *args, **kw) | |
1083 | ||
1084 | ||
1085 | def AddStretchSpacer(self, prop=1): | |
1086 | """AddStretchSpacer(int prop=1) --> SizerItem | |
1087 | ||
1088 | Add a stretchable spacer.""" | |
1089 | return self.Add((0,0), prop) | |
1090 | def PrependStretchSpacer(self, prop=1): | |
1091 | """PrependStretchSpacer(int prop=1) --> SizerItem | |
1092 | ||
1093 | Prepend a stretchable spacer.""" | |
1094 | return self.Prepend((0,0), prop) | |
1095 | def InsertStretchSpacer(self, index, prop=1): | |
1096 | """InsertStretchSpacer(int index, int prop=1) --> SizerItem | |
1097 | ||
1098 | Insert a stretchable spacer.""" | |
1099 | return self.Insert(index, (0,0), prop) | |
1100 | ||
1101 | ||
d147c724 | 1102 | %# for backwards compatibility only, please do not use in new code |
7e8f0df9 RD |
1103 | def AddWindow(self, *args, **kw): |
1104 | """Compatibility alias for `Add`.""" | |
1105 | return self.Add(*args, **kw) | |
1106 | def AddSizer(self, *args, **kw): | |
1107 | """Compatibility alias for `Add`.""" | |
1108 | return self.Add(*args, **kw) | |
7e8f0df9 RD |
1109 | |
1110 | def PrependWindow(self, *args, **kw): | |
1111 | """Compatibility alias for `Prepend`.""" | |
1112 | return self.Prepend(*args, **kw) | |
1113 | def PrependSizer(self, *args, **kw): | |
1114 | """Compatibility alias for `Prepend`.""" | |
1115 | return self.Prepend(*args, **kw) | |
7e8f0df9 RD |
1116 | |
1117 | def InsertWindow(self, *args, **kw): | |
1118 | """Compatibility alias for `Insert`.""" | |
1119 | return self.Insert(*args, **kw) | |
1120 | def InsertSizer(self, *args, **kw): | |
1121 | """Compatibility alias for `Insert`.""" | |
1122 | return self.Insert(*args, **kw) | |
7e8f0df9 RD |
1123 | |
1124 | def RemoveWindow(self, *args, **kw): | |
1125 | """Compatibility alias for `Remove`.""" | |
1126 | return self.Remove(*args, **kw) | |
1127 | def RemoveSizer(self, *args, **kw): | |
1128 | """Compatibility alias for `Remove`.""" | |
1129 | return self.Remove(*args, **kw) | |
1130 | def RemovePos(self, *args, **kw): | |
1131 | """Compatibility alias for `Remove`.""" | |
1132 | return self.Remove(*args, **kw) | |
d14a1e28 | 1133 | |
d14a1e28 RD |
1134 | } |
1135 | ||
1136 | ||
3ea6e0ec RD |
1137 | DocDeclStr( |
1138 | void , SetDimension( int x, int y, int width, int height ), | |
1139 | "Call this to force the sizer to take the given dimension and thus | |
1140 | force the items owned by the sizer to resize themselves according to | |
1141 | the rules defined by the parameter in the `Add`, `Insert` or `Prepend` | |
1142 | methods.", ""); | |
7e8f0df9 | 1143 | |
3ea6e0ec RD |
1144 | DocDeclStr( |
1145 | void , SetMinSize( const wxSize &size ), | |
1146 | "Call this to give the sizer a minimal size. Normally, the sizer will | |
1147 | calculate its minimal size based purely on how much space its children | |
1148 | need. After calling this method `GetMinSize` will return either the | |
1149 | minimal size as requested by its children or the minimal size set | |
1150 | here, depending on which is bigger.", ""); | |
7e8f0df9 | 1151 | |
d14a1e28 | 1152 | |
3ea6e0ec RD |
1153 | DocDeclStr( |
1154 | wxSize , GetSize(), | |
1155 | "Returns the current size of the space managed by the sizer.", ""); | |
7e8f0df9 | 1156 | |
3ea6e0ec RD |
1157 | DocDeclStr( |
1158 | wxPoint , GetPosition(), | |
1159 | "Returns the current position of the sizer's managed space.", ""); | |
7e8f0df9 | 1160 | |
3ea6e0ec RD |
1161 | DocDeclStr( |
1162 | wxSize , GetMinSize(), | |
1163 | "Returns the minimal size of the sizer. This is either the combined | |
1164 | minimal size of all the children and their borders or the minimal size | |
1165 | set by SetMinSize, depending on which is bigger.", ""); | |
7e8f0df9 | 1166 | |
d14a1e28 RD |
1167 | |
1168 | %pythoncode { | |
1169 | def GetSizeTuple(self): | |
60a71c29 | 1170 | return self.GetSize().Get() |
d14a1e28 | 1171 | def GetPositionTuple(self): |
60a71c29 | 1172 | return self.GetPosition().Get() |
d14a1e28 | 1173 | def GetMinSizeTuple(self): |
60a71c29 | 1174 | return self.GetMinSize().Get() |
d14a1e28 RD |
1175 | } |
1176 | ||
3ea6e0ec RD |
1177 | DocDeclStr( |
1178 | virtual void , RecalcSizes(), | |
1179 | "Using the sizes calculated by `CalcMin` reposition and resize all the | |
1180 | items managed by this sizer. You should not need to call this directly as | |
1181 | it is called by `Layout`.", ""); | |
7e8f0df9 | 1182 | |
3ea6e0ec RD |
1183 | DocDeclStr( |
1184 | virtual wxSize , CalcMin(), | |
1185 | "This method is where the sizer will do the actual calculation of its | |
1186 | children's minimal sizes. You should not need to call this directly as | |
1187 | it is called by `Layout`.", ""); | |
7e8f0df9 | 1188 | |
3ea6e0ec RD |
1189 | |
1190 | DocDeclStr( | |
1191 | void , Layout(), | |
1192 | "This method will force the recalculation and layout of the items | |
1193 | controlled by the sizer using the current space allocated to the | |
1194 | sizer. Normally this is called automatically from the owning window's | |
1195 | EVT_SIZE handler, but it is also useful to call it from user code when | |
1196 | one of the items in a sizer change size, or items are added or | |
1197 | removed.", ""); | |
7e8f0df9 | 1198 | |
d14a1e28 | 1199 | |
3ea6e0ec RD |
1200 | DocDeclStr( |
1201 | wxSize , Fit( wxWindow *window ), | |
1202 | "Tell the sizer to resize the *window* to match the sizer's minimal | |
1203 | size. This is commonly done in the constructor of the window itself in | |
1204 | order to set its initial size to match the needs of the children as | |
1205 | determined by the sizer. Returns the new size. | |
d14a1e28 | 1206 | |
3ea6e0ec | 1207 | For a top level window this is the total window size, not the client size.", ""); |
7e8f0df9 | 1208 | |
3ea6e0ec RD |
1209 | DocDeclStr( |
1210 | void , FitInside( wxWindow *window ), | |
1211 | "Tell the sizer to resize the *virtual size* of the *window* to match the | |
1212 | sizer's minimal size. This will not alter the on screen size of the | |
1213 | window, but may cause the addition/removal/alteration of scrollbars | |
1214 | required to view the virtual area in windows which manage it. | |
1215 | ||
1216 | :see: `wx.ScrolledWindow.SetScrollbars`, `SetVirtualSizeHints` | |
1217 | ", ""); | |
7e8f0df9 | 1218 | |
d14a1e28 | 1219 | |
3ea6e0ec RD |
1220 | DocDeclStr( |
1221 | void , SetSizeHints( wxWindow *window ), | |
1222 | "Tell the sizer to set (and `Fit`) the minimal size of the *window* to | |
1223 | match the sizer's minimal size. This is commonly done in the | |
1224 | constructor of the window itself if the window is resizable (as are | |
1225 | many dialogs under Unix and frames on probably all platforms) in order | |
1226 | to prevent the window from being sized smaller than the minimal size | |
1227 | required by the sizer.", ""); | |
7e8f0df9 | 1228 | |
3ea6e0ec RD |
1229 | DocDeclStr( |
1230 | void , SetVirtualSizeHints( wxWindow *window ), | |
1231 | "Tell the sizer to set the minimal size of the window virtual area to | |
1232 | match the sizer's minimal size. For windows with managed scrollbars | |
1233 | this will set them appropriately. | |
1234 | ||
1235 | :see: `wx.ScrolledWindow.SetScrollbars` | |
1236 | ", ""); | |
7e8f0df9 | 1237 | |
d14a1e28 | 1238 | |
3ea6e0ec | 1239 | DocDeclStr( |
a72f4631 | 1240 | void , Clear( bool deleteWindows=false ), |
3ea6e0ec RD |
1241 | "Clear all items from the sizer, optionally destroying the window items |
1242 | as well.", ""); | |
7e8f0df9 | 1243 | |
3ea6e0ec RD |
1244 | DocDeclStr( |
1245 | void , DeleteWindows(), | |
1246 | "Destroy all windows managed by the sizer.", ""); | |
7e8f0df9 | 1247 | |
d14a1e28 RD |
1248 | |
1249 | ||
1250 | // wxList& GetChildren(); | |
1251 | %extend { | |
3ea6e0ec | 1252 | DocAStr(GetChildren, |
50ed1e35 | 1253 | "GetChildren(self) -> list", |
3ea6e0ec | 1254 | "Returns a list of all the `wx.SizerItem` objects managed by the sizer.", ""); |
d14a1e28 RD |
1255 | PyObject* GetChildren() { |
1256 | wxSizerItemList& list = self->GetChildren(); | |
1257 | return wxPy_ConvertList(&list); | |
1258 | } | |
1259 | } | |
1260 | ||
1261 | ||
3ea6e0ec | 1262 | // Manage whether individual windows or subsizers are considered |
d14a1e28 RD |
1263 | // in the layout calculations or not. |
1264 | ||
1265 | %extend { | |
3ea6e0ec | 1266 | DocAStr(Show, |
a72f4631 | 1267 | "Show(self, item, bool show=True, bool recursive=false) -> bool", |
3ea6e0ec RD |
1268 | "Shows or hides an item managed by the sizer. To make a sizer item |
1269 | disappear or reappear, use Show followed by `Layout`. The *item* | |
1270 | parameter can be either a window, a sizer, or the zero-based index of | |
8f214674 RD |
1271 | the item. Use the recursive parameter to show or hide an item in a |
1272 | subsizer. Returns True if the item was found.", ""); | |
a72f4631 | 1273 | bool Show(PyObject* item, bool show = true, bool recursive=false) { |
6e6b3557 | 1274 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); |
a72f4631 | 1275 | wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, false, true); |
019fd9d3 | 1276 | wxPyEndBlockThreads(blocked); |
d14a1e28 | 1277 | if ( info.window ) |
8f214674 | 1278 | return self->Show(info.window, show, recursive); |
d14a1e28 | 1279 | else if ( info.sizer ) |
8f214674 | 1280 | return self->Show(info.sizer, show, recursive); |
3ea6e0ec | 1281 | else if ( info.gotPos ) |
8f214674 | 1282 | return self->Show(info.pos, show); |
5f476690 RD |
1283 | else |
1284 | return false; | |
d14a1e28 | 1285 | } |
7e8f0df9 | 1286 | |
3ea6e0ec RD |
1287 | DocAStr(IsShown, |
1288 | "IsShown(self, item)", | |
95109042 | 1289 | "Determines if the item is currently shown. To make a sizer |
3ea6e0ec RD |
1290 | item disappear or reappear, use Show followed by `Layout`. The *item* |
1291 | parameter can be either a window, a sizer, or the zero-based index of | |
1292 | the item.", ""); | |
d14a1e28 | 1293 | bool IsShown(PyObject* item) { |
6e6b3557 | 1294 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); |
a72f4631 | 1295 | wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, false, false); |
019fd9d3 | 1296 | wxPyEndBlockThreads(blocked); |
7e8f0df9 | 1297 | if ( info.window ) |
d14a1e28 | 1298 | return self->IsShown(info.window); |
7e8f0df9 | 1299 | else if ( info.sizer ) |
d14a1e28 | 1300 | return self->IsShown(info.sizer); |
3ea6e0ec RD |
1301 | else if ( info.gotPos ) |
1302 | return self->IsShown(info.pos); | |
d14a1e28 | 1303 | else |
a72f4631 | 1304 | return false; |
d14a1e28 RD |
1305 | } |
1306 | } | |
1307 | ||
3ea6e0ec | 1308 | %pythoncode { |
41b78a7a | 1309 | def Hide(self, item, recursive=False): |
3ea6e0ec | 1310 | """ |
d5a7caf6 | 1311 | A convenience method for `Show` (item, False, recursive). |
3ea6e0ec | 1312 | """ |
9dcf02b4 | 1313 | return self.Show(item, False, recursive) |
3ea6e0ec | 1314 | } |
d14a1e28 | 1315 | |
7e8f0df9 | 1316 | |
3ea6e0ec RD |
1317 | DocDeclStr( |
1318 | void , ShowItems(bool show), | |
e2837d11 | 1319 | "Recursively call `wx.SizerItem.Show` on all sizer items.", ""); |
7e8f0df9 | 1320 | |
7012bb9f RD |
1321 | %property(Children, GetChildren, doc="See `GetChildren`"); |
1322 | %property(ContainingWindow, GetContainingWindow, SetContainingWindow, doc="See `GetContainingWindow` and `SetContainingWindow`"); | |
1323 | %property(MinSize, GetMinSize, SetMinSize, doc="See `GetMinSize` and `SetMinSize`"); | |
1324 | %property(Position, GetPosition, doc="See `GetPosition`"); | |
1325 | %property(Size, GetSize, doc="See `GetSize`"); | |
d14a1e28 RD |
1326 | }; |
1327 | ||
1328 | ||
1329 | //--------------------------------------------------------------------------- | |
1330 | // Use this one for deriving Python classes from | |
1331 | %{ | |
7e8f0df9 | 1332 | // See pyclasses.h |
d14a1e28 RD |
1333 | IMP_PYCALLBACK___pure(wxPySizer, wxSizer, RecalcSizes); |
1334 | IMP_PYCALLBACK_wxSize__pure(wxPySizer, wxSizer, CalcMin); | |
1335 | IMPLEMENT_DYNAMIC_CLASS(wxPySizer, wxSizer); | |
1336 | %} | |
1337 | ||
1338 | ||
3ea6e0ec RD |
1339 | DocStr(wxPySizer, |
1340 | "wx.PySizer is a special version of `wx.Sizer` that has been | |
1341 | instrumented to allow the C++ virtual methods to be overloaded in | |
1342 | Python derived classes. You would derive from this class if you are | |
1343 | wanting to implement a custom sizer in Python code. Simply implement | |
1344 | `CalcMin` and `RecalcSizes` in the derived class and you're all set. | |
1345 | For example:: | |
1346 | ||
1347 | class MySizer(wx.PySizer): | |
1348 | def __init__(self): | |
1349 | wx.PySizer.__init__(self) | |
1350 | ||
1351 | def CalcMin(self): | |
1352 | for item in self.GetChildren(): | |
1353 | # calculate the total minimum width and height needed | |
1354 | # by all items in the sizer according to this sizer's | |
1355 | # layout algorithm. | |
1356 | ... | |
1357 | return wx.Size(width, height) | |
1358 | ||
1359 | def RecalcSizes(self): | |
1360 | # find the space allotted to this sizer | |
1361 | pos = self.GetPosition() | |
1362 | size = self.GetSize() | |
1363 | for item in self.GetChildren(): | |
1364 | # Recalculate (if necessary) the position and size of | |
1365 | # each item and then call item.SetDimension to do the | |
1366 | # actual positioning and sizing of the items within the | |
1367 | # space alloted to this sizer. | |
1368 | ... | |
1369 | item.SetDimension(itemPos, itemSize) | |
1370 | ||
1371 | ||
1372 | When `Layout` is called it first calls `CalcMin` followed by | |
1373 | `RecalcSizes` so you can optimize a bit by saving the results of | |
9283228f | 1374 | `CalcMin` and reusing them in `RecalcSizes`. |
3ea6e0ec RD |
1375 | |
1376 | :see: `wx.SizerItem`, `wx.Sizer.GetChildren` | |
1377 | ||
1378 | ", ""); | |
d14a1e28 RD |
1379 | class wxPySizer : public wxSizer { |
1380 | public: | |
c25f90f6 | 1381 | %pythonAppend wxPySizer "self._setOORInfo(self);" setCallbackInfo(PySizer) |
d14a1e28 | 1382 | |
3ea6e0ec RD |
1383 | DocCtorStr( |
1384 | wxPySizer(), | |
1385 | "Creates a wx.PySizer. Must be called from the __init__ in the derived | |
1386 | class.", ""); | |
7e8f0df9 | 1387 | |
d14a1e28 RD |
1388 | void _setCallbackInfo(PyObject* self, PyObject* _class); |
1389 | }; | |
1390 | ||
1391 | ||
1392 | //--------------------------------------------------------------------------- | |
1393 | %newgroup; | |
1394 | ||
3ea6e0ec RD |
1395 | |
1396 | DocStr(wxBoxSizer, | |
1397 | "The basic idea behind a box sizer is that windows will most often be | |
1398 | laid out in rather simple basic geometry, typically in a row or a | |
1399 | column or nested hierarchies of either. A wx.BoxSizer will lay out | |
1400 | its items in a simple row or column, depending on the orientation | |
1401 | parameter passed to the constructor.", " | |
1402 | ||
1403 | It is the unique feature of a box sizer, that it can grow in both | |
1404 | directions (height and width) but can distribute its growth in the | |
1405 | main direction (horizontal for a row) *unevenly* among its children. | |
1406 | This is determined by the proportion parameter give to items when they | |
1407 | are added to the sizer. It is interpreted as a weight factor, i.e. it | |
1408 | can be zero, indicating that the window may not be resized at all, or | |
1409 | above zero. If several windows have a value above zero, the value is | |
1410 | interpreted relative to the sum of all weight factors of the sizer, so | |
1411 | when adding two windows with a value of 1, they will both get resized | |
1412 | equally and each will receive half of the available space after the | |
1413 | fixed size items have been sized. If the items have unequal | |
1414 | proportion settings then they will receive a coresondingly unequal | |
1415 | allotment of the free space. | |
1416 | ||
1417 | :see: `wx.StaticBoxSizer` | |
1418 | "); | |
1419 | ||
d14a1e28 RD |
1420 | class wxBoxSizer : public wxSizer { |
1421 | public: | |
2b9048c5 | 1422 | %pythonAppend wxBoxSizer "self._setOORInfo(self)" |
d14a1e28 | 1423 | |
3ea6e0ec RD |
1424 | DocCtorStr( |
1425 | wxBoxSizer(int orient = wxHORIZONTAL), | |
1426 | "Constructor for a wx.BoxSizer. *orient* may be one of ``wx.VERTICAL`` | |
1427 | or ``wx.HORIZONTAL`` for creating either a column sizer or a row | |
1428 | sizer.", ""); | |
d14a1e28 | 1429 | |
7e8f0df9 | 1430 | |
3ea6e0ec RD |
1431 | DocDeclStr( |
1432 | int , GetOrientation(), | |
1433 | "Returns the current orientation of the sizer.", ""); | |
7e8f0df9 | 1434 | |
3ea6e0ec RD |
1435 | DocDeclStr( |
1436 | void , SetOrientation(int orient), | |
1437 | "Resets the orientation of the sizer.", ""); | |
7e8f0df9 | 1438 | |
a7c987f9 RD |
1439 | bool IsVertical() const; |
1440 | ||
0eae5d09 | 1441 | %property(Orientation, GetOrientation, SetOrientation, doc="See `GetOrientation` and `SetOrientation`"); |
d14a1e28 RD |
1442 | }; |
1443 | ||
1444 | //--------------------------------------------------------------------------- | |
1445 | %newgroup; | |
1446 | ||
3ea6e0ec RD |
1447 | |
1448 | DocStr(wxStaticBoxSizer, | |
1449 | "wx.StaticBoxSizer derives from and functions identically to the | |
1450 | `wx.BoxSizer` and adds a `wx.StaticBox` around the items that the sizer | |
1451 | manages. Note that this static box must be created separately and | |
1452 | passed to the sizer constructor.", ""); | |
1453 | ||
d14a1e28 RD |
1454 | class wxStaticBoxSizer : public wxBoxSizer { |
1455 | public: | |
2b9048c5 | 1456 | %pythonAppend wxStaticBoxSizer "self._setOORInfo(self)" |
d14a1e28 | 1457 | |
3ea6e0ec RD |
1458 | DocCtorStr( |
1459 | wxStaticBoxSizer(wxStaticBox *box, int orient = wxHORIZONTAL), | |
1460 | "Constructor. It takes an associated static box and the orientation | |
1461 | *orient* as parameters - orient can be either of ``wx.VERTICAL`` or | |
1462 | ``wx.HORIZONTAL``.", ""); | |
39d160c3 RD |
1463 | |
1464 | // TODO: wxStaticBoxSizer(int orient, wxWindow *win, const wxString& label = wxEmptyString); | |
7e8f0df9 | 1465 | |
39d160c3 RD |
1466 | DocDeclStr( |
1467 | wxStaticBox *, GetStaticBox(), | |
1468 | "Returns the static box associated with this sizer.", ""); | |
7e8f0df9 | 1469 | |
7012bb9f | 1470 | %property(StaticBox, GetStaticBox, doc="See `GetStaticBox`"); |
d14a1e28 RD |
1471 | }; |
1472 | ||
1473 | //--------------------------------------------------------------------------- | |
1474 | %newgroup; | |
1475 | ||
3ea6e0ec RD |
1476 | |
1477 | DocStr(wxGridSizer, | |
1478 | "A grid sizer is a sizer which lays out its children in a | |
1479 | two-dimensional table with all cells having the same size. In other | |
1480 | words, the width of each cell within the grid is the width of the | |
1481 | widest item added to the sizer and the height of each grid cell is the | |
1482 | height of the tallest item. An optional vertical and/or horizontal | |
1483 | gap between items can also be specified (in pixels.) | |
1484 | ||
1485 | Items are placed in the cells of the grid in the order they are added, | |
1486 | in row-major order. In other words, the first row is filled first, | |
1487 | then the second, and so on until all items have been added. (If | |
1488 | neccessary, additional rows will be added as items are added.) If you | |
1489 | need to have greater control over the cells that items are placed in | |
1490 | then use the `wx.GridBagSizer`. | |
1491 | ", ""); | |
1492 | ||
d14a1e28 RD |
1493 | class wxGridSizer: public wxSizer |
1494 | { | |
1495 | public: | |
2b9048c5 | 1496 | %pythonAppend wxGridSizer "self._setOORInfo(self)" |
d14a1e28 | 1497 | |
3ea6e0ec RD |
1498 | DocCtorStr( |
1499 | wxGridSizer( int rows=1, int cols=0, int vgap=0, int hgap=0 ), | |
1500 | "Constructor for a wx.GridSizer. *rows* and *cols* determine the number | |
1501 | of columns and rows in the sizer - if either of the parameters is | |
1502 | zero, it will be calculated to from the total number of children in | |
1503 | the sizer, thus making the sizer grow dynamically. *vgap* and *hgap* | |
1504 | define extra space between all children.", ""); | |
1505 | ||
1506 | DocDeclStr( | |
1507 | void , SetCols( int cols ), | |
1508 | "Sets the number of columns in the sizer.", ""); | |
7e8f0df9 | 1509 | |
3ea6e0ec RD |
1510 | DocDeclStr( |
1511 | void , SetRows( int rows ), | |
1512 | "Sets the number of rows in the sizer.", ""); | |
7e8f0df9 | 1513 | |
3ea6e0ec RD |
1514 | DocDeclStr( |
1515 | void , SetVGap( int gap ), | |
1516 | "Sets the vertical gap (in pixels) between the cells in the sizer.", ""); | |
7e8f0df9 | 1517 | |
3ea6e0ec RD |
1518 | DocDeclStr( |
1519 | void , SetHGap( int gap ), | |
1520 | "Sets the horizontal gap (in pixels) between cells in the sizer", ""); | |
7e8f0df9 | 1521 | |
3ea6e0ec RD |
1522 | DocDeclStr( |
1523 | int , GetCols(), | |
1524 | "Returns the number of columns in the sizer.", ""); | |
7e8f0df9 | 1525 | |
3ea6e0ec RD |
1526 | DocDeclStr( |
1527 | int , GetRows(), | |
1528 | "Returns the number of rows in the sizer.", ""); | |
7e8f0df9 | 1529 | |
3ea6e0ec RD |
1530 | DocDeclStr( |
1531 | int , GetVGap(), | |
1532 | "Returns the vertical gap (in pixels) between the cells in the sizer.", ""); | |
7e8f0df9 | 1533 | |
3ea6e0ec RD |
1534 | DocDeclStr( |
1535 | int , GetHGap(), | |
1536 | "Returns the horizontal gap (in pixels) between cells in the sizer.", ""); | |
7e8f0df9 | 1537 | |
c86fa5a1 RD |
1538 | %pythoncode { |
1539 | def CalcRowsCols(self): | |
1540 | """ | |
1541 | CalcRowsCols() -> (rows, cols) | |
1542 | ||
1543 | Calculates how many rows and columns will be in the sizer based | |
1544 | on the current number of items and also the rows, cols specified | |
1545 | in the constructor. | |
1546 | """ | |
1547 | nitems = len(self.GetChildren()) | |
1548 | rows = self.GetRows() | |
1549 | cols = self.GetCols() | |
1550 | assert rows != 0 or cols != 0, "Grid sizer must have either rows or columns fixed" | |
1551 | if cols != 0: | |
1552 | rows = (nitems + cols - 1) / cols | |
1553 | elif rows != 0: | |
1554 | cols = (nitems + rows - 1) / rows | |
1555 | return (rows, cols) | |
1556 | } | |
76b8fa1d RD |
1557 | |
1558 | %property(Cols, GetCols, SetCols, doc="See `GetCols` and `SetCols`"); | |
1559 | %property(HGap, GetHGap, SetHGap, doc="See `GetHGap` and `SetHGap`"); | |
1560 | %property(Rows, GetRows, SetRows, doc="See `GetRows` and `SetRows`"); | |
1561 | %property(VGap, GetVGap, SetVGap, doc="See `GetVGap` and `SetVGap`"); | |
d14a1e28 RD |
1562 | }; |
1563 | ||
1564 | //--------------------------------------------------------------------------- | |
1565 | %newgroup; | |
1566 | ||
1567 | enum wxFlexSizerGrowMode | |
1568 | { | |
1569 | // don't resize the cells in non-flexible direction at all | |
1570 | wxFLEX_GROWMODE_NONE, | |
1571 | ||
1572 | // uniformly resize only the specified ones (default) | |
1573 | wxFLEX_GROWMODE_SPECIFIED, | |
1574 | ||
1575 | // uniformly resize all cells | |
1576 | wxFLEX_GROWMODE_ALL | |
1577 | }; | |
1578 | ||
1579 | ||
3ea6e0ec RD |
1580 | |
1581 | ||
1582 | ||
1583 | DocStr(wxFlexGridSizer, | |
1584 | "A flex grid sizer is a sizer which lays out its children in a | |
1585 | two-dimensional table with all table cells in one row having the same | |
1586 | height and all cells in one column having the same width, but all | |
1587 | rows or all columns are not necessarily the same height or width as in | |
1588 | the `wx.GridSizer`. | |
1589 | ||
1590 | wx.FlexGridSizer can also size items equally in one direction but | |
1591 | unequally (\"flexibly\") in the other. If the sizer is only flexible | |
1592 | in one direction (this can be changed using `SetFlexibleDirection`), it | |
1593 | needs to be decided how the sizer should grow in the other (\"non | |
1594 | flexible\") direction in order to fill the available space. The | |
1595 | `SetNonFlexibleGrowMode` method serves this purpose. | |
1596 | ||
1597 | ", ""); | |
1598 | ||
d14a1e28 RD |
1599 | class wxFlexGridSizer: public wxGridSizer |
1600 | { | |
1601 | public: | |
2b9048c5 | 1602 | %pythonAppend wxFlexGridSizer "self._setOORInfo(self)" |
d14a1e28 | 1603 | |
3ea6e0ec RD |
1604 | DocCtorStr( |
1605 | wxFlexGridSizer( int rows=1, int cols=0, int vgap=0, int hgap=0 ), | |
1606 | "Constructor for a wx.FlexGridSizer. *rows* and *cols* determine the | |
1607 | number of columns and rows in the sizer - if either of the parameters | |
1608 | is zero, it will be calculated to from the total number of children in | |
1609 | the sizer, thus making the sizer grow dynamically. *vgap* and *hgap* | |
1610 | define extra space between all children.", ""); | |
7e8f0df9 | 1611 | |
3ea6e0ec RD |
1612 | |
1613 | DocDeclStr( | |
1614 | void , AddGrowableRow( size_t idx, int proportion = 0 ), | |
1615 | "Specifies that row *idx* (starting from zero) should be grown if there | |
1616 | is extra space available to the sizer. | |
1617 | ||
1618 | The *proportion* parameter has the same meaning as the stretch factor | |
1619 | for the box sizers except that if all proportions are 0, then all | |
1620 | columns are resized equally (instead of not being resized at all).", ""); | |
7e8f0df9 | 1621 | |
3ea6e0ec RD |
1622 | DocDeclStr( |
1623 | void , RemoveGrowableRow( size_t idx ), | |
1624 | "Specifies that row *idx* is no longer growable.", ""); | |
7e8f0df9 | 1625 | |
3ea6e0ec RD |
1626 | DocDeclStr( |
1627 | void , AddGrowableCol( size_t idx, int proportion = 0 ), | |
1628 | "Specifies that column *idx* (starting from zero) should be grown if | |
1629 | there is extra space available to the sizer. | |
1630 | ||
1631 | The *proportion* parameter has the same meaning as the stretch factor | |
1632 | for the box sizers except that if all proportions are 0, then all | |
1633 | columns are resized equally (instead of not being resized at all).", ""); | |
7e8f0df9 | 1634 | |
3ea6e0ec RD |
1635 | DocDeclStr( |
1636 | void , RemoveGrowableCol( size_t idx ), | |
1637 | "Specifies that column *idx* is no longer growable.", ""); | |
7e8f0df9 | 1638 | |
3ea6e0ec RD |
1639 | |
1640 | DocDeclStr( | |
1641 | void , SetFlexibleDirection(int direction), | |
1642 | "Specifies whether the sizer should flexibly resize its columns, rows, | |
1643 | or both. Argument *direction* can be one of the following values. Any | |
1644 | other value is ignored. | |
1645 | ||
1646 | ============== ======================================= | |
1647 | wx.VERTICAL Rows are flexibly sized. | |
1648 | wx.HORIZONTAL Columns are flexibly sized. | |
1649 | wx.BOTH Both rows and columns are flexibly sized | |
1650 | (this is the default value). | |
1651 | ============== ======================================= | |
1652 | ||
1653 | Note that this method does not trigger relayout. | |
1654 | ", ""); | |
7e8f0df9 | 1655 | |
3ea6e0ec RD |
1656 | DocDeclStr( |
1657 | int , GetFlexibleDirection(), | |
1658 | "Returns a value that specifies whether the sizer | |
1659 | flexibly resizes its columns, rows, or both (default). | |
d14a1e28 | 1660 | |
3ea6e0ec | 1661 | :see: `SetFlexibleDirection`", ""); |
d14a1e28 | 1662 | |
7e8f0df9 | 1663 | |
d14a1e28 | 1664 | |
3ea6e0ec RD |
1665 | DocDeclStr( |
1666 | void , SetNonFlexibleGrowMode(wxFlexSizerGrowMode mode), | |
1667 | "Specifies how the sizer should grow in the non-flexible direction if | |
1668 | there is one (so `SetFlexibleDirection` must have been called | |
1669 | previously). Argument *mode* can be one of the following values: | |
1670 | ||
1671 | ========================== ================================================= | |
1672 | wx.FLEX_GROWMODE_NONE Sizer doesn't grow in the non flexible direction. | |
1673 | wx.FLEX_GROWMODE_SPECIFIED Sizer honors growable columns/rows set with | |
1674 | `AddGrowableCol` and `AddGrowableRow`. In this | |
1675 | case equal sizing applies to minimum sizes of | |
1676 | columns or rows (this is the default value). | |
1677 | wx.FLEX_GROWMODE_ALL Sizer equally stretches all columns or rows in | |
1678 | the non flexible direction, whether they are | |
1679 | growable or not in the flexbile direction. | |
1680 | ========================== ================================================= | |
1681 | ||
42e2bbb9 | 1682 | Note that this method does not trigger relayout.", ""); |
7e8f0df9 | 1683 | |
3ea6e0ec RD |
1684 | DocDeclStr( |
1685 | wxFlexSizerGrowMode , GetNonFlexibleGrowMode(), | |
1686 | "Returns the value that specifies how the sizer grows in the | |
1687 | non-flexible direction if there is one. | |
d14a1e28 | 1688 | |
3ea6e0ec | 1689 | :see: `SetNonFlexibleGrowMode`", ""); |
7e8f0df9 | 1690 | |
dd9f7fea RD |
1691 | |
1692 | // Read-only access to the row heights and col widths arrays | |
3ea6e0ec RD |
1693 | DocDeclAStr( |
1694 | const wxArrayInt& , GetRowHeights() const, | |
1695 | "GetRowHeights(self) -> list", | |
1696 | "Returns a list of integers representing the heights of each of the | |
1697 | rows in the sizer.", ""); | |
7e8f0df9 | 1698 | |
3ea6e0ec RD |
1699 | DocDeclAStr( |
1700 | const wxArrayInt& , GetColWidths() const, | |
1701 | "GetColWidths(self) -> list", | |
1702 | "Returns a list of integers representing the widths of each of the | |
1703 | columns in the sizer.", ""); | |
7e8f0df9 | 1704 | |
42e2bbb9 RD |
1705 | |
1706 | %property(ColWidths, GetColWidths, doc="See `GetColWidths`"); | |
1707 | %property(FlexibleDirection, GetFlexibleDirection, SetFlexibleDirection, doc="See `GetFlexibleDirection` and `SetFlexibleDirection`"); | |
1708 | %property(NonFlexibleGrowMode, GetNonFlexibleGrowMode, SetNonFlexibleGrowMode, doc="See `GetNonFlexibleGrowMode` and `SetNonFlexibleGrowMode`"); | |
1709 | %property(RowHeights, GetRowHeights, doc="See `GetRowHeights`"); | |
1710 | ||
d14a1e28 RD |
1711 | }; |
1712 | ||
9283228f RD |
1713 | //--------------------------------------------------------------------------- |
1714 | ||
1715 | DocStr(wxStdDialogButtonSizer, | |
1716 | "A special sizer that knows how to order and position standard buttons | |
1717 | in order to conform to the current platform's standards. You simply | |
1718 | need to add each `wx.Button` to the sizer, and be sure to create the | |
718903fe | 1719 | buttons using the standard ID's. Then call `Realize` and the sizer |
9283228f RD |
1720 | will take care of the rest. |
1721 | ", ""); | |
1722 | ||
1723 | class wxStdDialogButtonSizer: public wxBoxSizer | |
1724 | { | |
1725 | public: | |
1726 | DocCtorStr( | |
1727 | wxStdDialogButtonSizer(), | |
1728 | "", ""); | |
1729 | ||
1730 | DocDeclStr( | |
1731 | void , AddButton(wxButton *button), | |
1732 | "Use this to add the buttons to this sizer. Do not use the `Add` | |
1733 | method in the base class.", ""); | |
7e8f0df9 | 1734 | |
9283228f | 1735 | DocDeclStr( |
718903fe | 1736 | void , Realize(), |
9283228f RD |
1737 | "This funciton needs to be called after all the buttons have been added |
1738 | to the sizer. It will reorder them and position them in a platform | |
1739 | specifc manner.", ""); | |
3ba93175 RD |
1740 | |
1741 | void SetAffirmativeButton( wxButton *button ); | |
1742 | void SetNegativeButton( wxButton *button ); | |
1743 | void SetCancelButton( wxButton *button ); | |
7e8f0df9 | 1744 | |
9283228f RD |
1745 | wxButton* GetAffirmativeButton() const; |
1746 | wxButton* GetApplyButton() const; | |
1747 | wxButton* GetNegativeButton() const; | |
1748 | wxButton* GetCancelButton() const; | |
1749 | wxButton* GetHelpButton() const; | |
7012bb9f RD |
1750 | |
1751 | %property(AffirmativeButton, GetAffirmativeButton, SetAffirmativeButton, doc="See `GetAffirmativeButton` and `SetAffirmativeButton`"); | |
1752 | %property(ApplyButton, GetApplyButton, doc="See `GetApplyButton`"); | |
1753 | %property(CancelButton, GetCancelButton, SetCancelButton, doc="See `GetCancelButton` and `SetCancelButton`"); | |
1754 | %property(HelpButton, GetHelpButton, doc="See `GetHelpButton`"); | |
1755 | %property(NegativeButton, GetNegativeButton, SetNegativeButton, doc="See `GetNegativeButton` and `SetNegativeButton`"); | |
9283228f RD |
1756 | }; |
1757 | ||
1758 | ||
d14a1e28 | 1759 | //--------------------------------------------------------------------------- |