]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/wxaddons/sized_controls.py
Upport scrolling changes and mouse wheel changes.
[wxWidgets.git] / wxPython / wxaddons / sized_controls.py
index 67a839fa09c1d0e3bfab5e5045a90f5203324ebd..4123752042807adc445f7ac77a0eb5a5efeab4ee 100644 (file)
@@ -330,7 +330,8 @@ def GetSizerProps(self):
 def SetSizerProp(self, prop, value):
     
     lprop = prop.lower()
-    item = self.GetParent().GetSizer().GetItem(self) 
+    sizer = self.GetParent().GetSizer()
+    item = sizer.GetItem(self) 
     flag = item.GetFlag()
     if lprop == "proportion":
         item.SetProportion(int(value))
@@ -359,6 +360,27 @@ def SetSizerProp(self, prop, value):
             flag = flag &~ misc_flags[lprop]
         else:
             flag = flag | misc_flags[lprop]
+    
+    # auto-adjust growable rows/columns if expand or proportion is set
+    # on a sizer item in a FlexGridSizer
+    if lprop in ["expand", "proportion"] and isinstance(sizer, wx.FlexGridSizer):
+        cols = sizer.GetCols()
+        rows = sizer.GetRows()
+        # FIXME: I'd like to get the item index in the sizer instead, but
+        # doing sizer.GetChildren.index(item) always gives an error
+        itemnum = self.GetParent().GetChildren().index(self)
+                
+        col = 0
+        row = 0
+        if cols == 0:
+            col, row = divmod( itemnum, rows )
+        else:
+            row, col = divmod( itemnum, cols )
+        
+        if lprop == "expand":
+            sizer.AddGrowableCol(col)
+        elif lprop == "proportion" and int(value) != 0:
+            sizer.AddGrowableRow(row)
 
     item.SetFlag(flag)
 
@@ -435,10 +457,21 @@ class SizedPanel(wx.PyPanel):
         self.sizerType = "vertical"
         
     def AddChild(self, child):
-        wx.PyPanel.base_AddChild(self, child)
-        
+        if wx.VERSION < (2,8):
+            wx.PyPanel.base_AddChild(self, child)
+        else:
+            wx.PyPanel.AddChild(self, child)
+
+        # Note: The wx.LogNull is used here to suppress a log message
+        # on wxMSW that happens because when AddChild is called the
+        # widget's hwnd hasn't been set yet, so the GetWindowRect that
+        # happens as a result of sizer.Add (in wxSizerItem::SetWindow)
+        # fails.  A better fix would be to defer this code somehow
+        # until after the child widget is fully constructed.
         sizer = self.GetSizer()
+        nolog = wx.LogNull()
         item = sizer.Add(child)
+        del nolog
         item.SetUserData({"HGrow":0, "VGrow":0})
         
         # Note: One problem is that the child class given to AddChild
@@ -462,7 +495,7 @@ class SizedPanel(wx.PyPanel):
         elif type == "form":
             #sizer = TableSizer(2, 0)
             sizer = wx.FlexGridSizer(0, 2, 0, 0)
-            sizer.AddGrowableCol(1)
+            #sizer.AddGrowableCol(1)
             
         elif type == "table":
             rows = cols = 0
@@ -554,4 +587,4 @@ class SizedFrame(wx.Frame):
         self.SetAutoLayout(True)
         
     def GetContentsPane(self):
-        return self.mainPanel
\ No newline at end of file
+        return self.mainPanel