From a29d18bd12ddbc65886e077e243c44c523c416de Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Sat, 29 Jan 2022 20:35:28 +0200 Subject: [PATCH] - updated the `new` Tcl command: now it has an argument `-keep_scripts` that when True, will keep the loaded scripts in the new project --- CHANGELOG.md | 1 + app_Main.py | 16 ++++++++++++---- defaults.py | 5 +++-- tclCommands/TclCommandNew.py | 28 ++++++++++++++++++++++------ 4 files changed, 38 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a6c3c6a8..7a883dd1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ CHANGELOG for FlatCAM beta - added a new preprocessor for Marlin that has movemements on the Z axis named `Marlin_laser_Z` - cleaned up Marlin preprocessors - in the `panelize`, `cutout` and `geocutout` Tcl commands updated the error strings and made sure that if an error occur then a potential script execution in chain is aborted +- updated the `new` Tcl command: now it has an argument `-keep_scripts` that when True, will keep the loaded scripts in the new project 28.01.2022 diff --git a/app_Main.py b/app_Main.py index 0b76083b..3fdf049a 100644 --- a/app_Main.py +++ b/app_Main.py @@ -651,7 +651,8 @@ class App(QtCore.QObject): # those need to be duplicated in self.defaults["util_autocomplete_keywords"] but within a string self.default_keywords = ['Berta_CNC', 'Default_no_M6', 'Desktop', 'Documents', 'FlatConfig', 'FlatPrj', 'False', 'GRBL_11', 'GRL_11_no_M6', 'GRBL_laser', 'grbl_laser_eleks_drd', - 'GRBL_laser_Z', 'ISEL_CNC', 'ISEL_ICP_CNC', 'Line_xyz', 'Marlin', + 'GRBL_laser_Z', 'ISEL_CNC', 'ISEL_ICP_CNC', + 'Line_xyz', 'Marlin', 'Marlin_laser_FAN_pin', 'Marlin_laser_Spindle_pin', 'NCCAD9', 'Marius', 'My Documents', 'Paste_1', 'Repetier', 'Roland_MDX_20', 'Roland_MDX_540', 'Toolchange_Manual', 'Toolchange_Probe_MACH3', @@ -662,7 +663,8 @@ class App(QtCore.QObject): 'depthperpass', 'dia', 'diatol', 'dist', 'drilled_dias', 'drillz', 'dpp', 'dwelltime', 'extracut_length', 'endxy', 'endz', 'f', 'factor', 'feedrate', 'feedrate_z', 'gridoffsety', 'gridx', 'gridy', - 'has_offset', 'holes', 'hpgl', 'iso_type', 'join', 'margin', 'marlin', 'method', + 'has_offset', 'holes', 'hpgl', 'iso_type', 'join', 'keep_scripts', + 'margin', 'marlin', 'method', 'milled_dias', 'minoffset', 'name', 'offset', 'opt_type', 'order', 'outname', 'overlap', 'obj_name', 'passes', 'postamble', 'pp', 'ppname_e', 'ppname_g', 'preamble', 'radius', 'ref', 'rest', 'rows', 'shellvar_', 'scale_factor', @@ -10150,7 +10152,7 @@ class MenuFileHandlers(QtCore.QObject): else: self.on_file_new_project(use_thread=True, silenced=True) - def on_file_new_project(self, cli=None, reset_tcl=True, use_thread=None, silenced=None): + def on_file_new_project(self, cli=None, reset_tcl=True, use_thread=None, silenced=None, keep_scripts=True): """ Returns the application to its startup state. This method is thread-safe. @@ -10159,6 +10161,7 @@ class MenuFileHandlers(QtCore.QObject): will remember all the previous variables. If True then the Tcl is re-instantiated. :param use_thread: Bool. If True some part of the initialization are done threaded :param silenced: Bool or None. If True then the app will not ask to save the current parameters. + :param keep_scripts: Bool. If True the Script objects are not deleted when creating a new project :return: None """ @@ -10204,7 +10207,12 @@ class MenuFileHandlers(QtCore.QObject): self.app.delete_selection_shape() # delete all FlatCAM objects - self.app.collection.delete_all() + if keep_scripts is True: + for prj_obj in self.app.collection.get_list(): + if prj_obj.kind != 'script': + self.app.collection.delete_by_name(prj_obj.options['name'], select_project=False) + else: + self.app.collection.delete_all() # add in Selected tab an initial text that describe the flow of work in FlatCAm self.app.setup_default_properties_tab() diff --git a/defaults.py b/defaults.py index bd40f558..96911b8b 100644 --- a/defaults.py +++ b/defaults.py @@ -792,7 +792,8 @@ class FlatCAMDefaults: # Keyword list "util_autocomplete_keywords": 'Berta_CNC, Default_no_M6, Desktop, Documents, FlatConfig, FlatPrj, False, ' 'GRBL_11, GRL_11_no_M6, GRBL_laser, grbl_laser_eleks_drd, GRBL_laser_Z, ' - 'ISEL_CNC, ISEL_ICP_CNC, Line_xyz, Marlin, Marlin_laser_FAN_pin, ' + 'ISEL_CNC, ISEL_ICP_CNC, ' + 'Line_xyz, Marlin, Marlin_laser_FAN_pin, ' 'Marlin_laser_Spindle_pin, NCCAD9, ' 'Marius, My Documents, Paste_1, ' 'Repetier, Roland_MDX_20, Roland_MDX_540,' @@ -802,7 +803,7 @@ class FlatCAMDefaults: 'depthperpass, dia, diatol, dist, drilled_dias, drillz, dpp, dwelltime, ' 'endxy, endz, extracut_length, f, factor, feedrate, ' 'feedrate_z, gridoffsety, gridx, gridy, has_offset, ' - 'holes, hpgl, iso_type, join, margin, marlin, method, milled_dias, ' + 'holes, hpgl, iso_type, join, keep_scripts, margin, marlin, method, milled_dias, ' 'minoffset, name, offset, opt_type, order, outname, overlap, obj_name' 'passes, postamble, pp, ppname_e, ppname_g, preamble, radius, ref, rest, ' 'rows, shellvar_, scale_factor, spacing_columns, spacing_rows, spindlespeed, ' diff --git a/tclCommands/TclCommandNew.py b/tclCommands/TclCommandNew.py index 0a770cb5..cd3ea200 100644 --- a/tclCommands/TclCommandNew.py +++ b/tclCommands/TclCommandNew.py @@ -19,6 +19,7 @@ class TclCommandNew(TclCommand): # dictionary of types from Tcl command, needs to be ordered , this is for options like -optionname value option_types = collections.OrderedDict([ ('reset', str), + ('keep_scripts', str) ]) # array of mandatory options for current Tcl command: required = {'name','outname'} @@ -26,12 +27,14 @@ class TclCommandNew(TclCommand): # structured help for current command, args needs to be ordered help = { - 'main': "Starts a new project. Clears objects from memory.", + 'main': "Starts a new project. Clears objects from memory. Default action: reset the Tcl environment.", 'args': collections.OrderedDict([ - ('reset', 'If True/0 or missing (default value) or no value provided then the Tcl is re-instantiated ' + ('reset', 'If True/1 or missing (default value) or no value provided then the Tcl is re-instantiated ' 'thus resetting all its variables.'), + ('keep_scripts', 'If True/1, all script objects are kept in the new project. ' + 'Default: scripts are not kept.') ]), - 'examples': ['new', 'new -reset False'] + 'examples': ['new', 'new -reset False', 'new -keep_scripts False'] } def execute(self, args, unnamed_args): @@ -46,7 +49,20 @@ class TclCommandNew(TclCommand): reset_tcl = True if 'reset' in args: - if args['reset'] and (args['reset'] == 0 or args['reset'].lower() == 'false'): - reset_tcl = False + if args['reset']: + try: + reset_tcl = bool(eval(str(args['reset']))) + except NameError: + if args['reset'].lower() == 'false': + reset_tcl = False - self.app.f_handlers.on_file_new_project(cli=True, reset_tcl=reset_tcl, silenced=True) + keep_scripts = False + if 'keep_scripts' in args: + if args['keep_scripts']: + try: + keep_scripts = bool(eval(str(args['keep_scripts']))) + except NameError: + if args['keep_scripts'].lower() == 'true': + keep_scripts = True + + self.app.f_handlers.on_file_new_project(cli=True, reset_tcl=reset_tcl, silenced=True, keep_scripts=keep_scripts)