Merge lp:~ovnicraft/openobject-client/client-decimal-separator-fixed into lp:openobject-client/6.0

Proposed by Cristian Salamea
Status: Needs review
Proposed branch: lp:~ovnicraft/openobject-client/client-decimal-separator-fixed
Merge into: lp:openobject-client/6.0
Diff against target: 365 lines (+124/-44)
7 files modified
bin/tools/__init__.py (+0/-27)
bin/tools/user_locale_format.py (+29/-0)
bin/widget/view/form_gtk/spinbutton.py (+23/-4)
bin/widget/view/form_gtk/spinint.py (+23/-4)
bin/widget/view/tree_gtk/parser.py (+2/-2)
bin/widget_search/spinbutton.py (+24/-4)
bin/widget_search/spinint.py (+23/-3)
To merge this branch: bzr merge lp:~ovnicraft/openobject-client/client-decimal-separator-fixed
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+65998@code.launchpad.net

Description of the change

Fixed error with decimal separator reported in bug https://bugs.launchpad.net/openobject-client/+bug/697625

To post a comment you must log in.

Unmerged revisions

1846. By Cristian Salamea

[FIX] apply patch from trunk to fix decimal separator; bug related #697625

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bin/tools/__init__.py'
--- bin/tools/__init__.py 2010-12-30 06:00:45 +0000
+++ bin/tools/__init__.py 2011-06-27 14:17:54 +0000
@@ -205,12 +205,6 @@
205205
206 return unicode(value, from_encoding)206 return unicode(value, from_encoding)
207207
208def locale_format(format, value):
209 label_str = locale.format(format, value, True, True)
210 if not locale.getpreferredencoding().lower().startswith('utf'):
211 label_str = label_str.replace('\xa0', '\xc2\xa0')
212 return label_str
213
214def format_connection_string(login, _passwd, server, port, protocol, dbname):208def format_connection_string(login, _passwd, server, port, protocol, dbname):
215#def format_connection_string(*args):209#def format_connection_string(*args):
216# login, _passwd, server, port, protocol, dbname = args210# login, _passwd, server, port, protocol, dbname = args
@@ -225,27 +219,6 @@
225 result += '/%s' % (dbname,)219 result += '/%s' % (dbname,)
226 return result220 return result
227221
228def str2int(string, default=None):
229 assert isinstance(string, basestring)
230 try:
231 integer = locale.atoi(string)
232 return integer
233 except:
234 if default is not None:
235 return default
236 raise ValueError("%r does not represent a valid integer value" % (string,))
237
238
239def str2float(string, default=None):
240 assert isinstance(string, basestring)
241 try:
242 float = locale.atof(string)
243 return float
244 except:
245 if default is not None:
246 return default
247 raise ValueError("%r does not represent a valid float value" % (string,))
248
249def str2bool(string, default=None):222def str2bool(string, default=None):
250 """Convert a string representing a boolean into the corresponding boolean223 """Convert a string representing a boolean into the corresponding boolean
251224
252225
=== 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-06-27 14:17:54 +0000
@@ -195,3 +195,32 @@
195 if grouping:195 if grouping:
196 formatted = group(formatted, monetary=monetary, grouping=lang_grouping, thousands_sep=thousands_sep)[0]196 formatted = group(formatted, monetary=monetary, grouping=lang_grouping, thousands_sep=thousands_sep)[0]
197 return formatted197 return formatted
198
199def str2int(string):
200 ''' Converts a string to an integer according to the locale settings
201 that the user has in Administration/Translations/Languages.
202 '''
203 assert isinstance(string, basestring)
204 return str2float(string, int)
205
206def str2float(string, func=float):
207 ''' Parses a string as a float according to the locale settings
208 that the user has in Administration/Translations/Languages.
209 '''
210 assert isinstance(string, basestring)
211 try:
212 #First, get rid of the thousand separator
213 ts = LOCALE_CACHE.get('thousands_sep')
214 if ts:
215 string = string.replace(ts, '')
216 #next, replace the decimal point with a dot
217 dd = LOCALE_CACHE.get('decimal_point')
218 if dd:
219 string = string.replace(dd, '.')
220 #finally, parse the string
221 return func(string)
222 except:
223 type = 'float'
224 if func == int:
225 type = 'integer'
226 raise ValueError("%r does not represent a valid %s value" % (string,type))
198227
=== 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-06-27 14:17:54 +0000
@@ -1,6 +1,6 @@
1# -*- coding: utf-8 -*-1# -*- coding: utf-8 -*-
2##############################################################################2##############################################################################
3# 3#
4# OpenERP, Open Source Management Solution4# OpenERP, Open Source Management Solution
5# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).5# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6#6#
@@ -15,14 +15,16 @@
15# GNU Affero General Public License for more details.15# GNU Affero General Public License for more details.
16#16#
17# You should have received a copy of the GNU Affero General Public License17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>. 18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#19#
20##############################################################################20##############################################################################
2121
22import gtk22import gtk
23import sys23import sys
24import ctypes
24import interface25import interface
2526import tools
27from tools import user_locale_format
2628
27class spinbutton(interface.widget_interface):29class spinbutton(interface.widget_interface):
28 def __init__(self, window, parent, model, attrs={}):30 def __init__(self, window, parent, model, attrs={}):
@@ -30,7 +32,6 @@
3032
31 adj = gtk.Adjustment(0.0, -sys.maxint, sys.maxint, 1.0, 5.0)33 adj = gtk.Adjustment(0.0, -sys.maxint, sys.maxint, 1.0, 5.0)
32 self.widget = gtk.SpinButton(adj, 1.0, digits=int( attrs.get('digits',(14,2))[1] ) )34 self.widget = gtk.SpinButton(adj, 1.0, digits=int( attrs.get('digits',(14,2))[1] ) )
33 self.widget.set_numeric(True)
34 self.widget.set_activates_default(True)35 self.widget.set_activates_default(True)
35 self.widget.connect('populate-popup', self._menu_open)36 self.widget.connect('populate-popup', self._menu_open)
36 if self.attrs['readonly']:37 if self.attrs['readonly']:
@@ -38,6 +39,24 @@
38 self.widget.connect('focus-in-event', lambda x,y: self._focus_in())39 self.widget.connect('focus-in-event', lambda x,y: self._focus_in())
39 self.widget.connect('focus-out-event', lambda x,y: self._focus_out())40 self.widget.connect('focus-out-event', lambda x,y: self._focus_out())
40 self.widget.connect('activate', self.sig_activate)41 self.widget.connect('activate', self.sig_activate)
42 self.widget.connect('input', self.format_input)
43 self.widget.connect('output', self.format_output)
44
45 def format_output(self, spin):
46 digits = spin.get_digits()
47 value = spin.get_value()
48 text = user_locale_format.format('%.' + str(digits) + 'f', value)
49 spin.set_text(text)
50 return True
51
52 def format_input(self, spin, new_value_pointer):
53 text = spin.get_text()
54 if text:
55 value = user_locale_format.str2float(text)
56 value_location = ctypes.c_double.from_address(hash(new_value_pointer))
57 value_location.value = float(value)
58 return True
59 return False
4160
42 def set_value(self, model, model_field):61 def set_value(self, model, model_field):
43 self.widget.update()62 self.widget.update()
4463
=== 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-06-27 14:17:54 +0000
@@ -1,6 +1,6 @@
1# -*- coding: utf-8 -*-1# -*- coding: utf-8 -*-
2##############################################################################2##############################################################################
3# 3#
4# OpenERP, Open Source Management Solution4# OpenERP, Open Source Management Solution
5# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).5# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6#6#
@@ -15,14 +15,16 @@
15# GNU Affero General Public License for more details.15# GNU Affero General Public License for more details.
16#16#
17# You should have received a copy of the GNU Affero General Public License17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>. 18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#19#
20##############################################################################20##############################################################################
2121
22import gtk22import gtk
23import sys23import sys
24import ctypes
24import interface25import interface
2526import tools
27from tools import user_locale_format
2628
27class spinint(interface.widget_interface):29class spinint(interface.widget_interface):
2830
@@ -31,7 +33,6 @@
3133
32 adj = gtk.Adjustment(0.0, -sys.maxint, sys.maxint, 1.0, 5.0)34 adj = gtk.Adjustment(0.0, -sys.maxint, sys.maxint, 1.0, 5.0)
33 self.widget = gtk.SpinButton(adj, 1, digits=0)35 self.widget = gtk.SpinButton(adj, 1, digits=0)
34 self.widget.set_numeric(True)
35 self.widget.set_width_chars(5)36 self.widget.set_width_chars(5)
36 self.widget.set_activates_default(True)37 self.widget.set_activates_default(True)
37 self.widget.connect('populate-popup', self._menu_open)38 self.widget.connect('populate-popup', self._menu_open)
@@ -40,6 +41,24 @@
40 self.widget.connect('focus-in-event', lambda x,y: self._focus_in())41 self.widget.connect('focus-in-event', lambda x,y: self._focus_in())
41 self.widget.connect('focus-out-event', lambda x,y: self._focus_out())42 self.widget.connect('focus-out-event', lambda x,y: self._focus_out())
42 self.widget.connect('activate', self.sig_activate)43 self.widget.connect('activate', self.sig_activate)
44 self.widget.connect('input', self.format_input)
45 self.widget.connect('output', self.format_output)
46
47 def format_output(self, spin):
48 digits = spin.get_digits()
49 value = spin.get_value()
50 text = user_locale_format.format('%.' + str(digits) + 'f', value)
51 spin.set_text(text)
52 return True
53
54 def format_input(self, spin, new_value_pointer):
55 text = spin.get_text()
56 if text:
57 value = user_locale_format.str2int(text)
58 value_location = ctypes.c_double.from_address(hash(new_value_pointer))
59 value_location.value = float(value)
60 return True
61 return False
4362
44 def set_value(self, model, model_field):63 def set_value(self, model, model_field):
45 self.widget.update()64 self.widget.update()
4665
=== 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-06-27 14:17:54 +0000
@@ -343,7 +343,7 @@
343class Int(Char):343class Int(Char):
344344
345 def value_from_text(self, model, text):345 def value_from_text(self, model, text):
346 return tools.str2int(text)346 return user_locale_format.str2int(text)
347347
348 def get_textual_value(self, model):348 def get_textual_value(self, model):
349 count = False349 count = False
@@ -472,7 +472,7 @@
472 return converted_val472 return converted_val
473473
474 def value_from_text(self, model, text):474 def value_from_text(self, model, text):
475 return tools.str2float(text)475 return user_locale_format.str2float(text)
476476
477class FloatTime(Char):477class FloatTime(Char):
478478
479479
=== 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-06-27 14:17:54 +0000
@@ -23,7 +23,9 @@
23import common23import common
24import wid_int24import wid_int
25import sys25import sys
26import ctypes
26import tools27import tools
28from tools import user_locale_format
2729
28class spinbutton(wid_int.wid_int):30class spinbutton(wid_int.wid_int):
29 def __init__(self, name, parent, attrs={},screen=None):31 def __init__(self, name, parent, attrs={},screen=None):
@@ -33,21 +35,39 @@
3335
34 adj1 = gtk.Adjustment(0.0, -sys.maxint, sys.maxint, 1.0, 5.0)36 adj1 = gtk.Adjustment(0.0, -sys.maxint, sys.maxint, 1.0, 5.0)
35 self.spin1 = gtk.SpinButton(adj1, 1.0, digits=int(attrs.get('digits', (14, 2))[1]))37 self.spin1 = gtk.SpinButton(adj1, 1.0, digits=int(attrs.get('digits', (14, 2))[1]))
36 self.spin1.set_numeric(True)
37 self.spin1.set_activates_default(True)38 self.spin1.set_activates_default(True)
39 self.spin1.connect('input', self.format_input)
40 self.spin1.connect('output', self.format_output)
38 self.widget.pack_start(self.spin1, expand=False, fill=True)41 self.widget.pack_start(self.spin1, expand=False, fill=True)
3942
40 self.widget.pack_start(gtk.Label('-'), expand=False, fill=False)43 self.widget.pack_start(gtk.Label('-'), expand=False, fill=False)
4144
42 adj2 = gtk.Adjustment(0.0, -sys.maxint, sys.maxint, 1.0, 5.0)45 adj2 = gtk.Adjustment(0.0, -sys.maxint, sys.maxint, 1.0, 5.0)
43 self.spin2 = gtk.SpinButton(adj2, 1.0, digits=int(attrs.get('digits', (14, 2))[1]))46 self.spin2 = gtk.SpinButton(adj2, 1.0, digits=int(attrs.get('digits', (14, 2))[1]))
44 self.spin2.set_numeric(True)
45 self.spin2.set_activates_default(True)47 self.spin2.set_activates_default(True)
48 self.spin2.connect('input', self.format_input)
49 self.spin2.connect('output', self.format_output)
46 self.widget.pack_start(self.spin2, expand=False, fill=True)50 self.widget.pack_start(self.spin2, expand=False, fill=True)
4751
48 if self.default_search:52 if self.default_search:
49 self.spin1.set_value(self.default_search)53 self.spin1.set_value(self.default_search)
5054
55 def format_output(self, spin):
56 digits = spin.get_digits()
57 value = spin.get_value()
58 text = user_locale_format.format('%.' + str(digits) + 'f', value)
59 spin.set_text(text)
60 return True
61
62 def format_input(self, spin, new_value_pointer):
63 text = spin.get_text()
64 if text:
65 value = user_locale_format.str2float(text)
66 value_location = ctypes.c_double.from_address(hash(new_value_pointer))
67 value_location.value = float(value)
68 return True
69 return False
70
51 def _value_get(self):71 def _value_get(self):
52 res = []72 res = []
53 self.spin1.update()73 self.spin1.update()
@@ -73,8 +93,8 @@
7393
74 def clear(self):94 def clear(self):
75 self.value = 0.0095 self.value = 0.00
76 96
77 97
78 def grab_focus(self):98 def grab_focus(self):
79 self.spin1.grab_focus()99 self.spin1.grab_focus()
80100
81101
=== 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-06-27 14:17:54 +0000
@@ -21,11 +21,13 @@
2121
22import gtk22import gtk
23from gtk import glade23from gtk import glade
24import ctypes
24import gettext25import gettext
25import sys26import sys
26import common27import common
27import wid_int28import wid_int
28import tools29import tools
30from tools import user_locale_format
2931
3032
31class spinint(wid_int.wid_int):33class spinint(wid_int.wid_int):
@@ -37,20 +39,38 @@
3739
38 adj1 = gtk.Adjustment(0.0, 0.0, sys.maxint, 1.0, 5.0)40 adj1 = gtk.Adjustment(0.0, 0.0, sys.maxint, 1.0, 5.0)
39 self.spin1 = gtk.SpinButton(adj1, 1, digits=0)41 self.spin1 = gtk.SpinButton(adj1, 1, digits=0)
40 self.spin1.set_numeric(True)
41 self.spin1.set_activates_default(True)42 self.spin1.set_activates_default(True)
43 self.spin1.connect('input', self.format_input)
44 self.spin1.connect('output', self.format_output)
42 self.widget.pack_start(self.spin1, expand=False, fill=True)45 self.widget.pack_start(self.spin1, expand=False, fill=True)
4346
44 self.widget.pack_start(gtk.Label('-'), expand=False, fill=False)47 self.widget.pack_start(gtk.Label('-'), expand=False, fill=False)
4548
46 adj2 = gtk.Adjustment(0.0, 0.0, sys.maxint, 1.0, 5.0)49 adj2 = gtk.Adjustment(0.0, 0.0, sys.maxint, 1.0, 5.0)
47 self.spin2 = gtk.SpinButton(adj2, 1, digits=0)50 self.spin2 = gtk.SpinButton(adj2, 1, digits=0)
48 self.spin2.set_numeric(True)
49 self.spin2.set_activates_default(True)51 self.spin2.set_activates_default(True)
52 self.spin2.connect('input', self.format_input)
53 self.spin2.connect('output', self.format_output)
50 self.widget.pack_start(self.spin2, expand=False, fill=True)54 self.widget.pack_start(self.spin2, expand=False, fill=True)
51 if self.default_search:55 if self.default_search:
52 self.spin1.set_value(self.default_search)56 self.spin1.set_value(self.default_search)
5357
58 def format_output(self, spin):
59 digits = spin.get_digits()
60 value = spin.get_value()
61 text = user_locale_format.format('%.' + str(digits) + 'f', value)
62 spin.set_text(text)
63 return True
64
65 def format_input(self, spin, new_value_pointer):
66 text = spin.get_text()
67 if text:
68 value = user_locale_format.str2int(text)
69 value_location = ctypes.c_double.from_address(hash(new_value_pointer))
70 value_location.value = float(value)
71 return True
72 return False
73
54 def _value_get(self):74 def _value_get(self):
55 res = []75 res = []
56 self.spin1.update()76 self.spin1.update()
@@ -76,7 +96,7 @@
7696
77 def clear(self):97 def clear(self):
78 self.value = 0.098 self.value = 0.0
79 99
80 def grab_focus(self):100 def grab_focus(self):
81 self.spin1.grab_focus()101 self.spin1.grab_focus()
82102