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.

83 lines
2.2 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 listbox(meta, value):
  46. if meta['commands'] and value:
  47. return u'{} {}'.format(meta['commands'][0], ' '.join(map(quote, value)))
  48. else:
  49. return ' '.join(map(quote, value)) if value else ''
  50. def general(metadata, value):
  51. if metadata.get('commands') and value:
  52. if not metadata.get('nargs'):
  53. v = quote(value)
  54. else:
  55. v = value
  56. return u'{0} {1}'.format(metadata['commands'][0], v)
  57. else:
  58. if not value:
  59. return None
  60. elif not metadata.get('nargs'):
  61. return quote(value)
  62. else:
  63. return value