TclCommandSetSys.py 1.8 KB

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