From 77493ce065b9a847f453e3f4d5b80d931a5bf5ba Mon Sep 17 00:00:00 2001 From: Hans Unzner Date: Fri, 28 Jun 2024 20:27:13 +0200 Subject: [PATCH] tooltable: create a backup file when error occurs on saving + add exception message --- lib/python/gladevcp/tooledit_widget.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/python/gladevcp/tooledit_widget.py b/lib/python/gladevcp/tooledit_widget.py index ad67208a044..de480efc19d 100644 --- a/lib/python/gladevcp/tooledit_widget.py +++ b/lib/python/gladevcp/tooledit_widget.py @@ -15,6 +15,7 @@ # GNU General Public License for more details. import sys, os, linuxcnc, hashlib +import shutil # for backup of tooltable datadir = os.path.abspath(os.path.dirname(__file__)) KEYWORDS = ['S','T', 'P', 'X', 'Y', 'Z', 'A', 'B', 'C', 'U', 'V', 'W', 'D', 'I', 'J', 'Q', ';'] @@ -330,6 +331,7 @@ def save(self,widget): self.warning_dialog(line_number) return + shutil.copy(self.toolfile, self.toolfile + ".bak") file = open(self.toolfile, "w") #print self.toolfile for row in liststore: @@ -345,7 +347,11 @@ def save(self,widget): line = line + "%s%s "%(KEYWORDS[num],test) else: test = i.lstrip() # localized floats - line = line + "%s%s "%(KEYWORDS[num], locale.atof(test)) + try: + line = line + "%s%s "%(KEYWORDS[num], locale.atof(test)) + except ValueError: + raise ExceptionMessage("\n\n"+_("Error converting a float with the given localization setting. A backup file has been created: " + + self.toolfile + ".bak")) print(line, file=file) # These lines are required to make sure the OS doesn't cache the data @@ -694,6 +700,12 @@ def on_tree_navigate_key_press(self, treeview, event, filter): else: pass +class ExceptionMessage(Exception): + """ Exception to display a Message as an Eception. + Usage: raise ExceptionMessage() + """ + def __init__(self, message): + super().__init__(message) # for testing without glade editor: # for what ever reason tooledit always shows both display lists,