TclCommandOpenGCode.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. # Dictionary of types from Tcl command, needs to be ordered.
  11. # For positional arguments
  12. arg_names = collections.OrderedDict([
  13. ('filename', str)
  14. ])
  15. # Dictionary of types from Tcl command, needs to be ordered.
  16. # For options like -optionname value
  17. option_types = collections.OrderedDict([
  18. ('outname', str)
  19. ])
  20. # array of mandatory options for current Tcl command: required = {'name','outname'}
  21. required = ['filename']
  22. # structured help for current command, args needs to be ordered
  23. help = {
  24. 'main': "Opens a G-Code file.",
  25. 'args': collections.OrderedDict([
  26. ('filename', 'Absolute path to file to open. Required.\n'
  27. 'WARNING: no spaces are allowed. If unsure enclose the entire path with quotes.'),
  28. ('outname', 'Name of the resulting CNCJob object.')
  29. ]),
  30. 'examples': ['open_gcode D:\\my_gcode_file.NC',
  31. 'open_gcode "D:\\my_gcode_file with spaces in the name.TXT"']
  32. }
  33. def execute(self, args, unnamed_args):
  34. """
  35. execute current TCL shell command
  36. :param args: array of known named arguments and options
  37. :param unnamed_args: array of other values which were passed into command
  38. without -somename and we do not have them in known arg_names
  39. :return: None or exception
  40. """
  41. args['plot'] = False
  42. filename = args["filename"]
  43. if ' ' in filename:
  44. return "The absolute path to the project file contain spaces which is not allowed.\n" \
  45. "Please enclose the path within quotes."
  46. self.app.open_gcode(filename, **args)