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.

101 lines
3.2 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. parser.add_argument("--colourchooser", default="#000000", widget='ColourChooser')
  66. dest_vars = [
  67. 'textfield',
  68. 'textarea',
  69. 'password',
  70. 'commandfield',
  71. 'dropdown',
  72. 'listboxie',
  73. 'counter',
  74. 'overwrite',
  75. 'mutextwo',
  76. 'filechooser',
  77. 'filesaver',
  78. 'dirchooser',
  79. 'datechooser',
  80. 'colourchooser'
  81. ]
  82. args = parser.parse_args()
  83. import time
  84. time.sleep(3)
  85. for i in dest_vars:
  86. assert getattr(args, i) is not None
  87. print("Success")
  88. if __name__ == '__main__':
  89. main()