From 039500b43fcc92b37bd6567a5cc460c6130b79be Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Sun, 7 Jun 2020 15:30:46 +0300 Subject: [PATCH] - fixed issue with trying to access GUI from different threads by adding a new signal for printing to shell messages --- CHANGELOG.md | 1 + appObjects/AppObject.py | 4 ++-- appTools/ToolIsolation.py | 6 +++--- app_Main.py | 11 +++++++++-- tclCommands/TclCommandSetOrigin.py | 2 +- tclCommands/TclCommandSetPath.py | 10 ++++------ 6 files changed, 20 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f85840da..0fdd759f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ CHANGELOG for FlatCAM beta 7.06.2020 - refactoring in camlib.py. Made sure that some conditions are met, if some of the parameters are None then return failure. Modifications in generate_from_geometry_2 and generate_from_multitool_geometry methods +- fixed issue with trying to access GUI from different threads by adding a new signal for printing to shell messages 6.06.2020 diff --git a/appObjects/AppObject.py b/appObjects/AppObject.py index b91e5c97..aa039f26 100644 --- a/appObjects/AppObject.py +++ b/appObjects/AppObject.py @@ -137,9 +137,9 @@ class AppObject(QtCore.QObject): return "fail" t2 = time.time() - msg = "%f seconds executing initialize()." % (t2 - t1) + msg = "New object with name: %s. %f seconds executing initialize()." % (name, (t2 - t1)) log.debug(msg) - self.app.shell_message(msg) + self.app.inform_shell.emit(msg) if return_value == 'fail': log.debug("Object (%s) parsing and/or geometry creation failed." % kind) diff --git a/appTools/ToolIsolation.py b/appTools/ToolIsolation.py index a520e04a..4e17b8fd 100644 --- a/appTools/ToolIsolation.py +++ b/appTools/ToolIsolation.py @@ -2083,14 +2083,14 @@ class ToolIsolation(AppTool, Gerber): self.app.inform.emit("[WARNING] %s" % _("Partial failure. The geometry was processed with all tools.\n" "But there are still not-isolated geometry elements. " "Try to include a tool with smaller diameter.")) - self.app.shell_message(msg=_("The following are coordinates for the copper features " - "that could not be isolated:")) + msg = _("The following are coordinates for the copper features that could not be isolated:") + self.app.inform_shell.emit(msg) msg = '' for geo in work_geo: pt = geo.representative_point() coords = '(%s, %s), ' % (str(pt.x), str(pt.y)) msg += coords - self.app.shell_message(msg=msg) + self.app.inform_shell.emit(msg=msg) def combined_normal(self, iso_obj, iso2geo, tools_storage, lim_area, negative_dia=None, plot=True): """ diff --git a/app_Main.py b/app_Main.py index 9be7df57..3b65ff01 100644 --- a/app_Main.py +++ b/app_Main.py @@ -203,9 +203,10 @@ class App(QtCore.QObject): # ############################################################################################################### # Inform the user - # Handled by: - # * App.info() --> Print on the status bar + # Handled by: App.info() --> Print on the status bar inform = QtCore.pyqtSignal([str], [str, bool]) + # Handled by: App.info_shell() --> Print on the shell + inform_shell = QtCore.pyqtSignal(str) app_quit = QtCore.pyqtSignal() @@ -762,6 +763,9 @@ class App(QtCore.QObject): self.inform[str].connect(self.info) self.inform[str, bool].connect(self.info) + # signal for displaying messages in the shell + self.inform_shell.connect(self.info_shell) + # signal to be called when the app is quiting self.app_quit.connect(self.quit_application, type=Qt.QueuedConnection) self.message.connect(lambda: message_dialog(parent=self.ui)) @@ -2428,6 +2432,9 @@ class App(QtCore.QObject): if msg != '' and shell_echo is True: self.shell_message(msg) + def info_shell(self, msg): + self.shell_message(msg=msg) + def on_import_preferences(self): """ Loads the application default settings from a saved file into diff --git a/tclCommands/TclCommandSetOrigin.py b/tclCommands/TclCommandSetOrigin.py index 2a5f5d18..4656cce7 100644 --- a/tclCommands/TclCommandSetOrigin.py +++ b/tclCommands/TclCommandSetOrigin.py @@ -100,4 +100,4 @@ class TclCommandSetOrigin(TclCommand): self.app.on_set_zero_click(event=None, location=loc, noplot=True, use_thread=False) msg = '[success] Tcl %s: %s' % (_('Origin set by offsetting all loaded objects with '), '{0:.4f}, {0:.4f}'.format(loc[0], loc[1])) - self.app.shell_message(msg, success=True, show=False) + self.app.inform_shell.emit(msg) diff --git a/tclCommands/TclCommandSetPath.py b/tclCommands/TclCommandSetPath.py index 7a8ae872..46a52fc4 100644 --- a/tclCommands/TclCommandSetPath.py +++ b/tclCommands/TclCommandSetPath.py @@ -79,18 +79,16 @@ class TclCommandSetPath(TclCommand): "The provided path", str(path), "is a path to file and not a directory as expected.") - self.app.shell_message(msg, success=True, show=False) + self.app.inform_shell.emit(msg) return "Failed. The Tcl command set_path was used but it was not a directory." else: msg = '[ERROR] %s: %s, %s' % ( - "The provided path", - str(path), - "do not exist. Check for typos.") - self.app.shell_message(msg, success=True, show=False) + "The provided path", str(path), "do not exist. Check for typos.") + self.app.inform_shell.emit(msg) return "Failed. The Tcl command set_path was used but it does not exist." cd_command = 'cd %s' % path self.app.shell.exec_command(cd_command, no_echo=False) self.app.defaults["global_tcl_path"] = str(path) msg = '[success] %s: %s' % ("Relative path set to", str(path)) - self.app.shell_message(msg, success=True, show=False) + self.app.inform_shell.emit(msg)