commit-gnue
[Top][All Lists]
Advanced

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

[gnue] r9141 - trunk/gnue-forms/src/uidrivers/curses/widgets


From: johannes
Subject: [gnue] r9141 - trunk/gnue-forms/src/uidrivers/curses/widgets
Date: Tue, 12 Dec 2006 08:58:02 -0600 (CST)

Author: johannes
Date: 2006-12-12 08:58:01 -0600 (Tue, 12 Dec 2006)
New Revision: 9141

Modified:
   trunk/gnue-forms/src/uidrivers/curses/widgets/_base.py
   trunk/gnue-forms/src/uidrivers/curses/widgets/button.py
   trunk/gnue-forms/src/uidrivers/curses/widgets/entry.py
   trunk/gnue-forms/src/uidrivers/curses/widgets/form.py
   trunk/gnue-forms/src/uidrivers/curses/widgets/hbox.py
   trunk/gnue-forms/src/uidrivers/curses/widgets/page.py
   trunk/gnue-forms/src/uidrivers/curses/widgets/vbox.py
Log:
Improving the layout management


Modified: trunk/gnue-forms/src/uidrivers/curses/widgets/_base.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/curses/widgets/_base.py      2006-12-12 
14:55:34 UTC (rev 9140)
+++ trunk/gnue-forms/src/uidrivers/curses/widgets/_base.py      2006-12-12 
14:58:01 UTC (rev 9141)
@@ -25,7 +25,7 @@
 
 from gnue.forms.uidrivers._base.widgets._base import UIWidget
 
-__all__ = ['UIHelper', 'box']
+__all__ = ['UIHelper', 'box', 'ManagedBoxMixin']
 
 # =============================================================================
 # Widget helper class
@@ -69,6 +69,7 @@
             result = parent.ready()
         else:
             result = False
+
         return result
 
     # -------------------------------------------------------------------------
@@ -123,13 +124,16 @@
     # Get the minimum size of a widget
     # -------------------------------------------------------------------------
 
-    def get_size_hints(self):
+    def get_size_hints(self, vertical=None):
         """
         Returns the minimal space needed by a widget as well as it's proportion
         within it's container and the size of it's label (if any).  For a
         positioned layout this is always the width and height specified in the
         GFD file.  Descendants will likely override this method.
 
+        @param vertical: if True, the widget is used in a vertical context,
+            otherwise in a horizontal.
+
         @returns: tuple (min-width, min-height, label-width, proportion)
         """
 
@@ -150,6 +154,7 @@
         self.width = width
         self.height = height
 
+
     # -------------------------------------------------------------------------
     # Properties
     # -------------------------------------------------------------------------
@@ -165,6 +170,264 @@
 
 
 # =============================================================================
+# Base class for managed boxes
+# =============================================================================
+
+class ManagedBox(UIHelper):
+    """
+    This class provides the basic algorithms for layout management in curses.
+
+    @cvar vertical: if True, the box is treated as a vertical container,
+        otherwise as a horizontal one
+    @cvar _hints_: dictionary with the size hints of the container's children
+        using the child-index (into self._children) as key
+    """
+
+    vertical = True
+    _hints_ = {}
+
+    # -------------------------------------------------------------------------
+    # Order the size hints according to their proportion
+    # -------------------------------------------------------------------------
+
+    def order_size_hints(self, hints):
+        """
+        Order the size hints according to their proportion starting with the
+        biggest one.
+
+        @param hints: dictionary with the size hints, where the child-index is
+            used as key
+
+        @returns: tuple with the ordered size hints and the minimum space
+            required (in the requested direction).  Each item of the ordered
+            sequence consists of a tuple (proportion, child-index).
+        """
+
+        result = []
+        needed = 0
+
+        for key, (minw, minh, label, proportion) in hints.items():
+            result.append((proportion, key))
+            if self.vertical:
+                needed += minh
+            else:
+                needed += minw
+
+        # Make sure to have the gap (space) between widgets also available
+        if not self.vertical:
+            needed += (len(result) - 1)
+            needed += self._horizontal_offset_()
+
+        result.sort()
+        result.reverse()
+
+        return result, needed
+
+
+    # -------------------------------------------------------------------------
+    # Get the minimum space required by this box
+    # -------------------------------------------------------------------------
+
+    def get_size_hints(self, vertical=None):
+        """
+        Returns the minimum space needed by this managed container.  As a side
+        effect this method populates the size-hints dictionary (_hints_).
+
+        @returns: tuple of (min. width, min. height, widest label, proportion)
+        """
+
+        self._hints_ = {}
+        for (index, child) in enumerate(self._children):
+            self._hints_[index] = child.get_size_hints(self.vertical)
+
+        if not self._hints_:
+            return (2, 2, 0, 0)
+
+        hints = self._hints_.values()
+
+        minh = sum([i[1] for i in hints])
+        prop = sum([i[3] for i in hints])
+
+        if self.vertical:
+            mx_label = max([i[2] for i in hints])
+            # min. width: space + widest label + space + widest widget + space
+            minw = mx_label + max([i[0] for i in hints]) + 3
+        else:
+            # min. width: space + max(widget/label) + space + ... + space
+            minw = sum([max(i[0], i[2]) for i in hints]) + len(hints) + 1
+
+        # If a box has a label we have to add the border to the minimum space
+        (decw, dech) = self._decoration_size_()
+        minw += decw
+        minh += dech
+
+        return (minw, minh, 0, prop)
+
+
+    # -------------------------------------------------------------------------
+    # Set the size of a box and arrange it's children
+    # -------------------------------------------------------------------------
+
+    def set_size_and_fit(self, width, height):
+        """
+        Set the size of a managed container and layout it's child widgets
+        according to this space.
+        """
+
+        self.width = width
+        self.height = height
+
+        (decw, dech) = self._decoration_size_()
+
+        (ordered, needed) = self.order_size_hints(self._hints_)
+        if self.vertical:
+            available = self.height - dech - needed
+        else:
+            available = self.width - decw - needed
+
+        # Distribute available space among the stretchable children
+        self._sizes_ = {}
+        sum_prop = sum([i[3] for i in self._hints_.values()]) or 1
+        max_label= max([i[2] for i in self._hints_.values()])
+
+        for (i, index) in ordered:
+            (minw, current_h, label, proportion) = self._hints_[index]
+
+            if self.vertical:
+                current_w = self.width - decw - self._horizontal_offset_()
+                if max_label:
+                    current_w -= (max_label + 1)
+            else:
+                current_w = max(minw, label)
+
+            if proportion and available:
+                add = min(int(available / sum_prop * proportion), available)
+                available -= add
+                if self.vertical:
+                    current_h += add
+                else:
+                    current_w += add
+
+            self._sizes_[index] = (current_w, current_h)
+
+        # If some of the available space is left, add it to the widget with the
+        # biggest proportion
+        if available and ordered:
+            index = ordered[0][1]
+            (cwidth, cheight) = self._sizes_[index]
+
+            if self.vertical:
+                cheight += available
+            else:
+                cwidth += available
+            self._sizes_[index] = (cwidth, cheight)
+
+        # Layout the children
+        self._add_decoration_()
+
+        last_x, last_y = self._get_upper_left_()
+
+        for (index, child) in enumerate(self._children):
+            cwidth, cheight = self._sizes_[index]
+
+            (inc_w, inc_h) = self._add_child_(child, index, last_x, last_y)
+            last_x += inc_w
+            last_y += inc_h
+
+            child.set_size_and_fit(cwidth, cheight)
+
+
+    # -------------------------------------------------------------------------
+    # Virtual methods
+    # -------------------------------------------------------------------------
+
+    def _decoration_size_(self):
+        """
+        Get the size for decorations (i.e. border) needed by this object.
+        Descendants might override this method.
+
+        @returns: tuple with (width, height) of the decoration
+        """
+        return (0, 0)
+
+    # -------------------------------------------------------------------------
+
+    def _add_decoration_(self):
+        """
+        Add the decoration (i.e. border) to the box
+        """
+        pass
+
+    # -------------------------------------------------------------------------
+
+    def _vertical_offset_(self):
+        """
+        Return the vertical offset of a child widget from the top left corner.
+        Descendants might override this method to take decorations into
+        account.
+        """
+        return 0
+
+    # -------------------------------------------------------------------------
+
+    def _horizontal_offset_(self):
+        """
+        Return the horizontal offset of a child widget from the top left
+        corner.  Descendants might override this method to take decorations
+        into account.
+        """
+        return 0
+
+    # -------------------------------------------------------------------------
+
+    def _get_upper_left_(self):
+        """
+        Return the upper left corner of this widget within it's parent.  This
+        provides a mapping between the logical coordinate 0/0 within the widget
+        and the outside world.
+
+        @returns: tuple (x, y)
+        """
+        return (self.left, self.top)
+
+    # -------------------------------------------------------------------------
+
+    def _add_child_(self, child, index, last_x, last_y):
+        """
+        Add a child widget to the managed box
+        """
+
+        cwidth, cheight = self._sizes_[index]
+        max_label= max([i[2] for i in self._hints_.values()])
+
+        if self.vertical:
+            child.left = self.left + self._horizontal_offset_() + max_label + 1
+            child.top = last_y + self._vertical_offset_()
+
+            result = (0, cheight)
+        else:
+            child.top = self.top + self._vertical_offset_() + 1
+            child.left = last_x + self._horizontal_offset_()
+
+            result = (cwidth + 1, 0)
+
+        label = getattr(child._gfObject, 'label', None)
+        if label and self._hints_[index][2]:
+            attr = self._uiDriver.attr['background']
+
+            if self.vertical:
+                left = self.left + self._horizontal_offset_()
+                top  = child.top
+            else:
+                left = child.left
+                top  = self.top + self._vertical_offset_()
+
+            self._parent.write(left, top, label, attr)
+
+        return result
+
+
+# =============================================================================
 # Draw a box on a given parent
 # =============================================================================
 

Modified: trunk/gnue-forms/src/uidrivers/curses/widgets/button.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/curses/widgets/button.py     2006-12-12 
14:55:34 UTC (rev 9140)
+++ trunk/gnue-forms/src/uidrivers/curses/widgets/button.py     2006-12-12 
14:58:01 UTC (rev 9141)
@@ -105,7 +105,7 @@
         else:
             UIHelper._keypress(self, key)
 
-    def get_size_hints(self):
+    def get_size_hints(self, vertical=None):
 
         return (self.min_width or 20, 1, 0, 0)
 

Modified: trunk/gnue-forms/src/uidrivers/curses/widgets/entry.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/curses/widgets/entry.py      2006-12-12 
14:55:34 UTC (rev 9140)
+++ trunk/gnue-forms/src/uidrivers/curses/widgets/entry.py      2006-12-12 
14:58:01 UTC (rev 9141)
@@ -476,24 +476,22 @@
     # Get the size hints for an entry
     # -------------------------------------------------------------------------
 
-    def get_size_hints(self):
+    def get_size_hints(self, vertical=None):
 
         label = ''
         if self.__style != 'checkbox':
             label = getattr(self._gfObject, 'label', '')
 
-        stretch = self.stretch
         # Only stretch entries if they're in a horizontal container or if they
         # are multiline edits
-        if self.getParent()._gfObject._type in ['GFVBox', 'GFPage']:
-            if not self.__is_multiline:
-                stretch = 0
+        if not vertical or self.__is_multiline:
+            stretch = self.stretch
+        else:
+            stretch = 0
 
-        result = (self.min_width or 20, self.min_height or 1, len(label),
-                stretch)
-        gLeave(2, result)
-        return result
+        return (self.min_width or 20, self.min_height or 1, len(label), 
stretch)
 
+
 # =============================================================================
 # Configuration data
 # =============================================================================

Modified: trunk/gnue-forms/src/uidrivers/curses/widgets/form.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/curses/widgets/form.py       2006-12-12 
14:55:34 UTC (rev 9140)
+++ trunk/gnue-forms/src/uidrivers/curses/widgets/form.py       2006-12-12 
14:58:01 UTC (rev 9141)
@@ -41,7 +41,6 @@
 
     def __init__(self, event):
 
-        gDebug(2, "Base is %s" % UIHelper)
         UIHelper.__init__(self, event)
 
         self.__pages = []
@@ -63,7 +62,6 @@
 
     def _create_widget_(self, event, spacer):
 
-        gDebug(2, "creating form widget: %s" % self.managed)
         self.__window = None
         self._container = self
 
@@ -74,7 +72,6 @@
 
     def _container_is_ready_(self):
 
-        gEnter(2)
         return self.__window is not None
 
 
@@ -195,13 +192,10 @@
 
     def get_canvas(self):
 
-        gEnter(2)
         if self.ready():
-            gDebug(2, "Ready for action!")
             (y, x) = self.__window.getmaxyx()
             return (0, 2, x, y - 2)
         else:
-            gDebug(2, "not ready yet")
             return None
 
     # -------------------------------------------------------------------------
@@ -297,10 +291,9 @@
             child.top = top
             child.set_size_and_fit(right-left, bottom-top)
 
-        gDebug(2, "creating windows for form-widget")
-
         self.__update_page_list()
         self.__update_status_bar()
+
         self._uiDriver._focus_widget._ui_set_focus_(0)
 
 

Modified: trunk/gnue-forms/src/uidrivers/curses/widgets/hbox.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/curses/widgets/hbox.py       2006-12-12 
14:55:34 UTC (rev 9140)
+++ trunk/gnue-forms/src/uidrivers/curses/widgets/hbox.py       2006-12-12 
14:58:01 UTC (rev 9141)
@@ -23,7 +23,7 @@
 
 import curses
 
-from _base import UIHelper, box
+from _base import ManagedBox, box
 
 __all__ = ['UIHBox']
 
@@ -31,117 +31,56 @@
 # VBox class
 # =============================================================================
 
-class UIHBox(UIHelper):
+class UIHBox(ManagedBox):
 
+    vertical = False
+
     def _create_widget_(self, event, spacer):
 
-        UIHelper._create_widget_(self, event, spacer)
+        ManagedBox._create_widget_(self, event, spacer)
         self._parent = event.container
         self._container = self._parent
 
 
-    def set_size_and_fit(self, width, height):
+    # -------------------------------------------------------------------------
+    # Virtual methods
+    # -------------------------------------------------------------------------
 
-        self.width = width
-        self.height = height
+    def _decoration_size_(self):
 
-        gDebug(2, "Size for hbox: %s/%s %s/%s %s/%s" % (self.width,
-            self.height, self.left, self.top, self.right, self.bottom))
+        if self._gfObject.label:
+            return (2, 2)
+        else:
+            return (0, 0)
 
-        attr = self._uiDriver.attr['background']
+    # -------------------------------------------------------------------------
 
+    def _add_decoration_(self):
+
         if self._gfObject.label:
+            attr = self._uiDriver.attr['background']
             box(self._parent, attr, self.left, self.top, self.right,
                     self.bottom, self._gfObject.label)
-            self.width -= 2
-            self.height -= 2
 
-        hints = {}
-        for (index, child) in enumerate(self._children):
-            hints[index] = child.get_size_hints()
+    # -------------------------------------------------------------------------
 
-        # Total of the stretching (proportion)
-        sum_sx = float(sum([i[3] for i in hints.values()]))
+    def _vertical_offset_(self):
 
-        # Reorder the list of size-hints starting with the highest
-        # stretching factor
-        needed = 0
-        ordered = []
-        for key, (minw, minh, label, propx) in hints.items():
-            ordered.append((propx, key))
-            needed += minw
-        ordered.sort()
-        ordered.reverse()
+        if self._gfObject.label:
+            return 1
+        else:
+            return 0
 
-        # Now let's have a look how much space is left if all children have
-        # used up their minimum width
-        available = self.width - needed
-
-        gDebug(2, "Ordered: w=%s n=%s a=%s o=%s" % (self.width, needed, 
available,
-            ordered))
-
-        # First assign the minimum space required to each child
-        sizes = {}
-        for (propx, index) in ordered:
-            child = self._children[index]
-
-            (minw, minh, label, propx) = hints[index]
-
-            current_w = max(minw, label)
-            current_h = minh
-
-            if propx and available:
-                add = int(available / sum_sx * propx)
-                current_w += add
-                available -= add
-                gDebug(2, "Adding %s to %s" % (add, child._gfObject.name))
-            else:
-                gDebug(2, "Propx: %s, av: %s" % (propx, available))
-
-            sizes[index] = (current_w, current_h)
-
-        last_x = self.left + 1
-        for (index, child) in enumerate(self._children):
-            cwidth, cheight = sizes[index]
-            child.left = last_x
-            child.top = self.top + 2
-            last_x += cwidth
-
-            gDebug(2, "Child %s: %x/%s" % (child._gfObject.name, child.left,
-                child.top))
-            # If there's a label, add it to the parent's window
-            if hints[index][2]:
-                attr = self._uiDriver.attr['background']
-                self._parent.write(child.left, child.top-1,
-                        child._gfObject.label, attr)
-            child.set_size_and_fit(cwidth, cheight)
-
-
-
     # -------------------------------------------------------------------------
-    # Get the size hints for the vbox
-    # -------------------------------------------------------------------------
 
-    def get_size_hints(self):
+    def _horizontal_offset_(self):
 
-        hints = []
-        for child in self._children:
-            hints.append(child.get_size_hints())
-
-        if hints:
-            minw = max([i[0] for i in hints]) + 3
-            minh = sum([i[1] for i in hints]) + 2
-            prop = sum([i[3] for i in hints])
+        if self._gfObject.label:
+            return 2
         else:
-            minw = minh = 2 
-            prop = 0
+            return 0
 
-        gDebug(2, "min: %s %s %s %s" % (minw, minh, 1, prop))
 
-        return (minw, minh, 1, prop)
-
-
-
 # =============================================================================
 # Configuration data
 # =============================================================================

Modified: trunk/gnue-forms/src/uidrivers/curses/widgets/page.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/curses/widgets/page.py       2006-12-12 
14:55:34 UTC (rev 9140)
+++ trunk/gnue-forms/src/uidrivers/curses/widgets/page.py       2006-12-12 
14:58:01 UTC (rev 9141)
@@ -24,20 +24,24 @@
 import curses
 
 from gnue.common.apps import i18n
-from _base import UIHelper
+from _base import ManagedBox
 
 # =============================================================================
 # Page class
 # =============================================================================
 
-class UIPage(UIHelper):
+class UIPage(ManagedBox):
 
+    vertical = True
+
     # -------------------------------------------------------------------------
     # Initialize page
     # -------------------------------------------------------------------------
 
     def _create_widget_(self, event, spacer):
 
+        ManagedBox._create_widget_(self, event, spacer)
+
         caption = getattr(self._gfObject, 'caption', None) or \
                 self._gfObject.name
 
@@ -45,7 +49,6 @@
         self.__cursor = (0, 0)
         self._container = self
 
-        self._parent = event.container
         event.parent.add_page(self, caption)
 
 
@@ -66,78 +69,20 @@
 
         self.width = width
         self.height = height
-
-        gDebug(2, "Size of Page: %s/%s at %s/%s %s/%s" % \
-                (width, height, self.left, self.top, self.right, self.bottom))
-
-        self.__window = curses.newpad(height, width)
-        self.__window.keypad(1)
-        self.__window.bkgd(' ', self._uiDriver.attr['background'])
-
+        
         if not self.managed:
+            self._add_decoration_()
+
             for child in self._children:
                 child.left = child.chr_x
                 child.top = child.chr_y
 
                 child.set_size_and_fit(child.chr_w, child.chr_h)
         else:
-            # Note: a page is an implicit vbox, so all it's childrens are lined
-            # up vertically
+            self.get_size_hints(True)
+            ManagedBox.set_size_and_fit(self, width, height)
 
-            hints = {}
-            for (index, child) in enumerate(self._children):
-                hints[index] = child.get_size_hints()
 
-            # Total of the stretching (proportion)
-            sum_sy = float(sum([i[3] for i in hints.values()]))
-
-            # Reorder the list of size-hints starting with the highest
-            # stretching factor (vertical)
-            needed = 0
-            ordered = []
-            for key, (minw, minh, label, stretch) in hints.items():
-                ordered.append((stretch, key))
-                needed += minh
-            ordered.sort()
-            ordered.reverse()
-
-            # Now let's have a look how much space is left if all children have
-            # used up their minimum height
-            available = height - needed
-
-            gDebug(2, "Ordered: %s/%s: %s" % (needed, available, ordered))
-
-            # First assign the minimum space required to each child
-            sizes = {}
-            for (propy, index) in ordered:
-                child = self._children[index]
-
-                (minw, minh, label, propy) = hints[index]
-
-                # A page is like a vbox, so all children can use all the
-                # horizontal space 
-                current_w = width
-                current_h = minh
-
-                if propy and available:
-                    add = int(available / sum_sy * propy)
-                    current_h += add
-                    available -= add
-
-                sizes[index] = (current_w, current_h)
-
-            last_y = 0
-            for (index, child) in enumerate(self._children):
-                cwidth, cheight = sizes[index]
-                child.left = 0
-                child.top = last_y
-                last_y += cheight
-
-                gDebug(2, "Child %s: %x/%s" % (child._gfObject.name, 
child.left,
-                    child.top))
-                child.set_size_and_fit(cwidth, cheight)
-
-
     # -------------------------------------------------------------------------
     # Write a text to a given position
     # -------------------------------------------------------------------------
@@ -170,7 +115,6 @@
 
     def move(self, x, y):
 
-        gDebug(2, "MOVE to %s/%s" % (x, y))
         self.__cursor = (x, y)
 
     # -------------------------------------------------------------------------
@@ -230,7 +174,42 @@
         return unicode("".join([chr(i) for i in result]), i18n.encoding)
 
 
+    # -------------------------------------------------------------------------
+    # Virtual methods
+    # -------------------------------------------------------------------------
 
+    def _add_decoration_(self):
+        """
+        A page has no decoration but a curses window.
+        """
+
+        self.__window = curses.newpad(self.height, self.width)
+        self.__window.keypad(1)
+        self.__window.bkgd(' ', self._uiDriver.attr['background'])
+
+    # -------------------------------------------------------------------------
+
+    def _get_upper_left_(self):
+        """
+        The upper left corner of a page is always 0/0 since the page provides
+        it's own window.
+        """
+        return (0, 0)
+
+    # -------------------------------------------------------------------------
+
+    def _add_child_(self, child, index, last_x, last_y):
+        """
+        Add a child widget to the page
+        """
+
+        cwidth, cheight = self._sizes_[index]
+        child.left = self.left + self._horizontal_offset_()
+        child.top = last_y + self._vertical_offset_()
+
+        return (0, cheight)
+
+
 # =============================================================================
 # Configuration data
 # =============================================================================

Modified: trunk/gnue-forms/src/uidrivers/curses/widgets/vbox.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/curses/widgets/vbox.py       2006-12-12 
14:55:34 UTC (rev 9140)
+++ trunk/gnue-forms/src/uidrivers/curses/widgets/vbox.py       2006-12-12 
14:58:01 UTC (rev 9141)
@@ -23,7 +23,7 @@
 
 import curses
 
-from _base import UIHelper, box
+from _base import ManagedBox, box
 
 __all__ = ['UIVBox']
 
@@ -31,128 +31,64 @@
 # VBox class
 # =============================================================================
 
-class UIVBox(UIHelper):
+class UIVBox(ManagedBox):
     """
     A vertical box container
     """
 
+    vertical = True
+
     # -------------------------------------------------------------------------
     # Create the widget
     # -------------------------------------------------------------------------
 
     def _create_widget_(self, event, spacer):
 
-        UIHelper._create_widget_(self, event, spacer)
+        ManagedBox._create_widget_(self, event, spacer)
+
         self._parent = event.container
         self._container = self._parent
 
 
     # -------------------------------------------------------------------------
-    # Set the widget size and fit all it's children
+    # Virtual methods
     # -------------------------------------------------------------------------
 
-    def set_size_and_fit(self, width, height):
+    def _decoration_size_(self):
 
-        self.width = width
-        self.height = height
+        if self._gfObject.label:
+            return (2, 2)
+        else:
+            return (0, 0)
 
-        gDebug(2, "Size for vbox: %s/%s %s/%s %s/%s" % (self.width,
-            self.height, self.left, self.top, self.right, self.bottom))
+    # -------------------------------------------------------------------------
 
-        attr = self._uiDriver.attr['background']
+    def _add_decoration_(self):
 
         if self._gfObject.label:
+            attr = self._uiDriver.attr['background']
             box(self._parent, attr, self.left, self.top, self.right,
                     self.bottom, self._gfObject.label)
-            self.width -= 2
-            self.height -= 2
 
-        hints = {}
-        for (index, child) in enumerate(self._children):
-            hints[index] = child.get_size_hints()
+    # -------------------------------------------------------------------------
 
-        # Total of the stretching (proportion)
-        sum_sy = float(sum([i[3] for i in hints.values()]))
+    def _vertical_offset_(self):
 
-        # The widest label
-        widest_label = max([i[2] for i in hints.values()])
+        if self._gfObject.label:
+            return 1
+        else:
+            return 0
 
-        # Reorder the list of size-hints starting with the highest
-        # stretching factor (vertical)
-        needed = 0
-        ordered = []
-        for key, (minw, minh, label, propy) in hints.items():
-            ordered.append((propy, key))
-            needed += minh
-        ordered.sort()
-        ordered.reverse()
-
-        # Now let's have a look how much space is left if all children have
-        # used up their minimum height
-        available = self.height - needed
-
-        gDebug(2, "Ordered: %s/%s: %s" % (needed, available, ordered))
-
-        # First assign the minimum space required to each child
-        sizes = {}
-        for (propy, index) in ordered:
-            child = self._children[index]
-
-            (minw, minh, label, propy) = hints[index]
-
-            current_w = self.width - widest_label - 2
-            current_h = minh
-
-            if propy and available:
-                add = int(available / sum_sy * propy)
-                current_h += add
-                available -= add
-                gDebug(2, "Adding %s to %s" % (add, child._gfObject.name))
-
-            sizes[index] = (current_w, current_h)
-
-        last_y = self.top + 1
-        for (index, child) in enumerate(self._children):
-            cwidth, cheight = sizes[index]
-            child.left = self.left + widest_label + 2
-            child.top = last_y
-            last_y += cheight
-
-            gDebug(2, "Child %s: %x/%s" % (child._gfObject.name, child.left,
-                child.top))
-            # If there's a label, add it to the parent's window
-            if hints[index][2]:
-                attr = self._uiDriver.attr['background']
-                self._parent.write(self.left + 1, child.top,
-                        child._gfObject.label, attr)
-            child.set_size_and_fit(cwidth, cheight)
-
-
-
     # -------------------------------------------------------------------------
-    # Get the size hints for the vbox
-    # -------------------------------------------------------------------------
 
-    def get_size_hints(self):
+    def _horizontal_offset_(self):
 
-        hints = []
-        for child in self._children:
-            hints.append(child.get_size_hints())
-
-        if hints:
-            widest_label = max([i[2] for i in hints])
-            minw = widest_label + max([i[0] for i in hints]) + 3
-            minh = sum([i[1] for i in hints]) + 2
-            prop = sum([i[3] for i in hints])
+        if self._gfObject.label:
+            return 2
         else:
-            minw = minh = 2 
-            prop = 0
+            return 0
 
-        gDebug(2, "min: %s %s %s %s" % (minw, minh, 1, prop))
 
-        return (minw, minh, 1, prop)
-
-
 # =============================================================================
 # Configuration data
 # =============================================================================





reply via email to

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