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.

99 lines
3.1 KiB

6 years ago
  1. from gooey import Gooey
  2. from gooey import GooeyParser
  3. @Gooey(
  4. sidebar_title="Your Custom Title",
  5. show_sidebar=True,
  6. dump_build_config=True,
  7. show_success_modal=False,
  8. force_stop_is_error=False,
  9. language='chinese'
  10. )
  11. def main():
  12. desc = "Example application to show Gooey's various widgets"
  13. parser = GooeyParser(description=desc, add_help=False)
  14. parser.add_argument('--textfield', default=2, widget="TextField", gooey_options={
  15. 'validator': {
  16. 'test': 'int(user_input) > 5',
  17. 'message': 'number must be greater than 5'
  18. }
  19. })
  20. parser.add_argument('--textarea', default="oneline twoline", widget='Textarea')
  21. parser.add_argument('--password', default="hunter42", widget='PasswordField')
  22. parser.add_argument('--commandfield', default="cmdr", widget='CommandField')
  23. parser.add_argument('--dropdown',
  24. choices=["one", "two"], default="two", widget='Dropdown')
  25. parser.add_argument('--listboxie',
  26. nargs='+',
  27. default=['Option three', 'Option four'],
  28. choices=['Option one', 'Option two', 'Option three',
  29. 'Option four'],
  30. widget='Listbox',
  31. gooey_options={
  32. 'height': 300,
  33. 'validate': '',
  34. 'heading_color': '',
  35. 'text_color': '',
  36. 'hide_heading': True,
  37. 'hide_text': True,
  38. }
  39. )
  40. parser.add_argument('-c', '--counter', default=3, action='count', widget='Counter')
  41. #
  42. parser.add_argument("-o", "--overwrite", action="store_true",
  43. default=True,
  44. widget='CheckBox')
  45. ### Mutex Group ###
  46. verbosity = parser.add_mutually_exclusive_group(
  47. required=True,
  48. gooey_options={
  49. 'initial_selection': 1
  50. }
  51. )
  52. verbosity.add_argument(
  53. '--mutexone',
  54. default=True,
  55. action='store_true',
  56. help="Show more details")
  57. verbosity.add_argument(
  58. '--mutextwo',
  59. default='mut-2',
  60. widget='TextField')
  61. parser.add_argument("--filechooser", default="fc-value", widget='FileChooser')
  62. parser.add_argument("--filesaver", default="fs-value", widget='FileSaver')
  63. parser.add_argument("--dirchooser", default="dc-value", widget='DirChooser')
  64. parser.add_argument("--datechooser", default="2015-01-01", widget='DateChooser')
  65. dest_vars = [
  66. 'textfield',
  67. 'textarea',
  68. 'password',
  69. 'commandfield',
  70. 'dropdown',
  71. 'listboxie',
  72. 'counter',
  73. 'overwrite',
  74. 'mutextwo',
  75. 'filechooser',
  76. 'filesaver',
  77. 'dirchooser',
  78. 'datechooser'
  79. ]
  80. args = parser.parse_args()
  81. import time
  82. time.sleep(3)
  83. for i in dest_vars:
  84. assert getattr(args, i) is not None
  85. print("Success")
  86. if __name__ == '__main__':
  87. main()