TclCommandSetSys.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. "l": "L",
  46. "L": "L",
  47. "T": "T",
  48. "t": "T",
  49. "0": "0",
  50. "1": "1",
  51. "2": "2",
  52. "3": "3",
  53. "4": "4",
  54. "5": "5",
  55. "in": "IN",
  56. "IN": "IN",
  57. "mm": "MM",
  58. "MM": "MM"
  59. }
  60. if param in self.app.defaults:
  61. try:
  62. value = tcl2py[value]
  63. except KeyError:
  64. pass
  65. self.app.defaults[param] = value
  66. self.app.propagate_defaults(silent=True)
  67. else:
  68. self.raise_tcl_error("No such system parameter \"{}\".".format(param))