Merge https://bitbucket.org/jpcgt/flatcam/src/master into Follow_TCL_command_add_to_new_architecture

# Conflicts:
#	FlatCAMApp.py
This commit is contained in:
Marius Stanciu
2018-05-31 17:53:35 +03:00
77 changed files with 431 additions and 437 deletions

View File

@@ -5,6 +5,7 @@ import abc
import collections
from PyQt4 import QtCore
from contextlib import contextmanager
from FlatCAMObj import FlatCAMGerber, FlatCAMExcellon, FlatCAMGeometry, FlatCAMCNCjob, FlatCAMObj
class TclCommand(object):
@@ -97,7 +98,7 @@ class TclCommand(object):
command_string = []
for arg_key, arg_type in self.help['args'].items():
for arg_key, arg_type in list(self.help['args'].items()):
command_string.append(get_decorated_argument(arg_key, arg_type, True))
return "> " + alias_name + " " + " ".join(command_string)
@@ -147,7 +148,7 @@ class TclCommand(object):
for alias in self.aliases:
help_string.append(get_decorated_command(alias))
for key, value in self.help['args'].items():
for key, value in list(self.help['args'].items()):
help_string.append(get_decorated_argument(key, value))
# timeout is unique for signaled commands (this is not best oop practice, but much easier for now)
@@ -206,13 +207,13 @@ class TclCommand(object):
# check arguments
idx = 0
arg_names_items = self.arg_names.items()
arg_names_items = list(self.arg_names.items())
for argument in arguments:
if len(self.arg_names) > idx:
key, arg_type = arg_names_items[idx]
try:
named_args[key] = arg_type(argument)
except Exception, e:
except Exception as e:
self.raise_tcl_error("Cannot cast named argument '%s' to type %s with exception '%s'."
% (key, arg_type, str(e)))
else:
@@ -228,7 +229,7 @@ class TclCommand(object):
named_args[key] = self.option_types[key](options[key])
else:
named_args[key] = int(options[key])
except Exception, e:
except Exception as e:
self.raise_tcl_error("Cannot cast argument '-%s' to type '%s' with exception '%s'."
% (key, self.option_types[key], str(e)))
@@ -292,7 +293,7 @@ class TclCommandSignaled(TclCommand):
"""
!!! I left it here only for demonstration !!!
Go to TclCommandCncjob and into class definition put
class TclCommandCncjob(TclCommand.TclCommandSignaled):
class TclCommandCncjob(TclCommandSignaled):
also change
obj.generatecncjob(use_thread = False, **args)
to

View File

@@ -1,8 +1,7 @@
from ObjectCollection import *
import TclCommand
from tclCommands.TclCommand import *
class TclCommandAddCircle(TclCommand.TclCommand):
class TclCommandAddCircle(TclCommand):
"""
Tcl shell command to creates a circle in the given Geometry object.

View File

@@ -1,8 +1,7 @@
from ObjectCollection import *
import TclCommand
from tclCommands.TclCommand import *
class TclCommandAddPolygon(TclCommand.TclCommandSignaled):
class TclCommandAddPolygon(TclCommandSignaled):
"""
Tcl shell command to create a polygon in the given Geometry object
"""

View File

@@ -1,8 +1,7 @@
from ObjectCollection import *
import TclCommand
from tclCommands.TclCommand import *
class TclCommandAddPolyline(TclCommand.TclCommandSignaled):
class TclCommandAddPolyline(TclCommandSignaled):
"""
Tcl shell command to create a polyline in the given Geometry object
"""

View File

@@ -1,8 +1,7 @@
from ObjectCollection import *
import TclCommand
from tclCommands.TclCommand import *
class TclCommandAddRectangle(TclCommand.TclCommandSignaled):
class TclCommandAddRectangle(TclCommandSignaled):
"""
Tcl shell command to add a rectange to the given Geometry object.
"""

View File

@@ -1,8 +1,7 @@
from ObjectCollection import *
import TclCommand
from tclCommands.TclCommand import *
class TclCommandAlignDrill(TclCommand.TclCommandSignaled):
class TclCommandAlignDrill(TclCommandSignaled):
"""
Tcl shell command to create excellon with drills for aligment.
"""
@@ -180,7 +179,7 @@ class TclCommandAlignDrill(TclCommand.TclCommandSignaled):
name + "_aligndrill",
alligndrill_init_me)
except Exception, e:
except Exception as e:
return "Operation failed: %s" % str(e)
else:
@@ -195,7 +194,7 @@ class TclCommandAlignDrill(TclCommand.TclCommandSignaled):
px = dist
py = dist
obj.app.new_object("excellon", name + "_alligndrill", alligndrill_init_me)
except Exception, e:
except Exception as e:
return "Operation failed: %s" % str(e)
return 'Ok'

View File

@@ -1,8 +1,7 @@
from ObjectCollection import *
import TclCommand
from tclCommands.TclCommand import *
class TclCommandAlignDrillGrid(TclCommand.TclCommandSignaled):
class TclCommandAlignDrillGrid(TclCommandSignaled):
"""
Tcl shell command to create an Excellon object
with drills for aligment grid.

View File

@@ -1,8 +1,7 @@
from ObjectCollection import *
import TclCommand
from tclCommands.TclCommand import *
class TclCommandCncjob(TclCommand.TclCommandSignaled):
class TclCommandCncjob(TclCommandSignaled):
"""
Tcl shell command to Generates a CNC Job from a Geometry Object.

View File

@@ -1,8 +1,7 @@
from ObjectCollection import *
import TclCommand
from tclCommands.TclCommand import *
class TclCommandCutout(TclCommand.TclCommand):
class TclCommandCutout(TclCommand):
"""
Tcl shell command to create a board cutout geometry.
@@ -95,5 +94,5 @@ class TclCommandCutout(TclCommand.TclCommand):
try:
obj.app.new_object("geometry", name + "_cutout", geo_init_me)
except Exception, e:
except Exception as e:
return "Operation failed: %s" % str(e)

View File

@@ -1,8 +1,7 @@
from ObjectCollection import *
import TclCommand
from tclCommands.TclCommand import *
class TclCommandDelete(TclCommand.TclCommand):
class TclCommandDelete(TclCommand):
"""
Tcl shell command to delete an object.

View File

@@ -1,8 +1,7 @@
from ObjectCollection import *
import TclCommand
from tclCommands.TclCommand import *
class TclCommandDrillcncjob(TclCommand.TclCommandSignaled):
class TclCommandDrillcncjob(TclCommandSignaled):
"""
Tcl shell command to Generates a Drill CNC Job from a Excellon Object.
"""

View File

@@ -1,8 +1,7 @@
from ObjectCollection import *
import TclCommand
from tclCommands.TclCommand import *
class TclCommandExportGcode(TclCommand.TclCommandSignaled):
class TclCommandExportGcode(TclCommandSignaled):
"""
Tcl shell command to export gcode as tcl output for "set X [export_gcode ...]"

View File

@@ -1,8 +1,7 @@
from ObjectCollection import *
import TclCommand
from tclCommands.TclCommand import *
class TclCommandExportSVG(TclCommand.TclCommand):
class TclCommandExportSVG(TclCommand):
"""
Tcl shell command to export a Geometry Object as an SVG File.

View File

@@ -1,8 +1,7 @@
from ObjectCollection import *
import TclCommand
from tclCommands.TclCommand import *
class TclCommandExteriors(TclCommand.TclCommandSignaled):
class TclCommandExteriors(TclCommandSignaled):
"""
Tcl shell command to get exteriors of polygons
"""
@@ -54,7 +53,7 @@ class TclCommandExteriors(TclCommand.TclCommandSignaled):
if obj is None:
self.raise_tcl_error("Object not found: %s" % name)
if not isinstance(obj, Geometry):
if not isinstance(obj, FlatCAMGeometry):
self.raise_tcl_error('Expected Geometry, got %s %s.' % (name, type(obj)))
def geo_init(geo_obj, app_obj):

View File

@@ -1,8 +1,7 @@
from ObjectCollection import *
import TclCommand
from tclCommands.TclCommand import *
class TclCommandGeoCutout(TclCommand.TclCommandSignaled):
class TclCommandGeoCutout(TclCommandSignaled):
"""
Tcl shell command to cut holding gaps from geometry.
"""

View File

@@ -1,8 +1,7 @@
from ObjectCollection import *
import TclCommand
from tclCommands.TclCommand import *
class TclCommandGeoUnion(TclCommand.TclCommand):
class TclCommandGeoUnion(TclCommand):
"""
Tcl shell command to run a union (addition) operation on the
components of a geometry object.

View File

@@ -1,8 +1,7 @@
from ObjectCollection import *
import TclCommand
from tclCommands.TclCommand import *
class TclCommandGetNames(TclCommand.TclCommand):
class TclCommandGetNames(TclCommand):
"""
Tcl shell command to set an object as active in the GUI.

View File

@@ -1,8 +1,7 @@
from ObjectCollection import *
import TclCommand
from tclCommands.TclCommand import *
class TclCommandGetSys(TclCommand.TclCommand):
class TclCommandGetSys(TclCommand):
"""
Tcl shell command to get the value of a system variable

View File

@@ -1,8 +1,7 @@
from ObjectCollection import *
import TclCommand
from tclCommands.TclCommand import *
class TclCommandImportSvg(TclCommand.TclCommandSignaled):
class TclCommandImportSvg(TclCommandSignaled):
"""
Tcl shell command to import an SVG file as a Geometry Object.
"""

View File

@@ -1,8 +1,7 @@
from ObjectCollection import *
import TclCommand
from tclCommands.TclCommand import *
class TclCommandInteriors(TclCommand.TclCommandSignaled):
class TclCommandInteriors(TclCommandSignaled):
"""
Tcl shell command to get interiors of polygons
"""

View File

@@ -1,8 +1,7 @@
from ObjectCollection import *
import TclCommand
from tclCommands.TclCommand import *
class TclCommandIsolate(TclCommand.TclCommandSignaled):
class TclCommandIsolate(TclCommandSignaled):
"""
Tcl shell command to Creates isolation routing geometry for the given Gerber.

View File

@@ -1,8 +1,7 @@
from ObjectCollection import *
import TclCommand
from tclCommands.TclCommand import *
class TclCommandJoinExcellon(TclCommand.TclCommand):
class TclCommandJoinExcellon(TclCommand):
"""
Tcl shell command to merge Excellon objects.

View File

@@ -1,8 +1,7 @@
from ObjectCollection import *
import TclCommand
from tclCommands.TclCommand import *
class TclCommandJoinGeometry(TclCommand.TclCommand):
class TclCommandJoinGeometry(TclCommand):
"""
Tcl shell command to merge Excellon objects.

View File

@@ -1,8 +1,7 @@
from ObjectCollection import *
import TclCommand
from tclCommands.TclCommand import *
class TclCommandMillHoles(TclCommand.TclCommandSignaled):
class TclCommandMillHoles(TclCommandSignaled):
"""
Tcl shell command to Create Geometry Object for milling holes from Excellon.

View File

@@ -1,8 +1,7 @@
from ObjectCollection import *
import TclCommand
from tclCommands.TclCommand import *
class TclCommandMirror(TclCommand.TclCommandSignaled):
class TclCommandMirror(TclCommandSignaled):
"""
Tcl shell command to mirror an object.
"""
@@ -90,7 +89,7 @@ class TclCommandMirror(TclCommand.TclCommandSignaled):
obj.mirror(axis, [px, py])
obj.plot()
except Exception, e:
except Exception as e:
return "Operation failed: %s" % str(e)
else:
@@ -104,5 +103,5 @@ class TclCommandMirror(TclCommand.TclCommandSignaled):
try:
obj.mirror(axis, [dist, dist])
obj.plot()
except Exception, e:
except Exception as e:
return "Operation failed: %s" % str(e)

View File

@@ -1,8 +1,7 @@
from ObjectCollection import *
import TclCommand
from tclCommands.TclCommand import *
class TclCommandNew(TclCommand.TclCommand):
class TclCommandNew(TclCommand):
"""
Tcl shell command to starts a new project. Clears objects from memory
"""

View File

@@ -1,8 +1,7 @@
from ObjectCollection import *
import TclCommand
from tclCommands.TclCommand import *
class TclCommandNewGeometry(TclCommand.TclCommandSignaled):
class TclCommandNewGeometry(TclCommandSignaled):
"""
Tcl shell command to subtract polygon from the given Geometry object.
"""

View File

@@ -1,8 +1,7 @@
from ObjectCollection import *
import TclCommand
from tclCommands.TclCommand import *
class TclCommandOffset(TclCommand.TclCommand):
class TclCommandOffset(TclCommand):
"""
Tcl shell command to change the position of the object.

View File

@@ -1,8 +1,7 @@
from ObjectCollection import *
import TclCommand
from tclCommands.TclCommand import *
class TclCommandOpenExcellon(TclCommand.TclCommandSignaled):
class TclCommandOpenExcellon(TclCommandSignaled):
"""
Tcl shell command to open an Excellon file.
"""

View File

@@ -1,8 +1,7 @@
from ObjectCollection import *
import TclCommand
from tclCommands.TclCommand import *
class TclCommandOpenGCode(TclCommand.TclCommandSignaled):
class TclCommandOpenGCode(TclCommandSignaled):
"""
Tcl shell command to open a G-Code file.
"""

View File

@@ -1,8 +1,7 @@
from ObjectCollection import *
import TclCommand
from tclCommands.TclCommand import *
class TclCommandOpenGerber(TclCommand.TclCommandSignaled):
class TclCommandOpenGerber(TclCommandSignaled):
"""
Tcl shell command to opens a Gerber file
"""
@@ -48,7 +47,7 @@ class TclCommandOpenGerber(TclCommand.TclCommandSignaled):
# How the object should be initialized
def obj_init(gerber_obj, app_obj):
if not isinstance(gerber_obj, Geometry):
if not isinstance(gerber_obj, FlatCAMGerber):
self.raise_tcl_error('Expected FlatCAMGerber, got %s %s.' % (outname, type(gerber_obj)))
# Opening the file happens here
@@ -61,7 +60,7 @@ class TclCommandOpenGerber(TclCommand.TclCommandSignaled):
app_obj.progress.emit(0)
self.raise_tcl_error('Failed to open file: %s' % filename)
except ParseError, e:
except ParseError as e:
app_obj.inform.emit("[error] Failed to parse file: %s, %s " % (filename, str(e)))
app_obj.progress.emit(0)
self.log.error(str(e))

View File

@@ -1,8 +1,7 @@
from ObjectCollection import *
import TclCommand
from tclCommands.TclCommand import *
class TclCommandOpenProject(TclCommand.TclCommandSignaled):
class TclCommandOpenProject(TclCommandSignaled):
"""
Tcl shell command to open a FlatCAM project.
"""

View File

@@ -1,8 +1,7 @@
from ObjectCollection import *
import TclCommand
from tclCommands.TclCommand import *
class TclCommandOptions(TclCommand.TclCommandSignaled):
class TclCommandOptions(TclCommandSignaled):
"""
Tcl shell command to open an Excellon file.
"""

View File

@@ -1,8 +1,7 @@
from ObjectCollection import *
import TclCommand
from tclCommands.TclCommand import *
class TclCommandPaint(TclCommand.TclCommandSignaled):
class TclCommandPaint(TclCommandSignaled):
"""
Paint the interior of polygons
"""

View File

@@ -1,10 +1,8 @@
from ObjectCollection import *
from copy import copy,deepcopy
import TclCommand
from tclCommands.TclCommand import *
class TclCommandPanelize(TclCommand.TclCommand):
class TclCommandPanelize(TclCommand):
"""
Tcl shell command to pannelize an object.

View File

@@ -1,8 +1,7 @@
from ObjectCollection import *
import TclCommand
from tclCommands.TclCommand import *
class TclCommandPlot(TclCommand.TclCommand):
class TclCommandPlot(TclCommand):
"""
Tcl shell command to update the plot on the user interface.

View File

@@ -1,8 +1,7 @@
from ObjectCollection import *
import TclCommand
from tclCommands.TclCommand import *
class TclCommandSaveProject(TclCommand.TclCommandSignaled):
class TclCommandSaveProject(TclCommandSignaled):
"""
Tcl shell command to save the FlatCAM project to file.
"""

View File

@@ -1,8 +1,7 @@
from ObjectCollection import *
import TclCommand
from tclCommands.TclCommand import *
class TclCommandScale(TclCommand.TclCommand):
class TclCommandScale(TclCommand):
"""
Tcl shell command to resizes the object by a factor.

View File

@@ -1,8 +1,7 @@
from ObjectCollection import *
import TclCommand
from tclCommands.TclCommand import *
class TclCommandSetActive(TclCommand.TclCommand):
class TclCommandSetActive(TclCommand):
"""
Tcl shell command to set an object as active in the GUI.

View File

@@ -1,8 +1,7 @@
from ObjectCollection import *
import TclCommand
from tclCommands.TclCommand import *
class TclCommandSetSys(TclCommand.TclCommand):
class TclCommandSetSys(TclCommand):
"""
Tcl shell command to set the value of a system variable

View File

@@ -1,8 +1,7 @@
from ObjectCollection import *
import TclCommand
from tclCommands.TclCommand import *
class TclCommandSubtractPoly(TclCommand.TclCommandSignaled):
class TclCommandSubtractPoly(TclCommandSignaled):
"""
Tcl shell command to create a new empty Geometry object.
"""

View File

@@ -1,8 +1,7 @@
from ObjectCollection import *
import TclCommand
from tclCommands.TclCommand import *
class TclCommandSubtractRectangle(TclCommand.TclCommandSignaled):
class TclCommandSubtractRectangle(TclCommandSignaled):
"""
Tcl shell command to subtract a rectange from the given Geometry object.
"""

View File

@@ -1,8 +1,7 @@
from ObjectCollection import *
import TclCommand
from tclCommands.TclCommand import *
class TclCommandVersion(TclCommand.TclCommand):
class TclCommandVersion(TclCommand):
"""
Tcl shell command to check the program version.

View File

@@ -1,8 +1,7 @@
from ObjectCollection import *
import TclCommand
from tclCommands.TclCommand import *
class TclCommandWriteGCode(TclCommand.TclCommandSignaled):
class TclCommandWriteGCode(TclCommandSignaled):
"""
Tcl shell command to save the G-code of a CNC Job object to file.
"""

View File

@@ -73,9 +73,9 @@ def register_all_commands(app, commands):
:return: None
"""
tcl_modules = {k: v for k, v in sys.modules.items() if k.startswith('tclCommands.TclCommand')}
tcl_modules = {k: v for k, v in list(sys.modules.items()) if k.startswith('tclCommands.TclCommand')}
for key, mod in tcl_modules.items():
for key, mod in list(tcl_modules.items()):
if key != 'tclCommands.TclCommand':
class_name = key.split('.')[1]
class_type = getattr(mod, class_name)