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.

749 lines
36 KiB

5 years ago
10 years ago
7 years ago
11 years ago
10 years ago
9 years ago
4 years ago
10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
9 years ago
6 years ago
6 years ago
9 years ago
10 years ago
6 years ago
6 years ago
6 years ago
9 years ago
9 years ago
9 years ago
10 years ago
10 years ago
7 years ago
10 years ago
7 years ago
10 years ago
9 years ago
10 years ago
9 years ago
10 years ago
10 years ago
9 years ago
9 years ago
9 years ago
9 years ago
10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
9 years ago
10 years ago
9 years ago
10 years ago
9 years ago
10 years ago
10 years ago
10 years ago
9 years ago
9 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
7 years ago
10 years ago
10 years ago
9 years ago
9 years ago
9 years ago
10 years ago
10 years ago
6 years ago
9 years ago
6 years ago
9 years ago
6 years ago
9 years ago
9 years ago
6 years ago
9 years ago
6 years ago
9 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
10 years ago
9 years ago
9 years ago
10 years ago
10 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
10 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
10 years ago
9 years ago
9 years ago
6 years ago
6 years ago
9 years ago
10 years ago
6 years ago
10 years ago
10 years ago
  1. Gooey
  2. =====
  3. Turn (almost) any Python 2 or 3 Console Program into a GUI application with one line
  4. <p align="center">
  5. <img src="https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/1-0-4-title-card.png" />
  6. </p>
  7. ### Support this project
  8. <a href="https://patreon.com/chriskiehl" target="_blank">
  9. <img src="https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/support-request.jpg" />
  10. </a>
  11. Table of Contents
  12. -----------------
  13. - [Gooey](#gooey)
  14. - [Table of contents](#table-of-contents)
  15. - [Latest Update](#latest-update)
  16. - [Quick Start](#quick-start)
  17. - [Installation Instructions](#installation-instructions)
  18. - [Usage](#usage)
  19. - [Examples](#examples)
  20. - [What It Is](#what-is-it)
  21. - [Why Is It](#why)
  22. - [Who is this for](#who-is-this-for)
  23. - [How does it work](#how-does-it-work)
  24. - [Internationalization](#internationalization)
  25. - [Global Configuration](#global-configuration)
  26. - [Layout Customization](#layout-customization)
  27. - [Run Modes](#run-modes)
  28. - [Full/Advanced](#advanced)
  29. - [Basic](#basic)
  30. - [No Config](#no-config)
  31. - [Menus](#menus)
  32. - [Input Validation](#input-validation)
  33. - [Using Dynamic Values](#using-dynamic-values)
  34. - [Showing Progress](#showing-progress)
  35. - [Customizing Icons](#customizing-icons)
  36. - [Packaging](#packaging)
  37. - [Screenshots](#screenshots)
  38. - [Contributing](#wanna-help)
  39. - [Image Credits](#image-credits)
  40. ----------------
  41. ## Quick Start
  42. ### Installation instructions
  43. The easiest way to install Gooey is via `pip`
  44. pip install Gooey
  45. Alternatively, you can install Gooey by cloning the project to your local directory
  46. git clone https://github.com/chriskiehl/Gooey.git
  47. run `setup.py`
  48. python setup.py install
  49. **NOTE:** Python 2 users must manually install WxPython! Unfortunately, this cannot be done as part of the pip installation and should be manually downloaded from the [wxPython website](http://www.wxpython.org/download.php).
  50. ### Usage
  51. Gooey is attached to your code via a simple decorator on whichever method has your `argparse` declarations (usually `main`).
  52. from gooey import Gooey
  53. @Gooey <--- all it takes! :)
  54. def main():
  55. parser = ArgumentParser(...)
  56. # rest of code
  57. Different styling and functionality can be configured by passing arguments into the decorator.
  58. # options
  59. @Gooey(advanced=Boolean, # toggle whether to show advanced config or not
  60. language=language_string, # Translations configurable via json
  61. show_config=True, # skip config screens all together
  62. target=executable_cmd, # Explicitly set the subprocess executable arguments
  63. program_name='name', # Defaults to script name
  64. program_description, # Defaults to ArgParse Description
  65. default_size=(610, 530), # starting size of the GUI
  66. required_cols=1, # number of columns in the "Required" section
  67. optional_cols=2, # number of columbs in the "Optional" section
  68. dump_build_config=False, # Dump the JSON Gooey uses to configure itself
  69. load_build_config=None, # Loads a JSON Gooey-generated configuration
  70. monospace_display=False) # Uses a mono-spaced font in the output screen
  71. )
  72. def main():
  73. parser = ArgumentParser(...)
  74. # rest of code
  75. See: [How does it Work](#how-does-it-work) section for details on each option.
  76. Gooey will do its best to choose sensible widget defaults to display in the GUI. However, if more fine tuning is desired, you can use the drop-in replacement `GooeyParser` in place of `ArgumentParser`. This lets you control which widget displays in the GUI. See: [GooeyParser](#gooeyparser)
  77. from gooey import Gooey, GooeyParser
  78. @Gooey
  79. def main():
  80. parser = GooeyParser(description="My Cool GUI Program!")
  81. parser.add_argument('Filename', widget="FileChooser")
  82. parser.add_argument('Date', widget="DateChooser")
  83. ...
  84. ### Examples
  85. Gooey downloaded and installed? Great! Wanna see it in action? Head over the the [Examples Repository](https://github.com/chriskiehl/GooeyExamples) to download a few ready-to-go example scripts. They'll give you a quick tour of all Gooey's various layouts, widgets, and features.
  86. [Direct Download](https://github.com/chriskiehl/GooeyExamples/archive/master.zip)
  87. What is it?
  88. -----------
  89. Gooey converts your Console Applications into end-user-friendly GUI applications. It lets you focus on building robust, configurable programs in a familiar way, all without having to worry about how it will be presented to and interacted with by your average user.
  90. Why?
  91. ---
  92. Because as much as we love the command prompt, the rest of the world looks at it like an ugly relic from the early '80s. On top of that, more often than not programs need to do more than just one thing, and that means giving options, which previously meant either building a GUI, or trying to explain how to supply arguments to a Console Application. Gooey was made to (hopefully) solve those problems. It makes programs easy to use, and pretty to look at!
  93. Who is this for?
  94. ----------------
  95. If you're building utilities for yourself, other programmers, or something which produces a result that you want to capture and pipe over to another console application (e.g. *nix philosophy utils), Gooey probably isn't the tool for you. However, if you're building 'run and done,' around-the-office-style scripts, things that shovel bits from point A to point B, or simply something that's targeted at a non-programmer, Gooey is the perfect tool for the job. It lets you build as complex of an application as your heart desires all while getting the GUI side for free.
  96. How does it work?
  97. -----------------
  98. Gooey is attached to your code via a simple decorator on whichever method has your `argparse` declarations.
  99. @Gooey
  100. def my_run_func():
  101. parser = ArgumentParser(...)
  102. # rest of code
  103. At run-time, it parses your Python script for all references to `ArgumentParser`. (The older `optparse` is currently not supported.) These references are then extracted, assigned a `component type` based on the `'action'` they provide, and finally used to assemble the GUI.
  104. #### Mappings:
  105. Gooey does its best to choose sensible defaults based on the options it finds. Currently, `ArgumentParser._actions` are mapped to the following `WX` components.
  106. | Parser Action | Widget | Example |
  107. |:----------------------|-----------|------|
  108. | store | TextCtrl | <img src="https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/f54e9f5e-07c5-11e5-86e5-82f011c538cf.png"/>|
  109. | store_const | CheckBox | <img src="https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/f538c850-07c5-11e5-8cbe-864badfa54a9.png"/>|
  110. | store_true| CheckBox | <img src="https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/f538c850-07c5-11e5-8cbe-864badfa54a9.png"/>|
  111. | store_False | CheckBox| <img src="https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/f538c850-07c5-11e5-8cbe-864badfa54a9.png"/> |
  112. | append | TextCtrl | <img src="https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/f54e9f5e-07c5-11e5-86e5-82f011c538cf.png"/> |
  113. | count| DropDown &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | <img src="https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/f53ccbe4-07c5-11e5-80e5-510e2aa22922.png"/> |
  114. | Mutually Exclusive Group | RadioGroup | <img src="https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/f553feb8-07c5-11e5-9d5b-eaa4772075a9.png"/>
  115. |choice &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| DropDown | <img src="https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/f54e4da6-07c5-11e5-9e66-d8e6d7f18ac6.png"/> |
  116. ### GooeyParser
  117. If the above defaults aren't cutting it, you can control the exact widget type by using the drop-in `ArgumentParser` replacement `GooeyParser`. This gives you the additional keyword argument `widget`, to which you can supply the name of the component you want to display. Best part? You don't have to change any of your `argparse` code to use it. Drop it in, and you're good to go.
  118. **Example:**
  119. from argparse import ArgumentParser
  120. ....
  121. def main():
  122. parser = ArgumentParser(description="My Cool Gooey App!")
  123. parser.add_argument('filename', help="name of the file to process")
  124. Given then above, Gooey would select a normal `TextField` as the widget type like this:
  125. <p align="center">
  126. <img src="https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/f5393e20-07c5-11e5-88e9-c153fc3ecfaa.PNG">
  127. </p>
  128. However, by dropping in `GooeyParser` and supplying a `widget` name, you can display a much more user friendly `FileChooser`
  129. from gooey import GooeyParser
  130. ....
  131. def main():
  132. parser = GooeyParser(description="My Cool Gooey App!")
  133. parser.add_argument('filename', help="name of the file to process", widget='FileChooser')
  134. <p align="center"><img src="https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/f53ae23e-07c5-11e5-8757-c8aa6f3013b5.PNG"></p>
  135. **Custom Widgets:**
  136. | Widget | Example |
  137. |----------------|------------------------------|
  138. | DirChooser, FileChooser, MultiFileChooser, FileSaver, MultiFileSaver | <p align="center"><img src="https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/f5483b28-07c5-11e5-9d01-1935635fc22d.gif" width="400"></p> |
  139. | DateChooser &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| <p align="center"><img src="https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/f544756a-07c5-11e5-86d6-862ac146ad35.gif" width="400"></p> |
  140. | PasswordField | <p align="center"><img src="https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/28953722-eae72cca-788e-11e7-8fa1-9a1ef332a053.png" width="400"></p> |
  141. | Listbox | ![image](https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/31590191-fadd06f2-b1c0-11e7-9a49-7cbf0c6d33d1.png) |
  142. | BlockCheckbox | ![image](https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/46922288-9296f200-cfbb-11e8-8b0d-ddde08064247.png) <br/> The default InlineCheck box can look less than ideal if a large help text block is present. `BlockCheckbox` moves the text block to the normal position and provides a short-form `block_label` for display next to the control. Use `gooey_options.checkbox_label` to control the label text |
  143. Internationalization
  144. --------------------
  145. <img src="https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/f52e9f1a-07c5-11e5-8f31-36a8fc14ac02.jpg" align="right" />
  146. Gooey is international ready and easily ported to your host language. Languages are controlled via an argument to the `Gooey` decorator.
  147. @Gooey(language='russian')
  148. def main():
  149. ...
  150. All program text is stored externally in `json` files. So adding new langauge support is as easy as pasting a few key/value pairs in the `gooey/languages/` directory.
  151. Thanks to some awesome [contributers](https://github.com/chriskiehl/Gooey/graphs/contributors), Gooey currently comes pre-stocked with over 18 different translations!
  152. Want to add another one? Submit a [pull request!](https://github.com/chriskiehl/Gooey/compare)
  153. -------------------------------------------
  154. Global Configuration
  155. --------------------
  156. Just about everything in Gooey's overall look and feel can be customized by passing arguments to the decorator.
  157. | Parameter | Summary |
  158. |-----------|---------|
  159. | encoding | Text encoding to use when displaying characters (default: 'utf-8') |
  160. | use_legacy_titles | Rewrites the default argparse group name from "Positional" to "Required". This is primarily for retaining backward compatibilty with previous versions of Gooey (which had poor support/awareness of groups and did its own naive bucketing of arguments). |
  161. | advanced | Toggles whether to show the 'full' configuration screen, or a simplified version |
  162. | auto_start | Skips the configuration all together and runs the program immediately |
  163. | language | Tells Gooey which language set to load from the `gooey/languages` directory.|
  164. | target | Tells Gooey how to re-invoke itself. By default Gooey will find python, but this allows you to specify the program (and arguments if supplied).|
  165. | suppress_gooey_flag | Should be set when using a custom `target`. Prevent Gooey from injecting additional CLI params |
  166. |program_name | The name displayed in the title bar of the GUI window. If not supplied, the title defaults to the script name pulled from `sys.argv[0]`. |
  167. | program_description | Sets the text displayed in the top panel of the `Settings` screen. Defaults to the description pulled from `ArgumentParser`. |
  168. | default_size | Initial size of the window |
  169. | required_cols | Controls how many columns are in the Required Arguments section <br> :warning: **Deprecation notice:** See [Group Parameters](#group-configuration) for modern layout controls|
  170. | optional_cols | Controls how many columns are in the Optional Arguments section <br> :warning: **Deprecation notice:** See [Group Parameters](#group-configuration) for modern layout controls|
  171. | dump_build_config | Saves a `json` copy of its build configuration on disk for reuse/editing |
  172. | load_build_config | Loads a `json` copy of its build configuration from disk |
  173. | monospace_display | Uses a mono-spaced font in the output screen <br> :warning: **Deprecation notice:** See [Group Parameters](#group-configuration) for modern font configuration|
  174. | image_dir | Path to the directory in which Gooey should look for custom images/icons |
  175. | language_dir | Path to the directory in which Gooey should look for custom languages files |
  176. | disable_stop_button | Disable the `Stop` button when running |
  177. | show_stop_warning | Displays a warning modal before allowing the user to force termination of your program |
  178. | force_stop_is_error | Toggles whether an early termination by the shows the success or error screen |
  179. | show_success_modal | Toggles whether or not to show a summary modal after a successful run |
  180. | show_failure_modal | Toggles whether or not to show a summary modal on failure |
  181. | show_restart_button | Toggles whether or not to show the restart button at the end of execution |
  182. | run_validators | Controls whether or not to have Gooey perform validation before calling your program |
  183. | poll_external_updates | (Experimental!) When True, Gooey will call your code with a `gooey-seed-ui` CLI argument and use the response to fill out dynamic values in the UI (See: [Using Dynamic Values](#using-dynamic-values))|
  184. | return_to_config | When True, Gooey will return to the configuration settings window upon successful run |
  185. | progress_regex | A text regex used to pattern match runtime progress information. See: [Showing Progress](#showing-progress) for a detailed how-to |
  186. | progress_expr | A python expression applied to any matches found via the `progress_regex`. See: [Showing Progress](#showing-progress) for a detailed how-to |
  187. | hide_progress_msg | Option to hide textual progress updates which match the `progress_regex`. See: [Showing Progress](#showing-progress) for a detailed how-to |
  188. | disable_progress_bar_animation | Disable the progress bar |
  189. | requires_shell | Controls whether or not the `shell` argument is used when invoking your program. [More info here](https://stackoverflow.com/questions/3172470/actual-meaning-of-shell-true-in-subprocess#3172488) |
  190. | navigation | Sets the "navigation" style of Gooey's top level window. <br>Options: <table> <thead> <tr><th>TABBED</th><th>SIDEBAR</th></tr></thead> <tbody> <tr> <td><img src="https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/34464826-2a946ba2-ee47-11e7-92a4-4afeb49dc9ca.png" width="200" height="auto"></td><td><img src="https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/34464847-9918fbb0-ee47-11e7-8d5f-0d42631c2bc0.png" width="200" height="auto"></td></tr></tbody></table>|
  191. | sidebar_title | <img src="https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/34472159-1bfedbd0-ef10-11e7-8bc3-b6d69febb8c3.png" width="250" height="auto" align="right"> Controls the heading title above the SideBar's navigation pane. Defaults to: "Actions" |
  192. | show_sidebar | Show/Hide the sidebar in when navigation mode == `SIDEBAR` |
  193. | body_bg_color | HEX value of the main Gooey window |
  194. | header_bg_color | HEX value of the header background |
  195. | header_height | height in pixels of the header |
  196. | header_show_title | Show/Hide the header title |
  197. | header_show_subtitle | Show/Hide the header subtitle |
  198. | footer_bg_color | HEX value of the Footer background |
  199. | sidebar_bg_color | HEX value of the Sidebar's background |
  200. | terminal_panel_color | HEX value of the terminal's panel |
  201. | terminal_font_color | HEX value of the font displayed in Gooey's terminal |
  202. | terminal_font_family | Name of the Font Family to use in the terminal |
  203. | terminal_font_weight | Weight of the font (NORMAL\|BOLD) |
  204. | terminal_font_size | Point size of the font displayed in the terminal |
  205. | error_color | HEX value of the text displayed when a validation error occurs |
  206. | richtext_controls | Switch on/off the console support for terminal control sequences (limited support for font weight and color). Defaults to : False |
  207. | menus | Show custom menu groups and items (see: [Menus](#menus) |
  208. Layout Customization
  209. --------------------
  210. You can achieve fairly flexible layouts with Gooey by using a few simple customizations.
  211. At the highest level, you have several overall layout options controllable via various arguments to the Gooey decorator.
  212. | `show_sidebar=True` | `show_sidebar=False` | `navigation='TABBED'` | `tabbed_groups=True` |
  213. |---------------------|----------------------|----------------------|------------------------|
  214. |<img src="https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/34464847-9918fbb0-ee47-11e7-8d5f-0d42631c2bc0.png" width="400"> |<img src="https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/35487799-762aa308-0434-11e8-8eb3-1e9fab2d13ae.png" width="400"> |<img src="https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/34464835-5ba9b0e4-ee47-11e7-9561-55e3647c2165.png" width="400"> |<img src="https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/34464826-2a946ba2-ee47-11e7-92a4-4afeb49dc9ca.png" width="400"> |
  215. **Grouping Inputs**
  216. By default, if you're using Argparse with Gooey, your inputs will be split into two buckets: `positional` and `optional`. However, these aren't always the most descriptive groups to present to your user. You can arbitrarily bucket inputs into logic groups and customize the layout of each.
  217. With `argparse` this is done via `add_argument_group()`
  218. <img src="https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/35487956-a4c9915e-0436-11e8-8a11-fd21528aedf0.png" align="right" width="410">
  219. ```
  220. parser = ArgumentParser()
  221. search_group = parser.add_argument_group(
  222. "Search Options",
  223. "Customize the search options"
  224. )
  225. ```
  226. You can add arguments to the group as normal
  227. ```
  228. search_group.add_argument(
  229. '--query',
  230. help='Base search string'
  231. )
  232. ```
  233. Which will display them as part of the group within the UI.
  234. Run Modes
  235. ---------
  236. Gooey has a handful of presentation modes so you can tailor its layout to your content type and user's level or experience.
  237. ### Advanced
  238. The default view is the "full" or "advanced" configuration screen. It has two different layouts depending on the type of command line interface it's wrapping. For most applications, the flat layout will be the one to go with, as its layout matches best to the familiar CLI schema of a primary command followed by many options (e.g. Curl, FFMPEG).
  239. On the other side is the Column Layout. This one is best suited for CLIs that have multiple paths or are made up of multiple little tools each with their own arguments and options (think: git). It displays the primary paths along the left column, and their corresponding arguments in the right. This is a great way to package a lot of varied functionality into a single app.
  240. <p align="center">
  241. <img src="https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/f06a36cc-08ad-11e5-843e-9322df96d4d6.png">
  242. </p>
  243. Both views present each action in the `Argument Parser` as a unique GUI component. It makes it ideal for presenting the program to users which are unfamiliar with command line options and/or Console Programs in general. Help messages are displayed along side each component to make it as clear as possible which each widget does.
  244. **Setting the layout style:**
  245. Currently, the layouts can't be explicitely specified via a parameter (on the TODO!). The layouts are built depending on whether or not there are `subparsers` used in your code base. So, if you want to trigger the `Column Layout`, you'll need to add a `subparser` to your `argparse` code.
  246. It can be toggled via the `advanced` parameter in the `Gooey` decorator.
  247. @gooey(advanced=True)
  248. def main():
  249. # rest of code
  250. --------------------------------------------
  251. ### Basic
  252. The basic view is best for times when the user is familiar with Console Applications, but you still want to present something a little more polished than a simple terminal. The basic display is accessed by setting the `advanced` parameter in the `gooey` decorator to `False`.
  253. @gooey(advanced=False)
  254. def main():
  255. # rest of code
  256. <p align="center">
  257. <img src="https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/f53a4306-07c5-11e5-8e63-b510d6db9953.png">
  258. </p>
  259. ----------------------------------------------
  260. ### No Config
  261. No Config pretty much does what you'd expect: it doesn't show a configuration screen. It hops right to the `display` section and begins execution of the host program. This is the one for improving the appearance of little one-off scripts.
  262. <p align="center">
  263. <img src="https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/f54fe6f2-07c5-11e5-92e4-f72a2ae12862.png">
  264. </p>
  265. --------------------------------------
  266. ### Menus
  267. ![image](https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/47250909-74782a00-d3df-11e8-88ac-182d06c4435a.png)
  268. >Added 1.0.2
  269. You can add a Menu Bar to the top of Gooey with customized menu groups and items.
  270. Menus are specified on the main `@Gooey` decorator as a list of maps.
  271. ```
  272. @Gooey(menu=[{}, {}, ...])
  273. ```
  274. Each map is made up of two key/value pairs
  275. 1. `name` - the name for this menu group
  276. 2. `items` - the individual menu items within this group
  277. You can have as many menu groups as you want. They're passed as a list to the `menu` argument on the `@Gooey` decorator.
  278. ```
  279. @Gooey(menu=[{'name': 'File', 'items: []},
  280. {'name': 'Tools', 'items': []},
  281. {'name': 'Help', 'items': []}])
  282. ```
  283. Individual menu items in a group are also just maps of key / value pairs. Their exact key set varies based on their `type`, but two keys will always be present:
  284. * `type` - this controls the behavior that will be attached to the menu item as well as the keys it needs specified
  285. * `menuTitle` - the name for this MenuItem
  286. Currently, three types of menu options are supported:
  287. * AboutDialog
  288. * MessageDialog
  289. * Link
  290. <img src="https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/47251026-9ffc1400-d3e1-11e8-9095-982a6367561b.png" width="400" height="auto" align="right" />
  291. **About Dialog** is your run-of-the-mill About Dialog. It displays program information such as name, version, and license info in a standard native AboutBox.
  292. Schema
  293. * `name` - (_optional_)
  294. * `description` - (_optional_)
  295. * `version` - (_optional_)
  296. * `copyright` - (_optional_)
  297. * `license` - (_optional_)
  298. * `website` - (_optional_)
  299. * `developer` - (_optional_)
  300. Example:
  301. ```
  302. {
  303. 'type': 'AboutDialog',
  304. 'menuTitle': 'About',
  305. 'name': 'Gooey Layout Demo',
  306. 'description': 'An example of Gooey\'s layout flexibility',
  307. 'version': '1.2.1',
  308. 'copyright': '2018',
  309. 'website': 'https://github.com/chriskiehl/Gooey',
  310. 'developer': 'http://chriskiehl.com/',
  311. 'license': 'MIT'
  312. }
  313. ```
  314. <img src="https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/47250925-bbfeb600-d3df-11e8-88a8-5ba838e9466d.png" width="400" height="auto" align="right" />
  315. **MessageDialog** is a generic informational dialog box. You can display anything from small alerts, to long-form informational text to the user.
  316. Schema:
  317. * `message` - (_required_) the text to display in the body of the modal
  318. * `caption` - (_optional_) the caption in the title bar of the modal
  319. Example:
  320. ```python
  321. {
  322. 'type': 'MessageDialog',
  323. 'menuTitle': 'Information',
  324. 'message': 'Hey, here is some cool info for ya!',
  325. 'caption': 'Stuff you should know'
  326. }
  327. ```
  328. **Link** is for sending the user to an external website. This will spawn their default browser at the URL you specify.
  329. Schema:
  330. * `url` - (_required_) - the fully qualified URL to visit
  331. Example:
  332. ```python
  333. {
  334. 'type': 'Link',
  335. 'menuTitle': 'Visit Out Site',
  336. 'url': 'http://www.example.com'
  337. }
  338. ```
  339. **A full example:**
  340. Two menu groups ("File" and "Help") with four menu items between them.
  341. ```python
  342. @Gooey(
  343. program_name='Advanced Layout Groups',
  344. menu=[{
  345. 'name': 'File',
  346. 'items': [{
  347. 'type': 'AboutDialog',
  348. 'menuTitle': 'About',
  349. 'name': 'Gooey Layout Demo',
  350. 'description': 'An example of Gooey\'s layout flexibility',
  351. 'version': '1.2.1',
  352. 'copyright': '2018',
  353. 'website': 'https://github.com/chriskiehl/Gooey',
  354. 'developer': 'http://chriskiehl.com/',
  355. 'license': 'MIT'
  356. }, {
  357. 'type': 'MessageDialog',
  358. 'menuTitle': 'Information',
  359. 'caption': 'My Message',
  360. 'message': 'I am demoing an informational dialog!'
  361. }, {
  362. 'type': 'Link',
  363. 'menuTitle': 'Visit Our Site',
  364. 'url': 'https://github.com/chriskiehl/Gooey'
  365. }]
  366. },{
  367. 'name': 'Help',
  368. 'items': [{
  369. 'type': 'Link',
  370. 'menuTitle': 'Documentation',
  371. 'url': 'https://www.readthedocs.com/foo'
  372. }]
  373. }]
  374. )
  375. ```
  376. ---------------------------------------
  377. ### Input Validation
  378. <img src="https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/34464861-0e82c214-ee48-11e7-8f4a-a8e00721efef.png" width="400" height="auto" align="right" />
  379. >:warning:
  380. >Note! This functionality is experimental. Its API may be changed or removed alltogether. Feedback/thoughts on this feature is welcome and encouraged!
  381. Gooey can optionally do some basic pre-flight validation on user input. Internally, it uses these validator functions to check for the presence of required arguments. However, by using [GooeyParser](#gooeyparser), you can extend these functions with your own validation rules. This allows Gooey to show much, much more user friendly feedback before it hands control off to your program.
  382. **Writing a validator:**
  383. Validators are specified as part of the `gooey_options` map available to `GooeyParser`. It's a simple map structure made up of a root key named `validator` and two internal pairs:
  384. * `test` The inner body of the validation test you wish to perform
  385. * `message` the error message that should display given a validation failure
  386. e.g.
  387. ```
  388. gooey_options={
  389. 'validator':{
  390. 'test': 'len(user_input) > 3',
  391. 'message': 'some helpful message'
  392. }
  393. }
  394. ```
  395. **The `test` function**
  396. Your test function can be made up of any valid Python expression. It receives the variable `user_input` as an argument against which to perform its validation. Note that all values coming from Gooey are in the form of a string, so you'll have to cast as needed in order to perform your validation.
  397. **Full Code Example**
  398. ```
  399. from gooey.python_bindings.gooey_decorator import Gooey
  400. from gooey.python_bindings.gooey_parser import GooeyParser
  401. @Gooey
  402. def main():
  403. parser = GooeyParser(description='Example validator')
  404. parser.add_argument(
  405. 'secret',
  406. metavar='Super Secret Number',
  407. help='A number specifically between 2 and 14',
  408. gooey_options={
  409. 'validator': {
  410. 'test': '2 <= int(user_input) <= 14',
  411. 'message': 'Must be between 2 and 14'
  412. }
  413. })
  414. args = parser.parse_args()
  415. print("Cool! Your secret number is: ", args.secret)
  416. ```
  417. <img src="https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/34465024-f011ac3e-ee4f-11e7-80ae-330adb4c47d6.png" width="400" height="auto" align="left" />
  418. With the validator in place, Gooey can present the error messages next to the relevant input field if any validators fail.
  419. ---------------------------------------
  420. ## Using Dynamic Values
  421. >:warning:
  422. >Note! This functionality is experimental. Its API may be changed or removed alltogether. Feedback on this feature is welcome and encouraged!
  423. Gooey's Choice style fields (Dropdown, Listbox) can be fed a dynamic set of values at runtime by enabling the `poll_external_updates` option. This will cause Gooey to request updated values from your program everytime the user visits the Configuration page. This can be used to, for instance, show the result of a previous execution on the config screen without requiring that the user restart the program.
  424. **How does it work?**
  425. <img src="https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/35487459-bd7fe938-0430-11e8-9f6d-fa8f703b9da5.gif" align="right" width="420"/>
  426. At runtime, whenever the user hits the Configuration screen, Gooey will call your program with a single CLI argument: `gooey-seed-ui`. This is a request to your program for updated values for the UI. In response to this, on `stdout`, your program should return a JSON string mapping cli-inputs to a list of options.
  427. For example, assuming a setup where you have a dropdown that lists user files:
  428. ```
  429. ...
  430. parser.add_argument(
  431. '--load',
  432. metavar='Load Previous Save',
  433. help='Load a Previous save file',
  434. dest='filename',
  435. widget='Dropdown',
  436. choices=list_savefiles(),
  437. )
  438. ```
  439. Here the input we want to populate is `--load`. So, in response to the `gooey-seed-ui` request, you would return a JSON string with `--load` as the key, and a list of strings that you'd like to display to the user as the value. e.g.
  440. ```
  441. {"--load": ["Filename_1.txt", "filename_2.txt", ..., "filename_n.txt]}
  442. ```
  443. Checkout the full example code in the [Examples Repository](https://github.com/chriskiehl/GooeyExamples/blob/master/examples/dynamic_updates.py). Or checkout a larger example in the silly little tool that spawned this feature: [SavingOverIt](https://github.com/chriskiehl/SavingOverIt).
  444. -------------------------------------
  445. ## Showing Progress
  446. <img src="https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/45590349-55bbda80-b8eb-11e8-9aed-b4fe377756ac.png" align="right" width="420"/>
  447. Giving visual progress feedback with Gooey is easy! If you're already displaying textual progress updates, you can tell Gooey to hook into that existing output in order to power its Progress Bar.
  448. For simple cases, output strings which resolve to a numeric representation of the completion percentage (e.g. `Progress 83%`) can be pattern matched and turned into a progress bar status with a simple regular expression (e.g. `@Gooey(progress_regex=r"^progress: (\d+)%$")`).
  449. For more complicated outputs, you can pass in a custom evaluation expression (`progress_expr`) to transform regular expression matches as needed.
  450. Output strings which satisfy the regular expression can be hidden from the console via the `hide_progress_msg` parameter (e.g. `@Gooey(progress_regex=r"^progress: (\d+)%$", hide_progress_msg=True)`.
  451. **Regex and Processing Expression**
  452. ```python
  453. @Gooey(progress_regex=r"^progress: (?P<current>\d+)/(?P<total>\d+)$",
  454. progress_expr="current / total * 100")
  455. ```
  456. **Program Output:**
  457. ```
  458. progress: 1/100
  459. progress: 2/100
  460. progress: 3/100
  461. ...
  462. ```
  463. There are lots of options for telling Gooey about progress as your program is running. Checkout the [Gooey Examples](https://github.com/chriskiehl/GooeyExamples) repository for more detailed usage and examples!
  464. --------------------------------------
  465. ## Customizing Icons
  466. Gooey comes with a set of six default icons. These can be overridden with your own custom images/icons by telling Gooey to search additional directories when initializing. This is done via the `image_dir` argument to the `Goeey` decorator.
  467. @Gooey(program_name='Custom icon demo', image_dir='/path/to/my/image/directory')
  468. def main():
  469. # rest of program
  470. Images are discovered by Gooey based on their _filenames_. So, for example, in order to supply a custom configuration icon, simply place an image with the filename `config_icon.png` in your images directory. These are the filenames which can be overridden:
  471. * program_icon.ico
  472. * success_icon.png
  473. * running_icon.png
  474. * loading_icon.gif
  475. * config_icon.png
  476. * error_icon.png
  477. ## Packaging
  478. Thanks to some [awesome contributers](https://github.com/chriskiehl/Gooey/issues/58), packaging Gooey as an executable is super easy.
  479. The tl;dr [pyinstaller](https://github.com/pyinstaller/pyinstaller) version is to drop this [build.spec](https://github.com/chriskiehl/Gooey/files/29568/build.spec.txt) into the root directory of your application. Edit its contents so that the `application` and `name` are relevant to your project, then execute `pyinstaller build.spec` to bundle your app into a ready-to-go executable.
  480. Detailed step by step instructions can be found [here](http://chriskiehl.com/article/packaging-gooey-with-pyinstaller/).
  481. Screenshots
  482. ------------
  483. | Flat Layout | Column Layout |Success Screen | Error Screen | Warning Dialog |
  484. |-------------|---------------|---------------|--------------|----------------|
  485. | <img src="https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/4414e54e-0965-11e5-964b-f717a7adaac6.jpg"> | <img src="https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/4411b824-0965-11e5-905a-3a2b5df0efb3.jpg"> | <img src="https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/44165442-0965-11e5-8edf-b8305353285f.jpg"> | <img src="https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/4410dcce-0965-11e5-8243-c1d832c05887.jpg"> | <img src="https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/4415432c-0965-11e5-9190-17f55460faf3.jpg"> |
  486. | Custom Groups | Tabbed Groups | Tabbed Navigation | Sidebar Navigation | Input Validation |
  487. |-------------|---------------|---------------|--------------|----------------|
  488. | <img src="https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/34464824-c044d57a-ee46-11e7-9c35-6e701a7c579a.png"> | <img src="https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/34464826-2a946ba2-ee47-11e7-92a4-4afeb49dc9ca.png"> | <img src="https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/34464835-5ba9b0e4-ee47-11e7-9561-55e3647c2165.png"> | <img src="https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/34464847-9918fbb0-ee47-11e7-8d5f-0d42631c2bc0.png"> | <img src="https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/34464861-0e82c214-ee48-11e7-8f4a-a8e00721efef.png"> |
  489. ----------------------------------------------
  490. Wanna help?
  491. -----------
  492. Code, translation, documentation, or graphics? All pull requests are welcome. Just make sure to checkout [the contributing guidelines](https://github.com/chriskiehl/Gooey/blob/master/CONTRIBUTING.md) first.