From 3878ddb78227be5fe2e67be9f616121297a50de2 Mon Sep 17 00:00:00 2001 From: Kamil Sopko Date: Mon, 29 Feb 2016 22:22:23 +0100 Subject: [PATCH 1/8] display more precise answer if something in TCL shell fail --- FlatCAMApp.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/FlatCAMApp.py b/FlatCAMApp.py index 711a6d66..0edea076 100644 --- a/FlatCAMApp.py +++ b/FlatCAMApp.py @@ -659,7 +659,11 @@ class App(QtCore.QObject): result = self.tcl.eval(str(text)) self.shell.append_output(result + '\n') except Tkinter.TclError, e: - self.shell.append_error('ERROR: ' + str(e) + '\n') + #this will display more precise answer if something in TCL shell fail + result = self.tcl.eval("set errorInfo") + self.log.error("Exec command Exception: %s" % (str(e)+ '\n' + result + '\n')) + self.shell.append_error('ERROR: ' + str(e) + '\n' + result + '\n') + raise e return """ From fd869ad88c727a24db438193902a4f6c837aa950 Mon Sep 17 00:00:00 2001 From: Kamil Sopko Date: Tue, 1 Mar 2016 18:15:38 +0100 Subject: [PATCH 2/8] remove raise, it does not kill app, but raise is unnecessary here --- FlatCAMApp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FlatCAMApp.py b/FlatCAMApp.py index 0edea076..78f606c1 100644 --- a/FlatCAMApp.py +++ b/FlatCAMApp.py @@ -663,7 +663,7 @@ class App(QtCore.QObject): result = self.tcl.eval("set errorInfo") self.log.error("Exec command Exception: %s" % (str(e)+ '\n' + result + '\n')) self.shell.append_error('ERROR: ' + str(e) + '\n' + result + '\n') - raise e + #show error in console and just return return """ From 2cc3d811c58ec0c25a135626b5791c99fdb7b14c Mon Sep 17 00:00:00 2001 From: Kamil Sopko Date: Tue, 1 Mar 2016 18:22:57 +0100 Subject: [PATCH 3/8] remove duplicity when print error --- FlatCAMApp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FlatCAMApp.py b/FlatCAMApp.py index 78f606c1..e87d5beb 100644 --- a/FlatCAMApp.py +++ b/FlatCAMApp.py @@ -662,7 +662,7 @@ class App(QtCore.QObject): #this will display more precise answer if something in TCL shell fail result = self.tcl.eval("set errorInfo") self.log.error("Exec command Exception: %s" % (str(e)+ '\n' + result + '\n')) - self.shell.append_error('ERROR: ' + str(e) + '\n' + result + '\n') + self.shell.append_error('ERROR: ' + result + '\n') #show error in console and just return return From 3fd9b361b8e47a9b1f1ed6c64569cada35df63bb Mon Sep 17 00:00:00 2001 From: Kamil Sopko Date: Wed, 2 Mar 2016 00:41:54 +0100 Subject: [PATCH 4/8] implement raiseTclError and as example use it in drillcncjob --- FlatCAMApp.py | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/FlatCAMApp.py b/FlatCAMApp.py index e87d5beb..15adb17a 100644 --- a/FlatCAMApp.py +++ b/FlatCAMApp.py @@ -644,6 +644,16 @@ class App(QtCore.QObject): else: self.defaults['stats'][resource] = 1 + def raiseTclError(self, text): + """ + this method pass exception from python into TCL as error, so we get stacktrace and reason + :param text: text of error + :return: raise exception + """ + self.tcl.eval('error "%s"' % text) + raise Exception(text) + + def exec_command(self, text): """ Handles input from the shell. See FlatCAMApp.setup_shell for shell commands. @@ -661,7 +671,7 @@ class App(QtCore.QObject): except Tkinter.TclError, e: #this will display more precise answer if something in TCL shell fail result = self.tcl.eval("set errorInfo") - self.log.error("Exec command Exception: %s" % (str(e)+ '\n' + result + '\n')) + self.log.error("Exec command Exception: %s" % (result + '\n')) self.shell.append_error('ERROR: ' + result + '\n') #show error in console and just return return @@ -2446,7 +2456,9 @@ class App(QtCore.QObject): return 'Ok' - def drillcncjob(name, *args): + def drillcncjob(name=None, *args): + #name should not be none, but we set it to default, because TCL return error without reason if argument is missing + #we should check it inside shell commamnd instead a, kwa = h(*args) types = {'tools': str, 'outname': str, @@ -2457,21 +2469,24 @@ class App(QtCore.QObject): 'toolchange': int } + if name is None: + self.raiseTclError('Argument name is missing.') + for key in kwa: if key not in types: - return 'Unknown parameter: %s' % key + self.raiseTclError('Unknown parameter: %s' % key) kwa[key] = types[key](kwa[key]) try: obj = self.collection.get_by_name(str(name)) except: - return "Could not retrieve object: %s" % name + self.raiseTclError("Could not retrieve object: %s" % name) if obj is None: - return "Object not found: %s" % name + self.raiseTclError('Object not found: %s' % name) if not isinstance(obj, FlatCAMExcellon): - return "ERROR: Only Excellon objects can be drilled." + self.raiseTclError('Only Excellon objects can be drilled: %s' % name) try: @@ -2497,7 +2512,7 @@ class App(QtCore.QObject): obj.app.new_object("cncjob", job_name, job_init) except Exception, e: - return "Operation failed: %s" % str(e) + self.raiseTclError("Operation failed: %s" % str(e)) return 'Ok' From a8159dee16f4c1c67fa3f637325942ae4c8750a2 Mon Sep 17 00:00:00 2001 From: Kamil Sopko Date: Wed, 2 Mar 2016 00:45:49 +0100 Subject: [PATCH 5/8] "return -code error XXX" display error in better way --- FlatCAMApp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FlatCAMApp.py b/FlatCAMApp.py index 15adb17a..719d1c21 100644 --- a/FlatCAMApp.py +++ b/FlatCAMApp.py @@ -650,7 +650,7 @@ class App(QtCore.QObject): :param text: text of error :return: raise exception """ - self.tcl.eval('error "%s"' % text) + self.tcl.eval('return -code error "%s"' % text) raise Exception(text) From b4abef8317bf0f6f9fae0eafef216279a809a693 Mon Sep 17 00:00:00 2001 From: Kamil Sopko Date: Wed, 2 Mar 2016 00:46:23 +0100 Subject: [PATCH 6/8] remove Empty line --- FlatCAMApp.py | 1 - 1 file changed, 1 deletion(-) diff --git a/FlatCAMApp.py b/FlatCAMApp.py index 719d1c21..835625f8 100644 --- a/FlatCAMApp.py +++ b/FlatCAMApp.py @@ -653,7 +653,6 @@ class App(QtCore.QObject): self.tcl.eval('return -code error "%s"' % text) raise Exception(text) - def exec_command(self, text): """ Handles input from the shell. See FlatCAMApp.setup_shell for shell commands. From e3c43f6de1a138dc2c9580876b37002e8b7abbbc Mon Sep 17 00:00:00 2001 From: Kamil Sopko Date: Wed, 2 Mar 2016 00:49:51 +0100 Subject: [PATCH 7/8] remove Empty line --- FlatCAMApp.py | 1 - 1 file changed, 1 deletion(-) diff --git a/FlatCAMApp.py b/FlatCAMApp.py index 835625f8..9671f021 100644 --- a/FlatCAMApp.py +++ b/FlatCAMApp.py @@ -2454,7 +2454,6 @@ class App(QtCore.QObject): return 'Ok' - def drillcncjob(name=None, *args): #name should not be none, but we set it to default, because TCL return error without reason if argument is missing #we should check it inside shell commamnd instead From 0f438db833fd2fc04493276e8c6bf22d022b0917 Mon Sep 17 00:00:00 2001 From: jpcgt Date: Thu, 3 Mar 2016 14:51:36 +0000 Subject: [PATCH 8/8] Several PEP8 cleanups in shell commands. --- FlatCAMApp.py | 105 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 72 insertions(+), 33 deletions(-) diff --git a/FlatCAMApp.py b/FlatCAMApp.py index 9671f021..a5d37f1c 100644 --- a/FlatCAMApp.py +++ b/FlatCAMApp.py @@ -2150,7 +2150,7 @@ class App(QtCore.QObject): def geocutout(name, *args): """ - subtract gaps from geometry, this will not create new object + Subtract gaps from geometry, this will not create new object :param name: :param args: @@ -2161,7 +2161,7 @@ class App(QtCore.QObject): 'gapsize': float, 'gaps': str} - #way gaps wil be rendered: + # How gaps wil be rendered: # lr - left + right # tb - top + bottom # 4 - left + right +top + bottom @@ -2179,24 +2179,53 @@ class App(QtCore.QObject): except: return "Could not retrieve object: %s" % name - - #get min and max data for each object as we just cut rectangles across X or Y + # Get min and max data for each object as we just cut rectangles across X or Y xmin, ymin, xmax, ymax = obj.bounds() px = 0.5 * (xmin + xmax) py = 0.5 * (ymin + ymax) lenghtx = (xmax - xmin) lenghty = (ymax - ymin) - gapsize = kwa['gapsize']+kwa['dia']/2 + gapsize = kwa['gapsize'] + kwa['dia'] / 2 + if kwa['gaps'] == '8' or kwa['gaps']=='2lr': - subtract_rectangle(name,xmin-gapsize,py-gapsize+lenghty/4,xmax+gapsize,py+gapsize+lenghty/4) - subtract_rectangle(name,xmin-gapsize,py-gapsize-lenghty/4,xmax+gapsize,py+gapsize-lenghty/4) + + subtract_rectangle(name, + xmin - gapsize, + py - gapsize + lenghty / 4, + xmax + gapsize, + py + gapsize + lenghty / 4) + subtract_rectangle(name, + xmin-gapsize, + py - gapsize - lenghty / 4, + xmax + gapsize, + py + gapsize - lenghty / 4) + if kwa['gaps'] == '8' or kwa['gaps']=='2tb': - subtract_rectangle(name,px-gapsize+lenghtx/4,ymin-gapsize,px+gapsize+lenghtx/4,ymax+gapsize) - subtract_rectangle(name,px-gapsize-lenghtx/4,ymin-gapsize,px+gapsize-lenghtx/4,ymax+gapsize) + subtract_rectangle(name, + px - gapsize + lenghtx / 4, + ymin-gapsize, + px + gapsize + lenghtx / 4, + ymax + gapsize) + subtract_rectangle(name, + px - gapsize - lenghtx / 4, + ymin - gapsize, + px + gapsize - lenghtx / 4, + ymax + gapsize) + if kwa['gaps'] == '4' or kwa['gaps']=='lr': - subtract_rectangle(name,xmin-gapsize,py-gapsize,xmax+gapsize,py+gapsize) + subtract_rectangle(name, + xmin - gapsize, + py - gapsize, + xmax + gapsize, + py + gapsize) + if kwa['gaps'] == '4' or kwa['gaps']=='tb': - subtract_rectangle(name,px-gapsize,ymin-gapsize,px+gapsize,ymax+gapsize) + subtract_rectangle(name, + px - gapsize, + ymin - gapsize, + px + gapsize, + ymax + gapsize) + return 'Ok' def mirror(name, *args): @@ -2222,14 +2251,12 @@ class App(QtCore.QObject): if not isinstance(obj, FlatCAMGerber) and not isinstance(obj, FlatCAMExcellon): return "ERROR: Only Gerber and Excellon objects can be mirrored." - # Axis try: axis = kwa['axis'].upper() except KeyError: return "ERROR: Specify -axis X or -axis Y" - # Box if 'box' in kwa: try: @@ -2302,20 +2329,23 @@ class App(QtCore.QObject): else: gridoffsety=kwa['gridoffsety'] - # Tools tools = {"1": {"C": kwa['dia']}} def aligndrillgrid_init_me(init_obj, app_obj): drills = [] currenty=0 + for row in range(kwa['rows']): currentx=0 + for col in range(kwa['columns']): - point = Point(currentx+gridoffsetx,currenty+gridoffsety) + point = Point(currentx + gridoffsetx, currenty + gridoffsety) drills.append({"point": point, "tool": "1"}) - currentx=currentx+kwa['gridx'] - currenty=currenty+kwa['gridy'] + currentx = currentx + kwa['gridx'] + + currenty = currenty + kwa['gridy'] + init_obj.tools = tools init_obj.drills = drills init_obj.create_geometry() @@ -2389,23 +2419,32 @@ class App(QtCore.QObject): else: axisoffset=0 - #this will align hole to given aligngridoffset and minimal offset from pcb, based on selected axis + # This will align hole to given aligngridoffset and minimal offset from pcb, based on selected axis if axis == "X": - firstpoint=kwa['gridoffset'] - while (xmin-kwa['minoffset'])lastpoint: - lastpoint=lastpoint+kwa['grid'] - localHoles=(firstpoint,axisoffset),(lastpoint,axisoffset) + firstpoint = kwa['gridoffset'] + + while (xmin - kwa['minoffset']) < firstpoint: + firstpoint = firstpoint - kwa['grid'] + + lastpoint = kwa['gridoffset'] + + while (xmax + kwa['minoffset']) > lastpoint: + lastpoint = lastpoint + kwa['grid'] + + localHoles = (firstpoint, axisoffset), (lastpoint, axisoffset) + else: - firstpoint=kwa['gridoffset'] - while (ymin-kwa['minoffset'])lastpoint: + firstpoint = kwa['gridoffset'] + + while (ymin - kwa['minoffset']) < firstpoint: + firstpoint = firstpoint - kwa['grid'] + + lastpoint = kwa['gridoffset'] + + while (ymax + kwa['minoffset']) > lastpoint: lastpoint=lastpoint+kwa['grid'] - localHoles=(axisoffset,firstpoint),(axisoffset,lastpoint) + + localHoles = (axisoffset, firstpoint), (axisoffset, lastpoint) for hole in localHoles: point = Point(hole) @@ -2455,8 +2494,8 @@ class App(QtCore.QObject): return 'Ok' def drillcncjob(name=None, *args): - #name should not be none, but we set it to default, because TCL return error without reason if argument is missing - #we should check it inside shell commamnd instead + # name should not be none, but we set it to default, because TCL return error without reason if argument is missing + # we should check it inside shell commamnd instead a, kwa = h(*args) types = {'tools': str, 'outname': str,