commit-gnue
[Top][All Lists]
Advanced

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

[gnue] r9317 - in trunk/gnue-forms/src: GFObjects input/displayHandlers


From: johannes
Subject: [gnue] r9317 - in trunk/gnue-forms/src: GFObjects input/displayHandlers uidrivers/wx26 uidrivers/wx26/widgets
Date: Tue, 16 Jan 2007 08:57:17 -0600 (CST)

Author: johannes
Date: 2007-01-16 08:57:03 -0600 (Tue, 16 Jan 2007)
New Revision: 9317

Modified:
   trunk/gnue-forms/src/GFObjects/GFField.py
   trunk/gnue-forms/src/input/displayHandlers/Cursor.py
   trunk/gnue-forms/src/uidrivers/wx26/UIdriver.py
   trunk/gnue-forms/src/uidrivers/wx26/widgets/_base.py
   trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py
   trunk/gnue-forms/src/uidrivers/wx26/widgets/form.py
   trunk/gnue-forms/src/uidrivers/wx26/widgets/image.py
Log:
Allow length attribute for lookup-fields again
Introduced minimum-, default- and maximum-size hints


Modified: trunk/gnue-forms/src/GFObjects/GFField.py
===================================================================
--- trunk/gnue-forms/src/GFObjects/GFField.py   2007-01-15 15:04:39 UTC (rev 
9316)
+++ trunk/gnue-forms/src/GFObjects/GFField.py   2007-01-16 14:57:03 UTC (rev 
9317)
@@ -196,8 +196,7 @@
 
         # Check if "length" attribute is allowed.
         if self.length is not None \
-                and (self.datatype not in ['text', 'number', 'raw'] \
-                    or self.__is_lookup):
+                and (self.datatype not in ['text', 'number', 'raw']):
             raise LengthNotAllowedError(self)
 
         # Check if "minLength" attribute is allowed.

Modified: trunk/gnue-forms/src/input/displayHandlers/Cursor.py
===================================================================
--- trunk/gnue-forms/src/input/displayHandlers/Cursor.py        2007-01-15 
15:04:39 UTC (rev 9316)
+++ trunk/gnue-forms/src/input/displayHandlers/Cursor.py        2007-01-16 
14:57:03 UTC (rev 9317)
@@ -298,9 +298,11 @@
         new_text = self.display[:start] + text + self.display[end:]
 
         # Check if max length isn't exceeded.
-        if self.field.length is not None and len(new_text) > self.field.length:
-            self.__error(u_("Maximum input length reached"))
-            return
+        if not hasattr(self.field, 'fk_source'):
+            if self.field.length is not None and \
+                    len(new_text) > self.field.length:
+                self.__error(u_("Maximum input length reached"))
+                return
 
         # If text was added at the end, do autocompletion.
         ende = len(self.display)

Modified: trunk/gnue-forms/src/uidrivers/wx26/UIdriver.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/UIdriver.py     2007-01-15 15:04:39 UTC 
(rev 9316)
+++ trunk/gnue-forms/src/uidrivers/wx26/UIdriver.py     2007-01-16 14:57:03 UTC 
(rev 9317)
@@ -96,18 +96,12 @@
 
     try:
       # First of all find out the preferred size of all widgets needed
-      label = wx.StaticText (frame, wx.ID_ANY)
-      result['label'] = label.GetBestSize()
-
       text = wx.TextCtrl (frame, wx.ID_ANY)
       result['default'] = text.GetBestSize()
 
       combo = wx.ComboBox (frame, wx.ID_ANY)
       result['dropdown'] = combo.GetBestSize()
 
-      check = wx.CheckBox (frame, wx.ID_ANY)
-      result['checkbox'] = check.GetBestSize()
-
       # Get the height and width of a form-cell for which we use the tallest
       # control and the avarage character width of the application font
       cellHeight = max([i[1] for i in result.values()]) + 2

Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/_base.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/_base.py        2007-01-15 
15:04:39 UTC (rev 9316)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/_base.py        2007-01-16 
14:57:03 UTC (rev 9317)
@@ -67,44 +67,50 @@
 
 
     # -------------------------------------------------------------------------
-    # Get the best size of a widget
+    # Get the minimum size of a widget
     # -------------------------------------------------------------------------
 
-    def get_default_size(self):
+    def get_minimum_size(self):
         """
-        Get the default size for a widget
-
-        @returns: Size-tuple (width, height) representing the default size for
-            the widget
+        Return a wx.Size with the minimum size of a widget
         """
+        return wx.DefaultSize
 
-        return self._get_default_size_()
 
     # -------------------------------------------------------------------------
-    # Get the size hints (minimum and maximum size) of a widget
+    # Get the default size
     # -------------------------------------------------------------------------
 
-    def get_size_hints(self):
+    def get_default_size(self):
         """
-        Get the SizeHints - minimum and maximum size - for a widget.
+        Return a wx.Size with the default (starting) size of a widget
+        """
+        return wx.DefaultSize
 
-        @returns: tuple of wx.Size instances representing the minimum and
-            maximum size
+
+    # -------------------------------------------------------------------------
+    # Get the maximum size
+    # -------------------------------------------------------------------------
+
+    def get_maximum_size(self):
         """
+        Return a wx.Size with the maximum size of a widget
+        """
+        return wx.DefaultSize
 
-        if not self.managed:
-            return (wx.DefaultSize, wx.DefaultSize)
-        else:
-            cellw, cellh = self._uiDriver.cellWidth, self._uiDriver.cellHeight
-            mins = wx.Size((self.min_width * cellw) or -1,
-                    (self.min_height * cellh) or -1)
 
-            length = self.max_width or self._gfObject._field.length or 0
-            maxs = wx.Size((length * cellw) or -1,
-                    (self.max_height * cellh) or -1)
-            return (mins, maxs)
+    # -------------------------------------------------------------------------
+    # Update the size hints of a widget
+    # -------------------------------------------------------------------------
 
+    def update_size_hints(self):
+        """
+        Descendants will override this method to update the size hints of all
+        it's UI widgets.
+        """
+        pass
 
+
     # -------------------------------------------------------------------------
     # Focus handling
     # -------------------------------------------------------------------------
@@ -226,41 +232,6 @@
             widget.Thaw()
 
 
-    # =========================================================================
-    # Virtual methods
-    # =========================================================================
-
-    def _get_default_size_(self):
-        """
-        Get the default widget size.
-
-        For positioned layout the default width is the product of the
-        character-width and the avarage cellWidth. The default height is set to
-        -1, which means it will be set by the sizers.
-
-        @returns: tuple with default size
-        """
-
-        cellw = self._uiDriver.cellWidth
-        cellh = self._uiDriver.cellHeight
-
-        if self.managed:
-            style = self._gfObject.style.lower()
-            (defw, defh) = self._uiDriver.best_sizes.get(style, (0, 0))
-
-            nc = min(max(self.def_width or 0, self._gfObject._field.length or
-                0), 64)
-            defw = max(nc * cellw, defw)
-            if self.def_height:
-                defh = max(self.def_height * cellh, defh)
-
-            return (defw, defh)
-        else:
-            # We're using the size of an empty GridCell instead of the average
-            # character width.  It returns better looking forms.
-            return (cellw * self.chr_w, -1)
-
-
     # -------------------------------------------------------------------------
     # Widget creation
     # -------------------------------------------------------------------------

Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py        2007-01-15 
15:04:39 UTC (rev 9316)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py        2007-01-16 
14:57:03 UTC (rev 9317)
@@ -64,12 +64,6 @@
         self.__border = 0
         (self.label, self.widget) = func(parent)
 
-        (mins, maxs) = self.get_size_hints()
-        if (mins != wx.DefaultSize):
-            self.widget.SetMinSize(mins)
-        if (maxs != wx.DefaultSize):
-            self.widget.SetMaxSize(maxs)
-
         owner.add_widgets(self, spacer, self.__border)
 
         if self.in_grid:
@@ -548,6 +542,112 @@
             widget.SelectAll()
 
 
+    # -------------------------------------------------------------------------
+    # Get the minimum size of a widget
+    # -------------------------------------------------------------------------
+
+    def get_minimum_size(self):
+        """
+        Return a wx.Size with the minimum size of a widget
+        """
+
+        cellw = self._uiDriver.cellWidth
+        cellh = self._uiDriver.cellHeight
+
+        style = self._gfObject.style.lower()
+        bw,bh = self._uiDriver.best_sizes.get(style, (-1, -1))
+
+        minw = (self.min_width * cellw) or bw or -1
+        minh = (self.min_height * cellh) or bh or -1
+
+        return wx.Size(minw, minh)
+
+
+    # -------------------------------------------------------------------------
+    # Get the default size
+    # -------------------------------------------------------------------------
+
+    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
+
+        if self.managed:
+            style = self._gfObject.style.lower()
+            if style == 'password':
+                style = 'default'
+
+            bw, bh = self._uiDriver.best_sizes.get(style, (-1, -1))
+
+            # Do not exceed either the maximum allowed or 64 characters
+            if (self.def_width or self._gfObject._field.length or 0) == 0:
+                defw = bw
+            else:
+                maxw = min(self.max_width or 64, 64)
+                flength = min(self._gfObject._field.length or maxw, maxw)
+                defw = (min(self.def_width or flength, flength) * cellw) or bw
+
+            if not self.def_height:
+                defh = -1
+            else:
+                maxh = max((self.max_height or 0) * cellh, bh)
+                defh = min(max((self.def_height or 0) * cellh, bh), maxh)
+
+            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)
+
+
+    # -------------------------------------------------------------------------
+    # Get the maximum size
+    # -------------------------------------------------------------------------
+
+    def get_maximum_size(self):
+        """
+        Return a wx.Size with the maximum size of a widget
+        """
+
+        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._gfObject._field.length or 0
+        if (self.max_width or length) == 0:
+            maxw = -1
+        else:
+            maxw = ((self.max_width or length) * cellw) or bw
+
+        if not self.max_height:
+            maxh = -1
+        else:
+            maxh = ((self.max_height or 0) * cellh) or bh
+
+        minw, minh = self.get_minimum_size().Get()
+        if maxw != -1:
+            maxw = max(maxw, minw)
+        if maxh != -1:
+            maxh = max(maxh, minh)
+        return wx.Size(maxw, maxh)
+
+    # -------------------------------------------------------------------------
+    # Update the size hints of a widget
+    # -------------------------------------------------------------------------
+
+    def update_size_hints(self):
+
+        if self.managed:
+            minw, minh = self.get_minimum_size().Get()
+            maxw, maxh = self.get_maximum_size().Get()
+
+            for item in self.widgets:
+                item.SetSizeHints(minw, minh, maxw, maxh)
+
+
 # =============================================================================
 # Configuration
 # =============================================================================

Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/form.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/form.py 2007-01-15 15:04:39 UTC 
(rev 9316)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/form.py 2007-01-16 14:57:03 UTC 
(rev 9317)
@@ -216,11 +216,25 @@
 
         self.show_page(0, True)
         if not self.__embedded:
-            self.main_window.SetSizerAndFit(self.__master_sizer)
+            self.main_window.SetSizer(self.__master_sizer)
+            self.main_window.Fit()
+
+            self.walk(self.__update_size_hints_walker)
+
             self.main_window.CenterOnScreen ()
 
 
     # -------------------------------------------------------------------------
+    # Update the size hints of all UI widgets
+    # -------------------------------------------------------------------------
+
+    def __update_size_hints_walker(self, item):
+
+        if item != self:
+            item.update_size_hints()
+
+
+    # -------------------------------------------------------------------------
     # Show the form/dialog
     # -------------------------------------------------------------------------
 

Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/image.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/image.py        2007-01-15 
15:04:39 UTC (rev 9316)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/image.py        2007-01-16 
14:57:03 UTC (rev 9317)
@@ -87,7 +87,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))





reply via email to

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