]>
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 | ||
3ea6e0ec RD |
24 | DocStr(wxSizerItem, |
25 | "The wx.SizerItem class is used to track the position, size and other | |
26 | attributes of each item managed by a `wx.Sizer`. In normal usage user | |
27 | code should never need to deal directly with a wx.SizerItem, but | |
28 | custom classes derived from `wx.PySizer` will probably need to use the | |
29 | collection of wx.SizerItems held by wx.Sizer when calculating layout. | |
30 | ||
31 | :see: `wx.Sizer`, `wx.GBSizerItem`", ""); | |
d14a1e28 RD |
32 | |
33 | class wxSizerItem : public wxObject { | |
34 | public: | |
3ea6e0ec RD |
35 | DocCtorStr( |
36 | wxSizerItem(), | |
37 | "Constructs an empty wx.SizerItem. Either a window, sizer or spacer | |
38 | size will need to be set before this item can be used in a Sizer. | |
39 | ||
40 | You will probably never need to create a wx.SizerItem directly as they | |
41 | are created automatically when the sizer's Add, Insert or Prepend | |
42 | methods are called. | |
43 | ||
44 | :see: `wx.SizerItemSpacer`, `wx.SizerItemWindow`, `wx.SizerItemSizer`", ""); | |
45 | ||
46 | ||
7e8f0df9 | 47 | |
3ea6e0ec RD |
48 | %extend { |
49 | DocStr( | |
50 | wxSizerItem( wxWindow *window, int proportion, int flag, | |
51 | int border, PyObject* userData=NULL ), | |
7e8f0df9 RD |
52 | "Constructs a `wx.SizerItem` for tracking a window.", ""); |
53 | ||
1b8c7ba6 RD |
54 | %RenameCtor(SizerItemWindow, wxSizerItem( wxWindow *window, int proportion, int flag, |
55 | int border, PyObject* userData=NULL )) | |
56 | { | |
3ea6e0ec RD |
57 | wxPyUserData* data = NULL; |
58 | if ( userData ) { | |
6e6b3557 | 59 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); |
3ea6e0ec RD |
60 | data = new wxPyUserData(userData); |
61 | wxPyEndBlockThreads(blocked); | |
62 | } | |
63 | return new wxSizerItem(window, proportion, flag, border, data); | |
64 | } | |
65 | ||
7e8f0df9 | 66 | |
3ea6e0ec RD |
67 | DocStr( |
68 | wxSizerItem( int width, int height, int proportion, int flag, | |
69 | int border, PyObject* userData=NULL), | |
70 | "Constructs a `wx.SizerItem` for tracking a spacer.", ""); | |
7e8f0df9 | 71 | |
1b8c7ba6 RD |
72 | %RenameCtor(SizerItemSpacer, wxSizerItem( int width, int height, int proportion, int flag, |
73 | int border, PyObject* userData=NULL)) | |
74 | { | |
3ea6e0ec RD |
75 | wxPyUserData* data = NULL; |
76 | if ( userData ) { | |
6e6b3557 | 77 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); |
3ea6e0ec RD |
78 | data = new wxPyUserData(userData); |
79 | wxPyEndBlockThreads(blocked); | |
80 | } | |
81 | return new wxSizerItem(width, height, proportion, flag, border, data); | |
82 | } | |
7e8f0df9 | 83 | |
3ea6e0ec RD |
84 | DocStr( |
85 | wxSizerItem( wxSizer *sizer, int proportion, int flag, | |
86 | int border, PyObject* userData=NULL ), | |
1b8c7ba6 | 87 | "Constructs a `wx.SizerItem` for tracking a subsizer", ""); |
7e8f0df9 | 88 | |
1b8c7ba6 RD |
89 | %RenameCtor(SizerItemSizer, wxSizerItem( wxSizer *sizer, int proportion, int flag, |
90 | int border, PyObject* userData=NULL )) | |
91 | { | |
3ea6e0ec RD |
92 | wxPyUserData* data = NULL; |
93 | if ( userData ) { | |
6e6b3557 | 94 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); |
3ea6e0ec RD |
95 | data = new wxPyUserData(userData); |
96 | wxPyEndBlockThreads(blocked); | |
97 | } | |
98 | return new wxSizerItem(sizer, proportion, flag, border, data); | |
99 | } | |
100 | } | |
d14a1e28 | 101 | |
d14a1e28 | 102 | |
7e8f0df9 | 103 | |
3ea6e0ec RD |
104 | DocDeclStr( |
105 | void , DeleteWindows(), | |
106 | "Destroy the window or the windows in a subsizer, depending on the type | |
107 | of item.", ""); | |
7e8f0df9 | 108 | |
3ea6e0ec RD |
109 | DocDeclStr( |
110 | void , DetachSizer(), | |
111 | "Enable deleting the SizerItem without destroying the contained sizer.", ""); | |
7e8f0df9 | 112 | |
d14a1e28 | 113 | |
3ea6e0ec RD |
114 | DocDeclStr( |
115 | wxSize , GetSize(), | |
116 | "Get the current size of the item, as set in the last Layout.", ""); | |
7e8f0df9 | 117 | |
3ea6e0ec RD |
118 | DocDeclStr( |
119 | wxSize , CalcMin(), | |
120 | "Calculates the minimum desired size for the item, including any space | |
121 | needed by borders.", ""); | |
7e8f0df9 | 122 | |
3ea6e0ec RD |
123 | DocDeclStr( |
124 | void , SetDimension( wxPoint pos, wxSize size ), | |
125 | "Set the position and size of the space allocated for this item by the | |
126 | sizer, and adjust the position and size of the item (window or | |
127 | subsizer) to be within that space taking alignment and borders into | |
128 | account.", ""); | |
7e8f0df9 | 129 | |
3ea6e0ec RD |
130 | |
131 | DocDeclStr( | |
132 | wxSize , GetMinSize(), | |
133 | "Get the minimum size needed for the item.", ""); | |
7e8f0df9 | 134 | |
329b045c RD |
135 | DocDeclStr( |
136 | wxSize , GetMinSizeWithBorder() const, | |
137 | "Get the minimum size needed for the item with space for the borders | |
138 | added, if needed.", ""); | |
139 | ||
3ea6e0ec RD |
140 | DocDeclStr( |
141 | void , SetInitSize( int x, int y ), | |
142 | "", ""); | |
7e8f0df9 | 143 | |
d14a1e28 | 144 | |
3ea6e0ec RD |
145 | DocStr(SetRatio, |
146 | "Set the ratio item attribute.", ""); | |
1b8c7ba6 | 147 | %Rename(SetRatioWH, void, SetRatio( int width, int height )); |
f1e759d7 | 148 | %Rename(SetRatioSize, void, SetRatio( const wxSize& size )); |
d14a1e28 | 149 | void SetRatio( float ratio ); |
7e8f0df9 | 150 | |
3ea6e0ec RD |
151 | DocDeclStr( |
152 | float , GetRatio(), | |
153 | "Set the ratio item attribute.", ""); | |
7aada1e0 RD |
154 | |
155 | DocDeclStr( | |
156 | wxRect , GetRect(), | |
157 | "Returns the rectangle that the sizer item should occupy", ""); | |
7e8f0df9 | 158 | |
d14a1e28 | 159 | |
3ea6e0ec RD |
160 | DocDeclStr( |
161 | bool , IsWindow(), | |
162 | "Is this sizer item a window?", ""); | |
7e8f0df9 | 163 | |
3ea6e0ec RD |
164 | DocDeclStr( |
165 | bool , IsSizer(), | |
166 | "Is this sizer item a subsizer?", ""); | |
7e8f0df9 | 167 | |
3ea6e0ec RD |
168 | DocDeclStr( |
169 | bool , IsSpacer(), | |
170 | "Is this sizer item a spacer?", ""); | |
7e8f0df9 | 171 | |
d14a1e28 | 172 | |
3ea6e0ec RD |
173 | DocDeclStr( |
174 | void , SetProportion( int proportion ), | |
175 | "Set the proportion value for this item.", ""); | |
7e8f0df9 | 176 | |
3ea6e0ec RD |
177 | DocDeclStr( |
178 | int , GetProportion(), | |
179 | "Get the proportion value for this item.", ""); | |
7e8f0df9 | 180 | |
3ea6e0ec RD |
181 | %pythoncode { SetOption = wx._deprecated(SetProportion, "Please use `SetProportion` instead.") } |
182 | %pythoncode { GetOption = wx._deprecated(GetProportion, "Please use `GetProportion` instead.") } | |
d14a1e28 | 183 | |
7e8f0df9 | 184 | |
3ea6e0ec RD |
185 | DocDeclStr( |
186 | void , SetFlag( int flag ), | |
187 | "Set the flag value for this item.", ""); | |
7e8f0df9 | 188 | |
3ea6e0ec RD |
189 | DocDeclStr( |
190 | int , GetFlag(), | |
191 | "Get the flag value for this item.", ""); | |
7e8f0df9 RD |
192 | |
193 | ||
3ea6e0ec RD |
194 | DocDeclStr( |
195 | void , SetBorder( int border ), | |
196 | "Set the border value for this item.", ""); | |
7e8f0df9 | 197 | |
3ea6e0ec RD |
198 | DocDeclStr( |
199 | int , GetBorder(), | |
200 | "Get the border value for this item.", ""); | |
d14a1e28 | 201 | |
7e8f0df9 RD |
202 | |
203 | ||
3ea6e0ec RD |
204 | DocDeclStr( |
205 | wxWindow *, GetWindow(), | |
206 | "Get the window (if any) that is managed by this sizer item.", ""); | |
7e8f0df9 | 207 | |
3ea6e0ec RD |
208 | DocDeclStr( |
209 | void , SetWindow( wxWindow *window ), | |
210 | "Set the window to be managed by this sizer item.", ""); | |
7e8f0df9 RD |
211 | |
212 | ||
3ea6e0ec RD |
213 | DocDeclStr( |
214 | wxSizer *, GetSizer(), | |
215 | "Get the subsizer (if any) that is managed by this sizer item.", ""); | |
7e8f0df9 | 216 | |
3ea6e0ec RD |
217 | DocDeclStr( |
218 | void , SetSizer( wxSizer *sizer ), | |
219 | "Set the subsizer to be managed by this sizer item.", ""); | |
7e8f0df9 RD |
220 | |
221 | ||
3ea6e0ec RD |
222 | DocDeclStr( |
223 | const wxSize& , GetSpacer(), | |
224 | "Get the size of the spacer managed by this sizer item.", ""); | |
7e8f0df9 | 225 | |
3ea6e0ec RD |
226 | DocDeclStr( |
227 | void , SetSpacer( const wxSize &size ), | |
228 | "Set the size of the spacer to be managed by this sizer item.", ""); | |
7e8f0df9 | 229 | |
d14a1e28 | 230 | |
3ea6e0ec RD |
231 | DocDeclStr( |
232 | void , Show( bool show ), | |
233 | "Set the show item attribute, which sizers use to determine if the item | |
234 | is to be made part of the layout or not. If the item is tracking a | |
235 | window then it is shown or hidden as needed.", ""); | |
7e8f0df9 | 236 | |
3ea6e0ec RD |
237 | DocDeclStr( |
238 | bool , IsShown(), | |
239 | "Is the item to be shown in the layout?", ""); | |
7e8f0df9 | 240 | |
3ea6e0ec RD |
241 | |
242 | DocDeclStr( | |
243 | wxPoint , GetPosition(), | |
244 | "Returns the current position of the item, as set in the last Layout.", ""); | |
7e8f0df9 | 245 | |
d14a1e28 RD |
246 | |
247 | // wxObject* GetUserData(); | |
248 | %extend { | |
249 | // Assume that the user data is a wxPyUserData object and return the contents | |
3ea6e0ec RD |
250 | |
251 | DocStr(GetUserData, | |
252 | "Returns the userData associated with this sizer item, or None if there | |
253 | isn't any.", ""); | |
d14a1e28 RD |
254 | PyObject* GetUserData() { |
255 | wxPyUserData* data = (wxPyUserData*)self->GetUserData(); | |
256 | if (data) { | |
257 | Py_INCREF(data->m_obj); | |
258 | return data->m_obj; | |
259 | } else { | |
260 | Py_INCREF(Py_None); | |
261 | return Py_None; | |
262 | } | |
263 | } | |
095315e2 RD |
264 | |
265 | DocStr(SetUserData, | |
266 | "Associate a Python object with this sizer item.", ""); | |
267 | void SetUserData(PyObject* userData) { | |
268 | wxPyUserData* data = NULL; | |
269 | if ( userData ) { | |
270 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); | |
271 | data = new wxPyUserData(userData); | |
272 | wxPyEndBlockThreads(blocked); | |
273 | } | |
274 | self->SetUserData(data); | |
275 | } | |
d14a1e28 RD |
276 | } |
277 | }; | |
278 | ||
279 | ||
280 | //--------------------------------------------------------------------------- | |
281 | ||
282 | %{ | |
283 | // Figure out the type of the sizer item | |
284 | ||
285 | struct wxPySizerItemInfo { | |
286 | wxPySizerItemInfo() | |
a72f4631 RD |
287 | : window(NULL), sizer(NULL), gotSize(false), |
288 | size(wxDefaultSize), gotPos(false), pos(-1) | |
d14a1e28 | 289 | {} |
7e8f0df9 | 290 | |
d14a1e28 RD |
291 | wxWindow* window; |
292 | wxSizer* sizer; | |
293 | bool gotSize; | |
294 | wxSize size; | |
295 | bool gotPos; | |
296 | int pos; | |
297 | }; | |
7e8f0df9 | 298 | |
d14a1e28 RD |
299 | static wxPySizerItemInfo wxPySizerItemTypeHelper(PyObject* item, bool checkSize, bool checkIdx ) { |
300 | ||
301 | wxPySizerItemInfo info; | |
302 | wxSize size; | |
303 | wxSize* sizePtr = &size; | |
304 | ||
305 | // Find out what the type of the item is | |
306 | // try wxWindow | |
307 | if ( ! wxPyConvertSwigPtr(item, (void**)&info.window, wxT("wxWindow")) ) { | |
308 | PyErr_Clear(); | |
309 | info.window = NULL; | |
7e8f0df9 | 310 | |
d14a1e28 RD |
311 | // try wxSizer |
312 | if ( ! wxPyConvertSwigPtr(item, (void**)&info.sizer, wxT("wxSizer")) ) { | |
313 | PyErr_Clear(); | |
314 | info.sizer = NULL; | |
7e8f0df9 | 315 | |
d14a1e28 RD |
316 | // try wxSize or (w,h) |
317 | if ( checkSize && wxSize_helper(item, &sizePtr)) { | |
318 | info.size = *sizePtr; | |
a72f4631 | 319 | info.gotSize = true; |
d14a1e28 RD |
320 | } |
321 | ||
322 | // or a single int | |
323 | if (checkIdx && PyInt_Check(item)) { | |
324 | info.pos = PyInt_AsLong(item); | |
a72f4631 | 325 | info.gotPos = true; |
d14a1e28 RD |
326 | } |
327 | } | |
328 | } | |
329 | ||
330 | if ( !(info.window || info.sizer || (checkSize && info.gotSize) || (checkIdx && info.gotPos)) ) { | |
331 | // no expected type, figure out what kind of error message to generate | |
332 | if ( !checkSize && !checkIdx ) | |
02b800ce | 333 | PyErr_SetString(PyExc_TypeError, "wx.Window or wx.Sizer expected for item"); |
d14a1e28 | 334 | else if ( checkSize && !checkIdx ) |
02b800ce | 335 | PyErr_SetString(PyExc_TypeError, "wx.Window, wx.Sizer, wx.Size, or (w,h) expected for item"); |
d14a1e28 | 336 | else if ( !checkSize && checkIdx) |
02b800ce | 337 | PyErr_SetString(PyExc_TypeError, "wx.Window, wx.Sizer or int (position) expected for item"); |
d14a1e28 RD |
338 | else |
339 | // can this one happen? | |
02b800ce | 340 | PyErr_SetString(PyExc_TypeError, "wx.Window, wx.Sizer, wx.Size, or (w,h) or int (position) expected for item"); |
d14a1e28 RD |
341 | } |
342 | ||
343 | return info; | |
344 | } | |
345 | %} | |
346 | ||
347 | ||
348 | ||
349 | ||
3ea6e0ec RD |
350 | DocStr(wxSizer, |
351 | "wx.Sizer is the abstract base class used for laying out subwindows in | |
352 | a window. You cannot use wx.Sizer directly; instead, you will have to | |
353 | use one of the sizer classes derived from it such as `wx.BoxSizer`, | |
354 | `wx.StaticBoxSizer`, `wx.NotebookSizer`, `wx.GridSizer`, `wx.FlexGridSizer` | |
355 | and `wx.GridBagSizer`. | |
356 | ||
357 | The concept implemented by sizers in wxWidgets is closely related to | |
358 | layout tools in other GUI toolkits, such as Java's AWT, the GTK | |
359 | toolkit or the Qt toolkit. It is based upon the idea of the individual | |
360 | subwindows reporting their minimal required size and their ability to | |
361 | get stretched if the size of the parent window has changed. This will | |
362 | most often mean that the programmer does not set the original size of | |
363 | a dialog in the beginning, rather the dialog will assigned a sizer and | |
364 | this sizer will be queried about the recommended size. The sizer in | |
365 | turn will query its children, which can be normal windows or contorls, | |
366 | empty space or other sizers, so that a hierarchy of sizers can be | |
367 | constructed. Note that wxSizer does not derive from wxWindow and thus | |
368 | do not interfere with tab ordering and requires very little resources | |
369 | compared to a real window on screen. | |
370 | ||
371 | What makes sizers so well fitted for use in wxWidgets is the fact that | |
372 | every control reports its own minimal size and the algorithm can | |
373 | handle differences in font sizes or different window (dialog item) | |
374 | sizes on different platforms without problems. If for example the | |
375 | standard font as well as the overall design of Mac widgets requires | |
376 | more space than on Windows, then the initial size of a dialog using a | |
377 | sizer will automatically be bigger on Mac than on Windows.", " | |
378 | ||
38260cce RD |
379 | Sizers may also be used to control the layout of custom drawn items on |
380 | the window. The `Add`, `Insert`, and `Prepend` functions return a | |
381 | pointer to the newly added `wx.SizerItem`. Just add empty space of the | |
382 | desired size and attributes, and then use the `wx.SizerItem.GetRect` | |
383 | method to determine where the drawing operations should take place. | |
384 | ||
3ea6e0ec RD |
385 | :note: If you wish to create a custom sizer class in wxPython you |
386 | should derive the class from `wx.PySizer` in order to get | |
387 | Python-aware capabilities for the various virtual methods. | |
388 | ||
389 | :see: `wx.SizerItem` | |
390 | ||
391 | :todo: More dscriptive text here along with some pictures... | |
392 | ||
393 | "); | |
394 | ||
d14a1e28 RD |
395 | class wxSizer : public wxObject { |
396 | public: | |
397 | // wxSizer(); **** abstract, can't instantiate | |
398 | // ~wxSizer(); | |
399 | ||
400 | %extend { | |
401 | void _setOORInfo(PyObject* _self) { | |
a77bf68f RD |
402 | if (!self->GetClientObject()) |
403 | self->SetClientObject(new wxPyOORClientData(_self)); | |
d14a1e28 RD |
404 | } |
405 | ||
3ea6e0ec RD |
406 | DocAStr(Add, |
407 | "Add(self, item, int proportion=0, int flag=0, int border=0, | |
7aada1e0 | 408 | PyObject userData=None) -> wx.SizerItem", |
3ea6e0ec RD |
409 | |
410 | "Appends a child item to the sizer.", " | |
411 | ||
412 | :param item: The item can be one of three kinds of objects: | |
413 | ||
414 | - **window**: A `wx.Window` to be managed by the sizer. Its | |
415 | minimal size (either set explicitly by the user or | |
416 | calculated internally when constructed with wx.DefaultSize) | |
417 | is interpreted as the minimal size to use when laying out | |
418 | item in the sizer. This is particularly useful in | |
419 | connection with `wx.Window.SetSizeHints`. | |
420 | ||
421 | - **sizer**: The (child-)sizer to be added to the sizer. This | |
422 | allows placing a child sizer in a sizer and thus to create | |
423 | hierarchies of sizers (typically a vertical box as the top | |
424 | sizer and several horizontal boxes on the level beneath). | |
425 | ||
426 | - **size**: A `wx.Size` or a 2-element sequence of integers | |
427 | that represents the width and height of a spacer to be added | |
428 | to the sizer. Adding spacers to sizers gives more | |
429 | flexibility in the design of dialogs; imagine for example a | |
430 | horizontal box with two buttons at the bottom of a dialog: | |
431 | you might want to insert a space between the two buttons and | |
432 | make that space stretchable using the *proportion* value and | |
433 | the result will be that the left button will be aligned with | |
434 | the left side of the dialog and the right button with the | |
435 | right side - the space in between will shrink and grow with | |
436 | the dialog. | |
437 | ||
438 | :param proportion: Although the meaning of this parameter is | |
439 | undefined in wx.Sizer, it is used in `wx.BoxSizer` to indicate | |
440 | if a child of a sizer can change its size in the main | |
441 | orientation of the wx.BoxSizer - where 0 stands for not | |
442 | changeable and a value of more than zero is interpreted | |
443 | relative (a proportion of the total) to the value of other | |
444 | children of the same wx.BoxSizer. For example, you might have | |
445 | a horizontal wx.BoxSizer with three children, two of which are | |
446 | supposed to change their size with the sizer. Then the two | |
447 | stretchable windows should each be given *proportion* value of | |
448 | 1 to make them grow and shrink equally with the sizer's | |
449 | horizontal dimension. But if one of them had a *proportion* | |
450 | value of 2 then it would get a double share of the space | |
451 | available after the fixed size items are positioned. | |
452 | ||
453 | :param flag: This parameter can be used to set a number of flags | |
454 | which can be combined using the binary OR operator ``|``. Two | |
455 | main behaviours are defined using these flags. One is the | |
456 | border around a window: the *border* parameter determines the | |
457 | border width whereas the flags given here determine which | |
458 | side(s) of the item that the border will be added. The other | |
459 | flags determine how the sizer item behaves when the space | |
460 | allotted to the sizer changes, and is somewhat dependent on | |
461 | the specific kind of sizer used. | |
462 | ||
463 | +----------------------------+------------------------------------------+ | |
464 | |- wx.TOP |These flags are used to specify | | |
465 | |- wx.BOTTOM |which side(s) of the sizer item that | | |
466 | |- wx.LEFT |the *border* width will apply to. | | |
467 | |- wx.RIGHT | | | |
468 | |- wx.ALL | | | |
469 | | | | | |
470 | +----------------------------+------------------------------------------+ | |
8b5895b0 | 471 | |- wx.EXPAND |The item will be expanded to fill | |
3ea6e0ec RD |
472 | | |the space allotted to the item. | |
473 | +----------------------------+------------------------------------------+ | |
474 | |- wx.SHAPED |The item will be expanded as much as | | |
475 | | |possible while also maintaining its | | |
476 | | |aspect ratio | | |
477 | +----------------------------+------------------------------------------+ | |
478 | |- wx.FIXED_MINSIZE |Normally wx.Sizers will use | | |
479 | | |`wx.Window.GetMinSize` or | | |
480 | | |`wx.Window.GetBestSize` to determine what | | |
481 | | |the minimal size of window items should | | |
482 | | |be, and will use that size to calculate | | |
483 | | |the layout. This allows layouts to adjust | | |
484 | | |when an item changes and it's best size | | |
485 | | |becomes different. If you would rather | | |
486 | | |have a window item stay the size it | | |
487 | | |started with then use wx.FIXED_MINSIZE. | | |
488 | +----------------------------+------------------------------------------+ | |
489 | |- wx.ALIGN_CENTER |The wx.ALIGN flags allow you to specify | | |
490 | |- wx.ALIGN_LEFT |the alignment of the item within the space| | |
491 | |- wx.ALIGN_RIGHT |allotted to it by the sizer, ajusted for | | |
492 | |- wx.ALIGN_TOP |the border if any. | | |
493 | |- wx.ALIGN_BOTTOM | | | |
494 | |- wx.ALIGN_CENTER_VERTICAL | | | |
495 | |- wx.ALIGN_CENTER_HORIZONTAL| | | |
496 | +----------------------------+------------------------------------------+ | |
497 | ||
498 | ||
499 | :param border: Determines the border width, if the *flag* | |
500 | parameter is set to include any border flag. | |
501 | ||
502 | :param userData: Allows an extra object to be attached to the | |
503 | sizer item, for use in derived classes when sizing information | |
504 | is more complex than the *proportion* and *flag* will allow for. | |
505 | "); | |
d14a1e28 | 506 | |
7aada1e0 RD |
507 | wxSizerItem* Add(PyObject* item, int proportion=0, int flag=0, int border=0, |
508 | PyObject* userData=NULL) { | |
7e8f0df9 | 509 | |
d14a1e28 | 510 | wxPyUserData* data = NULL; |
6e6b3557 | 511 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); |
a72f4631 | 512 | wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, true, false); |
d14a1e28 RD |
513 | if ( userData && (info.window || info.sizer || info.gotSize) ) |
514 | data = new wxPyUserData(userData); | |
da32eb53 | 515 | wxPyEndBlockThreads(blocked); |
7e8f0df9 | 516 | |
d14a1e28 RD |
517 | // Now call the real Add method if a valid item type was found |
518 | if ( info.window ) | |
7aada1e0 | 519 | return self->Add(info.window, proportion, flag, border, data); |
d14a1e28 | 520 | else if ( info.sizer ) |
7aada1e0 | 521 | return self->Add(info.sizer, proportion, flag, border, data); |
d14a1e28 | 522 | else if (info.gotSize) |
7aada1e0 RD |
523 | return self->Add(info.size.GetWidth(), info.size.GetHeight(), |
524 | proportion, flag, border, data); | |
525 | else | |
526 | return NULL; | |
d14a1e28 RD |
527 | } |
528 | ||
7aada1e0 RD |
529 | // virtual wxSizerItem* AddSpacer(int size); |
530 | // virtual wxSizerItem* AddStretchSpacer(int prop = 1); | |
d14a1e28 | 531 | |
3ea6e0ec RD |
532 | DocAStr(Insert, |
533 | "Insert(self, int before, item, int proportion=0, int flag=0, int border=0, | |
7aada1e0 | 534 | PyObject userData=None) -> wx.SizerItem", |
3ea6e0ec RD |
535 | |
536 | "Inserts a new item into the list of items managed by this sizer before | |
537 | the item at index *before*. See `Add` for a description of the parameters.", ""); | |
7aada1e0 RD |
538 | wxSizerItem* Insert(int before, PyObject* item, int proportion=0, int flag=0, |
539 | int border=0, PyObject* userData=NULL) { | |
d14a1e28 RD |
540 | |
541 | wxPyUserData* data = NULL; | |
6e6b3557 | 542 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); |
a72f4631 | 543 | wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, true, false); |
d14a1e28 RD |
544 | if ( userData && (info.window || info.sizer || info.gotSize) ) |
545 | data = new wxPyUserData(userData); | |
da32eb53 | 546 | wxPyEndBlockThreads(blocked); |
7e8f0df9 | 547 | |
d14a1e28 RD |
548 | // Now call the real Insert method if a valid item type was found |
549 | if ( info.window ) | |
7aada1e0 | 550 | return self->Insert(before, info.window, proportion, flag, border, data); |
d14a1e28 | 551 | else if ( info.sizer ) |
7aada1e0 | 552 | return self->Insert(before, info.sizer, proportion, flag, border, data); |
d14a1e28 | 553 | else if (info.gotSize) |
7aada1e0 RD |
554 | return self->Insert(before, info.size.GetWidth(), info.size.GetHeight(), |
555 | proportion, flag, border, data); | |
556 | else | |
557 | return NULL; | |
d14a1e28 RD |
558 | } |
559 | ||
560 | ||
7aada1e0 RD |
561 | // virtual wxSizerItem* InsertSpacer(size_t index, int size); |
562 | // virtual wxSizerItem* InsertStretchSpacer(size_t index, int prop = 1); | |
7e8f0df9 | 563 | |
3ea6e0ec RD |
564 | DocAStr(Prepend, |
565 | "Prepend(self, item, int proportion=0, int flag=0, int border=0, | |
7aada1e0 | 566 | PyObject userData=None) -> wx.SizerItem", |
d14a1e28 | 567 | |
3ea6e0ec RD |
568 | "Adds a new item to the begining of the list of sizer items managed by |
569 | this sizer. See `Add` for a description of the parameters.", ""); | |
7aada1e0 RD |
570 | wxSizerItem* Prepend(PyObject* item, int proportion=0, int flag=0, int border=0, |
571 | PyObject* userData=NULL) { | |
d14a1e28 RD |
572 | |
573 | wxPyUserData* data = NULL; | |
6e6b3557 | 574 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); |
a72f4631 | 575 | wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, true, false); |
d14a1e28 RD |
576 | if ( userData && (info.window || info.sizer || info.gotSize) ) |
577 | data = new wxPyUserData(userData); | |
da32eb53 | 578 | wxPyEndBlockThreads(blocked); |
7e8f0df9 | 579 | |
d14a1e28 RD |
580 | // Now call the real Prepend method if a valid item type was found |
581 | if ( info.window ) | |
7aada1e0 | 582 | return self->Prepend(info.window, proportion, flag, border, data); |
d14a1e28 | 583 | else if ( info.sizer ) |
7aada1e0 | 584 | return self->Prepend(info.sizer, proportion, flag, border, data); |
d14a1e28 | 585 | else if (info.gotSize) |
7aada1e0 RD |
586 | return self->Prepend(info.size.GetWidth(), info.size.GetHeight(), |
587 | proportion, flag, border, data); | |
588 | else | |
589 | return NULL; | |
d14a1e28 RD |
590 | } |
591 | ||
7aada1e0 RD |
592 | // virtual wxSizerItem* PrependSpacer(int size); |
593 | // virtual wxSizerItem* PrependStretchSpacer(int prop = 1); | |
3ea6e0ec RD |
594 | |
595 | DocAStr(Remove, | |
596 | "Remove(self, item) -> bool", | |
597 | "Removes an item from the sizer and destroys it. This method does not | |
598 | cause any layout or resizing to take place, call `Layout` to update | |
599 | the layout on screen after removing a child from the sizer. The | |
600 | *item* parameter can be either a window, a sizer, or the zero-based | |
601 | index of an item to remove. Returns True if the child item was found | |
602 | and removed.", " | |
603 | ||
604 | :note: For historical reasons calling this method with a `wx.Window` | |
605 | parameter is depreacted, as it will not be able to destroy the | |
606 | window since it is owned by its parent. You should use `Detach` | |
607 | instead. | |
608 | "); | |
d14a1e28 | 609 | bool Remove(PyObject* item) { |
6e6b3557 | 610 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); |
a72f4631 | 611 | wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, false, true); |
da32eb53 | 612 | wxPyEndBlockThreads(blocked); |
d14a1e28 RD |
613 | if ( info.window ) |
614 | return self->Remove(info.window); | |
615 | else if ( info.sizer ) | |
616 | return self->Remove(info.sizer); | |
617 | else if ( info.gotPos ) | |
618 | return self->Remove(info.pos); | |
7e8f0df9 | 619 | else |
a72f4631 | 620 | return false; |
d14a1e28 RD |
621 | } |
622 | ||
3ea6e0ec RD |
623 | |
624 | DocAStr(Detach, | |
625 | "Detach(self, item) -> bool", | |
626 | "Detaches an item from the sizer without destroying it. This method | |
627 | does not cause any layout or resizing to take place, call `Layout` to | |
628 | do so. The *item* parameter can be either a window, a sizer, or the | |
629 | zero-based index of the item to be detached. Returns True if the child item | |
630 | was found and detached.", ""); | |
60a71c29 | 631 | bool Detach(PyObject* item) { |
6e6b3557 | 632 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); |
a72f4631 | 633 | wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, false, true); |
60a71c29 RD |
634 | wxPyEndBlockThreads(blocked); |
635 | if ( info.window ) | |
636 | return self->Detach(info.window); | |
637 | else if ( info.sizer ) | |
638 | return self->Detach(info.sizer); | |
639 | else if ( info.gotPos ) | |
640 | return self->Detach(info.pos); | |
7e8f0df9 | 641 | else |
a72f4631 | 642 | return false; |
60a71c29 RD |
643 | } |
644 | ||
7e8f0df9 | 645 | |
7aada1e0 RD |
646 | DocAStr(GetItem, |
647 | "GetItem(self, item) -> wx.SizerItem", | |
648 | "Returns the `wx.SizerItem` which holds the *item* given. The *item* | |
649 | parameter can be either a window, a sizer, or the zero-based index of | |
aae5d34f | 650 | the item to be found.", ""); |
7aada1e0 | 651 | wxSizerItem* GetItem(PyObject* item) { |
6e6b3557 | 652 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); |
7aada1e0 RD |
653 | wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, false, true); |
654 | wxPyEndBlockThreads(blocked); | |
655 | if ( info.window ) | |
656 | return self->GetItem(info.window); | |
657 | else if ( info.sizer ) | |
658 | return self->GetItem(info.sizer); | |
659 | else if ( info.gotPos ) | |
660 | return self->GetItem(info.pos); | |
661 | else | |
662 | return NULL; | |
663 | } | |
664 | ||
7e8f0df9 | 665 | |
dd9f7fea | 666 | void _SetItemMinSize(PyObject* item, const wxSize& size) { |
6e6b3557 | 667 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); |
a72f4631 | 668 | wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, false, true); |
da32eb53 | 669 | wxPyEndBlockThreads(blocked); |
d14a1e28 RD |
670 | if ( info.window ) |
671 | self->SetItemMinSize(info.window, size); | |
672 | else if ( info.sizer ) | |
673 | self->SetItemMinSize(info.sizer, size); | |
674 | else if ( info.gotPos ) | |
675 | self->SetItemMinSize(info.pos, size); | |
676 | } | |
677 | } | |
678 | ||
3ea6e0ec RD |
679 | %pythoncode { |
680 | def SetItemMinSize(self, item, *args): | |
681 | """ | |
682 | SetItemMinSize(self, item, Size size) | |
683 | ||
684 | Sets the minimum size that will be allocated for an item in the sizer. | |
685 | The *item* parameter can be either a window, a sizer, or the | |
686 | zero-based index of the item. If a window or sizer is given then it | |
687 | will be searched for recursivly in subsizers if neccessary. | |
688 | """ | |
689 | if len(args) == 2: | |
690 | %# for backward compatibility accept separate width,height args too | |
691 | return self._SetItemMinSize(item, args) | |
692 | else: | |
693 | return self._SetItemMinSize(item, args[0]) | |
694 | } | |
7e8f0df9 | 695 | |
3ea6e0ec | 696 | DocDeclAStrName( |
7aada1e0 | 697 | wxSizerItem* , Add( wxSizerItem *item ), |
3ea6e0ec RD |
698 | "AddItem(self, SizerItem item)", |
699 | "Adds a `wx.SizerItem` to the sizer.", "", | |
700 | AddItem); | |
7e8f0df9 | 701 | |
3ea6e0ec | 702 | DocDeclAStrName( |
7aada1e0 | 703 | wxSizerItem* , Insert( size_t index, wxSizerItem *item ), |
3ea6e0ec RD |
704 | "InsertItem(self, int index, SizerItem item)", |
705 | "Inserts a `wx.SizerItem` to the sizer at the position given by *index*.", "", | |
706 | InsertItem); | |
7e8f0df9 | 707 | |
3ea6e0ec | 708 | DocDeclAStrName( |
7aada1e0 | 709 | wxSizerItem* , Prepend( wxSizerItem *item ), |
3ea6e0ec RD |
710 | "PrependItem(self, SizerItem item)", |
711 | "Prepends a `wx.SizerItem` to the sizer.", "", | |
712 | PrependItem); | |
7e8f0df9 | 713 | |
d14a1e28 RD |
714 | |
715 | ||
716 | %pythoncode { | |
3ea6e0ec | 717 | def AddMany(self, items): |
dce2bd22 RD |
718 | """ |
719 | AddMany is a convenience method for adding several items | |
720 | to a sizer at one time. Simply pass it a list of tuples, | |
721 | where each tuple consists of the parameters that you | |
722 | would normally pass to the `Add` method. | |
723 | """ | |
3ea6e0ec RD |
724 | for item in items: |
725 | if type(item) != type(()) or (len(item) == 2 and type(item[0]) == type(1)): | |
726 | item = (item, ) | |
727 | self.Add(*item) | |
d14a1e28 | 728 | |
d147c724 | 729 | %# for backwards compatibility only, please do not use in new code |
7e8f0df9 RD |
730 | def AddWindow(self, *args, **kw): |
731 | """Compatibility alias for `Add`.""" | |
732 | return self.Add(*args, **kw) | |
733 | def AddSizer(self, *args, **kw): | |
734 | """Compatibility alias for `Add`.""" | |
735 | return self.Add(*args, **kw) | |
736 | def AddSpacer(self, *args, **kw): | |
737 | """Compatibility alias for `Add`.""" | |
738 | return self.Add(*args, **kw) | |
739 | ||
740 | def PrependWindow(self, *args, **kw): | |
741 | """Compatibility alias for `Prepend`.""" | |
742 | return self.Prepend(*args, **kw) | |
743 | def PrependSizer(self, *args, **kw): | |
744 | """Compatibility alias for `Prepend`.""" | |
745 | return self.Prepend(*args, **kw) | |
746 | def PrependSpacer(self, *args, **kw): | |
747 | """Compatibility alias for `Prepend`.""" | |
748 | return self.Prepend(*args, **kw) | |
749 | ||
750 | def InsertWindow(self, *args, **kw): | |
751 | """Compatibility alias for `Insert`.""" | |
752 | return self.Insert(*args, **kw) | |
753 | def InsertSizer(self, *args, **kw): | |
754 | """Compatibility alias for `Insert`.""" | |
755 | return self.Insert(*args, **kw) | |
756 | def InsertSpacer(self, *args, **kw): | |
757 | """Compatibility alias for `Insert`.""" | |
758 | return self.Insert(*args, **kw) | |
759 | ||
760 | def RemoveWindow(self, *args, **kw): | |
761 | """Compatibility alias for `Remove`.""" | |
762 | return self.Remove(*args, **kw) | |
763 | def RemoveSizer(self, *args, **kw): | |
764 | """Compatibility alias for `Remove`.""" | |
765 | return self.Remove(*args, **kw) | |
766 | def RemovePos(self, *args, **kw): | |
767 | """Compatibility alias for `Remove`.""" | |
768 | return self.Remove(*args, **kw) | |
d14a1e28 | 769 | |
d14a1e28 RD |
770 | } |
771 | ||
772 | ||
3ea6e0ec RD |
773 | DocDeclStr( |
774 | void , SetDimension( int x, int y, int width, int height ), | |
775 | "Call this to force the sizer to take the given dimension and thus | |
776 | force the items owned by the sizer to resize themselves according to | |
777 | the rules defined by the parameter in the `Add`, `Insert` or `Prepend` | |
778 | methods.", ""); | |
7e8f0df9 | 779 | |
3ea6e0ec RD |
780 | DocDeclStr( |
781 | void , SetMinSize( const wxSize &size ), | |
782 | "Call this to give the sizer a minimal size. Normally, the sizer will | |
783 | calculate its minimal size based purely on how much space its children | |
784 | need. After calling this method `GetMinSize` will return either the | |
785 | minimal size as requested by its children or the minimal size set | |
786 | here, depending on which is bigger.", ""); | |
7e8f0df9 | 787 | |
d14a1e28 | 788 | |
3ea6e0ec RD |
789 | DocDeclStr( |
790 | wxSize , GetSize(), | |
791 | "Returns the current size of the space managed by the sizer.", ""); | |
7e8f0df9 | 792 | |
3ea6e0ec RD |
793 | DocDeclStr( |
794 | wxPoint , GetPosition(), | |
795 | "Returns the current position of the sizer's managed space.", ""); | |
7e8f0df9 | 796 | |
3ea6e0ec RD |
797 | DocDeclStr( |
798 | wxSize , GetMinSize(), | |
799 | "Returns the minimal size of the sizer. This is either the combined | |
800 | minimal size of all the children and their borders or the minimal size | |
801 | set by SetMinSize, depending on which is bigger.", ""); | |
7e8f0df9 | 802 | |
d14a1e28 RD |
803 | |
804 | %pythoncode { | |
805 | def GetSizeTuple(self): | |
60a71c29 | 806 | return self.GetSize().Get() |
d14a1e28 | 807 | def GetPositionTuple(self): |
60a71c29 | 808 | return self.GetPosition().Get() |
d14a1e28 | 809 | def GetMinSizeTuple(self): |
60a71c29 | 810 | return self.GetMinSize().Get() |
d14a1e28 RD |
811 | } |
812 | ||
3ea6e0ec RD |
813 | DocDeclStr( |
814 | virtual void , RecalcSizes(), | |
815 | "Using the sizes calculated by `CalcMin` reposition and resize all the | |
816 | items managed by this sizer. You should not need to call this directly as | |
817 | it is called by `Layout`.", ""); | |
7e8f0df9 | 818 | |
3ea6e0ec RD |
819 | DocDeclStr( |
820 | virtual wxSize , CalcMin(), | |
821 | "This method is where the sizer will do the actual calculation of its | |
822 | children's minimal sizes. You should not need to call this directly as | |
823 | it is called by `Layout`.", ""); | |
7e8f0df9 | 824 | |
3ea6e0ec RD |
825 | |
826 | DocDeclStr( | |
827 | void , Layout(), | |
828 | "This method will force the recalculation and layout of the items | |
829 | controlled by the sizer using the current space allocated to the | |
830 | sizer. Normally this is called automatically from the owning window's | |
831 | EVT_SIZE handler, but it is also useful to call it from user code when | |
832 | one of the items in a sizer change size, or items are added or | |
833 | removed.", ""); | |
7e8f0df9 | 834 | |
d14a1e28 | 835 | |
3ea6e0ec RD |
836 | DocDeclStr( |
837 | wxSize , Fit( wxWindow *window ), | |
838 | "Tell the sizer to resize the *window* to match the sizer's minimal | |
839 | size. This is commonly done in the constructor of the window itself in | |
840 | order to set its initial size to match the needs of the children as | |
841 | determined by the sizer. Returns the new size. | |
d14a1e28 | 842 | |
3ea6e0ec | 843 | For a top level window this is the total window size, not the client size.", ""); |
7e8f0df9 | 844 | |
3ea6e0ec RD |
845 | DocDeclStr( |
846 | void , FitInside( wxWindow *window ), | |
847 | "Tell the sizer to resize the *virtual size* of the *window* to match the | |
848 | sizer's minimal size. This will not alter the on screen size of the | |
849 | window, but may cause the addition/removal/alteration of scrollbars | |
850 | required to view the virtual area in windows which manage it. | |
851 | ||
852 | :see: `wx.ScrolledWindow.SetScrollbars`, `SetVirtualSizeHints` | |
853 | ", ""); | |
7e8f0df9 | 854 | |
d14a1e28 | 855 | |
3ea6e0ec RD |
856 | DocDeclStr( |
857 | void , SetSizeHints( wxWindow *window ), | |
858 | "Tell the sizer to set (and `Fit`) the minimal size of the *window* to | |
859 | match the sizer's minimal size. This is commonly done in the | |
860 | constructor of the window itself if the window is resizable (as are | |
861 | many dialogs under Unix and frames on probably all platforms) in order | |
862 | to prevent the window from being sized smaller than the minimal size | |
863 | required by the sizer.", ""); | |
7e8f0df9 | 864 | |
3ea6e0ec RD |
865 | DocDeclStr( |
866 | void , SetVirtualSizeHints( wxWindow *window ), | |
867 | "Tell the sizer to set the minimal size of the window virtual area to | |
868 | match the sizer's minimal size. For windows with managed scrollbars | |
869 | this will set them appropriately. | |
870 | ||
871 | :see: `wx.ScrolledWindow.SetScrollbars` | |
872 | ", ""); | |
7e8f0df9 | 873 | |
d14a1e28 | 874 | |
3ea6e0ec | 875 | DocDeclStr( |
a72f4631 | 876 | void , Clear( bool deleteWindows=false ), |
3ea6e0ec RD |
877 | "Clear all items from the sizer, optionally destroying the window items |
878 | as well.", ""); | |
7e8f0df9 | 879 | |
3ea6e0ec RD |
880 | DocDeclStr( |
881 | void , DeleteWindows(), | |
882 | "Destroy all windows managed by the sizer.", ""); | |
7e8f0df9 | 883 | |
d14a1e28 RD |
884 | |
885 | ||
886 | // wxList& GetChildren(); | |
887 | %extend { | |
3ea6e0ec | 888 | DocAStr(GetChildren, |
50ed1e35 | 889 | "GetChildren(self) -> list", |
3ea6e0ec | 890 | "Returns a list of all the `wx.SizerItem` objects managed by the sizer.", ""); |
d14a1e28 RD |
891 | PyObject* GetChildren() { |
892 | wxSizerItemList& list = self->GetChildren(); | |
893 | return wxPy_ConvertList(&list); | |
894 | } | |
895 | } | |
896 | ||
897 | ||
3ea6e0ec | 898 | // Manage whether individual windows or subsizers are considered |
d14a1e28 RD |
899 | // in the layout calculations or not. |
900 | ||
901 | %extend { | |
3ea6e0ec | 902 | DocAStr(Show, |
a72f4631 | 903 | "Show(self, item, bool show=True, bool recursive=false) -> bool", |
3ea6e0ec RD |
904 | "Shows or hides an item managed by the sizer. To make a sizer item |
905 | disappear or reappear, use Show followed by `Layout`. The *item* | |
906 | parameter can be either a window, a sizer, or the zero-based index of | |
8f214674 RD |
907 | the item. Use the recursive parameter to show or hide an item in a |
908 | subsizer. Returns True if the item was found.", ""); | |
a72f4631 | 909 | bool Show(PyObject* item, bool show = true, bool recursive=false) { |
6e6b3557 | 910 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); |
a72f4631 | 911 | wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, false, true); |
019fd9d3 | 912 | wxPyEndBlockThreads(blocked); |
d14a1e28 | 913 | if ( info.window ) |
8f214674 | 914 | return self->Show(info.window, show, recursive); |
d14a1e28 | 915 | else if ( info.sizer ) |
8f214674 | 916 | return self->Show(info.sizer, show, recursive); |
3ea6e0ec | 917 | else if ( info.gotPos ) |
8f214674 | 918 | return self->Show(info.pos, show); |
5f476690 RD |
919 | else |
920 | return false; | |
d14a1e28 | 921 | } |
7e8f0df9 | 922 | |
3ea6e0ec RD |
923 | DocAStr(IsShown, |
924 | "IsShown(self, item)", | |
925 | "Determines if the item is currently shown. sizer. To make a sizer | |
926 | item disappear or reappear, use Show followed by `Layout`. The *item* | |
927 | parameter can be either a window, a sizer, or the zero-based index of | |
928 | the item.", ""); | |
d14a1e28 | 929 | bool IsShown(PyObject* item) { |
6e6b3557 | 930 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); |
a72f4631 | 931 | wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, false, false); |
019fd9d3 | 932 | wxPyEndBlockThreads(blocked); |
7e8f0df9 | 933 | if ( info.window ) |
d14a1e28 | 934 | return self->IsShown(info.window); |
7e8f0df9 | 935 | else if ( info.sizer ) |
d14a1e28 | 936 | return self->IsShown(info.sizer); |
3ea6e0ec RD |
937 | else if ( info.gotPos ) |
938 | return self->IsShown(info.pos); | |
d14a1e28 | 939 | else |
a72f4631 | 940 | return false; |
d14a1e28 RD |
941 | } |
942 | } | |
943 | ||
3ea6e0ec | 944 | %pythoncode { |
41b78a7a | 945 | def Hide(self, item, recursive=False): |
3ea6e0ec | 946 | """ |
d5a7caf6 | 947 | A convenience method for `Show` (item, False, recursive). |
3ea6e0ec | 948 | """ |
9dcf02b4 | 949 | return self.Show(item, False, recursive) |
3ea6e0ec | 950 | } |
d14a1e28 | 951 | |
7e8f0df9 | 952 | |
3ea6e0ec RD |
953 | DocDeclStr( |
954 | void , ShowItems(bool show), | |
e2837d11 | 955 | "Recursively call `wx.SizerItem.Show` on all sizer items.", ""); |
7e8f0df9 | 956 | |
f1e759d7 RD |
957 | // TODO: |
958 | // void Show(bool show); | |
959 | // bool IsShown(); | |
960 | ||
d14a1e28 RD |
961 | }; |
962 | ||
963 | ||
964 | //--------------------------------------------------------------------------- | |
965 | // Use this one for deriving Python classes from | |
966 | %{ | |
7e8f0df9 | 967 | // See pyclasses.h |
d14a1e28 RD |
968 | IMP_PYCALLBACK___pure(wxPySizer, wxSizer, RecalcSizes); |
969 | IMP_PYCALLBACK_wxSize__pure(wxPySizer, wxSizer, CalcMin); | |
970 | IMPLEMENT_DYNAMIC_CLASS(wxPySizer, wxSizer); | |
971 | %} | |
972 | ||
973 | ||
3ea6e0ec RD |
974 | DocStr(wxPySizer, |
975 | "wx.PySizer is a special version of `wx.Sizer` that has been | |
976 | instrumented to allow the C++ virtual methods to be overloaded in | |
977 | Python derived classes. You would derive from this class if you are | |
978 | wanting to implement a custom sizer in Python code. Simply implement | |
979 | `CalcMin` and `RecalcSizes` in the derived class and you're all set. | |
980 | For example:: | |
981 | ||
982 | class MySizer(wx.PySizer): | |
983 | def __init__(self): | |
984 | wx.PySizer.__init__(self) | |
985 | ||
986 | def CalcMin(self): | |
987 | for item in self.GetChildren(): | |
988 | # calculate the total minimum width and height needed | |
989 | # by all items in the sizer according to this sizer's | |
990 | # layout algorithm. | |
991 | ... | |
992 | return wx.Size(width, height) | |
993 | ||
994 | def RecalcSizes(self): | |
995 | # find the space allotted to this sizer | |
996 | pos = self.GetPosition() | |
997 | size = self.GetSize() | |
998 | for item in self.GetChildren(): | |
999 | # Recalculate (if necessary) the position and size of | |
1000 | # each item and then call item.SetDimension to do the | |
1001 | # actual positioning and sizing of the items within the | |
1002 | # space alloted to this sizer. | |
1003 | ... | |
1004 | item.SetDimension(itemPos, itemSize) | |
1005 | ||
1006 | ||
1007 | When `Layout` is called it first calls `CalcMin` followed by | |
1008 | `RecalcSizes` so you can optimize a bit by saving the results of | |
9283228f | 1009 | `CalcMin` and reusing them in `RecalcSizes`. |
3ea6e0ec RD |
1010 | |
1011 | :see: `wx.SizerItem`, `wx.Sizer.GetChildren` | |
1012 | ||
1013 | ", ""); | |
d14a1e28 RD |
1014 | class wxPySizer : public wxSizer { |
1015 | public: | |
2b9048c5 | 1016 | %pythonAppend wxPySizer "self._setCallbackInfo(self, PySizer);self._setOORInfo(self)" |
d14a1e28 | 1017 | |
3ea6e0ec RD |
1018 | DocCtorStr( |
1019 | wxPySizer(), | |
1020 | "Creates a wx.PySizer. Must be called from the __init__ in the derived | |
1021 | class.", ""); | |
7e8f0df9 | 1022 | |
d14a1e28 RD |
1023 | void _setCallbackInfo(PyObject* self, PyObject* _class); |
1024 | }; | |
1025 | ||
1026 | ||
1027 | //--------------------------------------------------------------------------- | |
1028 | %newgroup; | |
1029 | ||
3ea6e0ec RD |
1030 | |
1031 | DocStr(wxBoxSizer, | |
1032 | "The basic idea behind a box sizer is that windows will most often be | |
1033 | laid out in rather simple basic geometry, typically in a row or a | |
1034 | column or nested hierarchies of either. A wx.BoxSizer will lay out | |
1035 | its items in a simple row or column, depending on the orientation | |
1036 | parameter passed to the constructor.", " | |
1037 | ||
1038 | It is the unique feature of a box sizer, that it can grow in both | |
1039 | directions (height and width) but can distribute its growth in the | |
1040 | main direction (horizontal for a row) *unevenly* among its children. | |
1041 | This is determined by the proportion parameter give to items when they | |
1042 | are added to the sizer. It is interpreted as a weight factor, i.e. it | |
1043 | can be zero, indicating that the window may not be resized at all, or | |
1044 | above zero. If several windows have a value above zero, the value is | |
1045 | interpreted relative to the sum of all weight factors of the sizer, so | |
1046 | when adding two windows with a value of 1, they will both get resized | |
1047 | equally and each will receive half of the available space after the | |
1048 | fixed size items have been sized. If the items have unequal | |
1049 | proportion settings then they will receive a coresondingly unequal | |
1050 | allotment of the free space. | |
1051 | ||
1052 | :see: `wx.StaticBoxSizer` | |
1053 | "); | |
1054 | ||
d14a1e28 RD |
1055 | class wxBoxSizer : public wxSizer { |
1056 | public: | |
2b9048c5 | 1057 | %pythonAppend wxBoxSizer "self._setOORInfo(self)" |
d14a1e28 | 1058 | |
3ea6e0ec RD |
1059 | DocCtorStr( |
1060 | wxBoxSizer(int orient = wxHORIZONTAL), | |
1061 | "Constructor for a wx.BoxSizer. *orient* may be one of ``wx.VERTICAL`` | |
1062 | or ``wx.HORIZONTAL`` for creating either a column sizer or a row | |
1063 | sizer.", ""); | |
d14a1e28 | 1064 | |
7e8f0df9 | 1065 | |
3ea6e0ec RD |
1066 | DocDeclStr( |
1067 | int , GetOrientation(), | |
1068 | "Returns the current orientation of the sizer.", ""); | |
7e8f0df9 | 1069 | |
3ea6e0ec RD |
1070 | DocDeclStr( |
1071 | void , SetOrientation(int orient), | |
1072 | "Resets the orientation of the sizer.", ""); | |
7e8f0df9 | 1073 | |
d14a1e28 RD |
1074 | }; |
1075 | ||
1076 | //--------------------------------------------------------------------------- | |
1077 | %newgroup; | |
1078 | ||
3ea6e0ec RD |
1079 | |
1080 | DocStr(wxStaticBoxSizer, | |
1081 | "wx.StaticBoxSizer derives from and functions identically to the | |
1082 | `wx.BoxSizer` and adds a `wx.StaticBox` around the items that the sizer | |
1083 | manages. Note that this static box must be created separately and | |
1084 | passed to the sizer constructor.", ""); | |
1085 | ||
d14a1e28 RD |
1086 | class wxStaticBoxSizer : public wxBoxSizer { |
1087 | public: | |
2b9048c5 | 1088 | %pythonAppend wxStaticBoxSizer "self._setOORInfo(self)" |
d14a1e28 | 1089 | |
3ea6e0ec RD |
1090 | DocCtorStr( |
1091 | wxStaticBoxSizer(wxStaticBox *box, int orient = wxHORIZONTAL), | |
1092 | "Constructor. It takes an associated static box and the orientation | |
1093 | *orient* as parameters - orient can be either of ``wx.VERTICAL`` or | |
1094 | ``wx.HORIZONTAL``.", ""); | |
39d160c3 RD |
1095 | |
1096 | // TODO: wxStaticBoxSizer(int orient, wxWindow *win, const wxString& label = wxEmptyString); | |
7e8f0df9 | 1097 | |
39d160c3 RD |
1098 | DocDeclStr( |
1099 | wxStaticBox *, GetStaticBox(), | |
1100 | "Returns the static box associated with this sizer.", ""); | |
7e8f0df9 | 1101 | |
d14a1e28 RD |
1102 | }; |
1103 | ||
1104 | //--------------------------------------------------------------------------- | |
1105 | %newgroup; | |
1106 | ||
3ea6e0ec RD |
1107 | |
1108 | DocStr(wxGridSizer, | |
1109 | "A grid sizer is a sizer which lays out its children in a | |
1110 | two-dimensional table with all cells having the same size. In other | |
1111 | words, the width of each cell within the grid is the width of the | |
1112 | widest item added to the sizer and the height of each grid cell is the | |
1113 | height of the tallest item. An optional vertical and/or horizontal | |
1114 | gap between items can also be specified (in pixels.) | |
1115 | ||
1116 | Items are placed in the cells of the grid in the order they are added, | |
1117 | in row-major order. In other words, the first row is filled first, | |
1118 | then the second, and so on until all items have been added. (If | |
1119 | neccessary, additional rows will be added as items are added.) If you | |
1120 | need to have greater control over the cells that items are placed in | |
1121 | then use the `wx.GridBagSizer`. | |
1122 | ", ""); | |
1123 | ||
d14a1e28 RD |
1124 | class wxGridSizer: public wxSizer |
1125 | { | |
1126 | public: | |
2b9048c5 | 1127 | %pythonAppend wxGridSizer "self._setOORInfo(self)" |
d14a1e28 | 1128 | |
3ea6e0ec RD |
1129 | DocCtorStr( |
1130 | wxGridSizer( int rows=1, int cols=0, int vgap=0, int hgap=0 ), | |
1131 | "Constructor for a wx.GridSizer. *rows* and *cols* determine the number | |
1132 | of columns and rows in the sizer - if either of the parameters is | |
1133 | zero, it will be calculated to from the total number of children in | |
1134 | the sizer, thus making the sizer grow dynamically. *vgap* and *hgap* | |
1135 | define extra space between all children.", ""); | |
1136 | ||
1137 | DocDeclStr( | |
1138 | void , SetCols( int cols ), | |
1139 | "Sets the number of columns in the sizer.", ""); | |
7e8f0df9 | 1140 | |
3ea6e0ec RD |
1141 | DocDeclStr( |
1142 | void , SetRows( int rows ), | |
1143 | "Sets the number of rows in the sizer.", ""); | |
7e8f0df9 | 1144 | |
3ea6e0ec RD |
1145 | DocDeclStr( |
1146 | void , SetVGap( int gap ), | |
1147 | "Sets the vertical gap (in pixels) between the cells in the sizer.", ""); | |
7e8f0df9 | 1148 | |
3ea6e0ec RD |
1149 | DocDeclStr( |
1150 | void , SetHGap( int gap ), | |
1151 | "Sets the horizontal gap (in pixels) between cells in the sizer", ""); | |
7e8f0df9 | 1152 | |
3ea6e0ec RD |
1153 | DocDeclStr( |
1154 | int , GetCols(), | |
1155 | "Returns the number of columns in the sizer.", ""); | |
7e8f0df9 | 1156 | |
3ea6e0ec RD |
1157 | DocDeclStr( |
1158 | int , GetRows(), | |
1159 | "Returns the number of rows in the sizer.", ""); | |
7e8f0df9 | 1160 | |
3ea6e0ec RD |
1161 | DocDeclStr( |
1162 | int , GetVGap(), | |
1163 | "Returns the vertical gap (in pixels) between the cells in the sizer.", ""); | |
7e8f0df9 | 1164 | |
3ea6e0ec RD |
1165 | DocDeclStr( |
1166 | int , GetHGap(), | |
1167 | "Returns the horizontal gap (in pixels) between cells in the sizer.", ""); | |
7e8f0df9 | 1168 | |
d14a1e28 RD |
1169 | }; |
1170 | ||
1171 | //--------------------------------------------------------------------------- | |
1172 | %newgroup; | |
1173 | ||
1174 | enum wxFlexSizerGrowMode | |
1175 | { | |
1176 | // don't resize the cells in non-flexible direction at all | |
1177 | wxFLEX_GROWMODE_NONE, | |
1178 | ||
1179 | // uniformly resize only the specified ones (default) | |
1180 | wxFLEX_GROWMODE_SPECIFIED, | |
1181 | ||
1182 | // uniformly resize all cells | |
1183 | wxFLEX_GROWMODE_ALL | |
1184 | }; | |
1185 | ||
1186 | ||
3ea6e0ec RD |
1187 | |
1188 | ||
1189 | ||
1190 | DocStr(wxFlexGridSizer, | |
1191 | "A flex grid sizer is a sizer which lays out its children in a | |
1192 | two-dimensional table with all table cells in one row having the same | |
1193 | height and all cells in one column having the same width, but all | |
1194 | rows or all columns are not necessarily the same height or width as in | |
1195 | the `wx.GridSizer`. | |
1196 | ||
1197 | wx.FlexGridSizer can also size items equally in one direction but | |
1198 | unequally (\"flexibly\") in the other. If the sizer is only flexible | |
1199 | in one direction (this can be changed using `SetFlexibleDirection`), it | |
1200 | needs to be decided how the sizer should grow in the other (\"non | |
1201 | flexible\") direction in order to fill the available space. The | |
1202 | `SetNonFlexibleGrowMode` method serves this purpose. | |
1203 | ||
1204 | ", ""); | |
1205 | ||
d14a1e28 RD |
1206 | class wxFlexGridSizer: public wxGridSizer |
1207 | { | |
1208 | public: | |
2b9048c5 | 1209 | %pythonAppend wxFlexGridSizer "self._setOORInfo(self)" |
d14a1e28 | 1210 | |
3ea6e0ec RD |
1211 | DocCtorStr( |
1212 | wxFlexGridSizer( int rows=1, int cols=0, int vgap=0, int hgap=0 ), | |
1213 | "Constructor for a wx.FlexGridSizer. *rows* and *cols* determine the | |
1214 | number of columns and rows in the sizer - if either of the parameters | |
1215 | is zero, it will be calculated to from the total number of children in | |
1216 | the sizer, thus making the sizer grow dynamically. *vgap* and *hgap* | |
1217 | define extra space between all children.", ""); | |
7e8f0df9 | 1218 | |
3ea6e0ec RD |
1219 | |
1220 | DocDeclStr( | |
1221 | void , AddGrowableRow( size_t idx, int proportion = 0 ), | |
1222 | "Specifies that row *idx* (starting from zero) should be grown if there | |
1223 | is extra space available to the sizer. | |
1224 | ||
1225 | The *proportion* parameter has the same meaning as the stretch factor | |
1226 | for the box sizers except that if all proportions are 0, then all | |
1227 | columns are resized equally (instead of not being resized at all).", ""); | |
7e8f0df9 | 1228 | |
3ea6e0ec RD |
1229 | DocDeclStr( |
1230 | void , RemoveGrowableRow( size_t idx ), | |
1231 | "Specifies that row *idx* is no longer growable.", ""); | |
7e8f0df9 | 1232 | |
3ea6e0ec RD |
1233 | DocDeclStr( |
1234 | void , AddGrowableCol( size_t idx, int proportion = 0 ), | |
1235 | "Specifies that column *idx* (starting from zero) should be grown if | |
1236 | there is extra space available to the sizer. | |
1237 | ||
1238 | The *proportion* parameter has the same meaning as the stretch factor | |
1239 | for the box sizers except that if all proportions are 0, then all | |
1240 | columns are resized equally (instead of not being resized at all).", ""); | |
7e8f0df9 | 1241 | |
3ea6e0ec RD |
1242 | DocDeclStr( |
1243 | void , RemoveGrowableCol( size_t idx ), | |
1244 | "Specifies that column *idx* is no longer growable.", ""); | |
7e8f0df9 | 1245 | |
3ea6e0ec RD |
1246 | |
1247 | DocDeclStr( | |
1248 | void , SetFlexibleDirection(int direction), | |
1249 | "Specifies whether the sizer should flexibly resize its columns, rows, | |
1250 | or both. Argument *direction* can be one of the following values. Any | |
1251 | other value is ignored. | |
1252 | ||
1253 | ============== ======================================= | |
1254 | wx.VERTICAL Rows are flexibly sized. | |
1255 | wx.HORIZONTAL Columns are flexibly sized. | |
1256 | wx.BOTH Both rows and columns are flexibly sized | |
1257 | (this is the default value). | |
1258 | ============== ======================================= | |
1259 | ||
1260 | Note that this method does not trigger relayout. | |
1261 | ", ""); | |
7e8f0df9 | 1262 | |
3ea6e0ec RD |
1263 | DocDeclStr( |
1264 | int , GetFlexibleDirection(), | |
1265 | "Returns a value that specifies whether the sizer | |
1266 | flexibly resizes its columns, rows, or both (default). | |
d14a1e28 | 1267 | |
3ea6e0ec | 1268 | :see: `SetFlexibleDirection`", ""); |
d14a1e28 | 1269 | |
7e8f0df9 | 1270 | |
d14a1e28 | 1271 | |
3ea6e0ec RD |
1272 | DocDeclStr( |
1273 | void , SetNonFlexibleGrowMode(wxFlexSizerGrowMode mode), | |
1274 | "Specifies how the sizer should grow in the non-flexible direction if | |
1275 | there is one (so `SetFlexibleDirection` must have been called | |
1276 | previously). Argument *mode* can be one of the following values: | |
1277 | ||
1278 | ========================== ================================================= | |
1279 | wx.FLEX_GROWMODE_NONE Sizer doesn't grow in the non flexible direction. | |
1280 | wx.FLEX_GROWMODE_SPECIFIED Sizer honors growable columns/rows set with | |
1281 | `AddGrowableCol` and `AddGrowableRow`. In this | |
1282 | case equal sizing applies to minimum sizes of | |
1283 | columns or rows (this is the default value). | |
1284 | wx.FLEX_GROWMODE_ALL Sizer equally stretches all columns or rows in | |
1285 | the non flexible direction, whether they are | |
1286 | growable or not in the flexbile direction. | |
1287 | ========================== ================================================= | |
1288 | ||
1289 | Note that this method does not trigger relayout. | |
1290 | ||
1291 | ", ""); | |
7e8f0df9 | 1292 | |
3ea6e0ec RD |
1293 | DocDeclStr( |
1294 | wxFlexSizerGrowMode , GetNonFlexibleGrowMode(), | |
1295 | "Returns the value that specifies how the sizer grows in the | |
1296 | non-flexible direction if there is one. | |
d14a1e28 | 1297 | |
3ea6e0ec | 1298 | :see: `SetNonFlexibleGrowMode`", ""); |
7e8f0df9 | 1299 | |
dd9f7fea RD |
1300 | |
1301 | // Read-only access to the row heights and col widths arrays | |
3ea6e0ec RD |
1302 | DocDeclAStr( |
1303 | const wxArrayInt& , GetRowHeights() const, | |
1304 | "GetRowHeights(self) -> list", | |
1305 | "Returns a list of integers representing the heights of each of the | |
1306 | rows in the sizer.", ""); | |
7e8f0df9 | 1307 | |
3ea6e0ec RD |
1308 | DocDeclAStr( |
1309 | const wxArrayInt& , GetColWidths() const, | |
1310 | "GetColWidths(self) -> list", | |
1311 | "Returns a list of integers representing the widths of each of the | |
1312 | columns in the sizer.", ""); | |
7e8f0df9 | 1313 | |
d14a1e28 RD |
1314 | }; |
1315 | ||
9283228f RD |
1316 | //--------------------------------------------------------------------------- |
1317 | ||
1318 | DocStr(wxStdDialogButtonSizer, | |
1319 | "A special sizer that knows how to order and position standard buttons | |
1320 | in order to conform to the current platform's standards. You simply | |
1321 | need to add each `wx.Button` to the sizer, and be sure to create the | |
718903fe | 1322 | buttons using the standard ID's. Then call `Realize` and the sizer |
9283228f RD |
1323 | will take care of the rest. |
1324 | ", ""); | |
1325 | ||
1326 | class wxStdDialogButtonSizer: public wxBoxSizer | |
1327 | { | |
1328 | public: | |
1329 | DocCtorStr( | |
1330 | wxStdDialogButtonSizer(), | |
1331 | "", ""); | |
1332 | ||
1333 | DocDeclStr( | |
1334 | void , AddButton(wxButton *button), | |
1335 | "Use this to add the buttons to this sizer. Do not use the `Add` | |
1336 | method in the base class.", ""); | |
7e8f0df9 | 1337 | |
9283228f | 1338 | DocDeclStr( |
718903fe | 1339 | void , Realize(), |
9283228f RD |
1340 | "This funciton needs to be called after all the buttons have been added |
1341 | to the sizer. It will reorder them and position them in a platform | |
1342 | specifc manner.", ""); | |
3ba93175 RD |
1343 | |
1344 | void SetAffirmativeButton( wxButton *button ); | |
1345 | void SetNegativeButton( wxButton *button ); | |
1346 | void SetCancelButton( wxButton *button ); | |
7e8f0df9 | 1347 | |
9283228f RD |
1348 | wxButton* GetAffirmativeButton() const; |
1349 | wxButton* GetApplyButton() const; | |
1350 | wxButton* GetNegativeButton() const; | |
1351 | wxButton* GetCancelButton() const; | |
1352 | wxButton* GetHelpButton() const; | |
1353 | }; | |
1354 | ||
1355 | ||
d14a1e28 | 1356 | //--------------------------------------------------------------------------- |