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