TclCommandSetSys.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. from ObjectCollection import *
  2. from tclCommands.TclCommand import TclCommand
  3. class TclCommandSetSys(TclCommand):
  4. """
  5. Tcl shell command to set the value of a system variable
  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_sys', 'setsys']
  10. # Dictionary of types from Tcl command, needs to be ordered
  11. arg_names = collections.OrderedDict([
  12. ('name', str),
  13. ('value', 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', 'value']
  20. # structured help for current command, args needs to be ordered
  21. help = {
  22. 'main': "Sets the value of the system variable.",
  23. 'args': collections.OrderedDict([
  24. ('name', 'Name of the system variable.'),
  25. ('value', 'Value to set.')
  26. ]),
  27. 'examples': []
  28. }
  29. def execute(self, args, unnamed_args):
  30. """
  31. :param args:
  32. :param unnamed_args:
  33. :return:
  34. """
  35. param = args['name']
  36. value = args['value']
  37. # TCL string to python keywords:
  38. tcl2py = {
  39. "None": None,
  40. "none": None,
  41. "false": False,
  42. "False": False,
  43. "true": True,
  44. "True": True
  45. }
  46. if param in self.app.defaults:
  47. try:
  48. value = tcl2py[value]
  49. except KeyError:
  50. pass
  51. self.app.defaults[param] = value
  52. self.app.propagate_defaults()
  53. else:
  54. self.raise_tcl_error("No such system parameter \"{}\".".format(param))