From e54dd14e6cff7242c9117248fbfbfeed7931bf1c Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Sun, 8 Dec 2019 22:11:39 +0200 Subject: [PATCH] - updated Tcl commands to make use of either 0 or False for False value or 1 or True for True in case of a parameter with type Bool --- README.md | 1 + tclCommands/TclCommandBbox.py | 2 +- tclCommands/TclCommandCopperClear.py | 8 ++++---- tclCommands/TclCommandCutout.py | 6 +++--- tclCommands/TclCommandGeoCutout.py | 6 +++--- tclCommands/TclCommandMillDrills.py | 5 ++++- tclCommands/TclCommandMillSlots.py | 3 +++ tclCommands/TclCommandNregions.py | 4 ++-- tclCommands/TclCommandOffset.py | 2 +- tclCommands/TclCommandPaint.py | 10 +++++----- tclCommands/TclCommandPanelize.py | 20 ++++++++++---------- tclCommands/TclCommandSetOrigin.py | 6 +++--- 12 files changed, 40 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index c3410225..754797ec 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ CAD program, and create G-Code for Isolation routing. - fixed an small issue in Object UI - small fixes: selected object in Project used to ask twice for UI build; if scale factor in Object UI is 1 do nothing as there is no point in scaling with a factor of 1 - in Geometry UI added a button that allow updating all the tools in the Tool Table with the current values in the UI form +- updated Tcl commands to make use of either 0 or False for False value or 1 or True for True in case of a parameter with type Bool 7.12.2019 diff --git a/tclCommands/TclCommandBbox.py b/tclCommands/TclCommandBbox.py index ba9ca2fc..06cef7d8 100644 --- a/tclCommands/TclCommandBbox.py +++ b/tclCommands/TclCommandBbox.py @@ -79,7 +79,7 @@ class TclCommandBbox(TclCommand): if 'rounded' not in args: args['rounded'] = self.app.defaults["gerber_bboxrounded"] - rounded = args['rounded'] + rounded = bool(args['rounded']) del args['name'] diff --git a/tclCommands/TclCommandCopperClear.py b/tclCommands/TclCommandCopperClear.py index 1cb2ccc3..ff4647de 100644 --- a/tclCommands/TclCommandCopperClear.py +++ b/tclCommands/TclCommandCopperClear.py @@ -126,18 +126,18 @@ class TclCommandCopperClear(TclCommand): method = str(self.app.defaults["tools_nccmethod"]) if 'connect' in args: - connect = eval(str(args['connect']).capitalize()) + connect = bool(args['connect']) else: connect = eval(str(self.app.defaults["tools_nccconnect"])) if 'contour' in args: - contour = eval(str(args['contour']).capitalize()) + contour = bool(args['contour']) else: contour = eval(str(self.app.defaults["tools_ncccontour"])) offset = 0.0 if 'has_offset' in args: - has_offset = args['has_offset'] + has_offset = bool(args['has_offset']) if args['has_offset'] is True: if 'offset' in args: offset = float(args['margin']) @@ -203,7 +203,7 @@ class TclCommandCopperClear(TclCommand): }) if 'rest' in args: - rest = eval(str(args['rest']).capitalize()) + rest = bool(args['rest']) else: rest = eval(str(self.app.defaults["tools_nccrest"])) diff --git a/tclCommands/TclCommandCutout.py b/tclCommands/TclCommandCutout.py index e56672af..3df71efb 100644 --- a/tclCommands/TclCommandCutout.py +++ b/tclCommands/TclCommandCutout.py @@ -67,12 +67,12 @@ class TclCommandCutout(TclCommand): return if 'margin' in args: - margin_par = args['margin'] + margin_par = float(args['margin']) else: margin_par = 0.001 if 'dia' in args: - dia_par = args['dia'] + dia_par = float(args['dia']) else: dia_par = 0.1 @@ -82,7 +82,7 @@ class TclCommandCutout(TclCommand): gaps_par = "4" if 'gapsize' in args: - gapsize_par = args['gapsize'] + gapsize_par = float(args['gapsize']) else: gapsize_par = 0.1 diff --git a/tclCommands/TclCommandGeoCutout.py b/tclCommands/TclCommandGeoCutout.py index d317308e..f7df8108 100644 --- a/tclCommands/TclCommandGeoCutout.py +++ b/tclCommands/TclCommandGeoCutout.py @@ -137,12 +137,12 @@ class TclCommandGeoCutout(TclCommandSignaled): return if 'margin' in args: - margin = args['margin'] + margin = float(args['margin']) else: margin = 0.001 if 'dia' in args: - dia = args['dia'] + dia = float(args['dia']) else: dia = 0.1 @@ -152,7 +152,7 @@ class TclCommandGeoCutout(TclCommandSignaled): gaps = 4 if 'gapsize' in args: - gapsize = args['gapsize'] + gapsize = float(args['gapsize']) else: gapsize = 0.1 diff --git a/tclCommands/TclCommandMillDrills.py b/tclCommands/TclCommandMillDrills.py index 625ac2db..a7d607c2 100644 --- a/tclCommands/TclCommandMillDrills.py +++ b/tclCommands/TclCommandMillDrills.py @@ -79,6 +79,9 @@ class TclCommandMillDrills(TclCommandSignaled): if 'outname' not in args: args['outname'] = name + "_mill_drills" + if 'use_thread' in args: + args['use_thread'] = bool(args['use_thread']) + if not obj.drills: self.raise_tcl_error("The Excellon object has no drills: %s" % name) @@ -96,7 +99,7 @@ class TclCommandMillDrills(TclCommandSignaled): req_dia_form = float('%.*f' % (obj.decimals, float(req_dia))) if 'diatol' in args: - tolerance = args['diatol'] / 100 + tolerance = float(args['diatol']) / 100 tolerance = 0.0 if tolerance < 0.0 else tolerance tolerance = 1.0 if tolerance > 1.0 else tolerance diff --git a/tclCommands/TclCommandMillSlots.py b/tclCommands/TclCommandMillSlots.py index 0ca129a7..9665c91d 100644 --- a/tclCommands/TclCommandMillSlots.py +++ b/tclCommands/TclCommandMillSlots.py @@ -79,6 +79,9 @@ class TclCommandMillSlots(TclCommandSignaled): if 'outname' not in args: args['outname'] = name + "_mill_slots" + if 'use_thread' in args: + args['use_thread'] = bool(args['use_thread']) + if not obj.slots: self.raise_tcl_error("The Excellon object has no slots: %s" % name) diff --git a/tclCommands/TclCommandNregions.py b/tclCommands/TclCommandNregions.py index 7bad21f7..6dbb22d5 100644 --- a/tclCommands/TclCommandNregions.py +++ b/tclCommands/TclCommandNregions.py @@ -74,11 +74,11 @@ class TclCommandNregions(TclCommand): if 'margin' not in args: args['margin'] = float(self.app.defaults["gerber_noncoppermargin"]) - margin = args['margin'] + margin = float(args['margin']) if 'rounded' not in args: args['rounded'] = self.app.defaults["gerber_noncopperrounded"] - rounded = args['rounded'] + rounded = bool(args['rounded']) del args['name'] diff --git a/tclCommands/TclCommandOffset.py b/tclCommands/TclCommandOffset.py index cbdd976e..a7306db9 100644 --- a/tclCommands/TclCommandOffset.py +++ b/tclCommands/TclCommandOffset.py @@ -49,6 +49,6 @@ class TclCommandOffset(TclCommand): """ name = args['name'] - x, y = args['x'], args['y'] + x, y = float(args['x']), float(args['y']) self.app.collection.get_by_name(name).offset((x, y)) diff --git a/tclCommands/TclCommandPaint.py b/tclCommands/TclCommandPaint.py index 14088dcc..3c9a7ec2 100644 --- a/tclCommands/TclCommandPaint.py +++ b/tclCommands/TclCommandPaint.py @@ -123,12 +123,12 @@ class TclCommandPaint(TclCommand): method = str(self.app.defaults["tools_paintmethod"]) if 'connect' in args: - connect = eval(str(args['connect']).capitalize()) + connect = bool(args['connect']) else: connect = eval(str(self.app.defaults["tools_pathconnect"])) if 'contour' in args: - contour = eval(str(args['contour']).capitalize()) + contour = bool(args['contour']) else: contour = eval(str(self.app.defaults["tools_paintcontour"])) @@ -195,7 +195,7 @@ class TclCommandPaint(TclCommand): return "Object not found: %s" % name # Paint all polygons in the painted object - if 'all' in args and args['all'] is True: + if 'all' in args and bool(args['all']) is True: self.app.paint_tool.paint_poly_all(obj=obj, tooldia=tooldia, overlap=overlap, @@ -211,7 +211,7 @@ class TclCommandPaint(TclCommand): return # Paint single polygon in the painted object - elif 'single' in args and args['single'] is True: + elif 'single' in args and bool(args['single']) is True: if 'x' not in args or 'y' not in args: self.raise_tcl_error('%s' % _("Expected -x and -y .")) else: @@ -234,7 +234,7 @@ class TclCommandPaint(TclCommand): return # Paint all polygons found within the box object from the the painted object - elif 'ref' in args and args['ref'] is True: + elif 'ref' in args and bool(args['ref']) is True: if 'box' not in args: self.raise_tcl_error('%s' % _("Expected -box .")) else: diff --git a/tclCommands/TclCommandPanelize.py b/tclCommands/TclCommandPanelize.py index 21d677b9..77fcb15d 100644 --- a/tclCommands/TclCommandPanelize.py +++ b/tclCommands/TclCommandPanelize.py @@ -34,7 +34,7 @@ class TclCommandPanelize(TclCommand): ('spacing_rows', float), ('box', str), ('outname', str), - ('threaded', int) + ('run_threaded', bool) ]) # array of mandatory options for current Tcl command: required = {'name','outname'} @@ -52,7 +52,7 @@ class TclCommandPanelize(TclCommand): ('columns', 'Number of columns.'), ('rows', 'Number of rows;'), ('outname', 'Name of the new geometry object.'), - ('threaded', '0 = non-threaded || 1 = threaded') + ('run_threaded', 'False = non-threaded || True = threaded') ]), 'examples': [] } @@ -93,23 +93,23 @@ class TclCommandPanelize(TclCommand): else: outname = name + '_panelized' - if 'threaded' in args: - threaded = args['threaded'] + if 'run_threaded' in args: + threaded = bool(args['run_threaded']) else: - threaded = 0 + threaded = False if 'spacing_columns' in args: - spacing_columns = args['spacing_columns'] + spacing_columns = int(args['spacing_columns']) else: spacing_columns = 5 if 'spacing_rows' in args: - spacing_rows = args['spacing_rows'] + spacing_rows = int(args['spacing_rows']) else: spacing_rows = 5 - rows = args['rows'] - columns = args['columns'] + rows = int(args['rows']) + columns = int(args['columns']) xmin, ymin, xmax, ymax = box.bounds() lenghtx = xmax - xmin + spacing_columns @@ -277,7 +277,7 @@ class TclCommandPanelize(TclCommand): self.app.progress.emit(50) self.app.new_object("geometry", outname, job_init_geometry, plot=False, autoselected=True) - if threaded == 1: + if threaded is True: proc = self.app.proc_container.new("Generating panel ... Please wait.") def job_thread(app_obj): diff --git a/tclCommands/TclCommandSetOrigin.py b/tclCommands/TclCommandSetOrigin.py index 8e77bfab..27f883ce 100644 --- a/tclCommands/TclCommandSetOrigin.py +++ b/tclCommands/TclCommandSetOrigin.py @@ -52,8 +52,8 @@ class TclCommandSetOrigin(TclCommand): 'main': "Will set the origin at the specified x,y location.", 'args': collections.OrderedDict([ ('loc', 'Location to offset all the selected objects. No spaces between x and y pair. Use like this: 2,3'), - ('auto', 'If set to 1 it will set the origin to the minimum x, y of the object selection bounding box.' - '-auto=1 is not correct but -auto 1 or -auto True is correct.') + ('auto', 'If set to True it will set the origin to the minimum x, y of the object selection bounding box.' + '-auto=True is not correct but -auto 1 or -auto True is correct.') ]), 'examples': ['set_origin 3,2', 'set_origin -auto 1'] } @@ -68,7 +68,7 @@ class TclCommandSetOrigin(TclCommand): loc = list() if 'auto' in args: - if args['auto'] == 1: + if bool(args['auto']) is True: objs = self.app.collection.get_list() minx, miny, __, ___ = get_bounds(objs)