~ovnicraft/openobject-client/client-decimal-separator-fixed

« back to all changes in this revision

Viewing changes to bin/widget/view/form_gtk/spinbutton.py

  • Committer: Cristian Salamea
  • Date: 2011-06-27 14:03:04 UTC
  • Revision ID: ovnicraft@gmail.com-20110627140304-oyjaohowf7ox1v0w
[FIX] apply patch from trunk to fix decimal separator; bug related #697625

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- coding: utf-8 -*-
2
2
##############################################################################
3
 
#    
 
3
#
4
4
#    OpenERP, Open Source Management Solution
5
5
#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6
6
#
15
15
#    GNU Affero General Public License for more details.
16
16
#
17
17
#    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
##############################################################################
21
21
 
22
22
import gtk
23
23
import sys
 
24
import ctypes
24
25
import interface
25
 
 
 
26
import tools
 
27
from tools import user_locale_format
26
28
 
27
29
class spinbutton(interface.widget_interface):
28
30
    def __init__(self, window, parent, model, attrs={}):
30
32
 
31
33
        adj = gtk.Adjustment(0.0, -sys.maxint, sys.maxint, 1.0, 5.0)
32
34
        self.widget = gtk.SpinButton(adj, 1.0, digits=int( attrs.get('digits',(14,2))[1] ) )
33
 
        self.widget.set_numeric(True)
34
35
        self.widget.set_activates_default(True)
35
36
        self.widget.connect('populate-popup', self._menu_open)
36
37
        if self.attrs['readonly']:
38
39
        self.widget.connect('focus-in-event', lambda x,y: self._focus_in())
39
40
        self.widget.connect('focus-out-event', lambda x,y: self._focus_out())
40
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
41
60
 
42
61
    def set_value(self, model, model_field):
43
62
        self.widget.update()