1515# GNU General Public License for more details.
1616
1717import sys , os , linuxcnc , hashlib
18+ import shutil # for backup of tooltable
1819datadir = os .path .abspath (os .path .dirname (__file__ ))
1920KEYWORDS = ['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