TclCommandOpenGCode.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. from tclCommands.TclCommand import TclCommandSignaled
  2. import collections
  3. class TclCommandOpenGCode(TclCommandSignaled):
  4. """
  5. Tcl shell command to open a G-Code file.
  6. """
  7. # array of all command aliases, to be able use old names for
  8. # backward compatibility (add_poly, add_polygon)
  9. aliases = ['open_gcode']
  10. description = '%s %s' % ("--", "Opens an GCode file, parse it and create a GCode object from it.")
  11. # Dictionary of types from Tcl command, needs to be ordered.
  12. # For positional arguments
  13. arg_names = collections.OrderedDict([
  14. ('filename', str)
  15. ])
  16. # Dictionary of types from Tcl command, needs to be ordered.
  17. # For options like -optionname value
  18. option_types = collections.OrderedDict([
  19. ('outname', str)
  20. ])
  21. # array of mandatory options for current Tcl command: required = {'name','outname'}
  22. required = ['filename']
  23. # structured help for current command, args needs to be ordered
  24. help = {
  25. 'main': "Opens an GCode file, parse it and create a GCode object from it.",
  26. 'args': collections.OrderedDict([
  27. ('filename', 'Absolute path to file to open. Required.\n'
  28. 'WARNING: no spaces are allowed. If unsure enclose the entire path with quotes.'),
  29. ('outname', 'Name of the resulting CNCJob object.')
  30. ]),
  31. 'examples': ['open_gcode D:\\my_gcode_file.NC',
  32. 'open_gcode "D:\\my_gcode_file with spaces in the name.TXT"']
  33. }
  34. def execute(self, args, unnamed_args):
  35. """
  36. execute current TCL shell command
  37. :param args: array of known named arguments and options
  38. :param unnamed_args: array of other values which were passed into command
  39. without -somename and we do not have them in known arg_names
  40. :return: None or exception
  41. """
  42. args['plot'] = False
  43. filename = args["filename"]
  44. if ' ' in filename:
  45. return "The absolute path to the project file contain spaces which is not allowed.\n" \
  46. "Please enclose the path within quotes."
  47. self.app.open_gcode(filename, **args)