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.

84 lines
2.2 KiB

  1. import os
  2. import itertools
  3. from gooey.gui.util.quoting import quote
  4. def checkbox(metadata, value):
  5. return metadata['commands'][0] if value else None
  6. def radioGroup(metadata, value):
  7. # TODO
  8. try:
  9. return self.commands[self._value.index(True)][0]
  10. except ValueError:
  11. return None
  12. def multiFileChooser(metadata, value):
  13. paths = ' '.join(quote(x) for x in value.split(os.pathsep) if x)
  14. if metadata['commands'] and paths:
  15. return u'{} {}'.format(metadata['commands'][0], paths)
  16. return paths or None
  17. def textArea(metadata, value):
  18. if metadata['commands'] and value:
  19. return '{} {}'.format(metadata['commands'][0], quote(value.encode('unicode_escape')))
  20. else:
  21. return quote(value.encode('unicode_escape')) if value else ''
  22. def commandField(metadata, value):
  23. if metadata['commands'] and value:
  24. return u'{} {}'.format(metadata['commands'][0], value)
  25. else:
  26. return value or None
  27. def counter(metatdata, value):
  28. '''
  29. Returns
  30. str(option_string * DropDown Value)
  31. e.g.
  32. -vvvvv
  33. '''
  34. if not str(value).isdigit():
  35. return None
  36. command = str(metatdata['commands'][0]).strip()
  37. return ' '.join(itertools.repeat(command, int(value)))
  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