From 09403a19ab92a818fa777fab92716aa82a5f90d3 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Fri, 13 Nov 2020 18:44:05 +0200 Subject: [PATCH] - added a message warning the user that the file is no longer available when it tries to open a file from the recent file, that was moved or deleted --- CHANGELOG.md | 1 + appTools/ToolImage.py | 5 +++++ appTools/ToolPDF.py | 5 +++++ app_Main.py | 21 +++++++++++++++++++++ 4 files changed, 32 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5c74fff..fdd358b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ CHANGELOG for FlatCAM beta - Milling Tool - made sure that on target object change the UI is build again - Geo Editor - Text sub-tool - fixed font size control not shown; fixes issue #470 - Geo Editor - fixed an issue with having a translatable text empty; updated the translation strings from sources +- added a message warning the user that the file is no longer available when it tries to open a file from the recent file, that was moved or deleted 12.11.2020 diff --git a/appTools/ToolImage.py b/appTools/ToolImage.py index 4aee5fb5..3f0b5473 100644 --- a/appTools/ToolImage.py +++ b/appTools/ToolImage.py @@ -10,6 +10,8 @@ from PyQt5 import QtGui, QtWidgets from appTool import AppTool from appGUI.GUIElements import RadioSet, FCComboBox, FCSpinner +import os + import gettext import appTranslation as fcTranslate import builtins @@ -128,6 +130,9 @@ class ToolImage(AppTool): """ self.app.defaults.report_usage("import_image()") + if not os.path.exists(filename): + self.app.inform.emit('[ERROR_NOTCL] %s' % _("File no longer available.")) + return if mask is None: mask = [250, 250, 250, 250] diff --git a/appTools/ToolPDF.py b/appTools/ToolPDF.py index 10449087..6aa7cdef 100644 --- a/appTools/ToolPDF.py +++ b/appTools/ToolPDF.py @@ -20,6 +20,7 @@ import re import time import logging import traceback +import os import gettext import appTranslation as fcTranslate @@ -106,6 +107,10 @@ class ToolPDF(AppTool): 'params': [filename]}) def open_pdf(self, filename): + if not os.path.exists(filename): + self.inform.emit('[ERROR_NOTCL] %s' % _("File no longer available.")) + return + short_name = filename.split('/')[-1].split('\\')[-1] self.parsing_promises.append(short_name) diff --git a/app_Main.py b/app_Main.py index c4e0bb1c..a27ca513 100644 --- a/app_Main.py +++ b/app_Main.py @@ -10099,6 +10099,9 @@ class MenuFileHandlers(QtCore.QObject): :return: """ self.app.log.debug("App.import_svg()") + if not os.path.exists(filename): + self.inform.emit('[ERROR_NOTCL] %s' % _("File no longer available.")) + return obj_type = "" if geo_type is None or geo_type == "geometry": @@ -10149,6 +10152,9 @@ class MenuFileHandlers(QtCore.QObject): :return: """ self.app.log.debug(" ********* Importing DXF as: %s ********* " % geo_type.capitalize()) + if not os.path.exists(filename): + self.inform.emit('[ERROR_NOTCL] %s' % _("File no longer available.")) + return obj_type = "" if geo_type is None or geo_type == "geometry": @@ -10235,6 +10241,9 @@ class MenuFileHandlers(QtCore.QObject): return "fail" self.app.log.debug("open_gerber()") + if not os.path.exists(filename): + self.inform.emit('[ERROR_NOTCL] %s' % _("File no longer available.")) + return with self.app.proc_container.new(_("Opening ...")): # Object name @@ -10270,6 +10279,9 @@ class MenuFileHandlers(QtCore.QObject): """ self.app.log.debug("open_excellon()") + if not os.path.exists(filename): + self.inform.emit('[ERROR_NOTCL] %s' % _("File no longer available.")) + return # How the object should be initialized def obj_init(excellon_obj, app_obj): @@ -10332,6 +10344,9 @@ class MenuFileHandlers(QtCore.QObject): :return: None """ self.app.log.debug("open_gcode()") + if not os.path.exists(filename): + self.inform.emit('[ERROR_NOTCL] %s' % _("File no longer available.")) + return # How the object should be initialized def obj_init(job_obj, app_obj_): @@ -10486,6 +10501,9 @@ class MenuFileHandlers(QtCore.QObject): return "fail" self.app.log.debug("open_script()") + if not os.path.exists(filename): + self.inform.emit('[ERROR_NOTCL] %s' % _("File no longer available.")) + return with self.app.proc_container.new(_("Opening ...")): @@ -10570,6 +10588,9 @@ class MenuFileHandlers(QtCore.QObject): :return: None """ self.app.log.debug("Opening project: " + filename) + if not os.path.exists(filename): + self.inform.emit('[ERROR_NOTCL] %s' % _("File no longer available.")) + return # block autosaving while a project is loaded self.app.block_autosave = True