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.

152 lines
5.5 KiB

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