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

« back to all changes in this revision

Viewing changes to bin/widget_search/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:
23
23
import common
24
24
import wid_int
25
25
import sys
 
26
import ctypes
26
27
import tools
 
28
from tools import user_locale_format
27
29
 
28
30
class spinbutton(wid_int.wid_int):
29
31
    def __init__(self, name, parent, attrs={},screen=None):
33
35
 
34
36
        adj1 = gtk.Adjustment(0.0, -sys.maxint, sys.maxint, 1.0, 5.0)
35
37
        self.spin1 = gtk.SpinButton(adj1, 1.0, digits=int(attrs.get('digits', (14, 2))[1]))
36
 
        self.spin1.set_numeric(True)
37
38
        self.spin1.set_activates_default(True)
 
39
        self.spin1.connect('input', self.format_input)
 
40
        self.spin1.connect('output', self.format_output)
38
41
        self.widget.pack_start(self.spin1, expand=False, fill=True)
39
42
 
40
43
        self.widget.pack_start(gtk.Label('-'), expand=False, fill=False)
41
44
 
42
45
        adj2 = gtk.Adjustment(0.0, -sys.maxint, sys.maxint, 1.0, 5.0)
43
46
        self.spin2 = gtk.SpinButton(adj2, 1.0, digits=int(attrs.get('digits', (14, 2))[1]))
44
 
        self.spin2.set_numeric(True)
45
47
        self.spin2.set_activates_default(True)
 
48
        self.spin2.connect('input', self.format_input)
 
49
        self.spin2.connect('output', self.format_output)
46
50
        self.widget.pack_start(self.spin2, expand=False, fill=True)
47
51
 
48
52
        if self.default_search:
49
53
            self.spin1.set_value(self.default_search)
50
54
 
 
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
71
    def _value_get(self):
52
72
        res = []
53
73
        self.spin1.update()
73
93
 
74
94
    def clear(self):
75
95
        self.value = 0.00
76
 
    
77
 
     
 
96
 
 
97
 
78
98
    def grab_focus(self):
79
99
        self.spin1.grab_focus()
80
100