toga icon indicating copy to clipboard operation
toga copied to clipboard

toga.NumberInput() on Windows does not accept decimal point in languages that use decimal comma

Open Pogzy opened this issue 1 year ago • 3 comments

Describe the bug

When trying to set a toga.NumberInput() with a decimal step, such as vmag = toga.NumberInput(max=12, min=7, step=0.1) there is an error at run time:

  File "C:\Users\Fabien\Documents\beeware-tutorial\astrofilter\src\astrofilter\app.py", line 24, in startup
    self.vmag = toga.NumberInput(max=12, min=7, step=0.1)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Fabien\Documents\beeware-tutorial\beeware-venv\Lib\site-packages\toga\widgets\numberinput.py", line 153, in __init__
    self.step = step
    ^^^^^^^^^
  File "C:\Users\Fabien\Documents\beeware-tutorial\beeware-venv\Lib\site-packages\toga\widgets\numberinput.py", line 189, in step
    self._impl.set_step(self._step)
  File "C:\Users\Fabien\Documents\beeware-tutorial\beeware-venv\Lib\site-packages\toga_winforms\widgets\numberinput.py", line 41, in set_step
    self.native.Increment = native_decimal(step)
                            ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Fabien\Documents\beeware-tutorial\beeware-venv\Lib\site-packages\toga_winforms\widgets\numberinput.py", line 18, in native_decimal
    return Convert.ToDecimal.__overloads__[String](str(value))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
System.FormatException: Le format de la chaîne d'entrée est incorrect.
   à System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
   à System.Number.ParseDecimal(String value, NumberStyles options, NumberFormatInfo numfmt)
   à System.Convert.ToDecimal(String value)

Steps to reproduce

  1. write any minimal app with a decimal step, not integer
  2. run it under windows (not tested on other platform
  3. see the error

Expected behavior

It should work with decimam number, such as described in the online documentation.

It does not work even if the step is a string

Screenshots

No response

Environment

  • Operating System: Windows 10
  • Python version: 3.11
  • Software versions:
    • Briefcase: 0.3.19
    • Toga: 0.4.5
    • ...

Logs


Additional context

No response

Pogzy avatar Aug 17 '24 14:08 Pogzy

Thanks for the report. This is probably because your system language is set to French, so Windows is expecting a decimal comma, but Toga is passing a decimal point.

I wouldn't be surprised if other platforms have a similar problem. For example, here is a related issue I hit on Android in a different project.

mhsmith avatar Aug 19 '24 11:08 mhsmith

Hi there,

I also encountered this issue. Right now I am using TextInput and validating before using the value - as a workaround. I believe this is not only for French, but almost all European languages + Russian which are using comma as decimal Separator.

Any first hints on how it can be solved?

vgezer avatar Aug 27 '25 18:08 vgezer

@vgezer The fix is that we need a localisation framework for Toga - or, at the very least, localisation awareness for the NumberInput widget.

I agree this is an important bug/feature to add; but localisation is a big topic (and an important one to get right). We'd welcome any contributions in this space.

freakboy3742 avatar Aug 27 '25 22:08 freakboy3742