Merge lp:~ovnicraft/openobject-client/client-decimal-separator-fixed into lp:openobject-client/6.0
- client-decimal-separator-fixed
- Merge into 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 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
OpenERP Core Team | Pending | ||
Review via email: mp+65998@code.launchpad.net |
Commit message
Description of the change
Fixed error with decimal separator reported in bug https:/
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
1 | === modified file 'bin/tools/__init__.py' | |||
2 | --- bin/tools/__init__.py 2010-12-30 06:00:45 +0000 | |||
3 | +++ bin/tools/__init__.py 2011-06-27 14:17:54 +0000 | |||
4 | @@ -205,12 +205,6 @@ | |||
5 | 205 | 205 | ||
6 | 206 | return unicode(value, from_encoding) | 206 | return unicode(value, from_encoding) |
7 | 207 | 207 | ||
8 | 208 | def locale_format(format, value): | ||
9 | 209 | label_str = locale.format(format, value, True, True) | ||
10 | 210 | if not locale.getpreferredencoding().lower().startswith('utf'): | ||
11 | 211 | label_str = label_str.replace('\xa0', '\xc2\xa0') | ||
12 | 212 | return label_str | ||
13 | 213 | |||
14 | 214 | def format_connection_string(login, _passwd, server, port, protocol, dbname): | 208 | def format_connection_string(login, _passwd, server, port, protocol, dbname): |
15 | 215 | #def format_connection_string(*args): | 209 | #def format_connection_string(*args): |
16 | 216 | # login, _passwd, server, port, protocol, dbname = args | 210 | # login, _passwd, server, port, protocol, dbname = args |
17 | @@ -225,27 +219,6 @@ | |||
18 | 225 | result += '/%s' % (dbname,) | 219 | result += '/%s' % (dbname,) |
19 | 226 | return result | 220 | return result |
20 | 227 | 221 | ||
21 | 228 | def str2int(string, default=None): | ||
22 | 229 | assert isinstance(string, basestring) | ||
23 | 230 | try: | ||
24 | 231 | integer = locale.atoi(string) | ||
25 | 232 | return integer | ||
26 | 233 | except: | ||
27 | 234 | if default is not None: | ||
28 | 235 | return default | ||
29 | 236 | raise ValueError("%r does not represent a valid integer value" % (string,)) | ||
30 | 237 | |||
31 | 238 | |||
32 | 239 | def str2float(string, default=None): | ||
33 | 240 | assert isinstance(string, basestring) | ||
34 | 241 | try: | ||
35 | 242 | float = locale.atof(string) | ||
36 | 243 | return float | ||
37 | 244 | except: | ||
38 | 245 | if default is not None: | ||
39 | 246 | return default | ||
40 | 247 | raise ValueError("%r does not represent a valid float value" % (string,)) | ||
41 | 248 | |||
42 | 249 | def str2bool(string, default=None): | 222 | def str2bool(string, default=None): |
43 | 250 | """Convert a string representing a boolean into the corresponding boolean | 223 | """Convert a string representing a boolean into the corresponding boolean |
44 | 251 | 224 | ||
45 | 252 | 225 | ||
46 | === modified file 'bin/tools/user_locale_format.py' | |||
47 | --- bin/tools/user_locale_format.py 2011-01-17 07:21:19 +0000 | |||
48 | +++ bin/tools/user_locale_format.py 2011-06-27 14:17:54 +0000 | |||
49 | @@ -195,3 +195,32 @@ | |||
50 | 195 | if grouping: | 195 | if grouping: |
51 | 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] |
52 | 197 | return formatted | 197 | return formatted |
53 | 198 | |||
54 | 199 | def str2int(string): | ||
55 | 200 | ''' Converts a string to an integer according to the locale settings | ||
56 | 201 | that the user has in Administration/Translations/Languages. | ||
57 | 202 | ''' | ||
58 | 203 | assert isinstance(string, basestring) | ||
59 | 204 | return str2float(string, int) | ||
60 | 205 | |||
61 | 206 | def str2float(string, func=float): | ||
62 | 207 | ''' Parses a string as a float according to the locale settings | ||
63 | 208 | that the user has in Administration/Translations/Languages. | ||
64 | 209 | ''' | ||
65 | 210 | assert isinstance(string, basestring) | ||
66 | 211 | try: | ||
67 | 212 | #First, get rid of the thousand separator | ||
68 | 213 | ts = LOCALE_CACHE.get('thousands_sep') | ||
69 | 214 | if ts: | ||
70 | 215 | string = string.replace(ts, '') | ||
71 | 216 | #next, replace the decimal point with a dot | ||
72 | 217 | dd = LOCALE_CACHE.get('decimal_point') | ||
73 | 218 | if dd: | ||
74 | 219 | string = string.replace(dd, '.') | ||
75 | 220 | #finally, parse the string | ||
76 | 221 | return func(string) | ||
77 | 222 | except: | ||
78 | 223 | type = 'float' | ||
79 | 224 | if func == int: | ||
80 | 225 | type = 'integer' | ||
81 | 226 | raise ValueError("%r does not represent a valid %s value" % (string,type)) | ||
82 | 198 | 227 | ||
83 | === modified file 'bin/widget/view/form_gtk/spinbutton.py' | |||
84 | --- bin/widget/view/form_gtk/spinbutton.py 2010-07-16 05:41:32 +0000 | |||
85 | +++ bin/widget/view/form_gtk/spinbutton.py 2011-06-27 14:17:54 +0000 | |||
86 | @@ -1,6 +1,6 @@ | |||
87 | 1 | # -*- coding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
88 | 2 | ############################################################################## | 2 | ############################################################################## |
90 | 3 | # | 3 | # |
91 | 4 | # OpenERP, Open Source Management Solution | 4 | # OpenERP, Open Source Management Solution |
92 | 5 | # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). | 5 | # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). |
93 | 6 | # | 6 | # |
94 | @@ -15,14 +15,16 @@ | |||
95 | 15 | # GNU Affero General Public License for more details. | 15 | # GNU Affero General Public License for more details. |
96 | 16 | # | 16 | # |
97 | 17 | # You should have received a copy of the GNU Affero General Public License | 17 | # You should have received a copy of the GNU Affero General Public License |
99 | 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/>. |
100 | 19 | # | 19 | # |
101 | 20 | ############################################################################## | 20 | ############################################################################## |
102 | 21 | 21 | ||
103 | 22 | import gtk | 22 | import gtk |
104 | 23 | import sys | 23 | import sys |
105 | 24 | import ctypes | ||
106 | 24 | import interface | 25 | import interface |
108 | 25 | 26 | import tools | |
109 | 27 | from tools import user_locale_format | ||
110 | 26 | 28 | ||
111 | 27 | class spinbutton(interface.widget_interface): | 29 | class spinbutton(interface.widget_interface): |
112 | 28 | def __init__(self, window, parent, model, attrs={}): | 30 | def __init__(self, window, parent, model, attrs={}): |
113 | @@ -30,7 +32,6 @@ | |||
114 | 30 | 32 | ||
115 | 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) |
116 | 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] ) ) |
117 | 33 | self.widget.set_numeric(True) | ||
118 | 34 | self.widget.set_activates_default(True) | 35 | self.widget.set_activates_default(True) |
119 | 35 | self.widget.connect('populate-popup', self._menu_open) | 36 | self.widget.connect('populate-popup', self._menu_open) |
120 | 36 | if self.attrs['readonly']: | 37 | if self.attrs['readonly']: |
121 | @@ -38,6 +39,24 @@ | |||
122 | 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()) |
123 | 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()) |
124 | 40 | self.widget.connect('activate', self.sig_activate) | 41 | self.widget.connect('activate', self.sig_activate) |
125 | 42 | self.widget.connect('input', self.format_input) | ||
126 | 43 | self.widget.connect('output', self.format_output) | ||
127 | 44 | |||
128 | 45 | def format_output(self, spin): | ||
129 | 46 | digits = spin.get_digits() | ||
130 | 47 | value = spin.get_value() | ||
131 | 48 | text = user_locale_format.format('%.' + str(digits) + 'f', value) | ||
132 | 49 | spin.set_text(text) | ||
133 | 50 | return True | ||
134 | 51 | |||
135 | 52 | def format_input(self, spin, new_value_pointer): | ||
136 | 53 | text = spin.get_text() | ||
137 | 54 | if text: | ||
138 | 55 | value = user_locale_format.str2float(text) | ||
139 | 56 | value_location = ctypes.c_double.from_address(hash(new_value_pointer)) | ||
140 | 57 | value_location.value = float(value) | ||
141 | 58 | return True | ||
142 | 59 | return False | ||
143 | 41 | 60 | ||
144 | 42 | def set_value(self, model, model_field): | 61 | def set_value(self, model, model_field): |
145 | 43 | self.widget.update() | 62 | self.widget.update() |
146 | 44 | 63 | ||
147 | === modified file 'bin/widget/view/form_gtk/spinint.py' | |||
148 | --- bin/widget/view/form_gtk/spinint.py 2010-07-16 05:41:32 +0000 | |||
149 | +++ bin/widget/view/form_gtk/spinint.py 2011-06-27 14:17:54 +0000 | |||
150 | @@ -1,6 +1,6 @@ | |||
151 | 1 | # -*- coding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
152 | 2 | ############################################################################## | 2 | ############################################################################## |
154 | 3 | # | 3 | # |
155 | 4 | # OpenERP, Open Source Management Solution | 4 | # OpenERP, Open Source Management Solution |
156 | 5 | # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). | 5 | # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). |
157 | 6 | # | 6 | # |
158 | @@ -15,14 +15,16 @@ | |||
159 | 15 | # GNU Affero General Public License for more details. | 15 | # GNU Affero General Public License for more details. |
160 | 16 | # | 16 | # |
161 | 17 | # You should have received a copy of the GNU Affero General Public License | 17 | # You should have received a copy of the GNU Affero General Public License |
163 | 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/>. |
164 | 19 | # | 19 | # |
165 | 20 | ############################################################################## | 20 | ############################################################################## |
166 | 21 | 21 | ||
167 | 22 | import gtk | 22 | import gtk |
168 | 23 | import sys | 23 | import sys |
169 | 24 | import ctypes | ||
170 | 24 | import interface | 25 | import interface |
172 | 25 | 26 | import tools | |
173 | 27 | from tools import user_locale_format | ||
174 | 26 | 28 | ||
175 | 27 | class spinint(interface.widget_interface): | 29 | class spinint(interface.widget_interface): |
176 | 28 | 30 | ||
177 | @@ -31,7 +33,6 @@ | |||
178 | 31 | 33 | ||
179 | 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) |
180 | 33 | self.widget = gtk.SpinButton(adj, 1, digits=0) | 35 | self.widget = gtk.SpinButton(adj, 1, digits=0) |
181 | 34 | self.widget.set_numeric(True) | ||
182 | 35 | self.widget.set_width_chars(5) | 36 | self.widget.set_width_chars(5) |
183 | 36 | self.widget.set_activates_default(True) | 37 | self.widget.set_activates_default(True) |
184 | 37 | self.widget.connect('populate-popup', self._menu_open) | 38 | self.widget.connect('populate-popup', self._menu_open) |
185 | @@ -40,6 +41,24 @@ | |||
186 | 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()) |
187 | 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()) |
188 | 42 | self.widget.connect('activate', self.sig_activate) | 43 | self.widget.connect('activate', self.sig_activate) |
189 | 44 | self.widget.connect('input', self.format_input) | ||
190 | 45 | self.widget.connect('output', self.format_output) | ||
191 | 46 | |||
192 | 47 | def format_output(self, spin): | ||
193 | 48 | digits = spin.get_digits() | ||
194 | 49 | value = spin.get_value() | ||
195 | 50 | text = user_locale_format.format('%.' + str(digits) + 'f', value) | ||
196 | 51 | spin.set_text(text) | ||
197 | 52 | return True | ||
198 | 53 | |||
199 | 54 | def format_input(self, spin, new_value_pointer): | ||
200 | 55 | text = spin.get_text() | ||
201 | 56 | if text: | ||
202 | 57 | value = user_locale_format.str2int(text) | ||
203 | 58 | value_location = ctypes.c_double.from_address(hash(new_value_pointer)) | ||
204 | 59 | value_location.value = float(value) | ||
205 | 60 | return True | ||
206 | 61 | return False | ||
207 | 43 | 62 | ||
208 | 44 | def set_value(self, model, model_field): | 63 | def set_value(self, model, model_field): |
209 | 45 | self.widget.update() | 64 | self.widget.update() |
210 | 46 | 65 | ||
211 | === modified file 'bin/widget/view/tree_gtk/parser.py' | |||
212 | --- bin/widget/view/tree_gtk/parser.py 2011-01-18 06:45:01 +0000 | |||
213 | +++ bin/widget/view/tree_gtk/parser.py 2011-06-27 14:17:54 +0000 | |||
214 | @@ -343,7 +343,7 @@ | |||
215 | 343 | class Int(Char): | 343 | class Int(Char): |
216 | 344 | 344 | ||
217 | 345 | def value_from_text(self, model, text): | 345 | def value_from_text(self, model, text): |
219 | 346 | return tools.str2int(text) | 346 | return user_locale_format.str2int(text) |
220 | 347 | 347 | ||
221 | 348 | def get_textual_value(self, model): | 348 | def get_textual_value(self, model): |
222 | 349 | count = False | 349 | count = False |
223 | @@ -472,7 +472,7 @@ | |||
224 | 472 | return converted_val | 472 | return converted_val |
225 | 473 | 473 | ||
226 | 474 | def value_from_text(self, model, text): | 474 | def value_from_text(self, model, text): |
228 | 475 | return tools.str2float(text) | 475 | return user_locale_format.str2float(text) |
229 | 476 | 476 | ||
230 | 477 | class FloatTime(Char): | 477 | class FloatTime(Char): |
231 | 478 | 478 | ||
232 | 479 | 479 | ||
233 | === modified file 'bin/widget_search/spinbutton.py' | |||
234 | --- bin/widget_search/spinbutton.py 2010-09-21 09:39:49 +0000 | |||
235 | +++ bin/widget_search/spinbutton.py 2011-06-27 14:17:54 +0000 | |||
236 | @@ -23,7 +23,9 @@ | |||
237 | 23 | import common | 23 | import common |
238 | 24 | import wid_int | 24 | import wid_int |
239 | 25 | import sys | 25 | import sys |
240 | 26 | import ctypes | ||
241 | 26 | import tools | 27 | import tools |
242 | 28 | from tools import user_locale_format | ||
243 | 27 | 29 | ||
244 | 28 | class spinbutton(wid_int.wid_int): | 30 | class spinbutton(wid_int.wid_int): |
245 | 29 | def __init__(self, name, parent, attrs={},screen=None): | 31 | def __init__(self, name, parent, attrs={},screen=None): |
246 | @@ -33,21 +35,39 @@ | |||
247 | 33 | 35 | ||
248 | 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) |
249 | 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])) |
250 | 36 | self.spin1.set_numeric(True) | ||
251 | 37 | self.spin1.set_activates_default(True) | 38 | self.spin1.set_activates_default(True) |
252 | 39 | self.spin1.connect('input', self.format_input) | ||
253 | 40 | self.spin1.connect('output', self.format_output) | ||
254 | 38 | self.widget.pack_start(self.spin1, expand=False, fill=True) | 41 | self.widget.pack_start(self.spin1, expand=False, fill=True) |
255 | 39 | 42 | ||
256 | 40 | self.widget.pack_start(gtk.Label('-'), expand=False, fill=False) | 43 | self.widget.pack_start(gtk.Label('-'), expand=False, fill=False) |
257 | 41 | 44 | ||
258 | 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) |
259 | 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])) |
260 | 44 | self.spin2.set_numeric(True) | ||
261 | 45 | self.spin2.set_activates_default(True) | 47 | self.spin2.set_activates_default(True) |
262 | 48 | self.spin2.connect('input', self.format_input) | ||
263 | 49 | self.spin2.connect('output', self.format_output) | ||
264 | 46 | self.widget.pack_start(self.spin2, expand=False, fill=True) | 50 | self.widget.pack_start(self.spin2, expand=False, fill=True) |
265 | 47 | 51 | ||
266 | 48 | if self.default_search: | 52 | if self.default_search: |
267 | 49 | self.spin1.set_value(self.default_search) | 53 | self.spin1.set_value(self.default_search) |
268 | 50 | 54 | ||
269 | 55 | def format_output(self, spin): | ||
270 | 56 | digits = spin.get_digits() | ||
271 | 57 | value = spin.get_value() | ||
272 | 58 | text = user_locale_format.format('%.' + str(digits) + 'f', value) | ||
273 | 59 | spin.set_text(text) | ||
274 | 60 | return True | ||
275 | 61 | |||
276 | 62 | def format_input(self, spin, new_value_pointer): | ||
277 | 63 | text = spin.get_text() | ||
278 | 64 | if text: | ||
279 | 65 | value = user_locale_format.str2float(text) | ||
280 | 66 | value_location = ctypes.c_double.from_address(hash(new_value_pointer)) | ||
281 | 67 | value_location.value = float(value) | ||
282 | 68 | return True | ||
283 | 69 | return False | ||
284 | 70 | |||
285 | 51 | def _value_get(self): | 71 | def _value_get(self): |
286 | 52 | res = [] | 72 | res = [] |
287 | 53 | self.spin1.update() | 73 | self.spin1.update() |
288 | @@ -73,8 +93,8 @@ | |||
289 | 73 | 93 | ||
290 | 74 | def clear(self): | 94 | def clear(self): |
291 | 75 | self.value = 0.00 | 95 | self.value = 0.00 |
294 | 76 | 96 | ||
295 | 77 | 97 | ||
296 | 78 | def grab_focus(self): | 98 | def grab_focus(self): |
297 | 79 | self.spin1.grab_focus() | 99 | self.spin1.grab_focus() |
298 | 80 | 100 | ||
299 | 81 | 101 | ||
300 | === modified file 'bin/widget_search/spinint.py' | |||
301 | --- bin/widget_search/spinint.py 2010-09-21 09:39:49 +0000 | |||
302 | +++ bin/widget_search/spinint.py 2011-06-27 14:17:54 +0000 | |||
303 | @@ -21,11 +21,13 @@ | |||
304 | 21 | 21 | ||
305 | 22 | import gtk | 22 | import gtk |
306 | 23 | from gtk import glade | 23 | from gtk import glade |
307 | 24 | import ctypes | ||
308 | 24 | import gettext | 25 | import gettext |
309 | 25 | import sys | 26 | import sys |
310 | 26 | import common | 27 | import common |
311 | 27 | import wid_int | 28 | import wid_int |
312 | 28 | import tools | 29 | import tools |
313 | 30 | from tools import user_locale_format | ||
314 | 29 | 31 | ||
315 | 30 | 32 | ||
316 | 31 | class spinint(wid_int.wid_int): | 33 | class spinint(wid_int.wid_int): |
317 | @@ -37,20 +39,38 @@ | |||
318 | 37 | 39 | ||
319 | 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) |
320 | 39 | self.spin1 = gtk.SpinButton(adj1, 1, digits=0) | 41 | self.spin1 = gtk.SpinButton(adj1, 1, digits=0) |
321 | 40 | self.spin1.set_numeric(True) | ||
322 | 41 | self.spin1.set_activates_default(True) | 42 | self.spin1.set_activates_default(True) |
323 | 43 | self.spin1.connect('input', self.format_input) | ||
324 | 44 | self.spin1.connect('output', self.format_output) | ||
325 | 42 | self.widget.pack_start(self.spin1, expand=False, fill=True) | 45 | self.widget.pack_start(self.spin1, expand=False, fill=True) |
326 | 43 | 46 | ||
327 | 44 | self.widget.pack_start(gtk.Label('-'), expand=False, fill=False) | 47 | self.widget.pack_start(gtk.Label('-'), expand=False, fill=False) |
328 | 45 | 48 | ||
329 | 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) |
330 | 47 | self.spin2 = gtk.SpinButton(adj2, 1, digits=0) | 50 | self.spin2 = gtk.SpinButton(adj2, 1, digits=0) |
331 | 48 | self.spin2.set_numeric(True) | ||
332 | 49 | self.spin2.set_activates_default(True) | 51 | self.spin2.set_activates_default(True) |
333 | 52 | self.spin2.connect('input', self.format_input) | ||
334 | 53 | self.spin2.connect('output', self.format_output) | ||
335 | 50 | self.widget.pack_start(self.spin2, expand=False, fill=True) | 54 | self.widget.pack_start(self.spin2, expand=False, fill=True) |
336 | 51 | if self.default_search: | 55 | if self.default_search: |
337 | 52 | self.spin1.set_value(self.default_search) | 56 | self.spin1.set_value(self.default_search) |
338 | 53 | 57 | ||
339 | 58 | def format_output(self, spin): | ||
340 | 59 | digits = spin.get_digits() | ||
341 | 60 | value = spin.get_value() | ||
342 | 61 | text = user_locale_format.format('%.' + str(digits) + 'f', value) | ||
343 | 62 | spin.set_text(text) | ||
344 | 63 | return True | ||
345 | 64 | |||
346 | 65 | def format_input(self, spin, new_value_pointer): | ||
347 | 66 | text = spin.get_text() | ||
348 | 67 | if text: | ||
349 | 68 | value = user_locale_format.str2int(text) | ||
350 | 69 | value_location = ctypes.c_double.from_address(hash(new_value_pointer)) | ||
351 | 70 | value_location.value = float(value) | ||
352 | 71 | return True | ||
353 | 72 | return False | ||
354 | 73 | |||
355 | 54 | def _value_get(self): | 74 | def _value_get(self): |
356 | 55 | res = [] | 75 | res = [] |
357 | 56 | self.spin1.update() | 76 | self.spin1.update() |
358 | @@ -76,7 +96,7 @@ | |||
359 | 76 | 96 | ||
360 | 77 | def clear(self): | 97 | def clear(self): |
361 | 78 | self.value = 0.0 | 98 | self.value = 0.0 |
363 | 79 | 99 | ||
364 | 80 | def grab_focus(self): | 100 | def grab_focus(self): |
365 | 81 | self.spin1.grab_focus() | 101 | self.spin1.grab_focus() |
366 | 82 | 102 |