TclCommandOpenProject.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. description = '%s %s' % ("--", "Opens an FlatCAm project file, parse it and recreate all the objects.")
  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. ])
  19. # array of mandatory options for current Tcl command: required = {'name','outname'}
  20. required = ['filename']
  21. # structured help for current command, args needs to be ordered
  22. help = {
  23. 'main': "Opens an FlatCAm project file, parse it and recreate all the objects.",
  24. 'args': collections.OrderedDict([
  25. ('filename', 'Absolute path to file to open. Required.\n'
  26. 'WARNING: no spaces are allowed. If unsure enclose the entire path with quotes.'),
  27. ]),
  28. 'examples': ['open_project D:\\my_project_file.FlatPrj',
  29. 'open_project "D:\\my_project_file with spaces in the name.FlatPrj"']
  30. }
  31. def execute(self, args, unnamed_args):
  32. """
  33. execute current TCL shell command
  34. :param args: array of known named arguments and options
  35. :param unnamed_args: array of other values which were passed into command
  36. without -somename and we do not have them in known arg_names
  37. :return: None or exception
  38. """
  39. filename = args['filename']
  40. # if ' ' in filename:
  41. # return "The absolute path to the project file contain spaces which is not allowed.\n" \
  42. # "Please enclose the path within quotes."
  43. self.app.f_handlers.open_project(filename, cli=True, plot=False, from_tcl=True)