Skip to content

Commit ae93251

Browse files
committed
Gmoccapy: Make value conversion in offsetpage independent of locale setting
Conversion of keyboard entries to float cells is now independent of locale: 10,123 --> 10.123 10.123 --> 10.123 10.12,3 --> error The old behavior using locale settings had issues but can be activated by setting 'self.use_localization = True'
1 parent 546e437 commit ae93251

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

lib/python/gladevcp/offsetpage_widget.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def __init__(self, filename = None, *a, **kw):
8888
self.status = linuxcnc.stat()
8989
self.cmd = linuxcnc.command()
9090
self.hash_check = None
91+
self.use_localization = False # Set to True for float value conversion using locale settings (not recommended)
9192
self.display_units_mm = 0 # imperial
9293
self.machine_units_mm = 0 # imperial
9394
self.program_units = 0 # imperial
@@ -378,27 +379,36 @@ def system_to_p(system):
378379
if col == 11:
379380
self.store[row][15] = new_text
380381
return
382+
# for all other columns we expect a float value
383+
else:
384+
try:
385+
if self.use_localization:
386+
# using locale settings can lead to issues but we make it optional for backwards compatibility
387+
new_float = float(locale.atof(new_text))
388+
else:
389+
# this is the preferred way, allowing dot or comma as decimal symbol
390+
new_float = float(new_text.replace(',', '.'))
391+
except Exception as error:
392+
print('new_text: ', new_text, error)
393+
print(_("offsetpage widget error: unrecognized float input"))
394+
return
381395

382396
# ignore entries to the Rot column in non-wcs rows
383397
if self.store[row][0] not in ["G54", "G55", "G56", "G57", "G58", "G59", "G59.1", "G59.2", "G59.3"] and col == 10:
384398
return
385399

386400
# set the text in the table
387-
try:
388-
self.store[row][col] = "%10.4f" % locale.atof(new_text)
389-
except Exception as error:
390-
print('new_text: ', new_text, error)
391-
print(_("offsetpage widget error: unrecognized float input"))
401+
self.store[row][col] = f"{new_float:10.4f}"
392402
# make sure we switch to correct units for machine and rotational, row 2, does not get converted
393403
try:
394404
if not self.display_units_mm == self.program_units and not row == 2:
395405
if self.program_units == 1:
396406
convert = 25.4
397407
else:
398408
convert = 1.0 / 25.4
399-
qualified = float(locale.atof(new_text)) * convert
409+
qualified = new_float * convert
400410
else:
401-
qualified = float(locale.atof(new_text))
411+
qualified = new_float
402412
except:
403413
print('error')
404414
# now update linuxcnc to the change

0 commit comments

Comments
 (0)