You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
1.9 KiB

  1. import os
  2. from gooey.gui.util.quoting import quote
  3. def checkbox(metadata, value):
  4. return metadata['commands'][0] if value else None
  5. def radioGroup(metadata, value):
  6. # TODO
  7. try:
  8. return self.commands[self._value.index(True)][0]
  9. except ValueError:
  10. return None
  11. def multiFileChooser(metadata, value):
  12. paths = ' '.join(quote(x) for x in value.split(os.pathsep) if x)
  13. if metadata['commands'] and paths:
  14. return u'{} {}'.format(metadata['commands'][0], paths)
  15. return paths or None
  16. def textArea(metadata, value):
  17. if metadata['commands'] and value:
  18. return '{} {}'.format(metadata['commands'][0], quote(value.encode('unicode_escape')))
  19. else:
  20. return quote(value.encode('unicode_escape')) if value else ''
  21. def commandField(metadata, value):
  22. if metadata['commands'] and value:
  23. return u'{} {}'.format(metadata['commands'][0], value)
  24. else:
  25. return value or None
  26. def counter(metatdata, value):
  27. '''
  28. Returns
  29. str(option_string * DropDown Value)
  30. e.g.
  31. -vvvvv
  32. '''
  33. if not str(value).isdigit():
  34. return None
  35. arg = str(metatdata['commands'][0]).replace('-', '')
  36. repeated_args = arg * int(value)
  37. return '-' + repeated_args
  38. def dropdown(metadata, value):
  39. if value == 'Select Option':
  40. return None
  41. elif metadata['commands'] and value:
  42. return u'{} {}'.format(metadata['commands'][0], quote(value))
  43. else:
  44. return quote(value) if value else ''
  45. def general(metadata, value):
  46. if metadata['commands'] and value:
  47. if not metadata['nargs']:
  48. v = quote(value)
  49. else:
  50. v = value
  51. return u'{0} {1}'.format(metadata['commands'][0], v)
  52. else:
  53. if not value:
  54. return None
  55. elif not metadata['nargs']:
  56. return quote(value)
  57. else:
  58. return value