Skip to content

Commit 7f4c1ed

Browse files
committed
Calculator_widget: Fix locale handling
1 parent 1a9d9d4 commit 7f4c1ed

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

lib/python/gladevcp/calculatorwidget.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,17 +170,15 @@ def get_preset_value( self ):
170170

171171
def compute( self ):
172172
qualified = ''
173-
# print"string:",self.eval_string
174173
temp = self.eval_string.strip( " " ).replace("Pi", "math.pi")
175174
# this loop adds only spaces around the mentioned operators
176175
for i in( '-', '+', '/', '*', 'math.pi', '(', ')' ):
177176
new = " %s " % i
178177
temp = temp.replace( i, new )
179178
for i in temp.split():
180-
# print ( "i in compute = ", i )
181179
try:
180+
# convert to decimal dot format
182181
i = str( locale.atof( i ) )
183-
# print ( "converted i in compute = ", i )
184182
except:
185183
pass
186184
if i.isdigit():
@@ -194,16 +192,13 @@ def compute( self ):
194192
b = str( eval( qualified ) )
195193
except:
196194
b = "Error"
197-
print("Calculator widget error, string:", self.eval_string, sys.exc_info()[0])
198195
self.eval_string = ''
199-
else : self.eval_string = b
200-
# if locale.localeconv()["decimal_point" = comma ,
201-
# we have to replace the internal dot by a comma,
202-
# otherwise it will be interpreted as an thousend separator
203196
try:
204197
b = locale.format_string( "%f", float( b ) ).rstrip( "0" )
205198
if b[-1] == locale.localeconv()["decimal_point"]:
206199
b = b.rstrip( locale.localeconv()["decimal_point"] )
200+
else:
201+
self.eval_string = b
207202
except:
208203
b = "Error"
209204
self.entry.set_text( b )

0 commit comments

Comments
 (0)