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.

147 lines
5.5 KiB

  1. """
  2. Example program to demonstrate Gooey's presentation of subparsers
  3. """
  4. from gooey import Gooey, GooeyParser
  5. @Gooey(
  6. optional_cols=2,
  7. program_name="Subparser Demo",
  8. dump_build_config=True,
  9. show_success_modal=False)
  10. def main():
  11. dest_vars = [
  12. 'textfield',
  13. 'textarea',
  14. 'password',
  15. 'commandfield',
  16. 'dropdown',
  17. 'listboxie',
  18. 'counter',
  19. 'overwrite',
  20. 'mutextwo',
  21. 'filechooser',
  22. 'filesaver',
  23. 'dirchooser',
  24. 'datechooser'
  25. ]
  26. parser = get_parser()
  27. args = parser.parse_args()
  28. import time
  29. time.sleep(.6)
  30. for i in dest_vars:
  31. assert getattr(args, i) is not None
  32. print("Success")
  33. def get_parser():
  34. parser = GooeyParser()
  35. subs = parser.add_subparsers(help='commands', dest='command')
  36. parser_one = subs.add_parser('parser1', prog="Parser 1")
  37. parser_one.add_argument('--textfield', default=2, widget="TextField")
  38. parser_one.add_argument('--textarea', default="oneline twoline",
  39. widget='Textarea')
  40. parser_one.add_argument('--password', default="hunter42",
  41. widget='PasswordField')
  42. parser_one.add_argument('--commandfield', default="cmdr",
  43. widget='CommandField')
  44. parser_one.add_argument('--dropdown',
  45. choices=["one", "two"], default="two",
  46. widget='Dropdown')
  47. parser_one.add_argument('--listboxie',
  48. nargs='+',
  49. default=['Option three', 'Option four'],
  50. choices=['Option one', 'Option two', 'Option three',
  51. 'Option four'],
  52. widget='Listbox',
  53. gooey_options={
  54. 'height': 300,
  55. 'validate': '',
  56. 'heading_color': '',
  57. 'text_color': '',
  58. 'hide_heading': True,
  59. 'hide_text': True,
  60. }
  61. )
  62. parser_one.add_argument('-c', '--counter', default=3, action='count',
  63. widget='Counter')
  64. #
  65. parser_one.add_argument("-o", "--overwrite", action="store_true",
  66. default=True,
  67. widget='CheckBox')
  68. ### Mutex Group ###
  69. verbosity = parser_one.add_mutually_exclusive_group(
  70. required=True,
  71. gooey_options={
  72. 'initial_selection': 1
  73. }
  74. )
  75. verbosity.add_argument(
  76. '--mutexone',
  77. default=True,
  78. action='store_true',
  79. help="Show more details")
  80. verbosity.add_argument(
  81. '--mutextwo',
  82. default='mut-2',
  83. widget='TextField')
  84. parser_one.add_argument("--filechooser", default="fc-value", widget='FileChooser')
  85. parser_one.add_argument("--filesaver", default="fs-value", widget='FileSaver')
  86. parser_one.add_argument("--dirchooser", default="dc-value", widget='DirChooser')
  87. parser_one.add_argument("--datechooser", default="2015-01-01", widget='DateChooser')
  88. parser_two = subs.add_parser('parser2', prog="parser 2")
  89. parser_two.add_argument('--textfield', default=2, widget="TextField")
  90. parser_two.add_argument('--textarea', default="oneline twoline", widget='Textarea')
  91. parser_two.add_argument('--password', default="hunter42", widget='PasswordField')
  92. parser_two.add_argument('--commandfield', default="cmdr", widget='CommandField')
  93. parser_two.add_argument('--dropdown', choices=["one", "two"], default="two", widget='Dropdown')
  94. parser_two.add_argument('--listboxie',
  95. nargs='+',
  96. default=['Option three', 'Option four'],
  97. choices=['Option one', 'Option two', 'Option three',
  98. 'Option four'],
  99. widget='Listbox',
  100. gooey_options={
  101. 'height': 300,
  102. 'validate': '',
  103. 'heading_color': '',
  104. 'text_color': '',
  105. 'hide_heading': True,
  106. 'hide_text': True,
  107. }
  108. )
  109. parser_two.add_argument('-c', '--counter', default=3, action='count', widget='Counter')
  110. parser_two.add_argument("-o", "--overwrite", action="store_true", default=True, widget='CheckBox')
  111. ### Mutex Group ###
  112. verbosity = parser_two.add_mutually_exclusive_group(
  113. required=True,
  114. gooey_options={
  115. 'initial_selection': 1
  116. }
  117. )
  118. verbosity.add_argument(
  119. '--mutexone',
  120. default=True,
  121. action='store_true',
  122. help="Show more details")
  123. verbosity.add_argument(
  124. '--mutextwo',
  125. default='mut-2',
  126. widget='TextField')
  127. parser_two.add_argument("--filechooser", default="fc-value", widget='FileChooser')
  128. parser_two.add_argument("--filesaver", default="fs-value", widget='FileSaver')
  129. parser_two.add_argument("--dirchooser", default="dc-value", widget='DirChooser')
  130. parser_two.add_argument("--datechooser", default="2015-01-01", widget='DateChooser')
  131. return parser
  132. if __name__ == '__main__':
  133. main()