FernV / NativeCAM

NativeCAM for LinuxCNC embeds in axis or gmoccapy interfaces
GNU General Public License v2.0
45 stars 29 forks source link

No frections input with germen localisation #5

Closed gmoccapy closed 5 years ago

gmoccapy commented 6 years ago

I just updated to the most recent release using package manager. now it is 0.1.7 I am using German localized debian wheezy, using "," as decimal separator!

If I try to enter a value like >2,5< with the key pad, I get >25,000< If I enter >2.5< I also get >25,000< If I use the mouse and use only the buttons from the calculator the result is the same.

The only way to enter fractional values I found is to enter >5/2<, this way I get >2,500<

This happen since your change from Keypad to Calculator.

I find a solution changing def compute to be:

     def compute(self):
        qualified = ''
        temp = self.vkb_entry.get_text()
        while temp.count('(') > temp.count(')') :
            temp = temp + ')'
        self.opened_paren = 0
        self.save_edit = temp
        temp = temp.replace('Pi', str(math.pi).replace(".",decimal_point))
        for i in('-', '+', '/', '*', '(', ')'):
            temp = temp.replace(i, " %s " % i)
        for i in temp.split():
            try:
                i = str(locale.atof(i))
            except:
                pass
            if i.isdigit():
                qualified = qualified + str(float(i))
            else:
                qualified = qualified + i
        try :
            return True, eval(qualified)
        except :
            return False, 0.0

It does work for me as expected.

Please note also the change to the Pi part, as math.pi will return a value with a dot as separator, not the localized one.

Norbert

gmoccapy commented 6 years ago

Hallo Fern,

you changes did solve the problem of the decimal separator with german Localisation, but the "Pi" problem is still there.

If I push Pi, the display of the calculator shows Pi, if I then press "=" I get 314159265359,000 I I press enter, the value is concerted to be "25399997,460"

But I expected to get something like 3.14159.... That happens, because math(Pi) does return a dot separated value, neverthereless what localisation you have.

That is why i changed the conversion to be

temp = temp.replace('Pi', str(math.pi).replace(".",decimal_point))

Norbert