LinuxCNC / linuxcnc

LinuxCNC controls CNC machines. It can drive milling machines, lathes, 3d printers, laser cutters, plasma cutters, robot arms, hexapods, and more.
http://linuxcnc.org/
GNU General Public License v2.0
1.73k stars 1.13k forks source link

Glade Tooltable widget destroys tooltable in a particular case #2966

Open hansu opened 2 months ago

hansu commented 2 months ago

When using locale settings for e.g. Germany, so having a "," as decimal point, the tool table shows the correct decimal point after starting. But after loading an (empty) G-code file and reloading the tool table, the decimal point changes to a dot:

https://github.com/LinuxCNC/linuxcnc/assets/67957916/421d6f9a-7a8d-4f6c-90cb-40ac777b398f

This can lead to loss of the complete tool table in the following (quite common) case:

  1. Load a G-code file
  2. Add the missing tool
  3. Apply the changes ... boom! all tools are gone!

https://github.com/LinuxCNC/linuxcnc/assets/67957916/a59e732b-f6b2-4aa1-a6b7-9ae81574fa16

Version: latest from 2.9 branch.

Traceback (most recent call last):
  File "/home/cnc/linuxcnc/linuxcnc-2.9/bin/gmoccapy", line 4947, in on_btn_apply_tool_changes_clicked
    self.widgets.tooledit1.save(None)
  File "/home/cnc/linuxcnc/linuxcnc-2.9/lib/python/gladevcp/tooledit_widget.py", line 348, in save
    line = line + "%s%s "%(KEYWORDS[num], locale.atof(test))
                                          ^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/locale.py", line 338, in atof
    return func(delocalize(string))
           ^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: could not convert string to float: '0,0000'
 (gmoccapy:62)
Tool file was modified since it was last read
/usr/lib/python3/dist-packages/gi/overrides/GObject.py:493: Warning: ../../../gobject/gsignal.c:2772: instance '0x460ff90' has no handler with id '113342181'
  return func(*args, **kwargs)
zz912 commented 2 months ago

I can confirm this behavior. Any G-code file can be used for recall, not just an empty G-code file.

In place for tool information is used as a decimal point and a dot. It is also in the Czech localization. tool It looks wierd.

hansu commented 5 days ago

Possible workarounds are:

  1. Click on reload tool table before adding a tool

  2. Use reload tool on start in the settings:

grafik

hansu commented 5 days ago

The problem does not appear on Debian Bullseye / Python 3.9.2

hansu commented 5 days ago

I was able to encircle the error. The problem is that the locale setting gets destroyed when showing the main box.

Good to see with these debug prints: https://github.com/hansu/linuxcnc/commit/0fe0482b10a29801de4deacfb1f438e90dd1139e

Output:

--- INIT:352, locale:  ('de_DE', 'UTF-8')
--- INIT:356, locale:  (None, None)

If I set the locale again after this with locale.setlocale(locale.LC_ALL, '') all works fine. But this does't sound like a clean solution.

@c-morley any idea on this?