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