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.

154 lines
5.7 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_one.add_argument("--colourchooser", default="#000000", widget='ColourChooser')
  63. parser_two = subs.add_parser('parser2', prog="parser 2")
  64. parser_two.add_argument('--textfield', default=2, widget="TextField")
  65. parser_two.add_argument('--textarea', default="oneline twoline",
  66. widget='Textarea')
  67. parser_two.add_argument('--password', default="hunter42", widget='PasswordField')
  68. parser_two.add_argument('--commandfield', default="cmdr", widget='CommandField')
  69. parser_two.add_argument('--dropdown',
  70. choices=["one", "two"], default="two", widget='Dropdown')
  71. parser_two.add_argument('--listboxie',
  72. nargs='+',
  73. default=['Option three', 'Option four'],
  74. choices=['Option one', 'Option two', 'Option three',
  75. 'Option four'],
  76. widget='Listbox',
  77. gooey_options={
  78. 'height': 300,
  79. 'validate': '',
  80. 'heading_color': '',
  81. 'text_color': '',
  82. 'hide_heading': True,
  83. 'hide_text': True,
  84. }
  85. )
  86. parser_two.add_argument('-c', '--counter', default=3, action='count',
  87. widget='Counter')
  88. #
  89. parser_two.add_argument("-o", "--overwrite", action="store_true",
  90. default=True,
  91. widget='CheckBox')
  92. ### Mutex Group ###
  93. verbosity = parser_two.add_mutually_exclusive_group(
  94. required=True,
  95. gooey_options={
  96. 'initial_selection': 1
  97. }
  98. )
  99. verbosity.add_argument(
  100. '--mutexone',
  101. default=True,
  102. action='store_true',
  103. help="Show more details")
  104. verbosity.add_argument(
  105. '--mutextwo',
  106. default='mut-2',
  107. widget='TextField')
  108. parser_two.add_argument("--filechooser", default="fc-value", widget='FileChooser')
  109. parser_two.add_argument("--filesaver", default="fs-value", widget='FileSaver')
  110. parser_two.add_argument("--dirchooser", default="dc-value", widget='DirChooser')
  111. parser_two.add_argument("--datechooser", default="2015-01-01",widget='DateChooser')
  112. parser_two.add_argument("--colourchooser", default="#000000", widget='ColourChooser')
  113. dest_vars = [
  114. 'textfield',
  115. 'textarea',
  116. 'password',
  117. 'commandfield',
  118. 'dropdown',
  119. 'listboxie',
  120. 'counter',
  121. 'overwrite',
  122. 'mutextwo',
  123. 'filechooser',
  124. 'filesaver',
  125. 'dirchooser',
  126. 'datechooser',
  127. 'colourchooser'
  128. ]
  129. parser.parse_args()
  130. args = parser.parse_args()
  131. import time
  132. time.sleep(.6)
  133. for i in dest_vars:
  134. assert getattr(args, i) is not None
  135. print("Success")
  136. if __name__ == '__main__':
  137. main()