TclCommandOpenProject.py 1.9 KB

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