From 6a5a408c47f34e23c91c4e342d0b31e0d290bab5 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Sat, 19 Mar 2022 23:12:43 +0200 Subject: [PATCH] - added a way to load older projects (made before recent changes) --- CHANGELOG.md | 1 + appPlugins/ToolExtract.py | 9 +++++++++ appPlugins/ToolPunchGerber.py | 9 +++++++++ app_Main.py | 31 +++++++++++++++++++++++++------ 4 files changed, 44 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba68c13c..243249c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ CHANGELOG for FlatCAM beta - updated the app translation strings to match the ones in the sources, for all languages - updated the Romanian language (native) - updated the Spanish language (Google-translated) +- added a way to load older projects (made before recent changes) 17.03.2022 diff --git a/appPlugins/ToolExtract.py b/appPlugins/ToolExtract.py index 47677e8c..94e515d0 100644 --- a/appPlugins/ToolExtract.py +++ b/appPlugins/ToolExtract.py @@ -46,6 +46,15 @@ class ToolExtract(AppTool): self.connect_signals_at_init() def on_object_combo_changed(self): + extract_plugin_found = False + for idx in range(self.app.ui.notebook.count()): + if self.app.ui.notebook.tabText(idx) == _("Extract"): + extract_plugin_found = True + break + + if extract_plugin_found is False: + return + # get the Gerber file who is the source of the punched Gerber selection_index = self.ui.gerber_object_combo.currentIndex() model_index = self.app.collection.index(selection_index, 0, self.ui.gerber_object_combo.rootModelIndex()) diff --git a/appPlugins/ToolPunchGerber.py b/appPlugins/ToolPunchGerber.py index ce5200b7..0b220d39 100644 --- a/appPlugins/ToolPunchGerber.py +++ b/appPlugins/ToolPunchGerber.py @@ -75,6 +75,15 @@ class ToolPunchGerber(AppTool, Gerber): self.connect_signals_at_init() def on_object_combo_changed(self): + punch_plugin_found = False + for idx in range(self.app.ui.notebook.count()): + if self.app.ui.notebook.tabText(idx) == _("Punch Gerber"): + punch_plugin_found = True + break + + if punch_plugin_found is False: + return + # get the Gerber file who is the source of the punched Gerber selection_index = self.ui.gerber_object_combo.currentIndex() model_index = self.app.collection.index(selection_index, 0, self.ui.gerber_object_combo.rootModelIndex()) diff --git a/app_Main.py b/app_Main.py index ae90fa6d..8778ebe9 100644 --- a/app_Main.py +++ b/app_Main.py @@ -11922,8 +11922,13 @@ class MenuFileHandlers(QtCore.QObject): ("Failed to open the CNCJob file:", str(obj['options']['name']), "Maybe it is an old project.")) continue - msg = "Recreating from opened project an %s object: %s" % \ - (obj['kind'].capitalize(), obj['obj_options']['name']) + try: + msg = "Recreating from opened project an %s object: %s" % \ + (obj['kind'].capitalize(), obj['obj_options']['name']) + except KeyError: + # allowance for older projects + msg = "Recreating from opened project an %s object: %s" % \ + (obj['kind'].capitalize(), obj['options']['name']) self.app.log.debug(msg) def obj_init(new_obj, app_inst): @@ -11952,6 +11957,10 @@ class MenuFileHandlers(QtCore.QObject): new_obj_options = LoudDict() new_obj_options.update(new_obj.obj_options) new_obj.obj_options = new_obj_options + except AttributeError: + new_obj_options = LoudDict() + new_obj_options.update(new_obj.options) + new_obj.obj_options = new_obj_options except Exception as erro: app_inst.log.error('MenuFileHandlers.open_project() make a LoudDict--> ' + str(erro)) return 'fail' @@ -11961,11 +11970,21 @@ class MenuFileHandlers(QtCore.QObject): # for some reason, setting ui_title does not work when this method is called from Tcl Shell # it's because the TclCommand is run in another thread (it inherit TclCommandSignaled) - if cli is None: - self.app.ui.set_ui_title(name="{} {}: {}".format( - _("Loading Project ... restoring"), obj['kind'].upper(), obj['obj_options']['name'])) + try: + if cli is None: + self.app.ui.set_ui_title(name="{} {}: {}".format( + _("Loading Project ... restoring"), obj['kind'].upper(), obj['obj_options']['name'])) - ret = self.app.app_obj.new_object(obj['kind'], obj['obj_options']['name'], obj_init, plot=plot) + ret = self.app.app_obj.new_object(obj['kind'], obj['obj_options']['name'], obj_init, plot=plot) + except KeyError: + # allowance for older projects + if cli is None: + self.app.ui.set_ui_title(name="{} {}: {}".format( + _("Loading Project ... restoring"), obj['kind'].upper(), obj['options']['name'])) + try: + ret = self.app.app_obj.new_object(obj['kind'], obj['options']['name'], obj_init, plot=plot) + except Exception: + continue if ret == 'fail': continue