TclCommandDelete.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. from ObjectCollection import *
  2. from tclCommands.TclCommand import TclCommand
  3. class TclCommandDelete(TclCommand):
  4. """
  5. Tcl shell command to delete an object.
  6. example:
  7. """
  8. # List of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon)
  9. aliases = ['delete']
  10. # Dictionary of types from Tcl command, needs to be ordered
  11. arg_names = collections.OrderedDict([
  12. ('name', str),
  13. ])
  14. # Dictionary of types from Tcl command, needs to be ordered , this is for options like -optionname value
  15. option_types = collections.OrderedDict([
  16. ])
  17. # array of mandatory options for current Tcl command: required = {'name','outname'}
  18. required = ['name']
  19. # structured help for current command, args needs to be ordered
  20. help = {
  21. 'main': 'Deletes the given object.',
  22. 'args': collections.OrderedDict([
  23. ('name', 'Name of the Object.'),
  24. ]),
  25. 'examples': []
  26. }
  27. def execute(self, args, unnamed_args):
  28. """
  29. :param args:
  30. :param unnamed_args:
  31. :return:
  32. """
  33. obj_name = args['name']
  34. try:
  35. # deselect all to avoid delete selected object when run delete from shell
  36. self.app.collection.set_all_inactive()
  37. self.app.collection.set_active(str(obj_name))
  38. self.app.on_delete() # Todo: This is an event handler for the GUI... bad?
  39. except Exception as e:
  40. return "Command failed: %s" % str(e)