From 56799a35b72dbff7eec6b641f65e4e9a12e4980b Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Fri, 13 Sep 2019 22:47:38 +0300 Subject: [PATCH] - added a new way to handle scripts with repeating Tcl commands - added new buttons in the Tools toolbar for running, opening and adding new scripts --- FlatCAMApp.py | 41 ++++++++++++++++++++++++++++++++++++--- README.md | 2 ++ flatcamGUI/FlatCAMGUI.py | 8 +++++++- share/script_new24.png | Bin 0 -> 345 bytes share/script_open18.png | Bin 0 -> 247 bytes share/script_open24.png | Bin 0 -> 356 bytes 6 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 share/script_new24.png create mode 100644 share/script_open18.png create mode 100644 share/script_open24.png diff --git a/FlatCAMApp.py b/FlatCAMApp.py index 9db136dd..74204df9 100644 --- a/FlatCAMApp.py +++ b/FlatCAMApp.py @@ -2661,7 +2661,11 @@ class App(QtCore.QObject): self.ui.editgeo_btn.triggered.connect(self.object2editor) self.ui.update_obj_btn.triggered.connect(lambda: self.editor2object()) self.ui.delete_btn.triggered.connect(self.on_delete) + self.ui.shell_btn.triggered.connect(self.on_toggle_shell) + self.ui.new_script_btn.triggered.connect(self.on_filenewscript) + self.ui.open_script_btn.triggered.connect(self.on_fileopenscript) + self.ui.run_script_btn.triggered.connect(self.on_filerunscript) # Tools Toolbar Signals self.ui.dblsided_btn.triggered.connect(lambda: self.dblsidedtool.run(toggle=True)) @@ -3028,7 +3032,7 @@ class App(QtCore.QObject): self.display_tcl_error(text) raise self.TclErrorException(text) - def exec_command(self, text): + def exec_command(self, text, no_plot=None): """ Handles input from the shell. See FlatCAMApp.setup_shell for shell commands. Also handles execution in separated threads @@ -3042,7 +3046,8 @@ class App(QtCore.QObject): result = self.exec_command_test(text, False) # MS: added this method call so the geometry is updated once the TCL command is executed - self.plot_all() + if no_plot is None: + self.plot_all() return result @@ -3060,6 +3065,7 @@ class App(QtCore.QObject): try: self.shell.open_proccessing() # Disables input box. + result = self.tcl.eval(str(tcl_command_string)) if result != 'None': self.shell.append_output(result + '\n') @@ -5758,6 +5764,9 @@ class App(QtCore.QObject): self.ui.shell_dock.show() script_code = self.ui.code_editor.toPlainText() + # self.shell._sysShell.exec_command(script_code) + + old_line = '' for tcl_command_line in script_code.splitlines(): # do not process lines starting with '#' = comment and empty lines if not tcl_command_line.startswith('#') and tcl_command_line != '': @@ -5766,8 +5775,34 @@ class App(QtCore.QObject): if sys.platform == 'win32': if "open" in tcl_command_line: tcl_command_line = tcl_command_line.replace('\\', '/') + + if old_line != '': + new_command = old_line + tcl_command_line + '\n' + else: + new_command = tcl_command_line + # execute the actual Tcl command - self.shell._sysShell.exec_command(tcl_command_line) + try: + self.shell.open_proccessing() # Disables input box. + + result = self.tcl.eval(str(new_command)) + if result != 'None': + self.shell.append_output(result + '\n') + + old_line = '' + except tk.TclError as e: + old_line = old_line + tcl_command_line + '\n' + + if old_line != '': + # it means that the script finished with an error + result = self.tcl.eval("set errorInfo") + self.log.error("Exec command Exception: %s" % (result + '\n')) + self.shell.append_error('ERROR: ' + result + '\n') + else: + # success! plot all objects + self.plot_all() + + self.shell.close_proccessing() def on_tool_add_keypress(self): # ## Current application units in Upper Case diff --git a/README.md b/README.md index 296cddc4..f8b0750e 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,8 @@ CAD program, and create G-Code for Isolation routing. - fixed some of the strings that were left in the old way - updated the POT file - updated Romanian language partially +- added a new way to handle scripts with repeating Tcl commands +- added new buttons in the Tools toolbar for running, opening and adding new scripts 12.09.2019 diff --git a/flatcamGUI/FlatCAMGUI.py b/flatcamGUI/FlatCAMGUI.py index 23449859..a05043a1 100644 --- a/flatcamGUI/FlatCAMGUI.py +++ b/flatcamGUI/FlatCAMGUI.py @@ -119,7 +119,7 @@ class FlatCAMGUI(QtWidgets.QMainWindow): self.menufilenewscript = QtWidgets.QAction(QtGui.QIcon('share/script_new16.png'), _('New Script ...'), self) self.menufileopenscript = QtWidgets.QAction(QtGui.QIcon('share/script_open16.png'), _('Open Script ...'), self) self.menufilerunscript = QtWidgets.QAction(QtGui.QIcon('share/script16.png'), - _('Run Script ...\tSHIFT+S'), self) + '%s\tSHIFT+S' % _('Run Script ...'), self) self.menufilerunscript.setToolTip( _("Will run the opened Tcl Script thus\n" "enabling the automation of certain\n" @@ -653,6 +653,9 @@ class FlatCAMGUI(QtWidgets.QMainWindow): # ## Shell Toolbar ## self.shell_btn = self.toolbarshell.addAction(QtGui.QIcon('share/shell32.png'), _("&Command Line")) + self.new_script_btn = self.toolbarshell.addAction(QtGui.QIcon('share/script_new24.png'), _('New Script ...')) + self.open_script_btn = self.toolbarshell.addAction(QtGui.QIcon('share/script_open18.png'), _('Open Script ...')) + self.run_script_btn = self.toolbarshell.addAction(QtGui.QIcon('share/script16.png'), _('Run Script ...')) # ## Tools Toolbar ## self.dblsided_btn = self.toolbartools.addAction(QtGui.QIcon('share/doubleside32.png'), _("2Sided Tool")) @@ -2079,6 +2082,9 @@ class FlatCAMGUI(QtWidgets.QMainWindow): # ## Shell Toolbar # ## self.shell_btn = self.toolbarshell.addAction(QtGui.QIcon('share/shell32.png'), _("&Command Line")) + self.new_script_btn = self.toolbarshell.addAction(QtGui.QIcon('share/script_new24.png'), _('New Script ...')) + self.open_script_btn = self.toolbarshell.addAction(QtGui.QIcon('share/script_open18.png'), _('Open Script ...')) + self.run_script_btn = self.toolbarshell.addAction(QtGui.QIcon('share/script16.png'), _('Run Script ...')) # ## Tools Toolbar # ## self.dblsided_btn = self.toolbartools.addAction(QtGui.QIcon('share/doubleside32.png'), _("2Sided Tool")) diff --git a/share/script_new24.png b/share/script_new24.png new file mode 100644 index 0000000000000000000000000000000000000000..1593be68c3f2791ea15074d8e1f08341ed5fc7e9 GIT binary patch literal 345 zcmV-f0jByIEMX+ka3&zW3&a6Hd=ZBl6iYxBxB~GaA`EAMs%-;eQv&K>mc)T9 za0B9nL|U*Mhz|krbRsQ?Cnbo4fcOp&D*^EbA`DLl;!UJPat;t%0C5blhJyr1Nv7w3 zxCDsz5o{=6%~_#_!SU0V^Iq$DliPkX8{8PYGDTo r9)BQyj71$toaDleYGBlYfwuqv9eYcpNVCCK00000NkvXXu0mjftv+=r literal 0 HcmV?d00001 diff --git a/share/script_open18.png b/share/script_open18.png new file mode 100644 index 0000000000000000000000000000000000000000..ba558b24de61bae3ee2ec7c2d910c22bceafeec8 GIT binary patch literal 247 zcmeAS@N?(olHy`uVBq!ia0vp^LLkh+0wn(&ce?|mn3BBRT^Rni_n+Ah$i8BrrOn#`xw`0De_=+~gNr_U-!pvqHW*(e)kYfc8hnGaqf~Ge-O$i*#%Oxus z_Pk!vrDiaP(OG(jlDR^@;3}mO1|v?c6>By4U&(RU993}M=E=#kdtrezv%E7;vx%AO z9UiX$4fZF6Mh24-V-=m15?yN?R&!`XwLB_y5m=$1y^F6mBxDDNOnrgt@5W9>VH4(9 rt#bv;(^^UzPi;`&ewjy3K$YR?`Tz&3WyWqmw=;OU`njxgN@xNA@UT#0 literal 0 HcmV?d00001 diff --git a/share/script_open24.png b/share/script_open24.png new file mode 100644 index 0000000000000000000000000000000000000000..4f2f956eaac5036c3db129977ce3b921cc29da2d GIT binary patch literal 356 zcmV-q0h|7bP)6~nn9!m=|H@Y93Lq>m3ugMc^?Uk73#bZ;X2;13BFfb?yE>H`@%0~%a; z=oY}@z#JL}|B>X-*~nr{Pz(x=Pe8mFh)a=t1O@;QWPsc~59YrB0000