TclCommandSetActive.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. from tclCommands.TclCommand import TclCommand
  2. import collections
  3. class TclCommandSetActive(TclCommand):
  4. """
  5. Tcl shell command to set an object as active in the GUI.
  6. example:
  7. """
  8. # List of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon)
  9. aliases = ['set_active']
  10. description = '%s %s' % ("--", "Sets a FlatCAM object as active (selected).")
  11. # Dictionary of types from Tcl command, needs to be ordered
  12. arg_names = collections.OrderedDict([
  13. ('name', str),
  14. ])
  15. # Dictionary of types from Tcl command, needs to be ordered , this is 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 = ['name']
  20. # structured help for current command, args needs to be ordered
  21. help = {
  22. 'main': 'Sets a FlatCAM object as active (selected).',
  23. 'args': collections.OrderedDict([
  24. ('name', 'Name of the FlatCAM object to be set as active (selected). Required.'),
  25. ]),
  26. 'examples': ['set_active object_name']
  27. }
  28. def execute(self, args, unnamed_args):
  29. """
  30. :param args:
  31. :param unnamed_args:
  32. :return:
  33. """
  34. obj_name = args['name']
  35. try:
  36. self.app.collection.set_active(str(obj_name))
  37. except Exception as e:
  38. return "Command failed: %s" % str(e)