Skip to content

Commit

Permalink
tooltable: create a backup file when error occurs on saving + add exc…
Browse files Browse the repository at this point in the history
…eption message
  • Loading branch information
hansu committed Jul 11, 2024
1 parent 1f0d14a commit 77493ce
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/python/gladevcp/tooledit_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', ';']

Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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(<message>)
"""
def __init__(self, message):
super().__init__(message)

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

0 comments on commit 77493ce

Please sign in to comment.