1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG interface defs for the Sizers
7 // Created: 18-Sept-1999
9 // Copyright: (c) 2003 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
16 //---------------------------------------------------------------------------
21 //---------------------------------------------------------------------------
25 "The wx.SizerItem class is used to track the position, size and other
26 attributes of each item managed by a `wx.Sizer`. In normal usage user
27 code should never need to deal directly with a wx.SizerItem, but
28 custom classes derived from `wx.PySizer` will probably need to use the
29 collection of wx.SizerItems held by wx.Sizer when calculating layout.
31 :see: `wx.Sizer`, `wx.GBSizerItem`", "");
33 class wxSizerItem : public wxObject {
37 "Constructs an empty wx.SizerItem. Either a window, sizer or spacer
38 size will need to be set before this item can be used in a Sizer.
40 You will probably never need to create a wx.SizerItem directly as they
41 are created automatically when the sizer's Add, Insert or Prepend
44 :see: `wx.SizerItemSpacer`, `wx.SizerItemWindow`, `wx.SizerItemSizer`", "");
52 wxSizerItem( wxWindow *window, int proportion, int flag,
53 int border, PyObject* userData=NULL ),
54 "Constructs a `wx.SizerItem` for tracking a window.", "");
56 %RenameCtor(SizerItemWindow, wxSizerItem( wxWindow *window, int proportion, int flag,
57 int border, PyObject* userData=NULL ))
59 wxPyUserData* data = NULL;
61 wxPyBlock_t blocked = wxPyBeginBlockThreads();
62 data = new wxPyUserData(userData);
63 wxPyEndBlockThreads(blocked);
65 return new wxSizerItem(window, proportion, flag, border, data);
70 wxSizerItem( int width, int height, int proportion, int flag,
71 int border, PyObject* userData=NULL),
72 "Constructs a `wx.SizerItem` for tracking a spacer.", "");
74 %RenameCtor(SizerItemSpacer, wxSizerItem( int width, int height, int proportion, int flag,
75 int border, PyObject* userData=NULL))
77 wxPyUserData* data = NULL;
79 wxPyBlock_t blocked = wxPyBeginBlockThreads();
80 data = new wxPyUserData(userData);
81 wxPyEndBlockThreads(blocked);
83 return new wxSizerItem(width, height, proportion, flag, border, data);
87 wxSizerItem( wxSizer *sizer, int proportion, int flag,
88 int border, PyObject* userData=NULL ),
89 "Constructs a `wx.SizerItem` for tracking a subsizer", "");
91 %disownarg( wxSizer *sizer );
92 %RenameCtor(SizerItemSizer, wxSizerItem( wxSizer *sizer, int proportion, int flag,
93 int border, PyObject* userData=NULL ))
95 wxPyUserData* data = NULL;
97 wxPyBlock_t blocked = wxPyBeginBlockThreads();
98 data = new wxPyUserData(userData);
99 wxPyEndBlockThreads(blocked);
101 return new wxSizerItem(sizer, proportion, flag, border, data);
103 %cleardisown( wxSizer *sizer );
109 void , DeleteWindows(),
110 "Destroy the window or the windows in a subsizer, depending on the type
114 void , DetachSizer(),
115 "Enable deleting the SizerItem without destroying the contained sizer.", "");
120 "Get the current size of the item, as set in the last Layout.", "");
124 "Calculates the minimum desired size for the item, including any space
125 needed by borders.", "");
128 void , SetDimension( const wxPoint& pos, const wxSize& size ),
129 "Set the position and size of the space allocated for this item by the
130 sizer, and adjust the position and size of the item (window or
131 subsizer) to be within that space taking alignment and borders into
136 wxSize , GetMinSize(),
137 "Get the minimum size needed for the item.", "");
140 wxSize , GetMinSizeWithBorder() const,
141 "Get the minimum size needed for the item with space for the borders
142 added, if needed.", "");
145 void , SetInitSize( int x, int y ),
150 "Set the ratio item attribute.", "");
151 %Rename(SetRatioWH, void, SetRatio( int width, int height ));
152 %Rename(SetRatioSize, void, SetRatio( const wxSize& size ));
153 void SetRatio( float ratio );
157 "Set the ratio item attribute.", "");
161 "Returns the rectangle that the sizer item should occupy", "");
166 "Is this sizer item a window?", "");
170 "Is this sizer item a subsizer?", "");
174 "Is this sizer item a spacer?", "");
178 void , SetProportion( int proportion ),
179 "Set the proportion value for this item.", "");
182 int , GetProportion(),
183 "Get the proportion value for this item.", "");
185 %pythoncode { SetOption = wx._deprecated(SetProportion, "Please use `SetProportion` instead.") }
186 %pythoncode { GetOption = wx._deprecated(GetProportion, "Please use `GetProportion` instead.") }
190 void , SetFlag( int flag ),
191 "Set the flag value for this item.", "");
195 "Get the flag value for this item.", "");
199 void , SetBorder( int border ),
200 "Set the border value for this item.", "");
204 "Get the border value for this item.", "");
209 wxWindow *, GetWindow(),
210 "Get the window (if any) that is managed by this sizer item.", "");
213 void , SetWindow( wxWindow *window ),
214 "Set the window to be managed by this sizer item.", "");
218 wxSizer *, GetSizer(),
219 "Get the subsizer (if any) that is managed by this sizer item.", "");
221 %disownarg( wxSizer *sizer );
223 void , SetSizer( wxSizer *sizer ),
224 "Set the subsizer to be managed by this sizer item.", "");
225 %cleardisown( wxSizer *sizer );
229 const wxSize& , GetSpacer(),
230 "Get the size of the spacer managed by this sizer item.", "");
233 void , SetSpacer( const wxSize &size ),
234 "Set the size of the spacer to be managed by this sizer item.", "");
238 void , Show( bool show ),
239 "Set the show item attribute, which sizers use to determine if the item
240 is to be made part of the layout or not. If the item is tracking a
241 window then it is shown or hidden as needed.", "");
245 "Is the item to be shown in the layout?", "");
249 wxPoint , GetPosition(),
250 "Returns the current position of the item, as set in the last Layout.", "");
253 // wxObject* GetUserData();
255 // Assume that the user data is a wxPyUserData object and return the contents
258 "Returns the userData associated with this sizer item, or None if there
260 PyObject* GetUserData() {
261 wxPyUserData* data = (wxPyUserData*)self->GetUserData();
263 Py_INCREF(data->m_obj);
272 "Associate a Python object with this sizer item.", "");
273 void SetUserData(PyObject* userData) {
274 wxPyUserData* data = NULL;
276 wxPyBlock_t blocked = wxPyBeginBlockThreads();
277 data = new wxPyUserData(userData);
278 wxPyEndBlockThreads(blocked);
280 self->SetUserData(data);
286 //---------------------------------------------------------------------------
289 // Figure out the type of the sizer item
291 struct wxPySizerItemInfo {
293 : window(NULL), sizer(NULL), gotSize(false),
294 size(wxDefaultSize), gotPos(false), pos(-1)
305 static wxPySizerItemInfo wxPySizerItemTypeHelper(PyObject* item, bool checkSize, bool checkIdx ) {
307 wxPySizerItemInfo info;
309 wxSize* sizePtr = &size;
311 // Find out what the type of the item is
313 if ( ! wxPyConvertSwigPtr(item, (void**)&info.window, wxT("wxWindow")) ) {
318 if ( ! wxPyConvertSwigPtr(item, (void**)&info.sizer, wxT("wxSizer")) ) {
322 // try wxSize or (w,h)
323 if ( checkSize && wxSize_helper(item, &sizePtr)) {
324 info.size = *sizePtr;
329 if (checkIdx && PyInt_Check(item)) {
330 info.pos = PyInt_AsLong(item);
336 if ( !(info.window || info.sizer || (checkSize && info.gotSize) || (checkIdx && info.gotPos)) ) {
337 // no expected type, figure out what kind of error message to generate
338 if ( !checkSize && !checkIdx )
339 PyErr_SetString(PyExc_TypeError, "wx.Window or wx.Sizer expected for item");
340 else if ( checkSize && !checkIdx )
341 PyErr_SetString(PyExc_TypeError, "wx.Window, wx.Sizer, wx.Size, or (w,h) expected for item");
342 else if ( !checkSize && checkIdx)
343 PyErr_SetString(PyExc_TypeError, "wx.Window, wx.Sizer or int (position) expected for item");
345 // can this one happen?
346 PyErr_SetString(PyExc_TypeError, "wx.Window, wx.Sizer, wx.Size, or (w,h) or int (position) expected for item");
357 "wx.Sizer is the abstract base class used for laying out subwindows in
358 a window. You cannot use wx.Sizer directly; instead, you will have to
359 use one of the sizer classes derived from it such as `wx.BoxSizer`,
360 `wx.StaticBoxSizer`, `wx.NotebookSizer`, `wx.GridSizer`, `wx.FlexGridSizer`
361 and `wx.GridBagSizer`.
363 The concept implemented by sizers in wxWidgets is closely related to
364 layout tools in other GUI toolkits, such as Java's AWT, the GTK
365 toolkit or the Qt toolkit. It is based upon the idea of the individual
366 subwindows reporting their minimal required size and their ability to
367 get stretched if the size of the parent window has changed. This will
368 most often mean that the programmer does not set the original size of
369 a dialog in the beginning, rather the dialog will assigned a sizer and
370 this sizer will be queried about the recommended size. The sizer in
371 turn will query its children, which can be normal windows or contorls,
372 empty space or other sizers, so that a hierarchy of sizers can be
373 constructed. Note that wxSizer does not derive from wxWindow and thus
374 do not interfere with tab ordering and requires very little resources
375 compared to a real window on screen.
377 What makes sizers so well fitted for use in wxWidgets is the fact that
378 every control reports its own minimal size and the algorithm can
379 handle differences in font sizes or different window (dialog item)
380 sizes on different platforms without problems. If for example the
381 standard font as well as the overall design of Mac widgets requires
382 more space than on Windows, then the initial size of a dialog using a
383 sizer will automatically be bigger on Mac than on Windows.", "
385 Sizers may also be used to control the layout of custom drawn items on
386 the window. The `Add`, `Insert`, and `Prepend` functions return a
387 pointer to the newly added `wx.SizerItem`. Just add empty space of the
388 desired size and attributes, and then use the `wx.SizerItem.GetRect`
389 method to determine where the drawing operations should take place.
391 :note: If you wish to create a custom sizer class in wxPython you
392 should derive the class from `wx.PySizer` in order to get
393 Python-aware capabilities for the various virtual methods.
397 :todo: More dscriptive text here along with some pictures...
401 class wxSizer : public wxObject {
403 // wxSizer(); **** abstract, can't instantiate
408 void _setOORInfo(PyObject* _self) {
409 if (!self->GetClientObject())
410 self->SetClientObject(new wxPyOORClientData(_self));
414 "Add(self, item, int proportion=0, int flag=0, int border=0,
415 PyObject userData=None) -> wx.SizerItem",
417 "Appends a child item to the sizer.", "
419 :param item: The item can be one of three kinds of objects:
421 - **window**: A `wx.Window` to be managed by the sizer. Its
422 minimal size (either set explicitly by the user or
423 calculated internally when constructed with wx.DefaultSize)
424 is interpreted as the minimal size to use when laying out
425 item in the sizer. This is particularly useful in
426 connection with `wx.Window.SetSizeHints`.
428 - **sizer**: The (child-)sizer to be added to the sizer. This
429 allows placing a child sizer in a sizer and thus to create
430 hierarchies of sizers (typically a vertical box as the top
431 sizer and several horizontal boxes on the level beneath).
433 - **size**: A `wx.Size` or a 2-element sequence of integers
434 that represents the width and height of a spacer to be added
435 to the sizer. Adding spacers to sizers gives more
436 flexibility in the design of dialogs; imagine for example a
437 horizontal box with two buttons at the bottom of a dialog:
438 you might want to insert a space between the two buttons and
439 make that space stretchable using the *proportion* value and
440 the result will be that the left button will be aligned with
441 the left side of the dialog and the right button with the
442 right side - the space in between will shrink and grow with
445 :param proportion: Although the meaning of this parameter is
446 undefined in wx.Sizer, it is used in `wx.BoxSizer` to indicate
447 if a child of a sizer can change its size in the main
448 orientation of the wx.BoxSizer - where 0 stands for not
449 changeable and a value of more than zero is interpreted
450 relative (a proportion of the total) to the value of other
451 children of the same wx.BoxSizer. For example, you might have
452 a horizontal wx.BoxSizer with three children, two of which are
453 supposed to change their size with the sizer. Then the two
454 stretchable windows should each be given *proportion* value of
455 1 to make them grow and shrink equally with the sizer's
456 horizontal dimension. But if one of them had a *proportion*
457 value of 2 then it would get a double share of the space
458 available after the fixed size items are positioned.
460 :param flag: This parameter can be used to set a number of flags
461 which can be combined using the binary OR operator ``|``. Two
462 main behaviours are defined using these flags. One is the
463 border around a window: the *border* parameter determines the
464 border width whereas the flags given here determine which
465 side(s) of the item that the border will be added. The other
466 flags determine how the sizer item behaves when the space
467 allotted to the sizer changes, and is somewhat dependent on
468 the specific kind of sizer used.
470 +----------------------------+------------------------------------------+
471 |- wx.TOP |These flags are used to specify |
472 |- wx.BOTTOM |which side(s) of the sizer item that |
473 |- wx.LEFT |the *border* width will apply to. |
477 +----------------------------+------------------------------------------+
478 |- wx.EXPAND |The item will be expanded to fill |
479 | |the space allotted to the item. |
480 +----------------------------+------------------------------------------+
481 |- wx.SHAPED |The item will be expanded as much as |
482 | |possible while also maintaining its |
484 +----------------------------+------------------------------------------+
485 |- wx.FIXED_MINSIZE |Normally wx.Sizers will use |
486 | |`wx.Window.GetMinSize` or |
487 | |`wx.Window.GetBestSize` to determine what |
488 | |the minimal size of window items should |
489 | |be, and will use that size to calculate |
490 | |the layout. This allows layouts to adjust |
491 | |when an item changes and it's best size |
492 | |becomes different. If you would rather |
493 | |have a window item stay the size it |
494 | |started with then use wx.FIXED_MINSIZE. |
495 +----------------------------+------------------------------------------+
496 |- wx.ALIGN_CENTER |The wx.ALIGN flags allow you to specify |
497 |- wx.ALIGN_LEFT |the alignment of the item within the space|
498 |- wx.ALIGN_RIGHT |allotted to it by the sizer, ajusted for |
499 |- wx.ALIGN_TOP |the border if any. |
500 |- wx.ALIGN_BOTTOM | |
501 |- wx.ALIGN_CENTER_VERTICAL | |
502 |- wx.ALIGN_CENTER_HORIZONTAL| |
503 +----------------------------+------------------------------------------+
506 :param border: Determines the border width, if the *flag*
507 parameter is set to include any border flag.
509 :param userData: Allows an extra object to be attached to the
510 sizer item, for use in derived classes when sizing information
511 is more complex than the *proportion* and *flag* will allow for.
514 wxSizerItem* Add(PyObject* item, int proportion=0, int flag=0, int border=0,
515 PyObject* userData=NULL) {
517 wxPyUserData* data = NULL;
518 wxPyBlock_t blocked = wxPyBeginBlockThreads();
519 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, true, false);
520 if ( userData && (info.window || info.sizer || info.gotSize) )
521 data = new wxPyUserData(userData);
523 PyObject_SetAttrString(item,"thisown",Py_False);
524 wxPyEndBlockThreads(blocked);
526 // Now call the real Add method if a valid item type was found
528 return self->Add(info.window, proportion, flag, border, data);
529 else if ( info.sizer )
530 return self->Add(info.sizer, proportion, flag, border, data);
531 else if (info.gotSize)
532 return self->Add(info.size.GetWidth(), info.size.GetHeight(),
533 proportion, flag, border, data);
538 // virtual wxSizerItem* AddSpacer(int size);
539 // virtual wxSizerItem* AddStretchSpacer(int prop = 1);
542 "Insert(self, int before, item, int proportion=0, int flag=0, int border=0,
543 PyObject userData=None) -> wx.SizerItem",
545 "Inserts a new item into the list of items managed by this sizer before
546 the item at index *before*. See `Add` for a description of the parameters.", "");
547 wxSizerItem* Insert(int before, PyObject* item, int proportion=0, int flag=0,
548 int border=0, PyObject* userData=NULL) {
550 wxPyUserData* data = NULL;
551 wxPyBlock_t blocked = wxPyBeginBlockThreads();
552 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, true, false);
553 if ( userData && (info.window || info.sizer || info.gotSize) )
554 data = new wxPyUserData(userData);
556 PyObject_SetAttrString(item,"thisown",Py_False);
557 wxPyEndBlockThreads(blocked);
559 // Now call the real Insert method if a valid item type was found
561 return self->Insert(before, info.window, proportion, flag, border, data);
562 else if ( info.sizer )
563 return self->Insert(before, info.sizer, proportion, flag, border, data);
564 else if (info.gotSize)
565 return self->Insert(before, info.size.GetWidth(), info.size.GetHeight(),
566 proportion, flag, border, data);
572 // virtual wxSizerItem* InsertSpacer(size_t index, int size);
573 // virtual wxSizerItem* InsertStretchSpacer(size_t index, int prop = 1);
576 "Prepend(self, item, int proportion=0, int flag=0, int border=0,
577 PyObject userData=None) -> wx.SizerItem",
579 "Adds a new item to the begining of the list of sizer items managed by
580 this sizer. See `Add` for a description of the parameters.", "");
581 wxSizerItem* Prepend(PyObject* item, int proportion=0, int flag=0, int border=0,
582 PyObject* userData=NULL) {
584 wxPyUserData* data = NULL;
585 wxPyBlock_t blocked = wxPyBeginBlockThreads();
586 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, true, false);
587 if ( userData && (info.window || info.sizer || info.gotSize) )
588 data = new wxPyUserData(userData);
590 PyObject_SetAttrString(item,"thisown",Py_False);
591 wxPyEndBlockThreads(blocked);
593 // Now call the real Prepend method if a valid item type was found
595 return self->Prepend(info.window, proportion, flag, border, data);
596 else if ( info.sizer )
597 return self->Prepend(info.sizer, proportion, flag, border, data);
598 else if (info.gotSize)
599 return self->Prepend(info.size.GetWidth(), info.size.GetHeight(),
600 proportion, flag, border, data);
605 // virtual wxSizerItem* PrependSpacer(int size);
606 // virtual wxSizerItem* PrependStretchSpacer(int prop = 1);
609 "Remove(self, item) -> bool",
610 "Removes an item from the sizer and destroys it. This method does not
611 cause any layout or resizing to take place, call `Layout` to update
612 the layout on screen after removing a child from the sizer. The
613 *item* parameter can be either a window, a sizer, or the zero-based
614 index of an item to remove. Returns True if the child item was found
617 :note: For historical reasons calling this method with a `wx.Window`
618 parameter is depreacted, as it will not be able to destroy the
619 window since it is owned by its parent. You should use `Detach`
622 bool Remove(PyObject* item) {
623 wxPyBlock_t blocked = wxPyBeginBlockThreads();
624 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, false, true);
625 wxPyEndBlockThreads(blocked);
627 return self->Remove(info.window);
628 else if ( info.sizer )
629 return self->Remove(info.sizer);
630 else if ( info.gotPos )
631 return self->Remove(info.pos);
638 "Detach(self, item) -> bool",
639 "Detaches an item from the sizer without destroying it. This method
640 does not cause any layout or resizing to take place, call `Layout` to
641 do so. The *item* parameter can be either a window, a sizer, or the
642 zero-based index of the item to be detached. Returns True if the child item
643 was found and detached.", "");
644 bool Detach(PyObject* item) {
645 wxPyBlock_t blocked = wxPyBeginBlockThreads();
646 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, false, true);
647 wxPyEndBlockThreads(blocked);
649 return self->Detach(info.window);
650 else if ( info.sizer )
651 return self->Detach(info.sizer);
652 else if ( info.gotPos )
653 return self->Detach(info.pos);
660 "GetItem(self, item) -> wx.SizerItem",
661 "Returns the `wx.SizerItem` which holds the *item* given. The *item*
662 parameter can be either a window, a sizer, or the zero-based index of
663 the item to be found.", "");
664 wxSizerItem* GetItem(PyObject* item) {
665 wxPyBlock_t blocked = wxPyBeginBlockThreads();
666 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, false, true);
667 wxPyEndBlockThreads(blocked);
669 return self->GetItem(info.window);
670 else if ( info.sizer )
671 return self->GetItem(info.sizer);
672 else if ( info.gotPos )
673 return self->GetItem(info.pos);
679 void _SetItemMinSize(PyObject* item, const wxSize& size) {
680 wxPyBlock_t blocked = wxPyBeginBlockThreads();
681 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, false, true);
682 wxPyEndBlockThreads(blocked);
684 self->SetItemMinSize(info.window, size);
685 else if ( info.sizer )
686 self->SetItemMinSize(info.sizer, size);
687 else if ( info.gotPos )
688 self->SetItemMinSize(info.pos, size);
693 def SetItemMinSize(self, item, *args):
695 SetItemMinSize(self, item, Size size)
697 Sets the minimum size that will be allocated for an item in the sizer.
698 The *item* parameter can be either a window, a sizer, or the
699 zero-based index of the item. If a window or sizer is given then it
700 will be searched for recursivly in subsizers if neccessary.
703 %# for backward compatibility accept separate width,height args too
704 return self._SetItemMinSize(item, args)
706 return self._SetItemMinSize(item, args[0])
710 %disownarg( wxSizerItem *item );
713 wxSizerItem* , Add( wxSizerItem *item ),
714 "AddItem(self, SizerItem item)",
715 "Adds a `wx.SizerItem` to the sizer.", "",
719 wxSizerItem* , Insert( size_t index, wxSizerItem *item ),
720 "InsertItem(self, int index, SizerItem item)",
721 "Inserts a `wx.SizerItem` to the sizer at the position given by *index*.", "",
725 wxSizerItem* , Prepend( wxSizerItem *item ),
726 "PrependItem(self, SizerItem item)",
727 "Prepends a `wx.SizerItem` to the sizer.", "",
730 %cleardisown( wxSizerItem *item );
734 def AddMany(self, items):
736 AddMany is a convenience method for adding several items
737 to a sizer at one time. Simply pass it a list of tuples,
738 where each tuple consists of the parameters that you
739 would normally pass to the `Add` method.
742 if type(item) != type(()) or (len(item) == 2 and type(item[0]) == type(1)):
746 %# for backwards compatibility only, please do not use in new code
747 def AddWindow(self, *args, **kw):
748 """Compatibility alias for `Add`."""
749 return self.Add(*args, **kw)
750 def AddSizer(self, *args, **kw):
751 """Compatibility alias for `Add`."""
752 return self.Add(*args, **kw)
753 def AddSpacer(self, *args, **kw):
754 """Compatibility alias for `Add`."""
755 return self.Add(*args, **kw)
757 def PrependWindow(self, *args, **kw):
758 """Compatibility alias for `Prepend`."""
759 return self.Prepend(*args, **kw)
760 def PrependSizer(self, *args, **kw):
761 """Compatibility alias for `Prepend`."""
762 return self.Prepend(*args, **kw)
763 def PrependSpacer(self, *args, **kw):
764 """Compatibility alias for `Prepend`."""
765 return self.Prepend(*args, **kw)
767 def InsertWindow(self, *args, **kw):
768 """Compatibility alias for `Insert`."""
769 return self.Insert(*args, **kw)
770 def InsertSizer(self, *args, **kw):
771 """Compatibility alias for `Insert`."""
772 return self.Insert(*args, **kw)
773 def InsertSpacer(self, *args, **kw):
774 """Compatibility alias for `Insert`."""
775 return self.Insert(*args, **kw)
777 def RemoveWindow(self, *args, **kw):
778 """Compatibility alias for `Remove`."""
779 return self.Remove(*args, **kw)
780 def RemoveSizer(self, *args, **kw):
781 """Compatibility alias for `Remove`."""
782 return self.Remove(*args, **kw)
783 def RemovePos(self, *args, **kw):
784 """Compatibility alias for `Remove`."""
785 return self.Remove(*args, **kw)
791 void , SetDimension( int x, int y, int width, int height ),
792 "Call this to force the sizer to take the given dimension and thus
793 force the items owned by the sizer to resize themselves according to
794 the rules defined by the parameter in the `Add`, `Insert` or `Prepend`
798 void , SetMinSize( const wxSize &size ),
799 "Call this to give the sizer a minimal size. Normally, the sizer will
800 calculate its minimal size based purely on how much space its children
801 need. After calling this method `GetMinSize` will return either the
802 minimal size as requested by its children or the minimal size set
803 here, depending on which is bigger.", "");
808 "Returns the current size of the space managed by the sizer.", "");
811 wxPoint , GetPosition(),
812 "Returns the current position of the sizer's managed space.", "");
815 wxSize , GetMinSize(),
816 "Returns the minimal size of the sizer. This is either the combined
817 minimal size of all the children and their borders or the minimal size
818 set by SetMinSize, depending on which is bigger.", "");
822 def GetSizeTuple(self):
823 return self.GetSize().Get()
824 def GetPositionTuple(self):
825 return self.GetPosition().Get()
826 def GetMinSizeTuple(self):
827 return self.GetMinSize().Get()
831 virtual void , RecalcSizes(),
832 "Using the sizes calculated by `CalcMin` reposition and resize all the
833 items managed by this sizer. You should not need to call this directly as
834 it is called by `Layout`.", "");
837 virtual wxSize , CalcMin(),
838 "This method is where the sizer will do the actual calculation of its
839 children's minimal sizes. You should not need to call this directly as
840 it is called by `Layout`.", "");
845 "This method will force the recalculation and layout of the items
846 controlled by the sizer using the current space allocated to the
847 sizer. Normally this is called automatically from the owning window's
848 EVT_SIZE handler, but it is also useful to call it from user code when
849 one of the items in a sizer change size, or items are added or
854 wxSize , Fit( wxWindow *window ),
855 "Tell the sizer to resize the *window* to match the sizer's minimal
856 size. This is commonly done in the constructor of the window itself in
857 order to set its initial size to match the needs of the children as
858 determined by the sizer. Returns the new size.
860 For a top level window this is the total window size, not the client size.", "");
863 void , FitInside( wxWindow *window ),
864 "Tell the sizer to resize the *virtual size* of the *window* to match the
865 sizer's minimal size. This will not alter the on screen size of the
866 window, but may cause the addition/removal/alteration of scrollbars
867 required to view the virtual area in windows which manage it.
869 :see: `wx.ScrolledWindow.SetScrollbars`, `SetVirtualSizeHints`
874 void , SetSizeHints( wxWindow *window ),
875 "Tell the sizer to set (and `Fit`) the minimal size of the *window* to
876 match the sizer's minimal size. This is commonly done in the
877 constructor of the window itself if the window is resizable (as are
878 many dialogs under Unix and frames on probably all platforms) in order
879 to prevent the window from being sized smaller than the minimal size
880 required by the sizer.", "");
883 void , SetVirtualSizeHints( wxWindow *window ),
884 "Tell the sizer to set the minimal size of the window virtual area to
885 match the sizer's minimal size. For windows with managed scrollbars
886 this will set them appropriately.
888 :see: `wx.ScrolledWindow.SetScrollbars`
893 void , Clear( bool deleteWindows=false ),
894 "Clear all items from the sizer, optionally destroying the window items
898 void , DeleteWindows(),
899 "Destroy all windows managed by the sizer.", "");
903 // wxList& GetChildren();
906 "GetChildren(self) -> list",
907 "Returns a list of all the `wx.SizerItem` objects managed by the sizer.", "");
908 PyObject* GetChildren() {
909 wxSizerItemList& list = self->GetChildren();
910 return wxPy_ConvertList(&list);
915 // Manage whether individual windows or subsizers are considered
916 // in the layout calculations or not.
920 "Show(self, item, bool show=True, bool recursive=false) -> bool",
921 "Shows or hides an item managed by the sizer. To make a sizer item
922 disappear or reappear, use Show followed by `Layout`. The *item*
923 parameter can be either a window, a sizer, or the zero-based index of
924 the item. Use the recursive parameter to show or hide an item in a
925 subsizer. Returns True if the item was found.", "");
926 bool Show(PyObject* item, bool show = true, bool recursive=false) {
927 wxPyBlock_t blocked = wxPyBeginBlockThreads();
928 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, false, true);
929 wxPyEndBlockThreads(blocked);
931 return self->Show(info.window, show, recursive);
932 else if ( info.sizer )
933 return self->Show(info.sizer, show, recursive);
934 else if ( info.gotPos )
935 return self->Show(info.pos, show);
941 "IsShown(self, item)",
942 "Determines if the item is currently shown. sizer. To make a sizer
943 item disappear or reappear, use Show followed by `Layout`. The *item*
944 parameter can be either a window, a sizer, or the zero-based index of
946 bool IsShown(PyObject* item) {
947 wxPyBlock_t blocked = wxPyBeginBlockThreads();
948 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, false, false);
949 wxPyEndBlockThreads(blocked);
951 return self->IsShown(info.window);
952 else if ( info.sizer )
953 return self->IsShown(info.sizer);
954 else if ( info.gotPos )
955 return self->IsShown(info.pos);
962 def Hide(self, item, recursive=False):
964 A convenience method for `Show` (item, False, recursive).
966 return self.Show(item, False, recursive)
971 void , ShowItems(bool show),
972 "Recursively call `wx.SizerItem.Show` on all sizer items.", "");
975 // void Show(bool show);
981 //---------------------------------------------------------------------------
982 // Use this one for deriving Python classes from
985 IMP_PYCALLBACK___pure(wxPySizer, wxSizer, RecalcSizes);
986 IMP_PYCALLBACK_wxSize__pure(wxPySizer, wxSizer, CalcMin);
987 IMPLEMENT_DYNAMIC_CLASS(wxPySizer, wxSizer);
992 "wx.PySizer is a special version of `wx.Sizer` that has been
993 instrumented to allow the C++ virtual methods to be overloaded in
994 Python derived classes. You would derive from this class if you are
995 wanting to implement a custom sizer in Python code. Simply implement
996 `CalcMin` and `RecalcSizes` in the derived class and you're all set.
999 class MySizer(wx.PySizer):
1001 wx.PySizer.__init__(self)
1004 for item in self.GetChildren():
1005 # calculate the total minimum width and height needed
1006 # by all items in the sizer according to this sizer's
1009 return wx.Size(width, height)
1011 def RecalcSizes(self):
1012 # find the space allotted to this sizer
1013 pos = self.GetPosition()
1014 size = self.GetSize()
1015 for item in self.GetChildren():
1016 # Recalculate (if necessary) the position and size of
1017 # each item and then call item.SetDimension to do the
1018 # actual positioning and sizing of the items within the
1019 # space alloted to this sizer.
1021 item.SetDimension(itemPos, itemSize)
1024 When `Layout` is called it first calls `CalcMin` followed by
1025 `RecalcSizes` so you can optimize a bit by saving the results of
1026 `CalcMin` and reusing them in `RecalcSizes`.
1028 :see: `wx.SizerItem`, `wx.Sizer.GetChildren`
1031 class wxPySizer : public wxSizer {
1033 %pythonAppend wxPySizer "self._setCallbackInfo(self, PySizer);self._setOORInfo(self)"
1037 "Creates a wx.PySizer. Must be called from the __init__ in the derived
1040 void _setCallbackInfo(PyObject* self, PyObject* _class);
1044 //---------------------------------------------------------------------------
1049 "The basic idea behind a box sizer is that windows will most often be
1050 laid out in rather simple basic geometry, typically in a row or a
1051 column or nested hierarchies of either. A wx.BoxSizer will lay out
1052 its items in a simple row or column, depending on the orientation
1053 parameter passed to the constructor.", "
1055 It is the unique feature of a box sizer, that it can grow in both
1056 directions (height and width) but can distribute its growth in the
1057 main direction (horizontal for a row) *unevenly* among its children.
1058 This is determined by the proportion parameter give to items when they
1059 are added to the sizer. It is interpreted as a weight factor, i.e. it
1060 can be zero, indicating that the window may not be resized at all, or
1061 above zero. If several windows have a value above zero, the value is
1062 interpreted relative to the sum of all weight factors of the sizer, so
1063 when adding two windows with a value of 1, they will both get resized
1064 equally and each will receive half of the available space after the
1065 fixed size items have been sized. If the items have unequal
1066 proportion settings then they will receive a coresondingly unequal
1067 allotment of the free space.
1069 :see: `wx.StaticBoxSizer`
1072 class wxBoxSizer : public wxSizer {
1074 %pythonAppend wxBoxSizer "self._setOORInfo(self)"
1077 wxBoxSizer(int orient = wxHORIZONTAL),
1078 "Constructor for a wx.BoxSizer. *orient* may be one of ``wx.VERTICAL``
1079 or ``wx.HORIZONTAL`` for creating either a column sizer or a row
1084 int , GetOrientation(),
1085 "Returns the current orientation of the sizer.", "");
1088 void , SetOrientation(int orient),
1089 "Resets the orientation of the sizer.", "");
1093 //---------------------------------------------------------------------------
1097 DocStr(wxStaticBoxSizer,
1098 "wx.StaticBoxSizer derives from and functions identically to the
1099 `wx.BoxSizer` and adds a `wx.StaticBox` around the items that the sizer
1100 manages. Note that this static box must be created separately and
1101 passed to the sizer constructor.", "");
1103 class wxStaticBoxSizer : public wxBoxSizer {
1105 %pythonAppend wxStaticBoxSizer "self._setOORInfo(self)"
1108 wxStaticBoxSizer(wxStaticBox *box, int orient = wxHORIZONTAL),
1109 "Constructor. It takes an associated static box and the orientation
1110 *orient* as parameters - orient can be either of ``wx.VERTICAL`` or
1111 ``wx.HORIZONTAL``.", "");
1113 // TODO: wxStaticBoxSizer(int orient, wxWindow *win, const wxString& label = wxEmptyString);
1116 wxStaticBox *, GetStaticBox(),
1117 "Returns the static box associated with this sizer.", "");
1121 //---------------------------------------------------------------------------
1126 "A grid sizer is a sizer which lays out its children in a
1127 two-dimensional table with all cells having the same size. In other
1128 words, the width of each cell within the grid is the width of the
1129 widest item added to the sizer and the height of each grid cell is the
1130 height of the tallest item. An optional vertical and/or horizontal
1131 gap between items can also be specified (in pixels.)
1133 Items are placed in the cells of the grid in the order they are added,
1134 in row-major order. In other words, the first row is filled first,
1135 then the second, and so on until all items have been added. (If
1136 neccessary, additional rows will be added as items are added.) If you
1137 need to have greater control over the cells that items are placed in
1138 then use the `wx.GridBagSizer`.
1141 class wxGridSizer: public wxSizer
1144 %pythonAppend wxGridSizer "self._setOORInfo(self)"
1147 wxGridSizer( int rows=1, int cols=0, int vgap=0, int hgap=0 ),
1148 "Constructor for a wx.GridSizer. *rows* and *cols* determine the number
1149 of columns and rows in the sizer - if either of the parameters is
1150 zero, it will be calculated to from the total number of children in
1151 the sizer, thus making the sizer grow dynamically. *vgap* and *hgap*
1152 define extra space between all children.", "");
1155 void , SetCols( int cols ),
1156 "Sets the number of columns in the sizer.", "");
1159 void , SetRows( int rows ),
1160 "Sets the number of rows in the sizer.", "");
1163 void , SetVGap( int gap ),
1164 "Sets the vertical gap (in pixels) between the cells in the sizer.", "");
1167 void , SetHGap( int gap ),
1168 "Sets the horizontal gap (in pixels) between cells in the sizer", "");
1172 "Returns the number of columns in the sizer.", "");
1176 "Returns the number of rows in the sizer.", "");
1180 "Returns the vertical gap (in pixels) between the cells in the sizer.", "");
1184 "Returns the horizontal gap (in pixels) between cells in the sizer.", "");
1188 //---------------------------------------------------------------------------
1191 enum wxFlexSizerGrowMode
1193 // don't resize the cells in non-flexible direction at all
1194 wxFLEX_GROWMODE_NONE,
1196 // uniformly resize only the specified ones (default)
1197 wxFLEX_GROWMODE_SPECIFIED,
1199 // uniformly resize all cells
1207 DocStr(wxFlexGridSizer,
1208 "A flex grid sizer is a sizer which lays out its children in a
1209 two-dimensional table with all table cells in one row having the same
1210 height and all cells in one column having the same width, but all
1211 rows or all columns are not necessarily the same height or width as in
1214 wx.FlexGridSizer can also size items equally in one direction but
1215 unequally (\"flexibly\") in the other. If the sizer is only flexible
1216 in one direction (this can be changed using `SetFlexibleDirection`), it
1217 needs to be decided how the sizer should grow in the other (\"non
1218 flexible\") direction in order to fill the available space. The
1219 `SetNonFlexibleGrowMode` method serves this purpose.
1223 class wxFlexGridSizer: public wxGridSizer
1226 %pythonAppend wxFlexGridSizer "self._setOORInfo(self)"
1229 wxFlexGridSizer( int rows=1, int cols=0, int vgap=0, int hgap=0 ),
1230 "Constructor for a wx.FlexGridSizer. *rows* and *cols* determine the
1231 number of columns and rows in the sizer - if either of the parameters
1232 is zero, it will be calculated to from the total number of children in
1233 the sizer, thus making the sizer grow dynamically. *vgap* and *hgap*
1234 define extra space between all children.", "");
1238 void , AddGrowableRow( size_t idx, int proportion = 0 ),
1239 "Specifies that row *idx* (starting from zero) should be grown if there
1240 is extra space available to the sizer.
1242 The *proportion* parameter has the same meaning as the stretch factor
1243 for the box sizers except that if all proportions are 0, then all
1244 columns are resized equally (instead of not being resized at all).", "");
1247 void , RemoveGrowableRow( size_t idx ),
1248 "Specifies that row *idx* is no longer growable.", "");
1251 void , AddGrowableCol( size_t idx, int proportion = 0 ),
1252 "Specifies that column *idx* (starting from zero) should be grown if
1253 there is extra space available to the sizer.
1255 The *proportion* parameter has the same meaning as the stretch factor
1256 for the box sizers except that if all proportions are 0, then all
1257 columns are resized equally (instead of not being resized at all).", "");
1260 void , RemoveGrowableCol( size_t idx ),
1261 "Specifies that column *idx* is no longer growable.", "");
1265 void , SetFlexibleDirection(int direction),
1266 "Specifies whether the sizer should flexibly resize its columns, rows,
1267 or both. Argument *direction* can be one of the following values. Any
1268 other value is ignored.
1270 ============== =======================================
1271 wx.VERTICAL Rows are flexibly sized.
1272 wx.HORIZONTAL Columns are flexibly sized.
1273 wx.BOTH Both rows and columns are flexibly sized
1274 (this is the default value).
1275 ============== =======================================
1277 Note that this method does not trigger relayout.
1281 int , GetFlexibleDirection(),
1282 "Returns a value that specifies whether the sizer
1283 flexibly resizes its columns, rows, or both (default).
1285 :see: `SetFlexibleDirection`", "");
1290 void , SetNonFlexibleGrowMode(wxFlexSizerGrowMode mode),
1291 "Specifies how the sizer should grow in the non-flexible direction if
1292 there is one (so `SetFlexibleDirection` must have been called
1293 previously). Argument *mode* can be one of the following values:
1295 ========================== =================================================
1296 wx.FLEX_GROWMODE_NONE Sizer doesn't grow in the non flexible direction.
1297 wx.FLEX_GROWMODE_SPECIFIED Sizer honors growable columns/rows set with
1298 `AddGrowableCol` and `AddGrowableRow`. In this
1299 case equal sizing applies to minimum sizes of
1300 columns or rows (this is the default value).
1301 wx.FLEX_GROWMODE_ALL Sizer equally stretches all columns or rows in
1302 the non flexible direction, whether they are
1303 growable or not in the flexbile direction.
1304 ========================== =================================================
1306 Note that this method does not trigger relayout.
1311 wxFlexSizerGrowMode , GetNonFlexibleGrowMode(),
1312 "Returns the value that specifies how the sizer grows in the
1313 non-flexible direction if there is one.
1315 :see: `SetNonFlexibleGrowMode`", "");
1318 // Read-only access to the row heights and col widths arrays
1320 const wxArrayInt& , GetRowHeights() const,
1321 "GetRowHeights(self) -> list",
1322 "Returns a list of integers representing the heights of each of the
1323 rows in the sizer.", "");
1326 const wxArrayInt& , GetColWidths() const,
1327 "GetColWidths(self) -> list",
1328 "Returns a list of integers representing the widths of each of the
1329 columns in the sizer.", "");
1333 //---------------------------------------------------------------------------
1335 DocStr(wxStdDialogButtonSizer,
1336 "A special sizer that knows how to order and position standard buttons
1337 in order to conform to the current platform's standards. You simply
1338 need to add each `wx.Button` to the sizer, and be sure to create the
1339 buttons using the standard ID's. Then call `Realize` and the sizer
1340 will take care of the rest.
1343 class wxStdDialogButtonSizer: public wxBoxSizer
1347 wxStdDialogButtonSizer(),
1351 void , AddButton(wxButton *button),
1352 "Use this to add the buttons to this sizer. Do not use the `Add`
1353 method in the base class.", "");
1357 "This funciton needs to be called after all the buttons have been added
1358 to the sizer. It will reorder them and position them in a platform
1359 specifc manner.", "");
1361 void SetAffirmativeButton( wxButton *button );
1362 void SetNegativeButton( wxButton *button );
1363 void SetCancelButton( wxButton *button );
1365 wxButton* GetAffirmativeButton() const;
1366 wxButton* GetApplyButton() const;
1367 wxButton* GetNegativeButton() const;
1368 wxButton* GetCancelButton() const;
1369 wxButton* GetHelpButton() const;
1373 //---------------------------------------------------------------------------