]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/src/_sizers.i
Comment why we don't call PyErr_Print after calling OnInit
[wxWidgets.git] / wxPython / src / _sizers.i
index 04fa9fed834ca470c3c1eb1c63c6b2e2e0cbb722..ad359886486cdddbd25042d48662ae5563975531 100644 (file)
 
 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`", "");
 
@@ -357,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
@@ -605,6 +608,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
@@ -689,6 +693,48 @@ the item to be found.", "");
         }
     }
 
+    
+    %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):
         """
@@ -939,7 +985,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.", "");
@@ -971,10 +1017,6 @@ the item.", "");
         void , ShowItems(bool show),
         "Recursively call `wx.SizerItem.Show` on all sizer items.", "");
 
-    // TODO:
-    //          void Show(bool show);
-    //          bool IsShown();
-    
 };
 
 
@@ -1088,6 +1130,7 @@ sizer.", "");
         void , SetOrientation(int orient),
         "Resets the orientation of the sizer.", "");
 
+    %property(Orientation, GetOrientation, SetOrientation, doc="See `GetOrientation` and `SetOrientation`");
 };
 
 //---------------------------------------------------------------------------
@@ -1183,6 +1226,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)
+    }
 };
 
 //---------------------------------------------------------------------------
@@ -1303,9 +1365,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(),
@@ -1328,6 +1388,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`");
+    
 };
 
 //---------------------------------------------------------------------------