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

« back to all changes in this revision

Viewing changes to bin/widget_search/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:
21
21
 
22
22
import gtk
23
23
from gtk import glade
 
24
import ctypes
24
25
import gettext
25
26
import sys
26
27
import common
27
28
import wid_int
28
29
import tools
 
30
from tools import user_locale_format
29
31
 
30
32
 
31
33
class spinint(wid_int.wid_int):
37
39
 
38
40
        adj1 = gtk.Adjustment(0.0, 0.0, sys.maxint, 1.0, 5.0)
39
41
        self.spin1 = gtk.SpinButton(adj1, 1, digits=0)
40
 
        self.spin1.set_numeric(True)
41
42
        self.spin1.set_activates_default(True)
 
43
        self.spin1.connect('input', self.format_input)
 
44
        self.spin1.connect('output', self.format_output)
42
45
        self.widget.pack_start(self.spin1, expand=False, fill=True)
43
46
 
44
47
        self.widget.pack_start(gtk.Label('-'), expand=False, fill=False)
45
48
 
46
49
        adj2 = gtk.Adjustment(0.0, 0.0, sys.maxint, 1.0, 5.0)
47
50
        self.spin2 = gtk.SpinButton(adj2, 1, digits=0)
48
 
        self.spin2.set_numeric(True)
49
51
        self.spin2.set_activates_default(True)
 
52
        self.spin2.connect('input', self.format_input)
 
53
        self.spin2.connect('output', self.format_output)
50
54
        self.widget.pack_start(self.spin2, expand=False, fill=True)
51
55
        if self.default_search:
52
56
            self.spin1.set_value(self.default_search)
53
57
 
 
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
74
    def _value_get(self):
55
75
        res = []
56
76
        self.spin1.update()
76
96
 
77
97
    def clear(self):
78
98
        self.value = 0.0
79
 
    
 
99
 
80
100
    def grab_focus(self):
81
101
        self.spin1.grab_focus()
82
102