@@ -46,6 +46,7 @@ class Calculator( Gtk.Box ):
4646
4747 def __init__ ( self , * a , ** kw ):
4848 Gtk .Box .__init__ ( self , * a , ** kw )
49+ self .use_localization = False # Set True for legacay behavior using value conversion using atof()
4950 self .preset_value = None
5051 self .eval_string = ""
5152 self .font = "sans 12"
@@ -170,19 +171,22 @@ def get_preset_value( self ):
170171
171172 def compute ( self ):
172173 qualified = ''
173- # print"string:",self.eval_string
174174 temp = self .eval_string .strip ( " " ).replace ("Pi" , "math.pi" )
175+ if self .use_localization :
176+ pass
177+ else :
178+ temp = temp .replace ("," , "." )
175179 # this loop adds only spaces around the mentioned operators
176180 for i in ( '-' , '+' , '/' , '*' , 'math.pi' , '(' , ')' ):
177181 new = " %s " % i
178182 temp = temp .replace ( i , new )
179183 for i in temp .split ():
180- # print ( "i in compute = ", i )
181- try :
182- i = str ( locale . atof ( i ) )
183- # print ( "converted i in compute = ", i )
184- except :
185- pass
184+ if self . use_localization :
185+ try :
186+ # convert to decimal dot format
187+ i = str ( locale . atof ( i ) )
188+ except :
189+ pass
186190 if i .isdigit ():
187191 qualified = qualified + str ( float ( i ) )
188192 else :
@@ -194,18 +198,16 @@ def compute( self ):
194198 b = str ( eval ( qualified ) )
195199 except :
196200 b = "Error"
197- print ("Calculator widget error, string:" , self .eval_string , sys .exc_info ()[0 ])
198201 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
203- try :
204- b = locale .format_string ( "%f" , float ( b ) ).rstrip ( "0" )
205- if b [- 1 ] == locale .localeconv ()["decimal_point" ]:
206- b = b .rstrip ( locale .localeconv ()["decimal_point" ] )
207- except :
208- b = "Error"
202+ if self .use_localization :
203+ try :
204+ b = locale .format_string ( "%f" , float ( b ) ).rstrip ( "0" )
205+ if b [- 1 ] == locale .localeconv ()["decimal_point" ]:
206+ b = b .rstrip ( locale .localeconv ()["decimal_point" ] )
207+ else :
208+ self .eval_string = b
209+ except :
210+ b = "Error"
209211 self .entry .set_text ( b )
210212 self .entry .set_position (len (self .eval_string ))
211213
0 commit comments