X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/02b800ce7c2bb1c1f08075f22be2e7412124b47f..c4287548985b4a8246eb1d9b4ced2f346fc95253:/wxPython/src/_sizers.i diff --git a/wxPython/src/_sizers.i b/wxPython/src/_sizers.i index ae97bc0d15..9726d7b4fc 100644 --- a/wxPython/src/_sizers.i +++ b/wxPython/src/_sizers.i @@ -23,10 +23,13 @@ DocStr(wxSizerItem, "The wx.SizerItem class is used to track the position, size and other -attributes of each item managed by a `wx.Sizer`. In normal usage user -code should never need to deal directly with a wx.SizerItem, but -custom classes derived from `wx.PySizer` will probably need to use the -collection of wx.SizerItems held by wx.Sizer when calculating layout. +attributes of each item managed by a `wx.Sizer`. It is not usually +necessary to use this class because the sizer elements can also be +identified by their positions or window or sizer references but +sometimes it may be more convenient to use wx.SizerItem directly. +Also, custom classes derived from `wx.PySizer` will probably need to +use the collection of wx.SizerItems held by wx.Sizer when calculating +layout. :see: `wx.Sizer`, `wx.GBSizerItem`", ""); @@ -43,6 +46,8 @@ methods are called. :see: `wx.SizerItemSpacer`, `wx.SizerItemWindow`, `wx.SizerItemSizer`", ""); + + ~wxSizerItem(); %extend { @@ -86,6 +91,7 @@ methods are called. int border, PyObject* userData=NULL ), "Constructs a `wx.SizerItem` for tracking a subsizer", ""); + %disownarg( wxSizer *sizer ); %RenameCtor(SizerItemSizer, wxSizerItem( wxSizer *sizer, int proportion, int flag, int border, PyObject* userData=NULL )) { @@ -97,6 +103,7 @@ methods are called. } return new wxSizerItem(sizer, proportion, flag, border, data); } + %cleardisown( wxSizer *sizer ); } @@ -121,7 +128,7 @@ of item.", ""); needed by borders.", ""); DocDeclStr( - void , SetDimension( wxPoint pos, wxSize size ), + void , SetDimension( const wxPoint& pos, const wxSize& size ), "Set the position and size of the space allocated for this item by the sizer, and adjust the position and size of the item (window or subsizer) to be within that space taking alignment and borders into @@ -214,9 +221,11 @@ added, if needed.", ""); wxSizer *, GetSizer(), "Get the subsizer (if any) that is managed by this sizer item.", ""); + %disownarg( wxSizer *sizer ); DocDeclStr( void , SetSizer( wxSizer *sizer ), "Set the subsizer to be managed by this sizer item.", ""); + %cleardisown( wxSizer *sizer ); DocDeclStr( @@ -261,6 +270,18 @@ isn't any.", ""); return Py_None; } } + + DocStr(SetUserData, + "Associate a Python object with this sizer item.", ""); + void SetUserData(PyObject* userData) { + wxPyUserData* data = NULL; + if ( userData ) { + wxPyBlock_t blocked = wxPyBeginBlockThreads(); + data = new wxPyUserData(userData); + wxPyEndBlockThreads(blocked); + } + self->SetUserData(data); + } } }; @@ -339,8 +360,8 @@ DocStr(wxSizer, "wx.Sizer is the abstract base class used for laying out subwindows in a window. You cannot use wx.Sizer directly; instead, you will have to use one of the sizer classes derived from it such as `wx.BoxSizer`, -`wx.StaticBoxSizer`, `wx.NotebookSizer`, `wx.GridSizer`, `wx.FlexGridSizer` -and `wx.GridBagSizer`. +`wx.StaticBoxSizer`, `wx.GridSizer`, `wx.FlexGridSizer` and +`wx.GridBagSizer`. The concept implemented by sizers in wxWidgets is closely related to layout tools in other GUI toolkits, such as Java's AWT, the GTK @@ -383,7 +404,8 @@ method to determine where the drawing operations should take place. class wxSizer : public wxObject { public: // wxSizer(); **** abstract, can't instantiate - // ~wxSizer(); + + ~wxSizer(); %extend { void _setOORInfo(PyObject* _self) { @@ -500,6 +522,8 @@ public: wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, true, false); if ( userData && (info.window || info.sizer || info.gotSize) ) data = new wxPyUserData(userData); + if ( info.sizer ) + PyObject_SetAttrString(item,"thisown",Py_False); wxPyEndBlockThreads(blocked); // Now call the real Add method if a valid item type was found @@ -531,6 +555,8 @@ the item at index *before*. See `Add` for a description of the parameters.", "" wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, true, false); if ( userData && (info.window || info.sizer || info.gotSize) ) data = new wxPyUserData(userData); + if ( info.sizer ) + PyObject_SetAttrString(item,"thisown",Py_False); wxPyEndBlockThreads(blocked); // Now call the real Insert method if a valid item type was found @@ -563,6 +589,8 @@ this sizer. See `Add` for a description of the parameters.", ""); wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, true, false); if ( userData && (info.window || info.sizer || info.gotSize) ) data = new wxPyUserData(userData); + if ( info.sizer ) + PyObject_SetAttrString(item,"thisown",Py_False); wxPyEndBlockThreads(blocked); // Now call the real Prepend method if a valid item type was found @@ -681,6 +709,9 @@ the item to be found.", ""); return self._SetItemMinSize(item, args[0]) } + + %disownarg( wxSizerItem *item ); + DocDeclAStrName( wxSizerItem* , Add( wxSizerItem *item ), "AddItem(self, SizerItem item)", @@ -699,6 +730,7 @@ the item to be found.", ""); "Prepends a `wx.SizerItem` to the sizer.", "", PrependItem); + %cleardisown( wxSizerItem *item ); %pythoncode { @@ -910,7 +942,7 @@ subsizer. Returns True if the item was found.", ""); DocAStr(IsShown, "IsShown(self, item)", - "Determines if the item is currently shown. sizer. To make a sizer + "Determines if the item is currently shown. To make a sizer item disappear or reappear, use Show followed by `Layout`. The *item* parameter can be either a window, a sizer, or the zero-based index of the item.", ""); @@ -942,10 +974,6 @@ the item.", ""); void , ShowItems(bool show), "Recursively call `wx.SizerItem.Show` on all sizer items.", ""); - // TODO: - // void Show(bool show); - // bool IsShown(); - }; @@ -1154,6 +1182,25 @@ define extra space between all children.", ""); int , GetHGap(), "Returns the horizontal gap (in pixels) between cells in the sizer.", ""); + %pythoncode { + def CalcRowsCols(self): + """ + CalcRowsCols() -> (rows, cols) + + Calculates how many rows and columns will be in the sizer based + on the current number of items and also the rows, cols specified + in the constructor. + """ + nitems = len(self.GetChildren()) + rows = self.GetRows() + cols = self.GetCols() + assert rows != 0 or cols != 0, "Grid sizer must have either rows or columns fixed" + if cols != 0: + rows = (nitems + cols - 1) / cols + elif rows != 0: + cols = (nitems + rows - 1) / rows + return (rows, cols) + } }; //---------------------------------------------------------------------------