commit-gnue
[Top][All Lists]
Advanced

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

[gnue] r9365 - in trunk/gnue-forms/src: . input/displayHandlers


From: johannes
Subject: [gnue] r9365 - in trunk/gnue-forms/src: . input/displayHandlers
Date: Fri, 9 Feb 2007 10:01:52 -0600 (CST)

Author: johannes
Date: 2007-02-09 10:01:52 -0600 (Fri, 09 Feb 2007)
New Revision: 9365

Modified:
   trunk/gnue-forms/src/GFConfig.py
   trunk/gnue-forms/src/input/displayHandlers/Cursor.py
   trunk/gnue-forms/src/input/displayHandlers/Numeric.py
Log:
Added display handler for numeric values


Modified: trunk/gnue-forms/src/GFConfig.py
===================================================================
--- trunk/gnue-forms/src/GFConfig.py    2007-02-09 11:17:51 UTC (rev 9364)
+++ trunk/gnue-forms/src/GFConfig.py    2007-02-09 16:01:52 UTC (rev 9365)
@@ -179,6 +179,21 @@
     'Typecast'   : GTypecast.text,
     'Default'    : '#0' },
 
+  { 'Name'       : 'numeric_grouping',
+    'Type'       : 'Setting',
+    'Comment'    : 'Grouping pattern used for thousands separating and ' \
+                   'definition of the decimal point. Format: <thousand ' \
+                   'separator><number of digits><decimal separator>.  ' \
+                   'The pair <thousand separator><number of ditigs> can ' \
+                   'be repeated multiple times.  Example: ,3.',
+    'Description': 'Grouping pattern used for thousands separating and ' \
+                   'definition of the decimal point. Format: <thousand ' \
+                   'separator><number of digits><decimal separator>.  ' \
+                   'The pair <thousand separator><number of ditigs> can ' \
+                   'be repeated multiple times. Example: ,3.',
+    'Typecast'   : GTypecast.text,
+    'Default'    : '' },
+
   { 'Name'       : 'SplashScreenPNG',
     'Type'       : 'Setting',
     'Comment'    : 'Location of startup graphic (PNG format)',

Modified: trunk/gnue-forms/src/input/displayHandlers/Cursor.py
===================================================================
--- trunk/gnue-forms/src/input/displayHandlers/Cursor.py        2007-02-09 
11:17:51 UTC (rev 9364)
+++ trunk/gnue-forms/src/input/displayHandlers/Cursor.py        2007-02-09 
16:01:52 UTC (rev 9365)
@@ -304,7 +304,7 @@
         # Check if the text is numeric if need to.
         if (self.field._numeric and self.field._block.mode == 'normal'):
             for char in text:
-                if not (char.isdigit() or char in '.-'):
+                if not (char.isdigit() or char in ',.-'):
                     self.__error(u_("This field allows numeric input only"))
                     return
 

Modified: trunk/gnue-forms/src/input/displayHandlers/Numeric.py
===================================================================
--- trunk/gnue-forms/src/input/displayHandlers/Numeric.py       2007-02-09 
11:17:51 UTC (rev 9364)
+++ trunk/gnue-forms/src/input/displayHandlers/Numeric.py       2007-02-09 
16:01:52 UTC (rev 9365)
@@ -1,6 +1,9 @@
-
-# This file is part of GNU Enterprise.
+# GNU Enterprise Forms - Display handler - Numeric values
 #
+# Copyright 2001-2007 Free Software Foundation
+#
+# This file is part of GNU Enterprise
+#
 # GNU Enterprise is free software; you can redistribute it
 # and/or modify it under the terms of the GNU General Public
 # License as published by the Free Software Foundation; either
@@ -16,28 +19,86 @@
 # write to the Free Software Foundation, Inc., 59 Temple Place
 # - Suite 330, Boston, MA 02111-1307, USA.
 #
-# Copyright 2002-2007 Free Software Foundation
-#
-# FILE:
-# GFDisplayHandler.py
-#
-# $Id$
+# $Id: $
 """
 DisplayHandler classes for Forms input validation
 """
 __revision__ = "$Id$"
 
-import types
+import re
 
+from gnue.common.utils import xlocale
 from gnue.forms.input.displayHandlers.Cursor import BaseCursor
 
+# =============================================================================
+# Display handler for numeric values
+# =============================================================================
+
 class Numeric(BaseCursor):
-  """
-  Class to handle the display and entry of numeric fields.
-  """
+    """
+    Class to handle the display and entry of numeric fields.
+    """
 
-  def parse_display(self, display):
-    if not len(display):
-        return None
+    # -------------------------------------------------------------------------
+    # Constructor
+    # -------------------------------------------------------------------------
 
-    return float(display)
+    def __init__(self, entry, eventHandler, subEventHandler, display_mask,
+            input_mask):
+
+        BaseCursor.__init__(self, entry, eventHandler, subEventHandler,
+                display_mask, input_mask)
+        if display_mask:
+            self._display_mask = display_mask
+        else:
+            if self.field.scale:
+                self._display_mask = '%%.%sf' % self.field.scale
+            elif self.field.length:
+                self._display_mask = '%d'
+            else:
+                self._display_mask = '%s'
+
+        self.__grouping = gConfigForms('numeric_grouping') or None
+
+
+    # -------------------------------------------------------------------------
+    # Try to guess what value is meant by a given string
+    # -------------------------------------------------------------------------
+
+    def parse_display(self, display):
+        """
+        Try to convert the given display string into a number
+        """
+
+        if not len(display):
+            return None
+
+        match = re.match('^(\D*)(\d*)(\D*)(\d*)$', display)
+        if match:
+            (sign, whole, dec, frac) = match.groups()
+            display = sign + whole
+            if frac:
+                display += "." + frac
+
+        return float(display)
+
+
+    # -------------------------------------------------------------------------
+    # Create a display string for the current value
+    # -------------------------------------------------------------------------
+
+    def build_display(self, value, editing):
+        """
+        Create a display string for the current value
+        """
+
+        if value is None:
+            return ''
+
+        if editing:
+            result = self._display_mask % value
+        else:
+            result = xlocale.format_numeric(self._display_mask, float(value),
+                    self.__grouping)
+
+        return result





reply via email to

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