Skip to content

Commit 3826495

Browse files
authored
Merge pull request #3026 from hansu/2966-gmoccapy-destroys-tooltable
Tool edit widget: backup tool table and add some checks
2 parents f5ee684 + fae0e67 commit 3826495

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,5 @@ docs/help/hu/*
5959
docs/help/nb/*
6060
docs/help/vi/*
6161
docs/help/zh_CN/*
62+
configs/**/*.tbl.bak
63+
configs/**/halshow.preferences

lib/python/gladevcp/tooledit_widget.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# GNU General Public License for more details.
1616

1717
import sys, os, linuxcnc, hashlib
18+
import shutil # for backup of tooltable
1819
datadir = os.path.abspath(os.path.dirname(__file__))
1920
KEYWORDS = ['S','T', 'P', 'X', 'Y', 'Z', 'A', 'B', 'C', 'U', 'V', 'W', 'D', 'I', 'J', 'Q', ';']
2021

@@ -330,6 +331,11 @@ def save(self,widget):
330331
self.warning_dialog(line_number)
331332
return
332333

334+
if(locale.getlocale(locale.LC_NUMERIC)[0] is None):
335+
raise ExceptionMessage("\n\n"+_("Something wrong with the locale settings. Will not save the tool table."))
336+
return
337+
338+
shutil.copy(self.toolfile, self.toolfile + ".bak")
333339
file = open(self.toolfile, "w")
334340
#print self.toolfile
335341
for row in liststore:
@@ -345,7 +351,11 @@ def save(self,widget):
345351
line = line + "%s%s "%(KEYWORDS[num],test)
346352
else:
347353
test = i.lstrip() # localized floats
348-
line = line + "%s%s "%(KEYWORDS[num], locale.atof(test))
354+
try:
355+
line = line + "%s%s "%(KEYWORDS[num], locale.atof(test))
356+
except ValueError:
357+
raise ExceptionMessage("\n\n"+_("Error converting a float with the given localization setting. A backup file has been created: "
358+
+ self.toolfile + ".bak"))
349359

350360
print(line, file=file)
351361
# These lines are required to make sure the OS doesn't cache the data
@@ -694,6 +704,12 @@ def on_tree_navigate_key_press(self, treeview, event, filter):
694704
else:
695705
pass
696706

707+
class ExceptionMessage(Exception):
708+
""" Exception to display a Message as an Eception.
709+
Usage: raise ExceptionMessage(<message>)
710+
"""
711+
def __init__(self, message):
712+
super().__init__(message)
697713

698714
# for testing without glade editor:
699715
# for what ever reason tooledit always shows both display lists,

0 commit comments

Comments
 (0)