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.

191 lines
7.1 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. * RadioGroups
  20. * Argument Group Options
  21. ## Global Widget Styles
  22. All widgets in Gooey (with the exception of RadioGroups) are made up of three basic components.
  23. 1. Label
  24. 2. Help Text
  25. 3. Input Control
  26. ![image](https://user-images.githubusercontent.com/1408720/56450719-cfca9c80-62dc-11e9-93ec-6ad56810e79a.png)
  27. The following options apply to all Widget types in Gooey.
  28. ```python
  29. parser.add_argument('-my-arg', gooey_options={
  30. 'label_color': '#ffffff',
  31. 'label_bg_color': '#ffffff',
  32. 'help_color': '#ffffff',
  33. 'help_bg_color': '#ffffff',
  34. 'error_color': '#ffffff',
  35. 'error_bg_color': '#ffffff',
  36. 'show_label': bool,
  37. 'show_help': bool,
  38. 'visible': bool,
  39. 'full_width': bool
  40. })
  41. ```
  42. | Keyword | Type | Description |
  43. |---------|------|-------------|
  44. | label_color | hex string | The foreground color of the label text (e.g. `#ff0000`) |
  45. | label_bg_color | hex string | The background color of the label text. |
  46. | help_color | hex string | The foreground color of the help text. |
  47. | help_bg_color | hex string | The background color of the help text. |
  48. | error_color | hex string | The foreground color of the error text (when visible). |
  49. | error_bg_color | hex string | The background color of the error text (when visible). |
  50. | show_label | bool | Toggles whether or not to display the label text |
  51. | show_help | bool | Toggles whether or not to display the help text |
  52. | 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. |
  53. | 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. |
  54. ## Individual Widget Options
  55. A few widgets have additional options for controlling their layout and behavior.
  56. ### Textarea
  57. ```python
  58. parser.add_argument('-my-arg', widget='Textarea', gooey_options={
  59. # height of the text area in pixels
  60. 'height': int,
  61. # prevents the user from editing when true
  62. 'readonly': bool
  63. })
  64. ```
  65. ### BlockCheckbox
  66. ```python
  67. parser.add_argument('-my-arg', widget='BlockCheckbox', gooey_options={
  68. # allows customizing the checkbox's label
  69. 'checkbox_label': str
  70. })
  71. ```
  72. ### Radio Group
  73. ```python
  74. parser.add_mutually_exclusive_group(gooey_options={
  75. # Pre-select a specific option within a mutually exclusive group.
  76. # default behavior is to have all options unselected by default.
  77. 'initial_selection': int
  78. })
  79. ```
  80. ## Argument Groups
  81. Argument Groups take a number of `gooey_options` to help control layout.
  82. ```python
  83. parser.add_argument_group('MyGroup', desription='my cool group', gooey_options={
  84. 'show_border': bool,
  85. 'show_underline': bool,
  86. 'label_color': '#FF9900',
  87. 'columns': int,
  88. 'margin_top': int
  89. })
  90. ```
  91. | Keyword | Type | Description |
  92. |---------|------|-------------|
  93. | show_border | bool | When `True` a labeled border will surround all widgets added to this group. |
  94. | show_underline | bool | Controls whether or not to display the underline when using the default border style |
  95. | label_color | hex string | The foreground color for the group name |
  96. | columns | int | Controls the number of widgets on each row |
  97. | margin_top | int | specifies the top margin in pixels for this group |
  98. ![image](https://user-images.githubusercontent.com/1408720/57576112-9c77bb00-740d-11e9-9dac-4e798699a35c.png)
  99. ## File and Folder choosers
  100. File and Folder Choosers Groups take a number of `gooey_options` to help control default values.
  101. ```python
  102. parser.add_argument("FileChooser", widget="FileChooser",
  103. gooey_options={
  104. 'wildcard':
  105. "Comma separated file (*.csv)|*.csv|"
  106. "All files (*.*)|*.*",
  107. 'default_dir': "c:/batch",
  108. 'default_file': "def_file.csv",
  109. 'message': "pick me"
  110. }
  111. )
  112. parser.add_argument("DirectoryChooser", widget="DirChooser",
  113. gooey_options={
  114. 'wildcard':
  115. "Comma separated file (*.csv)|*.csv|"
  116. "All files (*.*)|*.*",
  117. 'message': "pick folder",
  118. 'default_path': "c:/batch/stuff"
  119. }
  120. )
  121. parser.add_argument("FileSaver", widget="FileSaver",
  122. gooey_options={
  123. 'wildcard':
  124. "JPG (*.jpg)|*.jpg|"
  125. "All files (*.*)|*.*",
  126. 'message': "pick folder",
  127. 'default_dir': "c:/projects",
  128. 'default_file': "def_file.csv"
  129. }
  130. )
  131. parser.add_argument("MultiFileSaver", widget="MultiFileChooser",
  132. gooey_options={
  133. 'wildcard':
  134. "Comma separated file (*.csv)|*.csv|"
  135. "All files (*.*)|*.*",
  136. 'message': "pick folder",
  137. 'default_dir': "c:/temp",
  138. 'default_file': "def_file.csv"
  139. }
  140. )
  141. ```
  142. | Keyword | Type | Description |
  143. |---------|------|-------------|
  144. | wildcard | string | Sets the wildcard, which can contain multiple file types, for example: "BMP files (.bmp)|.bmp|GIF files (.gif)|.gif" |
  145. | message | string | Sets the message that will be displayed on the dialog. |
  146. | default_dir | string | The default directory |
  147. | default_file | string | The default filename |
  148. | default_path | string | The default path |