From eb5c6490f764d94e88e5ad061e0a654da1dfbafd Mon Sep 17 00:00:00 2001 From: uenz Date: Fri, 1 Jan 2021 22:26:29 +0100 Subject: [PATCH 1/5] Make scritname int tcl available via info script --- appObjects/FlatCAMScript.py | 33 +++++++++++++++++++++++++++++---- appTools/ToolShell.py | 1 - app_Main.py | 5 +++-- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/appObjects/FlatCAMScript.py b/appObjects/FlatCAMScript.py index cd3107f9..eeafc493 100644 --- a/appObjects/FlatCAMScript.py +++ b/appObjects/FlatCAMScript.py @@ -131,7 +131,7 @@ class ScriptObject(FlatCAMObj): try: # self.script_editor_tab.code_editor.setPlainText(self.source_file) - self.script_editor_tab.load_text(self.source_file, move_to_end=True) + self.script_editor_tab.load_text(self.script_code, move_to_end=True) except Exception as e: log.debug("ScriptObject.set_ui() --> %s" % str(e)) @@ -158,7 +158,7 @@ class ScriptObject(FlatCAMObj): def parse_file(self, filename): """ - Will set an attribute of the object, self.source_file, with the parsed data. + Will set an attribute of the object, self.script_code, with the parsed data. :param filename: Tcl Script file to parse :return: None @@ -167,7 +167,8 @@ class ScriptObject(FlatCAMObj): script_content = opened_script.readlines() script_content = ''.join(script_content) - self.source_file = script_content + self.script_code = script_content + self.source_file = filename def handle_run_code(self): # trying to run a Tcl command without having the Shell open will create some warnings because the Tcl Shell @@ -184,7 +185,31 @@ class ScriptObject(FlatCAMObj): self.script_code = self.script_editor_tab.code_editor.toPlainText() old_line = '' - for tcl_command_line in self.script_code.splitlines(): + + # set tcl info script to actual scriptfile + set_tcl_script_name='''proc procExists p {{ + return uplevel 1 [expr {{[llength [info command $p]] > 0}}] + }} + + #set alreadydefined [procExists "info_original"] + #if {{${{alreadydefined}}==0}} {{ + if {{[procExists "info_original"]==0}} {{ + rename info info_original + }} + proc info args {{ + switch [lindex $args 0] {{ + script {{ + return "{0}" + }} + default {{ + return [uplevel info_original $args] + }} + }} + }}'''.format(self.source_file) + + + + for tcl_command_line in set_tcl_script_name.splitlines()+self.script_code.splitlines(): # do not process lines starting with '#' = comment and empty lines if not tcl_command_line.startswith('#') and tcl_command_line != '': # id FlatCAM is run in Windows then replace all the slashes with diff --git a/appTools/ToolShell.py b/appTools/ToolShell.py index 02e093e0..2cf2c2b8 100644 --- a/appTools/ToolShell.py +++ b/appTools/ToolShell.py @@ -287,7 +287,6 @@ class FCShell(TermWidget): self.app = app self.tcl_commands_storage = {} - self.tcl = None self.init_tcl() diff --git a/app_Main.py b/app_Main.py index 6e918910..81ca8364 100644 --- a/app_Main.py +++ b/app_Main.py @@ -1931,8 +1931,9 @@ class App(QtCore.QObject): :return: None """ - # shell tool has t obe initialized always first because other tools print messages in the Shell Dock - self.shell = FCShell(app=self, version=self.version) + # shell tool has to be initialized always first because other tools print messages in the Shell Dock, but only if it not al´ready exists + if (hasattr(self,"shell") and self.shell is None) or hasattr(self,"shell")==False: + self.shell = FCShell(app=self, version=self.version) self.distance_tool = Distance(self) self.distance_tool.install(icon=QtGui.QIcon(self.resource_location + '/distance16.png'), pos=self.ui.menuedit, From 25785393fc14900bcba911ef7954344d0a3e217e Mon Sep 17 00:00:00 2001 From: uenz Date: Sun, 3 Jan 2021 13:31:57 +0100 Subject: [PATCH 2/5] Cleanup --- appObjects/FlatCAMScript.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/appObjects/FlatCAMScript.py b/appObjects/FlatCAMScript.py index eeafc493..fd40da74 100644 --- a/appObjects/FlatCAMScript.py +++ b/appObjects/FlatCAMScript.py @@ -191,8 +191,6 @@ class ScriptObject(FlatCAMObj): return uplevel 1 [expr {{[llength [info command $p]] > 0}}] }} - #set alreadydefined [procExists "info_original"] - #if {{${{alreadydefined}}==0}} {{ if {{[procExists "info_original"]==0}} {{ rename info info_original }} From 694e278c0cc2a3d9431c8710a4ca5f7786e45f01 Mon Sep 17 00:00:00 2001 From: uenz Date: Sun, 3 Jan 2021 14:31:18 +0100 Subject: [PATCH 3/5] Reverted changes --- app_Main.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app_Main.py b/app_Main.py index 81ca8364..6e918910 100644 --- a/app_Main.py +++ b/app_Main.py @@ -1931,9 +1931,8 @@ class App(QtCore.QObject): :return: None """ - # shell tool has to be initialized always first because other tools print messages in the Shell Dock, but only if it not al´ready exists - if (hasattr(self,"shell") and self.shell is None) or hasattr(self,"shell")==False: - self.shell = FCShell(app=self, version=self.version) + # shell tool has t obe initialized always first because other tools print messages in the Shell Dock + self.shell = FCShell(app=self, version=self.version) self.distance_tool = Distance(self) self.distance_tool.install(icon=QtGui.QIcon(self.resource_location + '/distance16.png'), pos=self.ui.menuedit, From ad417f5009b153aff43949da4b62ea5814377d88 Mon Sep 17 00:00:00 2001 From: uenz Date: Sun, 3 Jan 2021 14:37:32 +0100 Subject: [PATCH 4/5] Use new variable to store script filename --- appObjects/FlatCAMScript.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/appObjects/FlatCAMScript.py b/appObjects/FlatCAMScript.py index fd40da74..d853343a 100644 --- a/appObjects/FlatCAMScript.py +++ b/appObjects/FlatCAMScript.py @@ -54,6 +54,7 @@ class ScriptObject(FlatCAMObj): self.ser_attrs = ['options', 'kind', 'source_file'] self.source_file = '' self.script_code = '' + self.script_filename='' self.units_found = self.app.defaults['units'] @@ -131,7 +132,7 @@ class ScriptObject(FlatCAMObj): try: # self.script_editor_tab.code_editor.setPlainText(self.source_file) - self.script_editor_tab.load_text(self.script_code, move_to_end=True) + self.script_editor_tab.load_text(self.source_file, move_to_end=True) except Exception as e: log.debug("ScriptObject.set_ui() --> %s" % str(e)) @@ -158,7 +159,7 @@ class ScriptObject(FlatCAMObj): def parse_file(self, filename): """ - Will set an attribute of the object, self.script_code, with the parsed data. + Will set an attribute of the object, self.source_file, with the parsed data. :param filename: Tcl Script file to parse :return: None @@ -167,8 +168,8 @@ class ScriptObject(FlatCAMObj): script_content = opened_script.readlines() script_content = ''.join(script_content) - self.script_code = script_content - self.source_file = filename + self.source_file = script_content + self.script_filename = filename def handle_run_code(self): # trying to run a Tcl command without having the Shell open will create some warnings because the Tcl Shell @@ -203,7 +204,7 @@ class ScriptObject(FlatCAMObj): return [uplevel info_original $args] }} }} - }}'''.format(self.source_file) + }}'''.format(self.script_filename) From 0d27e30c14d249059df239422b936b79f6896d62 Mon Sep 17 00:00:00 2001 From: uenz Date: Mon, 4 Jan 2021 14:50:32 +0100 Subject: [PATCH 5/5] undone changes --- appTools/ToolShell.py | 1 + 1 file changed, 1 insertion(+) diff --git a/appTools/ToolShell.py b/appTools/ToolShell.py index 2cf2c2b8..e8e3e18f 100644 --- a/appTools/ToolShell.py +++ b/appTools/ToolShell.py @@ -287,6 +287,7 @@ class FCShell(TermWidget): self.app = app self.tcl_commands_storage = {} + self.tcl = None self.init_tcl()