TclCommandSetSys.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. from tclCommands.TclCommand import TclCommand
  2. import collections
  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. description = '%s %s' % ("--", "Sets the value of the specified system variable.")
  11. # Dictionary of types from Tcl command, needs to be ordered
  12. arg_names = collections.OrderedDict([
  13. ('name', str),
  14. ('value', str)
  15. ])
  16. # Dictionary of types from Tcl command, needs to be ordered , this is for options like -optionname value
  17. option_types = collections.OrderedDict([
  18. ])
  19. # array of mandatory options for current Tcl command: required = {'name','outname'}
  20. required = ['name', 'value']
  21. # structured help for current command, args needs to be ordered
  22. help = {
  23. 'main': "Sets the value of the specified system variable.",
  24. 'args': collections.OrderedDict([
  25. ('name', 'Name of the system variable. Required.'),
  26. ('value', 'Value to set.')
  27. ]),
  28. 'examples': ['set_sys global_gridx 1.0']
  29. }
  30. def execute(self, args, unnamed_args):
  31. """
  32. :param args:
  33. :param unnamed_args:
  34. :return:
  35. """
  36. param = args['name']
  37. value = args['value']
  38. # TCL string to python keywords:
  39. tcl2py = {
  40. "None": None,
  41. "none": None,
  42. "false": False,
  43. "False": False,
  44. "true": True,
  45. "True": True,
  46. "l": "L",
  47. "L": "L",
  48. "T": "T",
  49. "t": "T",
  50. "0": "0",
  51. "1": "1",
  52. "2": "2",
  53. "3": "3",
  54. "4": "4",
  55. "5": "5",
  56. "in": "IN",
  57. "IN": "IN",
  58. "mm": "MM",
  59. "MM": "MM"
  60. }
  61. if param in self.app.defaults:
  62. try:
  63. value = tcl2py[value]
  64. except KeyError:
  65. pass
  66. self.app.defaults[param] = value
  67. self.app.defaults.propagate_defaults()
  68. else:
  69. self.raise_tcl_error("No such system parameter \"{}\".".format(param))