Skip to content

Commit

Permalink
Merge pull request #3026 from hansu/2966-gmoccapy-destroys-tooltable
Browse files Browse the repository at this point in the history
Tool edit widget: backup tool table and add some checks
  • Loading branch information
andypugh authored Aug 3, 2024
2 parents f5ee684 + fae0e67 commit 3826495
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@ docs/help/hu/*
docs/help/nb/*
docs/help/vi/*
docs/help/zh_CN/*
configs/**/*.tbl.bak
configs/**/halshow.preferences
18 changes: 17 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,11 @@ def save(self,widget):
self.warning_dialog(line_number)
return

if(locale.getlocale(locale.LC_NUMERIC)[0] is None):
raise ExceptionMessage("\n\n"+_("Something wrong with the locale settings. Will not save the tool table."))
return

shutil.copy(self.toolfile, self.toolfile + ".bak")
file = open(self.toolfile, "w")
#print self.toolfile
for row in liststore:
Expand All @@ -345,7 +351,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 +704,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 3826495

Please sign in to comment.