commit-gnue
[Top][All Lists]
Advanced

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

[gnue] r10057 - trunk/gnue-forms/src/uidrivers/wx/widgets


From: reinhard
Subject: [gnue] r10057 - trunk/gnue-forms/src/uidrivers/wx/widgets
Date: Wed, 25 Nov 2009 17:24:49 -0600 (CST)

Author: reinhard
Date: 2009-11-25 17:24:48 -0600 (Wed, 25 Nov 2009)
New Revision: 10057

Modified:
   trunk/gnue-forms/src/uidrivers/wx/widgets/_base.py
   trunk/gnue-forms/src/uidrivers/wx/widgets/button.py
   trunk/gnue-forms/src/uidrivers/wx/widgets/entry.py
   trunk/gnue-forms/src/uidrivers/wx/widgets/gridline.py
   trunk/gnue-forms/src/uidrivers/wx/widgets/hbox.py
   trunk/gnue-forms/src/uidrivers/wx/widgets/image.py
   trunk/gnue-forms/src/uidrivers/wx/widgets/scrollbar.py
   trunk/gnue-forms/src/uidrivers/wx/widgets/vbox.py
Log:
Reworked minimum and maximum size determination.


Modified: trunk/gnue-forms/src/uidrivers/wx/widgets/_base.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx/widgets/_base.py  2009-11-25 14:14:04 UTC 
(rev 10056)
+++ trunk/gnue-forms/src/uidrivers/wx/widgets/_base.py  2009-11-25 23:24:48 UTC 
(rev 10057)
@@ -60,27 +60,6 @@
 
 
     # -------------------------------------------------------------------------
-    # Get the default size
-    # -------------------------------------------------------------------------
-
-    def get_default_size(self):
-        """
-        Return a wx.Size with the default (starting) size of a widget
-        """
-        return wx.DefaultSize
-
-
-    # -------------------------------------------------------------------------
-    # Get the maximum size
-    # -------------------------------------------------------------------------
-
-    def get_maximum_size(self):
-        """
-        Return a wx.Size with the maximum size of a widget
-        """
-        return wx.DefaultSize
-
-    # -------------------------------------------------------------------------
     # Get the length of a widget according to it's GFField
     # -------------------------------------------------------------------------
 
@@ -409,24 +388,3 @@
             block.next_record()
         else:
             block.prev_record()
-
-
-    # -------------------------------------------------------------------------
-    # Indicate whether this box is growable
-    # -------------------------------------------------------------------------
-
-    def can_grow_x(self):
-
-        for child in self._children:
-            if child.can_grow_x():
-                return True
-        return False
-
-    # -------------------------------------------------------------------------
-
-    def can_grow_y(self):
-
-        for child in self._children:
-            if child.can_grow_y():
-                return True
-        return False

Modified: trunk/gnue-forms/src/uidrivers/wx/widgets/button.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx/widgets/button.py 2009-11-25 14:14:04 UTC 
(rev 10056)
+++ trunk/gnue-forms/src/uidrivers/wx/widgets/button.py 2009-11-25 23:24:48 UTC 
(rev 10057)
@@ -58,7 +58,7 @@
             parent = event.container
 
         if not self.managed:
-            csize = (self.get_default_size()[0], self._uiDriver.cellHeight - 2)
+            csize = (wx.DefaultSize.x, self._uiDriver.cellHeight - 2)
         else:
             csize = wx.DefaultSize
 
@@ -152,6 +152,15 @@
         self.widgets[index].Enable(False)
 
 
+    # -------------------------------------------------------------------------
+    # Indicate whether this control is growable
+    # -------------------------------------------------------------------------
+
+    def can_grow_x(self):
+
+        return True
+
+
 # =============================================================================
 # Configuration data
 # =============================================================================

Modified: trunk/gnue-forms/src/uidrivers/wx/widgets/entry.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx/widgets/entry.py  2009-11-25 14:14:04 UTC 
(rev 10056)
+++ trunk/gnue-forms/src/uidrivers/wx/widgets/entry.py  2009-11-25 23:24:48 UTC 
(rev 10057)
@@ -97,20 +97,13 @@
         if self._gfObject._field.datatype == 'number':
             xFlags |= wx.TE_RIGHT
 
-        csize = self.get_default_size()
-
-        # NOTE: a multiline text control has a native size which is about 60
-        # pixels.  This height might be bigger than for example two grid cells.
-        # In that case those lines in the GridBagSizer would be stretched which
-        # is not what we want!  To avoid that, we set the size of the control
-        # to 1 pixel in height, which will be overriden by the containing
-        # GridBagSizer when it comes to layout.  These restrictions are needed
-        # for positioned layout only
         if multiline and not self.managed:
-            csize = (csize[0], 1)
             self.__border = self._uiDriver.control_border('default')
 
-        ctrl = wx.TextCtrl(parent, -1, size=csize, style=xFlags)
+        ctrl = wx.TextCtrl(parent, -1, style=xFlags)
+
+        self.__set_size(ctrl)
+
         ctrl.Bind(wx.EVT_TEXT, self.__on_text_changed)
         ctrl.Bind(wx.EVT_CHAR, self.__on_keypress)
         ctrl.Bind(wx.EVT_KEY_DOWN, self.__on_key_down)
@@ -135,6 +128,9 @@
     def __build_label(self, parent):
 
         ctrl = wx.StaticText(parent, -1, "")
+
+        self.__set_size(ctrl)
+
         return [self.__add_entry_label(parent), ctrl]
 
     # -------------------------------------------------------------------------
@@ -156,10 +152,11 @@
 
     def __build_dropdown(self, parent):
 
-        csize = self.get_default_size()
-        result = wx.ComboBox(parent, -1, size=csize, style=wx.CB_DROPDOWN |
+        result = wx.ComboBox(parent, -1, style=wx.CB_DROPDOWN |
                 wx.TE_PROCESS_TAB | wx.TE_PROCESS_ENTER)
 
+        self.__set_size(result)
+
         # On wxMac a Combobox is a container holding a TextCtrl and a Choice.
         # We have to bind the Focus- and Char-Events to the TextCtrl widget.
         if 'wxMac' in wx.PlatformInfo:
@@ -195,13 +192,12 @@
 
         # NOTE: please have a look at the note on multiline text edits above
         if not self.managed:
-            csize = (self.get_default_size()[0], 1)
-        else:
-            csize = (self.get_default_size()[0], -1)
-        self.__border = self._uiDriver.control_border('default')
+            self.__border = self._uiDriver.control_border('default')
 
-        result = wx.ListBox(parent, -1, size=csize, style=wx.LB_SINGLE)
+        result = wx.ListBox(parent, style=wx.LB_SINGLE)
 
+        self.__set_size(result)
+
         result.Bind(wx.EVT_LISTBOX, self.__on_item_selected)
         result.Bind(wx.EVT_KEY_DOWN, self.__on_key_down)
         result.Bind(wx.EVT_SET_FOCUS, self.__on_set_focus)
@@ -683,93 +679,80 @@
 
 
     # -------------------------------------------------------------------------
-    # Get the default size
+    # Set minimum and maximum size for the control
     # -------------------------------------------------------------------------
 
-    def get_default_size(self):
-        """
-        Return a wx.Size with the default (starting) size of a widget
-        """
-        cellw = self._uiDriver.cellWidth
-        cellh = self._uiDriver.cellHeight
+    def __set_size(self, control):
 
         if self.managed:
-            style = self._gfObject.style.lower()
-            if style == 'password':
-                style = 'default'
+            # Explicitly set default width.
+            min_w = self.min_width
 
-            bw, bh = self._uiDriver.best_sizes.get(style, (-1, -1))
+            # If not explicitly set, assume field length.
+            if not min_w:
+                min_w = min(self.get_field_length(), 32)
+                if not min_w:
+                    min_w = 32
 
-            deffield = self.get_field_length()
-            # Do not exceed either the maximum allowed or 64 characters
-            if (self.def_width or deffield) == 0:
-                defw = bw
-            else:
-                if self.def_width:
-                    defw = self.def_width * cellw
-                else:
-                    maxw = min(self.max_width or 32, 32)
-                    defw = min(deffield, maxw) * cellw
+            # Explicitly set maximum width.
+            max_w = self.max_width
 
-            if not self.def_height:
-                defh = -1
+            # If not explicitly set, assume field length.
+            if not max_w:
+                max_w = self.get_field_length()
+
+            # Add border width.
+            # FIXME: This is only an estimate, but I haven't found out how to
+            # determine the real border width in wx.
+            if self._gfObject.style.lower() == 'dropdown':
+                min_w += 4
+                if max_w:
+                    max_w += 4
             else:
-                maxh = max((self.max_height or 0) * cellh, bh)
-                defh = min(max((self.def_height or 0) * cellh, bh), maxh)
+                min_w += 1
+                if max_w:
+                    max_w += 1
 
-            return wx.Size(defw, defh)
-        else:
-            # We're using the size of an empty GridCell instead of the average
-            # character width.  It returns better looking forms.
-            return wx.Size(cellw * self.chr_w, -1)
+            min_w *= self._uiDriver.cellWidth
+            max_w *= self._uiDriver.cellWidth
 
+            if not max_w:
+                max_w = wx.DefaultSize.width
 
-    # -------------------------------------------------------------------------
-    # Get the maximum size
-    # -------------------------------------------------------------------------
+            # Find out widget height.
+            if self.min_height:
+                min_h = self.min_height * self._uiDriver.cellHeight
+            else:
+                min_h = wx.DefaultSize.height
 
-    def get_maximum_size(self):
-        """
-        Return a wx.Size with the maximum size of a widget
-        """
+            if self.max_height:
+                max_h = self.max_height * self._uiDriver.cellHeight
+            else:
+                max_h = wx.DefaultSize.height
 
-        style = self._gfObject.style.lower()
-        bw, bh = self._uiDriver.best_sizes.get(style, (-1, -1))
-        cellw = self._uiDriver.cellWidth
-        cellh = self._uiDriver.cellHeight
-
-        length = self.get_field_length()
-        if (self.max_width or length) == 0:
-            maxw = -1
+            control.SetMinSize((min_w, min_h))
+            control.SetMaxSize((max_w, max_h))
         else:
-            maxw = ((self.max_width or length) * cellw) or bw
+            # We're using the size of an empty GridCell instead of the average
+            # character width.  It returns better looking forms.
+            w = self.chr_w * self._uiDriver.cellWidth
 
-        if not self.max_height:
-            maxh = -1
-        else:
-            maxh = ((self.max_height or 0) * cellh) or bh
+            # NOTE: a multiline text control has a native size which is about
+            # 60 pixels.  This height might be bigger than for example two grid
+            # cells.  In that case those lines in the GridBagSizer would be
+            # stretched which is not what we want!  To avoid that, we set the
+            # size of the control to 1 pixel in height, which will be overriden
+            # by the containing GridBagSizer when it comes to layout.  These
+            # restrictions are needed for positioned layout only.
+            if self._gfObject.style.lower() in ['multiline', 'listbox']:
+                h = 1
+            else:
+                h = wx.DefaultSize.height
 
-        minw, minh = self.get_default_size().Get()
-        if maxw != -1:
-            maxw = max(maxw, minw)
-        if maxh != -1:
-            maxh = max(maxh, minh)
-        return wx.Size(maxw, maxh)
+            control.SetMinSize((w, h))
+            control.SetMaxSize((w, wx.DefaultSize.height))
 
-    # -------------------------------------------------------------------------
-    # Update the size hints of a widget
-    # -------------------------------------------------------------------------
 
-    def update_size_hints(self):
-
-        if self.managed:
-            minw, minh = self.get_default_size().Get()
-            maxw, maxh = self.get_maximum_size().Get()
-
-            for item in self.widgets:
-                item.SetSizeHints(minw, minh, maxw, maxh)
-
-
     # -------------------------------------------------------------------------
     # Indicate whether this widget is growable
     # -------------------------------------------------------------------------

Modified: trunk/gnue-forms/src/uidrivers/wx/widgets/gridline.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx/widgets/gridline.py       2009-11-25 
14:14:04 UTC (rev 10056)
+++ trunk/gnue-forms/src/uidrivers/wx/widgets/gridline.py       2009-11-25 
23:24:48 UTC (rev 10057)
@@ -140,10 +140,7 @@
         else:
             sizer.Add(ui_widget.widget, 1, wx.ALIGN_CENTER)
 
-        best = ui_widget.widget.GetBestSize()
-        default = ui_widget.get_default_size()
-        sizer.SetMinSize(wx.Size(max(best.width, default.width),
-            max(best.height, default.height)))
+        sizer.SetMinSize(ui_widget.widget.GetMinSize())
         if ui_widget.label:
             ui_widget.widget.Hide()
 

Modified: trunk/gnue-forms/src/uidrivers/wx/widgets/hbox.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx/widgets/hbox.py   2009-11-25 14:14:04 UTC 
(rev 10056)
+++ trunk/gnue-forms/src/uidrivers/wx/widgets/hbox.py   2009-11-25 23:24:48 UTC 
(rev 10057)
@@ -104,6 +104,27 @@
         self.last_item += add
 
 
+    # -------------------------------------------------------------------------
+    # Indicate whether this box is growable
+    # -------------------------------------------------------------------------
+
+    def can_grow_x(self):
+
+        for child in self._children:
+            if child.can_grow_x():
+                return True
+        return False
+
+    # -------------------------------------------------------------------------
+
+    def can_grow_y(self):
+
+        for child in self._children:
+            if child.can_grow_y():
+                return True
+        return False
+
+
 # =============================================================================
 # Configuration data
 # =============================================================================

Modified: trunk/gnue-forms/src/uidrivers/wx/widgets/image.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx/widgets/image.py  2009-11-25 14:14:04 UTC 
(rev 10056)
+++ trunk/gnue-forms/src/uidrivers/wx/widgets/image.py  2009-11-25 23:24:48 UTC 
(rev 10057)
@@ -194,7 +194,7 @@
 
         parent = event.container
 
-        self.image_size = self.get_default_size()
+        self.image_size = self.__get_default_size()
 
         self.widget = ImageViewer(parent, self.image_size, self._gfObject.fit)
 
@@ -207,7 +207,7 @@
     # Get the default size for the image
     # -------------------------------------------------------------------------
 
-    def get_default_size(self):
+    def __get_default_size(self):
 
         if self.managed:
             width = int(getattr(self._gfObject, 'Sizer__width', -1))

Modified: trunk/gnue-forms/src/uidrivers/wx/widgets/scrollbar.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx/widgets/scrollbar.py      2009-11-25 
14:14:04 UTC (rev 10056)
+++ trunk/gnue-forms/src/uidrivers/wx/widgets/scrollbar.py      2009-11-25 
23:24:48 UTC (rev 10057)
@@ -39,7 +39,7 @@
 
         parent = event.container
 
-        csize = self.get_default_size()
+        csize = self.__get_default_size()
         self.widget = wx.ScrollBar(parent, -1, size=csize,
                 style=wx.SB_VERTICAL)
         self.getParent().add_widgets(self, spacer)
@@ -64,7 +64,7 @@
     # Get the default size of a scrollbar
     # -------------------------------------------------------------------------
 
-    def _get_default_size_(self):
+    def __get_default_size(self):
         """
         Get the default widget size.
 

Modified: trunk/gnue-forms/src/uidrivers/wx/widgets/vbox.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx/widgets/vbox.py   2009-11-25 14:14:04 UTC 
(rev 10056)
+++ trunk/gnue-forms/src/uidrivers/wx/widgets/vbox.py   2009-11-25 23:24:48 UTC 
(rev 10057)
@@ -72,10 +72,13 @@
             add = True
             if isinstance(ui_widget, button.UIButton):
                 item = self.add_to_hbox(ui_widget.widget)
-                #item = ui_widget.widget
             else:
                 item = ui_widget.widget
 
+            flags = 0
+            if ui_widget.can_grow_x():
+                flags |= wx.EXPAND
+
             if not ui_widget.label:
                 pos = (self.last_item, 0)
                 span = (1, 2)
@@ -90,9 +93,9 @@
                     bfl = wx.TOP | wx.RIGHT
                 else:
                     bfl = wx.RIGHT
-                self._sizer.Add(item, pos, span, wx.EXPAND | bfl, 3)
+                self._sizer.Add(item, pos, span, flags | bfl, 3)
             else:
-                self._sizer.Add(item, pos, span, wx.EXPAND)
+                self._sizer.Add(item, pos, span, flags)
 
         if add and ui_widget.can_grow_y():
             # FIXME: If a stretch factor is used, the *whole* newly calculated
@@ -104,6 +107,24 @@
         self.last_item += add
 
 
+    # -------------------------------------------------------------------------
+    # Indicate whether this box is growable
+    # -------------------------------------------------------------------------
+
+    def can_grow_x(self):
+
+        return True
+
+    # -------------------------------------------------------------------------
+
+    def can_grow_y(self):
+
+        for child in self._children:
+            if child.can_grow_y():
+                return True
+        return False
+
+
 # =============================================================================
 # Configuration data
 # =============================================================================





reply via email to

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