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.

200 lines
7.2 KiB

  1. # Gooey Options
  2. Using `GooeyParser` we can extend the API of `argparse` to support lots of cool additional functionality.
  3. The main addition to the top-level `argparse` API is that we pick up extra keywords: `widget` and `gooey_options`. `widget` is used to specified which UI element to provide for the argument, i.e., a listbox or a file browser. `gooey_options` accepts a dictionary of configuration parameters that lets you specify things like custom validators, style overrides, and a bunch of behavioral extensions for the various widget classes.
  4. `GooeyParser` is a drop-in replacement for `argparse`. You can import it from the root Gooey namespace like this:
  5. ```python
  6. from gooey import GooeyParser
  7. ```
  8. and replace `ArgumentParser` with `GooeyParser`
  9. ```python
  10. # parser = ArgumentParser() # old busted
  11. parser = GooeyParser() # new hotness
  12. ```
  13. and with that, you're ready to rock.
  14. ## Overview
  15. * Global Style Options
  16. * Custom Widget Options
  17. * Textarea
  18. * BlockCheckbox
  19. * Listbox
  20. * RadioGroups
  21. * Argument Group Options
  22. ## Global Widget Styles
  23. All widgets in Gooey (with the exception of RadioGroups) are made up of three basic components.
  24. 1. Label
  25. 2. Help Text
  26. 3. Input Control
  27. ![image](https://user-images.githubusercontent.com/1408720/56450719-cfca9c80-62dc-11e9-93ec-6ad56810e79a.png)
  28. The following options apply to all Widget types in Gooey.
  29. ```python
  30. parser.add_argument('-my-arg', gooey_options={
  31. 'label_color': '#ffffff',
  32. 'label_bg_color': '#ffffff',
  33. 'help_color': '#ffffff',
  34. 'help_bg_color': '#ffffff',
  35. 'error_color': '#ffffff',
  36. 'error_bg_color': '#ffffff',
  37. 'show_label': bool,
  38. 'show_help': bool,
  39. 'visible': bool,
  40. 'full_width': bool
  41. })
  42. ```
  43. | Keyword | Type | Description |
  44. |---------|------|-------------|
  45. | label_color | hex string | The foreground color of the label text (e.g. `#ff0000`) |
  46. | label_bg_color | hex string | The background color of the label text. |
  47. | help_color | hex string | The foreground color of the help text. |
  48. | help_bg_color | hex string | The background color of the help text. |
  49. | error_color | hex string | The foreground color of the error text (when visible). |
  50. | error_bg_color | hex string | The background color of the error text (when visible). |
  51. | show_label | bool | Toggles whether or not to display the label text |
  52. | show_help | bool | Toggles whether or not to display the help text |
  53. | visible | bool | Hides the entire widget when `False`. Note: the widget is still present in the UI and will still send along any default values that have been provided in code. This option is here for when you want to hide certain advanced / dangerous inputs from your GUI users. |
  54. | full_width | bool | This is a layout hint for this widget. When `True` the widget will fill the entire available space within a given row. Otherwise, it will be sized based on the column rules provided elsewhere. |
  55. ## Individual Widget Options
  56. A few widgets have additional options for controlling their layout and behavior.
  57. ### Textarea
  58. ```python
  59. parser.add_argument('-my-arg', widget='Textarea', gooey_options={
  60. # height of the text area in pixels
  61. 'height': int,
  62. # prevents the user from editing when true
  63. 'readonly': bool
  64. })
  65. ```
  66. ### BlockCheckbox
  67. ```python
  68. parser.add_argument('-my-arg', widget='BlockCheckbox', gooey_options={
  69. # allows customizing the checkbox's label
  70. 'checkbox_label': str
  71. })
  72. ```
  73. ### Listbox
  74. ```python
  75. parser.add_argument('-my-arg', widget='Listbox', gooey_options={
  76. # height of the listbox in pixels
  77. 'height': int
  78. })
  79. ```
  80. ### Radio Group
  81. ```python
  82. parser.add_mutually_exclusive_group(gooey_options={
  83. # Pre-select a specific option within a mutually exclusive group.
  84. # default behavior is to have all options unselected by default.
  85. 'initial_selection': int
  86. })
  87. ```
  88. ## Argument Groups
  89. Argument Groups take a number of `gooey_options` to help control layout.
  90. ```python
  91. parser.add_argument_group('MyGroup', desription='my cool group', gooey_options={
  92. 'show_border': bool,
  93. 'show_underline': bool,
  94. 'label_color': '#FF9900',
  95. 'columns': int,
  96. 'margin_top': int
  97. })
  98. ```
  99. | Keyword | Type | Description |
  100. |---------|------|-------------|
  101. | show_border | bool | When `True` a labeled border will surround all widgets added to this group. |
  102. | show_underline | bool | Controls whether or not to display the underline when using the default border style |
  103. | label_color | hex string | The foreground color for the group name |
  104. | columns | int | Controls the number of widgets on each row |
  105. | margin_top | int | specifies the top margin in pixels for this group |
  106. ![image](https://user-images.githubusercontent.com/1408720/57576112-9c77bb00-740d-11e9-9dac-4e798699a35c.png)
  107. ## File and Folder choosers
  108. File and Folder Choosers Groups take a number of `gooey_options` to help control default values.
  109. ```python
  110. parser.add_argument("FileChooser", widget="FileChooser",
  111. gooey_options={
  112. 'wildcard':
  113. "Comma separated file (*.csv)|*.csv|"
  114. "All files (*.*)|*.*",
  115. 'default_dir': "c:/batch",
  116. 'default_file': "def_file.csv",
  117. 'message': "pick me"
  118. }
  119. )
  120. parser.add_argument("DirectoryChooser", widget="DirChooser",
  121. gooey_options={
  122. 'wildcard':
  123. "Comma separated file (*.csv)|*.csv|"
  124. "All files (*.*)|*.*",
  125. 'message': "pick folder",
  126. 'default_path': "c:/batch/stuff"
  127. }
  128. )
  129. parser.add_argument("FileSaver", widget="FileSaver",
  130. gooey_options={
  131. 'wildcard':
  132. "JPG (*.jpg)|*.jpg|"
  133. "All files (*.*)|*.*",
  134. 'message': "pick folder",
  135. 'default_dir': "c:/projects",
  136. 'default_file': "def_file.csv"
  137. }
  138. )
  139. parser.add_argument("MultiFileSaver", widget="MultiFileChooser",
  140. gooey_options={
  141. 'wildcard':
  142. "Comma separated file (*.csv)|*.csv|"
  143. "All files (*.*)|*.*",
  144. 'message': "pick folder",
  145. 'default_dir': "c:/temp",
  146. 'default_file': "def_file.csv"
  147. }
  148. )
  149. ```
  150. | Keyword | Type | Description |
  151. |---------|------|-------------|
  152. | wildcard | string | Sets the wildcard, which can contain multiple file types, for example: "BMP files (.bmp)|.bmp|GIF files (.gif)|.gif" |
  153. | message | string | Sets the message that will be displayed on the dialog. |
  154. | default_dir | string | The default directory |
  155. | default_file | string | The default filename |
  156. | default_path | string | The default path |