commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnue] r9996 - trunk/gnue-forms/src/uidrivers/wx26/widgets


From: reinhard
Subject: [gnue] r9996 - trunk/gnue-forms/src/uidrivers/wx26/widgets
Date: Thu, 22 Oct 2009 17:48:06 -0500 (CDT)

Author: reinhard
Date: 2009-10-22 17:48:06 -0500 (Thu, 22 Oct 2009)
New Revision: 9996

Modified:
   trunk/gnue-forms/src/uidrivers/wx26/widgets/grid.py
Log:
Reworked grid resize magic.


Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/grid.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/grid.py 2009-10-22 18:22:44 UTC 
(rev 9995)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/grid.py 2009-10-22 22:48:06 UTC 
(rev 9996)
@@ -64,31 +64,57 @@
         @param event: the creation-event instance carrying information like
             container (parent-widget)
         @param spacer: not used for grid tags
-
-        @returns: the wx.GridBagSizer instance used for adding the rows
         """
 
         owner  = self.getParent()
         parent = event.container
 
+        # We need a little hack here: When the user enlarges the form, we want
+        # the grid to add more lines.  That's easy.  However, when the user
+        # makes the form smaller again, we want those extra grid lines to
+        # disappear again.  Unfortunately, the extra grid lines will define the
+        # minimum size for the whole grid, so the sizers will never reduce the
+        # size of the grid below what the current number of lines need, and we
+        # will never even notice that we should reduce the number of lines.
+        # Our hack: The grid, together with a small 3 pixel high panel is
+        # placed on a vertical sizer.  The grid is not resizable, but the panel
+        # is.  Now if the panel grows smaller than 3 pixel, we need to remove a
+        # grid line.
+        # The size of the panel is chosen with 3 pixel so it can double as the
+        # lower border of the grid.
+
         # The base panel for the grid control
-        self.widget = wx.Panel(parent, -1) # , style=wx.SUNKEN_BORDER)
+        self.widget = wx.Panel(parent, -1)
         self.widget.Bind(wx.EVT_SIZE, self.__on_size)
         self.widget.Bind(wx.EVT_MOUSEWHEEL, self.__on_mousewheel)
 
+        # The outer sizer: a vertical sizer containing the grid and the small 3
+        # pixel panel.
+        outer = wx.BoxSizer(wx.VERTICAL)
+        self.widget.SetSizer(outer)
+
+        # The inner sizer: a horizontal sizer containing the grid to the left
+        # and the scroll bar to the right.
         inner = wx.BoxSizer(wx.HORIZONTAL)
-        self.widget.SetSizer(inner)
+        outer.Add(inner, 0, wx.EXPAND)
 
+        # The actual grid.
         self._container = wx.Panel(self.widget, -1)
         self._container.SetSizer(wx.GridBagSizer())
+        inner.Add(self._container, 1, wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, 
3)
 
-        inner.Add(self._container, 1, wx.EXPAND | wx.ALL, 3)
-
+        # The scroll bar.
         self.scroll = wx.ScrollBar(self.widget, -1, style=wx.SB_VERTICAL)
-        inner.Add(self.scroll, 0, wx.EXPAND | wx.TOP | wx.BOTTOM, 3)
-
         self.scroll.Bind(wx.EVT_SCROLL, self.__on_scroll)
+        inner.Add(self.scroll, 0, wx.EXPAND | wx.TOP, 3)
 
+        # The small 3 pixel panel that doubles as the lower border.  We have to
+        # reset the min size to 0 later (in update_size_hints) *after* the form
+        # has been initially layouted, so the panel starts with 3 pixel height
+        # in the initial layout.
+        self.__spacer = wx.Panel(self.widget, -1, size=(0, 3))
+        outer.Add(self.__spacer, 1, wx.EXPAND)
+
         self.__max = self._gfObject.rows
         self.__visible = self.__max
 
@@ -156,25 +182,19 @@
         self._uiForm.sizing_enabled = False
 
         try:
-            height = self.widget.GetContainingSizer().GetSize()[1]
+            free_height = self.__spacer.GetSize()[1] - 3
 
-            rech = 0
+            rec_height = 0
             for item in self._children:
-                rech += max([panel.GetBestSize()[1] \
-                        for panel in item._columns[0]])
+                rec_height += max([panel.GetBestSize()[1] \
+                    for panel in item._columns[0]])
 
-            hd_height = self._container.GetSizer().GetCellSize(0, 0)[1]
-            available = height - hd_height
-            num_recs = int(available / float(rech))
-            num_recs = (height - hd_height) / rech
-
-            # Get the diff
-            if num_recs > self.__visible:
-                self.__add_new_records(num_recs - self.__visible)
+            if free_height >= rec_height:
+                self.__add_new_records(free_height / rec_height)
                 self._gfObject._event_rows_changed(self.__visible)
 
-            elif num_recs < self.__visible:
-                self.__hide_records(self.__visible - num_recs)
+            elif free_height < 0:
+                self.__hide_records(1)
                 self._gfObject._event_rows_changed(self.__visible)
 
         finally:
@@ -254,6 +274,8 @@
     def __hide_records(self, num_recs):
 
         for index in range(num_recs):
+            if self.__visible == 1:
+                break
             self.__change_visibility(self.__visible-1, False)
             self.__visible -= 1
 
@@ -261,6 +283,15 @@
 
 
     # -------------------------------------------------------------------------
+    # Change our spacer to be allowed to be reduced to 0
+    # -------------------------------------------------------------------------
+
+    def update_size_hints(self):
+
+        self.__spacer.SetMinSize((0, 0))
+
+
+    # -------------------------------------------------------------------------
     # Adjust scrollbar if the current record has changed
     # -------------------------------------------------------------------------
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]