X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/76b8fa1d2077661a6710f532eb141468ab36c1c8..729b47568addbc2cd18378a47cf6010428825f26:/wxPython/src/_sizers.i diff --git a/wxPython/src/_sizers.i b/wxPython/src/_sizers.i index 0648544543..24dab87eed 100644 --- a/wxPython/src/_sizers.i +++ b/wxPython/src/_sizers.i @@ -21,6 +21,155 @@ //--------------------------------------------------------------------------- %newgroup; +DocStr(wxSizerFlags, +"Normally, when you add an item to a sizer via `wx.Sizer.Add`, you have +to specify a lot of flags and parameters which can be unwieldy. This +is where wx.SizerFlags comes in: it allows you to specify all +parameters using the named methods instead. For example, instead of:: + + sizer.Add(ctrl, 0, wx.EXPAND | wx.ALL, 10) + +you can now write:: + + sizer.AddF(ctrl, wx.SizerFlags().Expand().Border(wx.ALL, 10)) + +This is more readable and also allows you to create wx.SizerFlags +objects which can be reused for several sizer items.:: + + flagsExpand = wx.SizerFlags(1) + flagsExpand.Expand().Border(wx.ALL, 10) + sizer.AddF(ctrl1, flagsExpand) + sizer.AddF(ctrl2, flagsExpand) + +Note that by specification, all methods of wx.SizerFlags return the +wx.SizerFlags object itself allowing chaining multiple method calls +like in the examples above.", ""); + +class wxSizerFlags +{ +public: + // construct the flags object initialized with the given proportion (0 by + // default) + DocCtorStr( + wxSizerFlags(int proportion = 0), + "Constructs the flags object with the specified proportion.", ""); + + ~wxSizerFlags(); + + // This typemap ensures that the returned object is the same + // Python instance as what was passed in as `self`, instead of + // creating a new proxy as SWIG would normally do. + %typemap(out) wxSizerFlags& { $result = $self; Py_INCREF($result); } + + DocDeclStr( + wxSizerFlags& , Proportion(int proportion), + "Sets the item's proportion value.", ""); + + DocDeclStr( + wxSizerFlags& , Align(int alignment), + "Sets the item's alignment", ""); + + DocDeclStr( + wxSizerFlags& , Expand(), + "Sets the wx.EXPAND flag, which will cause the item to be expanded to +fill as much space as it is given by the sizer.", ""); + + DocDeclStr( + wxSizerFlags& , Centre(), + "Same as `Center` for those with an alternate dialect of English.", ""); + + DocDeclStr( + wxSizerFlags& , Center(), + "Sets the centering alignment flags.", ""); + + DocDeclStr( + wxSizerFlags& , Left(), + "Aligns the object to the left, a shortcut for calling +Align(wx.ALIGN_LEFT)", ""); + + DocDeclStr( + wxSizerFlags& , Right(), + "Aligns the object to the right, a shortcut for calling +Align(wx.ALIGN_RIGHT)", ""); + + DocDeclStr( + wxSizerFlags& , Top(), + "Aligns the object to the top of the available space, a shortcut for +calling Align(wx.ALIGN_TOP)", ""); + + DocDeclStr( + wxSizerFlags& , Bottom(), + "Aligns the object to the bottom of the available space, a shortcut for +calling Align(wx.ALIGN_BOTTOM)", ""); + + DocDeclStr( + wxSizerFlags& , Shaped(), + "Sets the wx.SHAPED flag.", ""); + + DocDeclStr( + wxSizerFlags& , FixedMinSize(), + "Sets the wx.FIXED_MINSIZE flag.", ""); + + + + %extend { + DocDeclStr( + wxSizerFlags& , Border(int direction=wxALL, int borderInPixels=-1), + "Sets the border of the item in the direction(s) or sides given by the +direction parameter. If the borderInPixels value is not given then +the default border size (see `GetDefaultBorder`) will be used.", "") + { + if (borderInPixels == -1) + return self->Border(direction); + else + return self->Border(direction, borderInPixels); + } + } + + DocDeclStr( + wxSizerFlags& , DoubleBorder(int direction = wxALL), + "Sets the border in the given direction to twice the default border +size.", ""); + + DocDeclStr( + wxSizerFlags& , TripleBorder(int direction = wxALL), + "Sets the border in the given direction to three times the default +border size.", ""); + + DocDeclStr( + wxSizerFlags& , HorzBorder(), + "Sets the left and right borders to the default border size.", ""); + + DocDeclStr( + wxSizerFlags& , DoubleHorzBorder(), + "Sets the left and right borders to twice the default border size.", ""); + + + // Clear the typemap + %typemap(out) wxSizerFlags& ; + + + + DocDeclStr( + static int , GetDefaultBorder(), + "Returns the default border size used by the other border methods", ""); + + + DocDeclStr( + int , GetProportion() const, + "Returns the proportion value to be used in the sizer item.", ""); + + DocDeclStr( + int , GetFlags() const, + "Returns the flags value to be used in the sizer item.", ""); + + DocDeclStr( + int , GetBorderInPixels() const, + "Returns the border value in pixels to be used in the sizer item.", ""); +}; + +//--------------------------------------------------------------------------- + DocStr(wxSizerItem, "The wx.SizerItem class is used to track the position, size and other attributes of each item managed by a `wx.Sizer`. It is not usually @@ -212,30 +361,54 @@ added, if needed.", ""); wxWindow *, GetWindow(), "Get the window (if any) that is managed by this sizer item.", ""); - DocDeclStr( - void , SetWindow( wxWindow *window ), - "Set the window to be managed by this sizer item.", ""); - DocDeclStr( wxSizer *, GetSizer(), "Get the subsizer (if any) that is managed by this sizer item.", ""); + DocDeclStr( + wxSize , GetSpacer(), + "Get the size of the spacer managed by this sizer item.", ""); + + + + + DocDeclStr( + void , SetWindow( wxWindow *window ), + "Set the window to be 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(), - "Get the size of the spacer managed by this sizer item.", ""); + void , SetSpacer( const wxSize &size ), + "Set the size of the spacer to be managed by this sizer item.", ""); + + %pythoncode { + SetWindow = wx._deprecated(SetWindow, "Use `AssignWindow` instead.") + SetSizer = wx._deprecated(SetSizer, "Use `AssignSizer` instead.") + SetSpacer = wx._deprecated(SetSpacer, "Use `AssignSpacer` instead.") + } + + DocDeclStr( - void , SetSpacer( const wxSize &size ), + void , AssignWindow(wxWindow *window), + "Set the window to be managed by this sizer item.", ""); + + DocDeclStr( + void , AssignSizer(wxSizer *sizer), + "Set the subsizer to be managed by this sizer item.", ""); + + DocDeclStr( + void , AssignSpacer(const wxSize& size), "Set the size of the spacer to be managed by this sizer item.", ""); + + DocDeclStr( void , Show( bool show ), @@ -283,6 +456,20 @@ isn't any.", ""); 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, AssignSizer, doc="See `GetSizer` and `AssignSizer`"); + %property(Spacer, GetSpacer, AssignSpacer, doc="See `GetSpacer` and `AssignSpacer`"); + %property(UserData, GetUserData, SetUserData, doc="See `GetUserData` and `SetUserData`"); + %property(Window, GetWindow, AssignWindow, doc="See `GetWindow` and `AssignWindow`"); }; @@ -430,7 +617,7 @@ public: - **sizer**: The (child-)sizer to be added to the sizer. This allows placing a child sizer in a sizer and thus to create - hierarchies of sizers (typically a vertical box as the top + hierarchies of sizers (for example a vertical box as the top sizer and several horizontal boxes on the level beneath). - **size**: A `wx.Size` or a 2-element sequence of integers @@ -538,8 +725,34 @@ public: return NULL; } -// virtual wxSizerItem* AddSpacer(int size); -// virtual wxSizerItem* AddStretchSpacer(int prop = 1); + + DocAStr(AddF, + "AddF(self, item, wx.SizerFlags flags) -> wx.SizerItem", + "Similar to `Add` but uses the `wx.SizerFlags` convenience class for +setting the various flags, options and borders.", ""); + wxSizerItem* AddF(PyObject* item, wxSizerFlags& flags) { + + wxPyBlock_t blocked = wxPyBeginBlockThreads(); + wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, true, false); + if ( info.sizer ) + PyObject_SetAttrString(item,"thisown",Py_False); + wxPyEndBlockThreads(blocked); + + // Now call the real Add method if a valid item type was found + if ( info.window ) + return self->Add(info.window, flags); + else if ( info.sizer ) + return self->Add(info.sizer, flags); + else if (info.gotSize) + return self->Add(info.size.GetWidth(), info.size.GetHeight(), + flags.GetProportion(), + flags.GetFlags(), + flags.GetBorderInPixels()); + else + return NULL; + } + + DocAStr(Insert, "Insert(self, int before, item, int proportion=0, int flag=0, int border=0, @@ -572,8 +785,35 @@ the item at index *before*. See `Add` for a description of the parameters.", "" } -// virtual wxSizerItem* InsertSpacer(size_t index, int size); -// virtual wxSizerItem* InsertStretchSpacer(size_t index, int prop = 1); + + DocAStr(InsertF, + "InsertF(self, int before, item, wx.SizerFlags flags) -> wx.SizerItem", + "Similar to `Insert`, but uses the `wx.SizerFlags` convenience class +for setting the various flags, options and borders.", ""); + wxSizerItem* InsertF(int before, PyObject* item, wxSizerFlags& flags) { + + wxPyBlock_t blocked = wxPyBeginBlockThreads(); + wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, true, false); + if ( info.sizer ) + PyObject_SetAttrString(item,"thisown",Py_False); + wxPyEndBlockThreads(blocked); + + // Now call the real Insert method if a valid item type was found + if ( info.window ) + return self->Insert(before, info.window, flags); + else if ( info.sizer ) + return self->Insert(before, info.sizer, flags); + else if (info.gotSize) + return self->Insert(before, info.size.GetWidth(), info.size.GetHeight(), + flags.GetProportion(), + flags.GetFlags(), + flags.GetBorderInPixels()); + else + return NULL; + } + + + DocAStr(Prepend, "Prepend(self, item, int proportion=0, int flag=0, int border=0, @@ -605,10 +845,36 @@ this sizer. See `Add` for a description of the parameters.", ""); return NULL; } -// virtual wxSizerItem* PrependSpacer(int size); -// virtual wxSizerItem* PrependStretchSpacer(int prop = 1); + DocAStr(PrependF, + "PrependF(self, item, wx.SizerFlags flags) -> wx.SizerItem", + "Similar to `Prepend` but uses the `wx.SizerFlags` convenience class +for setting the various flags, options and borders.", ""); + wxSizerItem* PrependF(PyObject* item, wxSizerFlags& flags) { + + wxPyBlock_t blocked = wxPyBeginBlockThreads(); + wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, true, false); + if ( info.sizer ) + PyObject_SetAttrString(item,"thisown",Py_False); + wxPyEndBlockThreads(blocked); + + // Now call the real Add method if a valid item type was found + if ( info.window ) + return self->Prepend(info.window, flags); + else if ( info.sizer ) + return self->Prepend(info.sizer, flags); + else if (info.gotSize) + return self->Prepend(info.size.GetWidth(), info.size.GetHeight(), + flags.GetProportion(), + flags.GetFlags(), + flags.GetBorderInPixels()); + else + return NULL; + } + + + DocAStr(Remove, "Remove(self, item) -> bool", "Removes an item from the sizer and destroys it. This method does not @@ -628,7 +894,7 @@ and removed.", " wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, false, true); wxPyEndBlockThreads(blocked); if ( info.window ) - return self->Remove(info.window); + return false; //self->Remove(info.window); else if ( info.sizer ) return self->Remove(info.sizer); else if ( info.gotPos ) @@ -661,18 +927,18 @@ was found and detached.", ""); DocAStr(GetItem, - "GetItem(self, item) -> wx.SizerItem", + "GetItem(self, item, recursive=False) -> 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 found.", ""); - wxSizerItem* GetItem(PyObject* item) { + wxSizerItem* GetItem(PyObject* item, bool recursive=false) { wxPyBlock_t blocked = wxPyBeginBlockThreads(); wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, false, true); wxPyEndBlockThreads(blocked); if ( info.window ) - return self->GetItem(info.window); + return self->GetItem(info.window, recursive); else if ( info.sizer ) - return self->GetItem(info.sizer); + return self->GetItem(info.sizer, recursive); else if ( info.gotPos ) return self->GetItem(info.pos); else @@ -717,9 +983,9 @@ the item to be found.", ""); """ if isinstance(olditem, wx.Window): return self._ReplaceWin(olditem, item, recursive) - elif isinstnace(olditem, wx.Sizer): + elif isinstance(olditem, wx.Sizer): return self._ReplaceSizer(olditem, item, recursive) - elif isinstnace(olditem, int): + elif isinstance(olditem, int): return self._ReplaceItem(olditem, item) else: raise TypeError("Expected Window, Sizer, or integer for first parameter.") @@ -789,6 +1055,50 @@ the item to be found.", ""); 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`.""" @@ -796,9 +1106,6 @@ the item to be found.", ""); 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`.""" @@ -806,9 +1113,6 @@ the item to be found.", ""); 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`.""" @@ -816,9 +1120,6 @@ the item to be found.", ""); 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`.""" @@ -1017,6 +1318,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`"); }; @@ -1072,7 +1378,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(), @@ -1130,6 +1436,8 @@ sizer.", ""); void , SetOrientation(int orient), "Resets the orientation of the sizer.", ""); + bool IsVertical() const; + %property(Orientation, GetOrientation, SetOrientation, doc="See `GetOrientation` and `SetOrientation`"); }; @@ -1159,6 +1467,7 @@ public: wxStaticBox *, GetStaticBox(), "Returns the static box associated with this sizer.", ""); + %property(StaticBox, GetStaticBox, doc="See `GetStaticBox`"); }; //--------------------------------------------------------------------------- @@ -1438,6 +1747,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`"); };