Consistent black formatting of all Path python files
This commit is contained in:
@@ -26,23 +26,24 @@
|
||||
|
||||
import datetime
|
||||
from PathScripts import PostUtils
|
||||
|
||||
now = datetime.datetime.now()
|
||||
|
||||
'''
|
||||
"""
|
||||
Generate g-code compatible with fablin from a Path.
|
||||
|
||||
import fablin_post
|
||||
fablin_post.export(object,"/path/to/file.ncc")
|
||||
'''
|
||||
"""
|
||||
|
||||
TOOLTIP_ARGS = '''
|
||||
TOOLTIP_ARGS = """
|
||||
Arguments for fablin:
|
||||
--rapids-feedrate ... feedrate to be used for rapids (e.g. --rapids-feedrate=300)
|
||||
--header,--no-header ... output headers (--header)
|
||||
--comments,--no-comments ... output comments (--comments)
|
||||
--line-numbers,--no-line-numbers ... prefix with line numbers (--no-lin-numbers)
|
||||
--show-editor, --no-show-editor ... pop up editor before writing output(--show-editor)
|
||||
'''
|
||||
"""
|
||||
|
||||
# These globals set common customization preferences
|
||||
OUTPUT_COMMENTS = False # Fablin does not support parenthesis, it will echo the command complaining. As a side effect the spinner may turn at a very reduced speed (do not ask me why).
|
||||
@@ -58,38 +59,38 @@ LINENR = 100 # line number starting value
|
||||
# These globals will be reflected in the Machine configuration of the project
|
||||
UNITS = "" # only metric, G20/G21 is ignored
|
||||
MACHINE_NAME = "FABLIN"
|
||||
CORNER_MIN = {'x': 0, 'y': 0, 'z': 0}
|
||||
CORNER_MAX = {'x': 500, 'y': 300, 'z': 300}
|
||||
CORNER_MIN = {"x": 0, "y": 0, "z": 0}
|
||||
CORNER_MAX = {"x": 500, "y": 300, "z": 300}
|
||||
|
||||
RAPID_MOVES = ['G0', 'G00']
|
||||
RAPID_MOVES = ["G0", "G00"]
|
||||
|
||||
RAPID_FEEDRATE = 10000
|
||||
|
||||
# Preamble text will appear at the beginning of the GCODE output file.
|
||||
PREAMBLE = '''G90
|
||||
'''
|
||||
PREAMBLE = """G90
|
||||
"""
|
||||
|
||||
# Postamble text will appear following the last operation.
|
||||
POSTAMBLE = '''M5
|
||||
POSTAMBLE = """M5
|
||||
G00 X-1.0 Y1.0
|
||||
G90
|
||||
'''
|
||||
"""
|
||||
|
||||
# These commands are ignored by commenting them out
|
||||
SUPPRESS_COMMANDS = ['G98', 'G80', 'M6', 'G17']
|
||||
SUPPRESS_COMMANDS = ["G98", "G80", "M6", "G17"]
|
||||
|
||||
# Pre operation text will be inserted before every operation
|
||||
PRE_OPERATION = ''''''
|
||||
PRE_OPERATION = """"""
|
||||
|
||||
# Post operation text will be inserted after every operation
|
||||
POST_OPERATION = ''''''
|
||||
POST_OPERATION = """"""
|
||||
|
||||
# Tool Change commands will be inserted before a tool change
|
||||
TOOL_CHANGE = ''''''
|
||||
TOOL_CHANGE = """"""
|
||||
|
||||
|
||||
# to distinguish python built-in open function from the one declared below
|
||||
if open.__module__ in ['__builtin__', 'io']:
|
||||
if open.__module__ in ["__builtin__", "io"]:
|
||||
pythonopen = open
|
||||
|
||||
|
||||
@@ -100,26 +101,26 @@ def processArguments(argstring):
|
||||
global SHOW_EDITOR
|
||||
global RAPID_FEEDRATE
|
||||
for arg in argstring.split():
|
||||
if arg == '--header':
|
||||
if arg == "--header":
|
||||
OUTPUT_HEADER = True
|
||||
elif arg == '--no-header':
|
||||
elif arg == "--no-header":
|
||||
OUTPUT_HEADER = False
|
||||
elif arg == '--comments':
|
||||
elif arg == "--comments":
|
||||
OUTPUT_COMMENTS = True
|
||||
elif arg == '--no-comments':
|
||||
elif arg == "--no-comments":
|
||||
OUTPUT_COMMENTS = False
|
||||
elif arg == '--line-numbers':
|
||||
elif arg == "--line-numbers":
|
||||
OUTPUT_LINE_NUMBERS = True
|
||||
elif arg == '--no-line-numbers':
|
||||
elif arg == "--no-line-numbers":
|
||||
OUTPUT_LINE_NUMBERS = False
|
||||
elif arg == '--show-editor':
|
||||
elif arg == "--show-editor":
|
||||
SHOW_EDITOR = True
|
||||
elif arg == '--no-show-editor':
|
||||
elif arg == "--no-show-editor":
|
||||
SHOW_EDITOR = False
|
||||
|
||||
params = arg.split('=')
|
||||
params = arg.split("=")
|
||||
|
||||
if params[0] == '--rapids-feedrate':
|
||||
if params[0] == "--rapids-feedrate":
|
||||
RAPID_FEEDRATE = params[1]
|
||||
|
||||
|
||||
@@ -128,7 +129,11 @@ def export(objectslist, filename, argstring):
|
||||
global UNITS
|
||||
for obj in objectslist:
|
||||
if not hasattr(obj, "Path"):
|
||||
print("the object " + obj.Name + " is not a path. Please select only path and Compounds.")
|
||||
print(
|
||||
"the object "
|
||||
+ obj.Name
|
||||
+ " is not a path. Please select only path and Compounds."
|
||||
)
|
||||
return
|
||||
|
||||
print("postprocessing...")
|
||||
@@ -216,7 +221,21 @@ def parse(pathobj):
|
||||
out = ""
|
||||
lastcommand = None
|
||||
|
||||
params = ['X', 'Y', 'Z', 'A', 'B', 'I', 'J', 'F', 'S', 'T', 'Q', 'R', 'L'] # linuxcnc doesn't want K properties on XY plane Arcs need work.
|
||||
params = [
|
||||
"X",
|
||||
"Y",
|
||||
"Z",
|
||||
"A",
|
||||
"B",
|
||||
"I",
|
||||
"J",
|
||||
"F",
|
||||
"S",
|
||||
"T",
|
||||
"Q",
|
||||
"R",
|
||||
"L",
|
||||
] # linuxcnc doesn't want K properties on XY plane Arcs need work.
|
||||
|
||||
if hasattr(pathobj, "Group"): # We have a compound or project.
|
||||
if OUTPUT_COMMENTS:
|
||||
@@ -226,7 +245,9 @@ def parse(pathobj):
|
||||
return out
|
||||
else: # parsing simple path
|
||||
|
||||
if not hasattr(pathobj, "Path"): # groups might contain non-path things like stock.
|
||||
if not hasattr(
|
||||
pathobj, "Path"
|
||||
): # groups might contain non-path things like stock.
|
||||
return out
|
||||
|
||||
if OUTPUT_COMMENTS:
|
||||
@@ -237,7 +258,7 @@ def parse(pathobj):
|
||||
command = c.Name
|
||||
|
||||
# fablin does not support parenthesis syntax, so removing that (pocket) in the agnostic gcode
|
||||
if command[0] == '(':
|
||||
if command[0] == "(":
|
||||
if not OUTPUT_COMMENTS:
|
||||
pass
|
||||
else:
|
||||
@@ -251,22 +272,22 @@ def parse(pathobj):
|
||||
# Now add the remaining parameters in order
|
||||
for param in params:
|
||||
if param in c.Parameters:
|
||||
if param == 'F':
|
||||
if param == "F":
|
||||
if command not in RAPID_MOVES:
|
||||
outstring.append(param + format(c.Parameters['F'], '.2f'))
|
||||
elif param == 'T':
|
||||
outstring.append(param + str(c.Parameters['T']))
|
||||
outstring.append(param + format(c.Parameters["F"], ".2f"))
|
||||
elif param == "T":
|
||||
outstring.append(param + str(c.Parameters["T"]))
|
||||
else:
|
||||
outstring.append(param + format(c.Parameters[param], '.4f'))
|
||||
outstring.append(param + format(c.Parameters[param], ".4f"))
|
||||
|
||||
if command in RAPID_MOVES and command != lastcommand:
|
||||
outstring.append('F' + format(RAPID_FEEDRATE))
|
||||
outstring.append("F" + format(RAPID_FEEDRATE))
|
||||
|
||||
# store the latest command
|
||||
lastcommand = command
|
||||
|
||||
# Check for Tool Change:
|
||||
if command == 'M6':
|
||||
if command == "M6":
|
||||
if OUTPUT_COMMENTS:
|
||||
out += linenumber() + "(begin toolchange)\n"
|
||||
if not OUTPUT_TOOL_CHANGE:
|
||||
|
||||
Reference in New Issue
Block a user