TclCommandSetSys.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. "mm": "MM",
  46. "in": "IN"
  47. }
  48. if param in self.app.defaults:
  49. try:
  50. value = tcl2py[value]
  51. except KeyError:
  52. pass
  53. self.app.defaults[param] = value
  54. self.app.propagate_defaults()
  55. else:
  56. self.raise_tcl_error("No such system parameter \"{}\".".format(param))