X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7e8f0df9532601e54e7b6bec7c97e2bf2b164bf1..0a5bb138a71dfc1c706fc0858fb2801500e2c2e8:/wxPython/src/_sizers.i?ds=sidebyside diff --git a/wxPython/src/_sizers.i b/wxPython/src/_sizers.i index 4544eac9dc..2b1e26a76c 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 { @@ -56,7 +61,7 @@ methods are called. { wxPyUserData* data = NULL; if ( userData ) { - bool blocked = wxPyBeginBlockThreads(); + wxPyBlock_t blocked = wxPyBeginBlockThreads(); data = new wxPyUserData(userData); wxPyEndBlockThreads(blocked); } @@ -74,7 +79,7 @@ methods are called. { wxPyUserData* data = NULL; if ( userData ) { - bool blocked = wxPyBeginBlockThreads(); + wxPyBlock_t blocked = wxPyBeginBlockThreads(); data = new wxPyUserData(userData); wxPyEndBlockThreads(blocked); } @@ -86,17 +91,19 @@ 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 )) { wxPyUserData* data = NULL; if ( userData ) { - bool blocked = wxPyBeginBlockThreads(); + wxPyBlock_t blocked = wxPyBeginBlockThreads(); data = new wxPyUserData(userData); wxPyEndBlockThreads(blocked); } 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 @@ -145,7 +152,7 @@ added, if needed.", ""); DocStr(SetRatio, "Set the ratio item attribute.", ""); %Rename(SetRatioWH, void, SetRatio( int width, int height )); - %Rename(SetRatioSize, void, SetRatio( wxSize size )); + %Rename(SetRatioSize, void, SetRatio( const wxSize& size )); void SetRatio( float ratio ); DocDeclStr( @@ -214,13 +221,15 @@ 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( - const wxSize& , GetSpacer(), + wxSize , GetSpacer(), "Get the size of the spacer managed by this sizer item.", ""); DocDeclStr( @@ -261,7 +270,33 @@ 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); + } } + + %property(Border, GetBorder, SetBorder, doc="See `GetBorder` and `SetBorder`"); + %property(Flag, GetFlag, SetFlag, doc="See `GetFlag` and `SetFlag`"); + %property(MinSize, GetMinSize, doc="See `GetMinSize`"); + %property(MinSizeWithBorder, GetMinSizeWithBorder, doc="See `GetMinSizeWithBorder`"); + %property(Position, GetPosition, doc="See `GetPosition`"); + %property(Proportion, GetProportion, SetProportion, doc="See `GetProportion` and `SetProportion`"); + %property(Ratio, GetRatio, SetRatio, doc="See `GetRatio` and `SetRatio`"); + %property(Rect, GetRect, doc="See `GetRect`"); + %property(Size, GetSize, doc="See `GetSize`"); + %property(Sizer, GetSizer, SetSizer, doc="See `GetSizer` and `SetSizer`"); + %property(Spacer, GetSpacer, SetSpacer, doc="See `GetSpacer` and `SetSpacer`"); + %property(UserData, GetUserData, SetUserData, doc="See `GetUserData` and `SetUserData`"); + %property(Window, GetWindow, SetWindow, doc="See `GetWindow` and `SetWindow`"); }; @@ -318,14 +353,14 @@ static wxPySizerItemInfo wxPySizerItemTypeHelper(PyObject* item, bool checkSize, if ( !(info.window || info.sizer || (checkSize && info.gotSize) || (checkIdx && info.gotPos)) ) { // no expected type, figure out what kind of error message to generate if ( !checkSize && !checkIdx ) - PyErr_SetString(PyExc_TypeError, "wxWindow or wxSizer expected for item"); + PyErr_SetString(PyExc_TypeError, "wx.Window or wx.Sizer expected for item"); else if ( checkSize && !checkIdx ) - PyErr_SetString(PyExc_TypeError, "wxWindow, wxSizer, wxSize, or (w,h) expected for item"); + PyErr_SetString(PyExc_TypeError, "wx.Window, wx.Sizer, wx.Size, or (w,h) expected for item"); else if ( !checkSize && checkIdx) - PyErr_SetString(PyExc_TypeError, "wxWindow, wxSizer or int (position) expected for item"); + PyErr_SetString(PyExc_TypeError, "wx.Window, wx.Sizer or int (position) expected for item"); else // can this one happen? - PyErr_SetString(PyExc_TypeError, "wxWindow, wxSizer, wxSize, or (w,h) or int (position) expected for item"); + PyErr_SetString(PyExc_TypeError, "wx.Window, wx.Sizer, wx.Size, or (w,h) or int (position) expected for item"); } return info; @@ -339,8 +374,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 @@ -364,6 +399,12 @@ standard font as well as the overall design of Mac widgets requires more space than on Windows, then the initial size of a dialog using a sizer will automatically be bigger on Mac than on Windows.", " +Sizers may also be used to control the layout of custom drawn items on +the window. The `Add`, `Insert`, and `Prepend` functions return a +pointer to the newly added `wx.SizerItem`. Just add empty space of the +desired size and attributes, and then use the `wx.SizerItem.GetRect` +method to determine where the drawing operations should take place. + :note: If you wish to create a custom sizer class in wxPython you should derive the class from `wx.PySizer` in order to get Python-aware capabilities for the various virtual methods. @@ -377,7 +418,8 @@ sizer will automatically be bigger on Mac than on Windows.", " class wxSizer : public wxObject { public: // wxSizer(); **** abstract, can't instantiate - // ~wxSizer(); + + ~wxSizer(); %extend { void _setOORInfo(PyObject* _self) { @@ -450,7 +492,7 @@ public: |- wx.ALL | | | | | +----------------------------+------------------------------------------+ - |- wx.EXAPAND |The item will be expanded to fill | + |- wx.EXPAND |The item will be expanded to fill | | |the space allotted to the item. | +----------------------------+------------------------------------------+ |- wx.SHAPED |The item will be expanded as much as | @@ -490,10 +532,12 @@ public: PyObject* userData=NULL) { wxPyUserData* data = NULL; - bool blocked = wxPyBeginBlockThreads(); + wxPyBlock_t blocked = wxPyBeginBlockThreads(); 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 @@ -521,10 +565,12 @@ the item at index *before*. See `Add` for a description of the parameters.", "" int border=0, PyObject* userData=NULL) { wxPyUserData* data = NULL; - bool blocked = wxPyBeginBlockThreads(); + wxPyBlock_t blocked = wxPyBeginBlockThreads(); 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 @@ -553,10 +599,12 @@ this sizer. See `Add` for a description of the parameters.", ""); PyObject* userData=NULL) { wxPyUserData* data = NULL; - bool blocked = wxPyBeginBlockThreads(); + wxPyBlock_t blocked = wxPyBeginBlockThreads(); 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 @@ -574,6 +622,7 @@ this sizer. See `Add` for a description of the parameters.", ""); // virtual wxSizerItem* PrependSpacer(int size); // virtual wxSizerItem* PrependStretchSpacer(int prop = 1); + DocAStr(Remove, "Remove(self, item) -> bool", "Removes an item from the sizer and destroys it. This method does not @@ -589,7 +638,7 @@ and removed.", " instead. "); bool Remove(PyObject* item) { - bool blocked = wxPyBeginBlockThreads(); + wxPyBlock_t blocked = wxPyBeginBlockThreads(); wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, false, true); wxPyEndBlockThreads(blocked); if ( info.window ) @@ -611,7 +660,7 @@ do so. The *item* parameter can be either a window, a sizer, or the zero-based index of the item to be detached. Returns True if the child item was found and detached.", ""); bool Detach(PyObject* item) { - bool blocked = wxPyBeginBlockThreads(); + wxPyBlock_t blocked = wxPyBeginBlockThreads(); wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, false, true); wxPyEndBlockThreads(blocked); if ( info.window ) @@ -629,9 +678,9 @@ was found and detached.", ""); "GetItem(self, item) -> wx.SizerItem", "Returns the `wx.SizerItem` which holds the *item* given. The *item* parameter can be either a window, a sizer, or the zero-based index of -the item to be detached.", ""); +the item to be found.", ""); wxSizerItem* GetItem(PyObject* item) { - bool blocked = wxPyBeginBlockThreads(); + wxPyBlock_t blocked = wxPyBeginBlockThreads(); wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, false, true); wxPyEndBlockThreads(blocked); if ( info.window ) @@ -646,7 +695,7 @@ the item to be detached.", ""); void _SetItemMinSize(PyObject* item, const wxSize& size) { - bool blocked = wxPyBeginBlockThreads(); + wxPyBlock_t blocked = wxPyBeginBlockThreads(); wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, false, true); wxPyEndBlockThreads(blocked); if ( info.window ) @@ -658,6 +707,48 @@ the item to be detached.", ""); } } + + %Rename(_ReplaceWin, + bool, Replace( wxWindow *oldwin, wxWindow *newwin, bool recursive = false )); + %Rename(_ReplaceSizer, + bool, Replace( wxSizer *oldsz, wxSizer *newsz, bool recursive = false )); + %Rename(_ReplaceItem, + bool, Replace( size_t index, wxSizerItem *newitem )); + %pythoncode { + def Replace(self, olditem, item, recursive=False): + """ + Detaches the given ``olditem`` from the sizer and replaces it with + ``item`` which can be a window, sizer, or `wx.SizerItem`. The + detached child is destroyed only if it is not a window, (because + windows are owned by their parent, not the sizer.) The + ``recursive`` parameter can be used to search for the given + element recursivly in subsizers. + + This method does not cause any layout or resizing to take place, + call `Layout` to do so. + + Returns ``True`` if the child item was found and removed. + """ + if isinstance(olditem, wx.Window): + return self._ReplaceWin(olditem, item, recursive) + elif isinstnace(olditem, wx.Sizer): + return self._ReplaceSizer(olditem, item, recursive) + elif isinstnace(olditem, int): + return self._ReplaceItem(olditem, item) + else: + raise TypeError("Expected Window, Sizer, or integer for first parameter.") + } + + + DocDeclStr( + void , SetContainingWindow(wxWindow *window), + "Set (or unset) the window this sizer is used in.", ""); + + DocDeclStr( + wxWindow *, GetContainingWindow() const, + "Get the window this sizer is used in.", ""); + + %pythoncode { def SetItemMinSize(self, item, *args): """ @@ -675,6 +766,9 @@ the item to be detached.", ""); return self._SetItemMinSize(item, args[0]) } + + %disownarg( wxSizerItem *item ); + DocDeclAStrName( wxSizerItem* , Add( wxSizerItem *item ), "AddItem(self, SizerItem item)", @@ -693,6 +787,7 @@ the item to be detached.", ""); "Prepends a `wx.SizerItem` to the sizer.", "", PrependItem); + %cleardisown( wxSizerItem *item ); %pythoncode { @@ -708,6 +803,50 @@ the item to be detached.", ""); item = (item, ) self.Add(*item) + def AddSpacer(self, *args, **kw): + """AddSpacer(int size) --> SizerItem + + Add a spacer that is (size,size) pixels. + """ + if args and type(args[0]) == int: + return self.Add( (args[0],args[0] ), 0) + else: %# otherwise stay compatible with old AddSpacer + return self.Add(*args, **kw) + def PrependSpacer(self, *args, **kw): + """PrependSpacer(int size) --> SizerItem + + Prepend a spacer that is (size, size) pixels.""" + if args and type(args[0]) == int: + return self.Prepend( (args[0],args[0] ), 0) + else: %# otherwise stay compatible with old PrependSpacer + return self.Prepend(*args, **kw) + def InsertSpacer(self, index, *args, **kw): + """InsertSpacer(int index, int size) --> SizerItem + + Insert a spacer at position index that is (size, size) pixels.""" + if args and type(args[0]) == int: + return self.Insert( index, (args[0],args[0] ), 0) + else: %# otherwise stay compatible with old InsertSpacer + return self.Insert(index, *args, **kw) + + + def AddStretchSpacer(self, prop=1): + """AddStretchSpacer(int prop=1) --> SizerItem + + Add a stretchable spacer.""" + return self.Add((0,0), prop) + def PrependStretchSpacer(self, prop=1): + """PrependStretchSpacer(int prop=1) --> SizerItem + + Prepend a stretchable spacer.""" + return self.Prepend((0,0), prop) + def InsertStretchSpacer(self, index, prop=1): + """InsertStretchSpacer(int index, int prop=1) --> SizerItem + + Insert a stretchable spacer.""" + return self.Insert(index, (0,0), prop) + + %# for backwards compatibility only, please do not use in new code def AddWindow(self, *args, **kw): """Compatibility alias for `Add`.""" @@ -715,9 +854,6 @@ the item to be detached.", ""); def AddSizer(self, *args, **kw): """Compatibility alias for `Add`.""" return self.Add(*args, **kw) - def AddSpacer(self, *args, **kw): - """Compatibility alias for `Add`.""" - return self.Add(*args, **kw) def PrependWindow(self, *args, **kw): """Compatibility alias for `Prepend`.""" @@ -725,9 +861,6 @@ the item to be detached.", ""); def PrependSizer(self, *args, **kw): """Compatibility alias for `Prepend`.""" return self.Prepend(*args, **kw) - def PrependSpacer(self, *args, **kw): - """Compatibility alias for `Prepend`.""" - return self.Prepend(*args, **kw) def InsertWindow(self, *args, **kw): """Compatibility alias for `Insert`.""" @@ -735,9 +868,6 @@ the item to be detached.", ""); def InsertSizer(self, *args, **kw): """Compatibility alias for `Insert`.""" return self.Insert(*args, **kw) - def InsertSpacer(self, *args, **kw): - """Compatibility alias for `Insert`.""" - return self.Insert(*args, **kw) def RemoveWindow(self, *args, **kw): """Compatibility alias for `Remove`.""" @@ -889,7 +1019,7 @@ parameter can be either a window, a sizer, or the zero-based index of the item. Use the recursive parameter to show or hide an item in a subsizer. Returns True if the item was found.", ""); bool Show(PyObject* item, bool show = true, bool recursive=false) { - bool blocked = wxPyBeginBlockThreads(); + wxPyBlock_t blocked = wxPyBeginBlockThreads(); wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, false, true); wxPyEndBlockThreads(blocked); if ( info.window ) @@ -904,12 +1034,12 @@ 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.", ""); bool IsShown(PyObject* item) { - bool blocked = wxPyBeginBlockThreads(); + wxPyBlock_t blocked = wxPyBeginBlockThreads(); wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, false, false); wxPyEndBlockThreads(blocked); if ( info.window ) @@ -926,7 +1056,7 @@ the item.", ""); %pythoncode { def Hide(self, item, recursive=False): """ - A convenience method for Show(item, False, recursive). + A convenience method for `Show` (item, False, recursive). """ return self.Show(item, False, recursive) } @@ -936,6 +1066,11 @@ the item.", ""); void , ShowItems(bool show), "Recursively call `wx.SizerItem.Show` on all sizer items.", ""); + %property(Children, GetChildren, doc="See `GetChildren`"); + %property(ContainingWindow, GetContainingWindow, SetContainingWindow, doc="See `GetContainingWindow` and `SetContainingWindow`"); + %property(MinSize, GetMinSize, SetMinSize, doc="See `GetMinSize` and `SetMinSize`"); + %property(Position, GetPosition, doc="See `GetPosition`"); + %property(Size, GetSize, doc="See `GetSize`"); }; @@ -991,7 +1126,7 @@ When `Layout` is called it first calls `CalcMin` followed by ", ""); class wxPySizer : public wxSizer { public: - %pythonAppend wxPySizer "self._setCallbackInfo(self, PySizer);self._setOORInfo(self)" + %pythonAppend wxPySizer "self._setOORInfo(self);" setCallbackInfo(PySizer) DocCtorStr( wxPySizer(), @@ -1049,6 +1184,7 @@ sizer.", ""); void , SetOrientation(int orient), "Resets the orientation of the sizer.", ""); + %property(Orientation, GetOrientation, SetOrientation, doc="See `GetOrientation` and `SetOrientation`"); }; //--------------------------------------------------------------------------- @@ -1077,6 +1213,7 @@ public: wxStaticBox *, GetStaticBox(), "Returns the static box associated with this sizer.", ""); + %property(StaticBox, GetStaticBox, doc="See `GetStaticBox`"); }; //--------------------------------------------------------------------------- @@ -1144,6 +1281,30 @@ 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) + } + + %property(Cols, GetCols, SetCols, doc="See `GetCols` and `SetCols`"); + %property(HGap, GetHGap, SetHGap, doc="See `GetHGap` and `SetHGap`"); + %property(Rows, GetRows, SetRows, doc="See `GetRows` and `SetRows`"); + %property(VGap, GetVGap, SetVGap, doc="See `GetVGap` and `SetVGap`"); }; //--------------------------------------------------------------------------- @@ -1264,9 +1425,7 @@ previously). Argument *mode* can be one of the following values: growable or not in the flexbile direction. ========================== ================================================= -Note that this method does not trigger relayout. - -", ""); +Note that this method does not trigger relayout.", ""); DocDeclStr( wxFlexSizerGrowMode , GetNonFlexibleGrowMode(), @@ -1289,6 +1448,12 @@ rows in the sizer.", ""); "Returns a list of integers representing the widths of each of the columns in the sizer.", ""); + + %property(ColWidths, GetColWidths, doc="See `GetColWidths`"); + %property(FlexibleDirection, GetFlexibleDirection, SetFlexibleDirection, doc="See `GetFlexibleDirection` and `SetFlexibleDirection`"); + %property(NonFlexibleGrowMode, GetNonFlexibleGrowMode, SetNonFlexibleGrowMode, doc="See `GetNonFlexibleGrowMode` and `SetNonFlexibleGrowMode`"); + %property(RowHeights, GetRowHeights, doc="See `GetRowHeights`"); + }; //--------------------------------------------------------------------------- @@ -1328,6 +1493,12 @@ specifc manner.", ""); wxButton* GetNegativeButton() const; wxButton* GetCancelButton() const; wxButton* GetHelpButton() const; + + %property(AffirmativeButton, GetAffirmativeButton, SetAffirmativeButton, doc="See `GetAffirmativeButton` and `SetAffirmativeButton`"); + %property(ApplyButton, GetApplyButton, doc="See `GetApplyButton`"); + %property(CancelButton, GetCancelButton, SetCancelButton, doc="See `GetCancelButton` and `SetCancelButton`"); + %property(HelpButton, GetHelpButton, doc="See `GetHelpButton`"); + %property(NegativeButton, GetNegativeButton, SetNegativeButton, doc="See `GetNegativeButton` and `SetNegativeButton`"); };