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

« back to all changes in this revision

Viewing changes to bin/widget/view/form_gtk/spinint.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 spinint(interface.widget_interface):
28
30
 
31
33
 
32
34
        adj = gtk.Adjustment(0.0, -sys.maxint, sys.maxint, 1.0, 5.0)
33
35
        self.widget = gtk.SpinButton(adj, 1, digits=0)
34
 
        self.widget.set_numeric(True)
35
36
        self.widget.set_width_chars(5)
36
37
        self.widget.set_activates_default(True)
37
38
        self.widget.connect('populate-popup', self._menu_open)
40
41
        self.widget.connect('focus-in-event', lambda x,y: self._focus_in())
41
42
        self.widget.connect('focus-out-event', lambda x,y: self._focus_out())
42
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
43
62
 
44
63
    def set_value(self, model, model_field):
45
64
        self.widget.update()