- added Exception handing for the case when the user is trying to save & overwrite a file already opened in another file
This commit is contained in:
@@ -4669,10 +4669,13 @@ class App(QtCore.QObject):
|
||||
with open(filename, 'w') as f:
|
||||
for line in my_gcode:
|
||||
f.write(line)
|
||||
|
||||
except FileNotFoundError:
|
||||
self.inform.emit(_("[WARNING] No such file or directory"))
|
||||
return
|
||||
except PermissionError:
|
||||
self.inform.emit(_("[WARNING] Permission denied, saving not possible.\n"
|
||||
"Most likely another app is holding the file open and not accessible."))
|
||||
return
|
||||
|
||||
# Just for adding it to the recent files list.
|
||||
if self.defaults["global_open_style"] is False:
|
||||
@@ -7109,8 +7112,14 @@ class App(QtCore.QObject):
|
||||
# Parse the xml through a xml parser just to add line feeds
|
||||
# and to make it look more pretty for the output
|
||||
svgcode = parse_xml_string(svg_elem)
|
||||
with open(filename, 'w') as fp:
|
||||
fp.write(svgcode.toprettyxml())
|
||||
try:
|
||||
with open(filename, 'w') as fp:
|
||||
fp.write(svgcode.toprettyxml())
|
||||
except PermissionError:
|
||||
self.inform.emit(_("[WARNING] Permission denied, saving not possible.\n"
|
||||
"Most likely another app is holding the file open and not accessible."))
|
||||
return 'fail'
|
||||
|
||||
if self.defaults["global_open_style"] is False:
|
||||
self.file_opened.emit("SVG", filename)
|
||||
self.file_saved.emit("SVG", filename)
|
||||
@@ -7213,8 +7222,13 @@ class App(QtCore.QObject):
|
||||
# Parse the xml through a xml parser just to add line feeds
|
||||
# and to make it look more pretty for the output
|
||||
doc = parse_xml_string(svg_elem)
|
||||
with open(filename, 'w') as fp:
|
||||
fp.write(doc.toprettyxml())
|
||||
try:
|
||||
with open(filename, 'w') as fp:
|
||||
fp.write(doc.toprettyxml())
|
||||
except PermissionError:
|
||||
self.inform.emit(_("[WARNING] Permission denied, saving not possible.\n"
|
||||
"Most likely another app is holding the file open and not accessible."))
|
||||
return 'fail'
|
||||
|
||||
self.progress.emit(100)
|
||||
if self.defaults["global_open_style"] is False:
|
||||
@@ -7329,8 +7343,14 @@ class App(QtCore.QObject):
|
||||
# Parse the xml through a xml parser just to add line feeds
|
||||
# and to make it look more pretty for the output
|
||||
doc = parse_xml_string(svg_elem)
|
||||
with open(filename, 'w') as fp:
|
||||
fp.write(doc.toprettyxml())
|
||||
try:
|
||||
with open(filename, 'w') as fp:
|
||||
fp.write(doc.toprettyxml())
|
||||
except PermissionError:
|
||||
self.inform.emit(_("[WARNING] Permission denied, saving not possible.\n"
|
||||
"Most likely another app is holding the file open and not accessible."))
|
||||
return 'fail'
|
||||
|
||||
self.progress.emit(100)
|
||||
if self.defaults["global_open_style"] is False:
|
||||
self.file_opened.emit("SVG", filename)
|
||||
@@ -7371,15 +7391,20 @@ class App(QtCore.QObject):
|
||||
file_string = StringIO(obj.source_file)
|
||||
time_string = "{:%A, %d %B %Y at %H:%M}".format(datetime.now())
|
||||
|
||||
with open(filename, 'w') as file:
|
||||
file.writelines('G04*\n')
|
||||
file.writelines('G04 %s (RE)GENERATED BY FLATCAM v%s - www.flatcam.org - Version Date: %s*\n' %
|
||||
(obj.kind.upper(), str(self.version), str(self.version_date)))
|
||||
file.writelines('G04 Filename: %s*\n' % str(obj_name))
|
||||
file.writelines('G04 Created on : %s*\n' % time_string)
|
||||
try:
|
||||
with open(filename, 'w') as file:
|
||||
file.writelines('G04*\n')
|
||||
file.writelines('G04 %s (RE)GENERATED BY FLATCAM v%s - www.flatcam.org - Version Date: %s*\n' %
|
||||
(obj.kind.upper(), str(self.version), str(self.version_date)))
|
||||
file.writelines('G04 Filename: %s*\n' % str(obj_name))
|
||||
file.writelines('G04 Created on : %s*\n' % time_string)
|
||||
|
||||
for line in file_string:
|
||||
file.writelines(line)
|
||||
for line in file_string:
|
||||
file.writelines(line)
|
||||
except PermissionError:
|
||||
self.inform.emit(_("[WARNING] Permission denied, saving not possible.\n"
|
||||
"Most likely another app is holding the file open and not accessible."))
|
||||
return 'fail'
|
||||
|
||||
def export_excellon(self, obj_name, filename, use_thread=True):
|
||||
"""
|
||||
@@ -7481,8 +7506,14 @@ class App(QtCore.QObject):
|
||||
exported_excellon += excellon_code
|
||||
exported_excellon += footer
|
||||
|
||||
with open(filename, 'w') as fp:
|
||||
fp.write(exported_excellon)
|
||||
try:
|
||||
with open(filename, 'w') as fp:
|
||||
fp.write(exported_excellon)
|
||||
except PermissionError:
|
||||
self.inform.emit(_("[WARNING] Permission denied, saving not possible.\n"
|
||||
"Most likely another app is holding the file open and not accessible."))
|
||||
return 'fail'
|
||||
|
||||
if self.defaults["global_open_style"] is False:
|
||||
self.file_opened.emit("Excellon", filename)
|
||||
self.file_saved.emit("Excellon", filename)
|
||||
@@ -7598,8 +7629,14 @@ class App(QtCore.QObject):
|
||||
exported_gerber += gerber_code
|
||||
exported_gerber += footer
|
||||
|
||||
with open(filename, 'w') as fp:
|
||||
fp.write(exported_gerber)
|
||||
try:
|
||||
with open(filename, 'w') as fp:
|
||||
fp.write(exported_gerber)
|
||||
except PermissionError:
|
||||
self.inform.emit(_("[WARNING] Permission denied, saving not possible.\n"
|
||||
"Most likely another app is holding the file open and not accessible."))
|
||||
return 'fail'
|
||||
|
||||
if self.defaults["global_open_style"] is False:
|
||||
self.file_opened.emit("Gerber", filename)
|
||||
self.file_saved.emit("Gerber", filename)
|
||||
|
||||
Reference in New Issue
Block a user