Anup(OpenERP) has proposed merging 
lp:~openerp-dev/openobject-client/6.0-opw-16966-ach into 
lp:openobject-client/6.0.

Requested reviews:
  Jay Vora (OpenERP) (jvo-openerp)
Related bugs:
  Bug #697625 in OpenERP GTK Client: "Clients should respect locale parameters 
defined in OpenERP locales (thousands separator, etc.)"
  https://bugs.launchpad.net/openobject-client/+bug/697625

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-client/6.0-opw-16966-ach/+merge/72019

Hello,

The thousand seperator doesn't work properly.

This fixes the issue.

It has been proposed to backport in stable.

Thanks.
-- 
https://code.launchpad.net/~openerp-dev/openobject-client/6.0-opw-16966-ach/+merge/72019
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-client/6.0-opw-16966-ach.
=== modified file 'bin/tools/__init__.py'
--- bin/tools/__init__.py	2010-12-30 06:00:45 +0000
+++ bin/tools/__init__.py	2011-08-18 11:12:26 +0000
@@ -205,12 +205,6 @@
 
     return unicode(value, from_encoding)
 
-def locale_format(format, value):
-    label_str = locale.format(format, value, True, True)
-    if not locale.getpreferredencoding().lower().startswith('utf'):
-        label_str = label_str.replace('\xa0', '\xc2\xa0')
-    return label_str
-
 def format_connection_string(login, _passwd, server, port, protocol, dbname):
 #def format_connection_string(*args):
 #    login, _passwd, server, port, protocol, dbname = args
@@ -225,27 +219,6 @@
     result += '/%s' % (dbname,)
     return result
 
-def str2int(string, default=None):
-    assert isinstance(string, basestring)
-    try:
-        integer = locale.atoi(string)
-        return integer
-    except:
-        if default is not None:
-            return default
-    raise ValueError("%r does not represent a valid integer value" % (string,))
-
-
-def str2float(string, default=None):
-    assert isinstance(string, basestring)
-    try:
-        float = locale.atof(string)
-        return float
-    except:
-        if default is not None:
-            return default
-    raise ValueError("%r does not represent a valid float value" % (string,))
-
 def str2bool(string, default=None):
     """Convert a string representing a boolean into the corresponding boolean
 

=== modified file 'bin/tools/user_locale_format.py'
--- bin/tools/user_locale_format.py	2011-01-17 07:21:19 +0000
+++ bin/tools/user_locale_format.py	2011-08-18 11:12:26 +0000
@@ -195,3 +195,32 @@
         if grouping:
             formatted = group(formatted, monetary=monetary, grouping=lang_grouping, thousands_sep=thousands_sep)[0]
     return formatted
+
+def str2int(string):
+    ''' Converts a string to an integer according to the locale settings
+        that the user has in Administration/Translations/Languages.
+    '''
+    assert isinstance(string, basestring)
+    return str2float(string, int)
+
+def str2float(string, func=float):
+    ''' Parses a string as a float according to the locale settings
+    that the user has in Administration/Translations/Languages.
+    '''
+    assert isinstance(string, basestring)
+    try:
+        #First, get rid of the thousand separator
+        ts = LOCALE_CACHE.get('thousands_sep')
+        if ts:
+            string = string.replace(ts, '')
+        #next, replace the decimal point with a dot
+        dd = LOCALE_CACHE.get('decimal_point')
+        if dd:
+            string = string.replace(dd, '.')
+        #finally, parse the string
+        return func(string)
+    except:
+        type = 'float'
+        if func == int:
+            type = 'integer'
+        raise ValueError("%r does not represent a valid %s value" % (string,type))

=== modified file 'bin/widget/view/form_gtk/spinbutton.py'
--- bin/widget/view/form_gtk/spinbutton.py	2010-07-16 05:41:32 +0000
+++ bin/widget/view/form_gtk/spinbutton.py	2011-08-18 11:12:26 +0000
@@ -22,7 +22,8 @@
 import gtk
 import sys
 import interface
-
+import ctypes
+from tools import user_locale_format
 
 class spinbutton(interface.widget_interface):
     def __init__(self, window, parent, model, attrs={}):
@@ -30,7 +31,6 @@
 
         adj = gtk.Adjustment(0.0, -sys.maxint, sys.maxint, 1.0, 5.0)
         self.widget = gtk.SpinButton(adj, 1.0, digits=int( attrs.get('digits',(14,2))[1] ) )
-        self.widget.set_numeric(True)
         self.widget.set_activates_default(True)
         self.widget.connect('populate-popup', self._menu_open)
         if self.attrs['readonly']:
@@ -38,6 +38,24 @@
         self.widget.connect('focus-in-event', lambda x,y: self._focus_in())
         self.widget.connect('focus-out-event', lambda x,y: self._focus_out())
         self.widget.connect('activate', self.sig_activate)
+        self.widget.connect('input', self.format_input)
+        self.widget.connect('output', self.format_output)
+
+    def format_output(self, spin):
+        digits = spin.get_digits()
+        value = spin.get_value()
+        text = user_locale_format.format('%.' + str(digits) + 'f', value)
+        spin.set_text(text)
+        return True
+ 
+    def format_input(self, spin, new_value_pointer):
+        text = spin.get_text()
+        if text:
+            value = user_locale_format.str2int(text)
+            value_location = ctypes.c_double.from_address(hash(new_value_pointer))
+            value_location.value = float(value)
+            return True
+        return False
 
     def set_value(self, model, model_field):
         self.widget.update()

=== modified file 'bin/widget/view/form_gtk/spinint.py'
--- bin/widget/view/form_gtk/spinint.py	2010-07-16 05:41:32 +0000
+++ bin/widget/view/form_gtk/spinint.py	2011-08-18 11:12:26 +0000
@@ -22,7 +22,8 @@
 import gtk
 import sys
 import interface
-
+import ctypes
+from tools import user_locale_format
 
 class spinint(interface.widget_interface):
 
@@ -31,7 +32,6 @@
 
         adj = gtk.Adjustment(0.0, -sys.maxint, sys.maxint, 1.0, 5.0)
         self.widget = gtk.SpinButton(adj, 1, digits=0)
-        self.widget.set_numeric(True)
         self.widget.set_width_chars(5)
         self.widget.set_activates_default(True)
         self.widget.connect('populate-popup', self._menu_open)
@@ -40,6 +40,24 @@
         self.widget.connect('focus-in-event', lambda x,y: self._focus_in())
         self.widget.connect('focus-out-event', lambda x,y: self._focus_out())
         self.widget.connect('activate', self.sig_activate)
+        self.widget.connect('input', self.format_input)
+        self.widget.connect('output', self.format_output)
+
+    def format_output(self, spin):
+        digits = spin.get_digits()
+        value = spin.get_value()
+        text = user_locale_format.format('%.' + str(digits) + 'f', value)
+        spin.set_text(text)
+        return True
+ 
+    def format_input(self, spin, new_value_pointer):
+        text = spin.get_text()
+        if text:
+            value = user_locale_format.str2float(text)
+            value_location = ctypes.c_double.from_address(hash(new_value_pointer))
+            value_location.value = float(value)
+            return True
+        return False
 
     def set_value(self, model, model_field):
         self.widget.update()

=== modified file 'bin/widget/view/tree_gtk/parser.py'
--- bin/widget/view/tree_gtk/parser.py	2011-01-18 06:45:01 +0000
+++ bin/widget/view/tree_gtk/parser.py	2011-08-18 11:12:26 +0000
@@ -343,7 +343,7 @@
 class Int(Char):
 
     def value_from_text(self, model, text):
-        return tools.str2int(text)
+        return user_locale_format.str2int(text)
 
     def get_textual_value(self, model):
         count = False
@@ -472,7 +472,7 @@
         return converted_val
 
     def value_from_text(self, model, text):
-        return tools.str2float(text)
+        return user_locale_format.str2float(text)
 
 class FloatTime(Char):
 

=== modified file 'bin/widget_search/spinbutton.py'
--- bin/widget_search/spinbutton.py	2010-09-21 09:39:49 +0000
+++ bin/widget_search/spinbutton.py	2011-08-18 11:12:26 +0000
@@ -23,7 +23,8 @@
 import common
 import wid_int
 import sys
-import tools
+from tools import user_locale_format
+import ctypes
 
 class spinbutton(wid_int.wid_int):
     def __init__(self, name, parent, attrs={},screen=None):
@@ -33,21 +34,39 @@
 
         adj1 = gtk.Adjustment(0.0, -sys.maxint, sys.maxint, 1.0, 5.0)
         self.spin1 = gtk.SpinButton(adj1, 1.0, digits=int(attrs.get('digits', (14, 2))[1]))
-        self.spin1.set_numeric(True)
         self.spin1.set_activates_default(True)
+        self.spin1.connect('input', self.format_input)
+        self.spin1.connect('output', self.format_output)
         self.widget.pack_start(self.spin1, expand=False, fill=True)
 
         self.widget.pack_start(gtk.Label('-'), expand=False, fill=False)
 
         adj2 = gtk.Adjustment(0.0, -sys.maxint, sys.maxint, 1.0, 5.0)
         self.spin2 = gtk.SpinButton(adj2, 1.0, digits=int(attrs.get('digits', (14, 2))[1]))
-        self.spin2.set_numeric(True)
         self.spin2.set_activates_default(True)
+        self.spin2.connect('input', self.format_input)
+        self.spin2.connect('output', self.format_output)
         self.widget.pack_start(self.spin2, expand=False, fill=True)
 
         if self.default_search:
             self.spin1.set_value(self.default_search)
 
+    def format_output(self, spin):
+        digits = spin.get_digits()
+        value = spin.get_value()
+        text = user_locale_format.format('%.' + str(digits) + 'f', value)
+        spin.set_text(text)
+        return True
+ 
+    def format_input(self, spin, new_value_pointer):
+        text = spin.get_text()
+        if text:
+            value = user_locale_format.str2float(text)
+            value_location = ctypes.c_double.from_address(hash(new_value_pointer))
+            value_location.value = float(value)
+            return True
+        return False
+
     def _value_get(self):
         res = []
         self.spin1.update()

=== modified file 'bin/widget_search/spinint.py'
--- bin/widget_search/spinint.py	2010-09-21 09:39:49 +0000
+++ bin/widget_search/spinint.py	2011-08-18 11:12:26 +0000
@@ -25,8 +25,8 @@
 import sys
 import common
 import wid_int
-import tools
-
+from tools import user_locale_format
+import ctypes
 
 class spinint(wid_int.wid_int):
 
@@ -37,20 +37,38 @@
 
         adj1 = gtk.Adjustment(0.0, 0.0, sys.maxint, 1.0, 5.0)
         self.spin1 = gtk.SpinButton(adj1, 1, digits=0)
-        self.spin1.set_numeric(True)
         self.spin1.set_activates_default(True)
+        self.spin1.connect('input', self.format_input)
+        self.spin1.connect('output', self.format_output)
         self.widget.pack_start(self.spin1, expand=False, fill=True)
 
         self.widget.pack_start(gtk.Label('-'), expand=False, fill=False)
 
         adj2 = gtk.Adjustment(0.0, 0.0, sys.maxint, 1.0, 5.0)
         self.spin2 = gtk.SpinButton(adj2, 1, digits=0)
-        self.spin2.set_numeric(True)
         self.spin2.set_activates_default(True)
+        self.spin2.connect('input', self.format_input)
+        self.spin2.connect('output', self.format_output)
         self.widget.pack_start(self.spin2, expand=False, fill=True)
         if self.default_search:
             self.spin1.set_value(self.default_search)
 
+    def format_output(self, spin):
+        digits = spin.get_digits()
+        value = spin.get_value()
+        text = user_locale_format.format('%.' + str(digits) + 'f', value)
+        spin.set_text(text)
+        return True
+ 
+    def format_input(self, spin, new_value_pointer):
+        text = spin.get_text()
+        if text:
+            value = user_locale_format.str2int(text)
+            value_location = ctypes.c_double.from_address(hash(new_value_pointer))
+            value_location.value = float(value)
+            return True
+        return False
+
     def _value_get(self):
         res = []
         self.spin1.update()

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to