1. GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line

Skip to content

Sign up

Sign in

Sign up

chriskiehl / Gooey Public

Turn (almost) any Python command line program into a full GUI application with one line

License

MIT license

16.2k stars 876 forks

Star

Notifications

More

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

master

Switch branches/tags

Branches Tags

View all branches

View all tags

20 branches 9 tags

Go to file Code

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

加速

加速通道列表

github.91chi.fun加速通道

加速下载 ZIP

Latest commit

GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图1 GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图2

namujae and chriskiehl [fix] install dataclasses pkg only in python 3.6

be4b11b 25 days ago

[fix] install dataclasses pkg only in python 3.6

be4b11b

Git stats

Files

Permalink

Failed to load latest commit information.

Type

Name

Latest commit message

Commit time

docs

removed unused file

4 months ago

gooey

add missing Dutch translations

4 months ago

images @ 5a721a2

add images submodule

3 years ago

.gitignore

ignore all virtualenvs

4 years ago

.gitmodules

add images submodule

3 years ago

CONTRIBUTING.md

Update CONTRIBUTING.md

4 months ago

ISSUE_TEMPLATE.md

Fix typo in ISSUE_TEMPLATE.md.

2 years ago

LICENSE.txt

Update LICENSE.txt

5 years ago

MANIFEST.in

clean the project directory

8 years ago

README.md

[update packaging section in readme](/chriskiehl/Gooey/commit/a451f5265a405951be367217ef8363bf88a46176 “update packaging section in readme

build.spec didn’t point to latest version and update link to detailed step-by-step instructions (previous link no longer worked).”)

4 months ago

TODO.md

mark completed items

4 years ago

pip_deploy.py

Update pip deploy script to use twine

5 years ago

requirements.txt

1.2.0

4 months ago

setup.py

[fix] install dataclasses pkg only in python 3.6

25 days ago

View code

Gooey Table of Contents Quick Start Installation instructions Usage Examples What is it? Why? Who is this for? How does it work? Mappings: GooeyParser Internationalization Global Configuration Layout Customization Run Modes Advanced Basic No Config Menus Dynamic Validation Lifecycle Events and UI control Showing Progress Elapsed / Remaining Time Customizing Icons Packaging Screenshots Wanna help?

README.md

Gooey

Turn (almost) any Python 3 Console Program into a GUI application with one line

GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图3

Table of Contents


Quick Start

Installation instructions

The easiest way to install Gooey is via pip

  1. pip install Gooey

Alternatively, you can install Gooey by cloning the project to your local directory

  1. git clone https://github.com/chriskiehl/Gooey.git

run setup.py

  1. python setup.py install

Usage

Gooey is attached to your code via a simple decorator on whichever method has your argparse declarations (usually main).

  1. from gooey import Gooey
  2. @Gooey <--- all it takes! :)
  3. def main():
  4. parser = ArgumentParser(...)
  5. # rest of code

Different styling and functionality can be configured by passing arguments into the decorator.

  1. # options
  2. @Gooey(advanced=Boolean, # toggle whether to show advanced config or not
  3. language=language_string, # Translations configurable via json
  4. auto_start=True, # skip config screens all together
  5. target=executable_cmd, # Explicitly set the subprocess executable arguments
  6. program_name='name', # Defaults to script name
  7. program_description, # Defaults to ArgParse Description
  8. default_size=(610, 530), # starting size of the GUI
  9. required_cols=1, # number of columns in the "Required" section
  10. optional_cols=2, # number of columns in the "Optional" section
  11. dump_build_config=False, # Dump the JSON Gooey uses to configure itself
  12. load_build_config=None, # Loads a JSON Gooey-generated configuration
  13. monospace_display=False) # Uses a mono-spaced font in the output screen
  14. )
  15. def main():
  16. parser = ArgumentParser(...)
  17. # rest of code

See: How does it Work section for details on each option.

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

  1. from gooey import Gooey, GooeyParser
  2. @Gooey
  3. def main():
  4. parser = GooeyParser(description="My Cool GUI Program!")
  5. parser.add_argument('Filename', widget="FileChooser")
  6. parser.add_argument('Date', widget="DateChooser")
  7. ...

Examples

Gooey downloaded and installed? Great! Wanna see it in action? Head over the the Examples Repository 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.

Direct Download

What is it?

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.

Why?

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!

Who is this for?

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.

How does it work?

Gooey is attached to your code via a simple decorator on whichever method has your argparse declarations.

  1. @Gooey
  2. def my_run_func():
  3. parser = ArgumentParser(...)
  4. # rest of code

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.

Mappings:

Gooey does its best to choose sensible defaults based on the options it finds. Currently, ArgumentParser._actions are mapped to the following WX components.

Parser Action Widget Example
store TextCtrl [GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图4
](https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/f54e9f5e-07c5-11e5-86e5-82f011c538cf.png)
store_const CheckBox [GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图5
](https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/f538c850-07c5-11e5-8cbe-864badfa54a9.png)
store_true CheckBox [GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图6
](https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/f538c850-07c5-11e5-8cbe-864badfa54a9.png)
store_False CheckBox [GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图7
](https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/f538c850-07c5-11e5-8cbe-864badfa54a9.png)
version CheckBox [GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图8
](https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/f538c850-07c5-11e5-8cbe-864badfa54a9.png)
append TextCtrl [GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图9
](https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/f54e9f5e-07c5-11e5-86e5-82f011c538cf.png)
count DropDown [GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图10
](https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/f53ccbe4-07c5-11e5-80e5-510e2aa22922.png)
Mutually Exclusive Group RadioGroup [GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图11
](https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/f553feb8-07c5-11e5-9d5b-eaa4772075a9.png)
choice DropDown [GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图12
](https://github.com/chriskiehl/GooeyImages/raw/images/readme-images/f54e4da6-07c5-11e5-9e66-d8e6d7f18ac6.png)

GooeyParser

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.

Example:

  1. from argparse import ArgumentParser
  2. ....
  3. def main():
  4. parser = ArgumentParser(description="My Cool Gooey App!")
  5. parser.add_argument('filename', help="name of the file to process")

Given then above, Gooey would select a normal TextField as the widget type like this:

GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图13

However, by dropping in GooeyParser and supplying a widget name, you can display a much more user friendly FileChooser

  1. from gooey import GooeyParser
  2. ....
  3. def main():
  4. parser = GooeyParser(description="My Cool Gooey App!")
  5. parser.add_argument('filename', help="name of the file to process", widget='FileChooser')

GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图14

Custom Widgets:

Widget Example
DirChooser, FileChooser, MultiFileChooser, FileSaver, MultiFileSaver

GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图15
GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图16

|
| DateChooser/TimeChooser |

GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图17
GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图18

Please note that for both of these widgets the values passed to the application will always be in ISO format while localized values may appear in some parts of the GUI depending on end-user settings.

|
| PasswordField |

GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图19

|
| Listbox | GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图20
|
| BlockCheckbox | GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图21

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 |
| ColourChooser |

GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图22
GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图23

|
| FilterableDropdown |

GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图24
GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图25

|
| IntegerField |

GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图26

|
| DecimalField |

GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图27

|
| Slider |

GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图28

|

Internationalization

GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图29

Gooey is international ready and easily ported to your host language. Languages are controlled via an argument to the Gooey decorator.

  1. @Gooey(language='russian')
  2. def main():
  3. ...

All program text is stored externally in json files. So adding new language support is as easy as pasting a few key/value pairs in the gooey/languages/ directory.

Thanks to some awesome contributors, Gooey currently comes pre-stocked with over 18 different translations!

Want to add another one? Submit a pull request!


Global Configuration

Just about everything in Gooey’s overall look and feel can be customized by passing arguments to the decorator.

Parameter Summary
encoding Text encoding to use when displaying characters (default: ‘utf-8’)
use_legacy_titles Rewrites the default argparse group name from “Positional” to “Required”. This is primarily for retaining backward compatibility with previous versions of Gooey (which had poor support/awareness of groups and did its own naive bucketing of arguments).
advanced Toggles whether to show the ‘full’ configuration screen, or a simplified version
auto_start Skips the configuration all together and runs the program immediately
language Tells Gooey which language set to load from the gooey/languages directory.
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).
suppress_gooey_flag Should be set when using a custom target. Prevent Gooey from injecting additional CLI params
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].
program_description Sets the text displayed in the top panel of the Settings screen. Defaults to the description pulled from ArgumentParser.
default_size Initial size of the window
fullscreen start Gooey in fullscreen mode
required_cols Controls how many columns are in the Required Arguments section
⚠️ Deprecation notice: See Layout Customization for modern layout controls
optional_cols Controls how many columns are in the Optional Arguments section
⚠️ Deprecation notice: See Layout Customization for modern layout controls
dump_build_config Saves a json copy of its build configuration on disk for reuse/editing
load_build_config Loads a json copy of its build configuration from disk
monospace_display Uses a mono-spaced font in the output screen
⚠️ Deprecation notice: See Layout Customization for modern font configuration
image_dir Path to the directory in which Gooey should look for custom images/icons
language_dir Path to the directory in which Gooey should look for custom languages files
disable_stop_button Disable the Stop button when running
show_stop_warning Displays a warning modal before allowing the user to force termination of your program
force_stop_is_error Toggles whether an early termination by the shows the success or error screen
show_success_modal Toggles whether or not to show a summary modal after a successful run
show_failure_modal Toggles whether or not to show a summary modal on failure
show_restart_button Toggles whether or not to show the restart button at the end of execution
run_validators Controls whether or not to have Gooey perform validation before calling your program
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)
use_cmd_args Substitute any command line arguments provided at run time for the default values specified in the Gooey configuration
return_to_config When True, Gooey will return to the configuration settings window upon successful run
progress_regex A text regex used to pattern match runtime progress information. See: Showing Progress for a detailed how-to
progress_expr A python expression applied to any matches found via the progress_regex. See: Showing Progress for a detailed how-to
hide_progress_msg Option to hide textual progress updates which match the progress_regex. See: Showing Progress for a detailed how-to
disable_progress_bar_animation Disable the progress bar
timing_options This contains the options for displaying time remaining and elapsed time, to be used with progress_regex and progress_expr. Elapsed / Remaining Time. Contained as a dictionary with the options show_time_remaining and hide_time_remaining_on_complete. Eg: timing_options={'show_time_remaining':True,'hide_time_remaining_on_complete':True}
show_time_remaining Disable the time remaining text see Elapsed / Remaining Time
hide_time_remaining_on_complete Hide time remaining on complete screen see Elapsed / Remaining Time
requires_shell Controls whether or not the shell argument is used when invoking your program. More info here
shutdown_signal Specifies the signal to send to the child process when the stop button is pressed. See Gracefully Stopping in the docs for more info.
navigation Sets the “navigation” style of Gooey’s top level window.

Options:
| TABBED | SIDEBAR |
| —- | —- |
| GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图30
| GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图31
| |
| sidebar_title | GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图32
Controls the heading title above the SideBar’s navigation pane. Defaults to:”Actions” |
| show_sidebar | Show/Hide the sidebar in when navigation mode == SIDEBAR |
| body_bg_color | HEX value of the main Gooey window |
| header_bg_color | HEX value of the header background |
| header_height | height in pixels of the header |
| header_show_title | Show/Hide the header title |
| header_show_subtitle | Show/Hide the header subtitle |
| footer_bg_color | HEX value of the Footer background |
| sidebar_bg_color | HEX value of the Sidebar’s background |
| terminal_panel_color | HEX value of the terminal’s panel |
| terminal_font_color | HEX value of the font displayed in Gooey’s terminal |
| terminal_font_family | Name of the Font Family to use in the terminal |
| terminal_font_weight | Weight of the font (constants.FONTWEIGHT_NORMAL, constants.FONTWEIGHT_XXX) |
| terminal_font_size | Point size of the font displayed in the terminal |
| error_color | HEX value of the text displayed when a validation error occurs |
| richtext_controls | Switch on/off the console support for terminal control sequences (limited support for font weight and color). Defaults to : False. See docs for additional details |
| menus | Show custom menu groups and items (see: Menus |
| clear_before_run | When true, previous output will be cleared from the terminal when running program again |

Layout Customization

You can achieve fairly flexible layouts with Gooey by using a few simple customizations.

At the highest level, you have several overall layout options controllable via various arguments to the Gooey decorator.

show_sidebar=True show_sidebar=False navigation='TABBED' tabbed_groups=True

| GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图33
| GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图34
| GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图35
| GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图36
|

Grouping Inputs

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.

With argparse this is done via add_argument_group()

GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图37

  1. parser = ArgumentParser()
  2. search_group = parser.add_argument_group(
  3. "Search Options",
  4. "Customize the search options"
  5. )

You can add arguments to the group as normal

  1. search_group.add_argument(
  2. '--query',
  3. help='Base search string'
  4. )

Which will display them as part of the group within the UI.

Run Modes

Gooey has a handful of presentation modes so you can tailor its layout to your content type and user’s level or experience.

Advanced

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).

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.

GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图38

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.

Setting the layout style:

Currently, the layouts can’t be explicitly 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.

It can be toggled via the advanced parameter in the Gooey decorator.

  1. @gooey(advanced=True)
  2. def main():
  3. # rest of code

Basic

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.

  1. @gooey(advanced=False)
  2. def main():
  3. # rest of code

GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图39


No Config

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.

To use this mode, set auto_start=True in the Gooey decorator.

  1. @Gooey(auto_start=True)
  2. def main ():
  3. ...

GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图40


Menus

GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图41

Added 1.0.2

You can add a Menu Bar to the top of Gooey with customized menu groups and items.

Menus are specified on the main @Gooey decorator as a list of maps.

  1. @Gooey(menu=[{}, {}, ...])

Each map is made up of two key/value pairs

  1. name - the name for this menu group
  2. items - the individual menu items within this group

You can have as many menu groups as you want. They’re passed as a list to the menu argument on the @Gooey decorator.

  1. @Gooey(menu=[{'name': 'File', 'items: []},
  2. {'name': 'Tools', 'items': []},
  3. {'name': 'Help', 'items': []}])

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:

  • type - this controls the behavior that will be attached to the menu item as well as the keys it needs specified
  • menuTitle - the name for this MenuItem

Currently, three types of menu options are supported:

  • AboutDialog
  • MessageDialog
  • Link
  • HtmlDialog

GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图42

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.

Schema

  • name - (optional)
  • description - (optional)
  • version - (optional)
  • copyright - (optional)
  • license - (optional)
  • website - (optional)
  • developer - (optional)

Example:

  1. {
  2. 'type': 'AboutDialog',
  3. 'menuTitle': 'About',
  4. 'name': 'Gooey Layout Demo',
  5. 'description': 'An example of Gooey\'s layout flexibility',
  6. 'version': '1.2.1',
  7. 'copyright': '2018',
  8. 'website': 'https://github.com/chriskiehl/Gooey',
  9. 'developer': 'http://chriskiehl.com/',
  10. 'license': 'MIT'
  11. }

GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图43

MessageDialog is a generic informational dialog box. You can display anything from small alerts, to long-form informational text to the user.

Schema:

  • message - (required) the text to display in the body of the modal
  • caption - (optional) the caption in the title bar of the modal

Example:

  1. {
  2. 'type': 'MessageDialog',
  3. 'menuTitle': 'Information',
  4. 'message': 'Hey, here is some cool info for ya!',
  5. 'caption': 'Stuff you should know'
  6. }

Link is for sending the user to an external website. This will spawn their default browser at the URL you specify.

Schema:

  • url - (required) - the fully qualified URL to visit

Example:

  1. {
  2. 'type': 'Link',
  3. 'menuTitle': 'Visit Out Site',
  4. 'url': 'http://www.example.com'
  5. }

GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图44

HtmlDialog gives you full control over what’s displayed in the message dialog (bonus: people can copy/paste text from this one!).

Schema:

  • caption - (optional) the caption in the title bar of the modal
  • html - (required) the html you want displayed in the dialog. Note: only a small subset of HTML is supported. See the WX docs for more info.

Example:

  1. {
  2. 'type': 'HtmlDialog',
  3. 'menuTitle': 'Fancy Dialog!',
  4. 'caption': 'Demo of the HtmlDialog',
  5. 'html': '''
  6. <body bgcolor="white">
  7. <img src=/path/to/your/image.png" />
  8. <h1>Hello world!</h1>
  9. <p><font color="red">Lorem ipsum dolor sit amet, consectetur</font></p>
  10. </body>
  11. '''
  12. }

A full example:

Two menu groups (“File” and “Help”) with four menu items between them.

  1. @Gooey(
  2. program_name='Advanced Layout Groups',
  3. menu=[{
  4. 'name': 'File',
  5. 'items': [{
  6. 'type': 'AboutDialog',
  7. 'menuTitle': 'About',
  8. 'name': 'Gooey Layout Demo',
  9. 'description': 'An example of Gooey\'s layout flexibility',
  10. 'version': '1.2.1',
  11. 'copyright': '2018',
  12. 'website': 'https://github.com/chriskiehl/Gooey',
  13. 'developer': 'http://chriskiehl.com/',
  14. 'license': 'MIT'
  15. }, {
  16. 'type': 'MessageDialog',
  17. 'menuTitle': 'Information',
  18. 'caption': 'My Message',
  19. 'message': 'I am demoing an informational dialog!'
  20. }, {
  21. 'type': 'Link',
  22. 'menuTitle': 'Visit Our Site',
  23. 'url': 'https://github.com/chriskiehl/Gooey'
  24. }]
  25. },{
  26. 'name': 'Help',
  27. 'items': [{
  28. 'type': 'Link',
  29. 'menuTitle': 'Documentation',
  30. 'url': 'https://www.readthedocs.com/foo'
  31. }]
  32. }]
  33. )

Dynamic Validation

GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图45

⚠️ Note! This functionality is experimental and likely to be unstable. Its API may be changed or removed altogether. Feedback/thoughts on this feature is welcome and encouraged!

⚠️ See Release Notes for guidance on upgrading from 1.0.8 to 1.2.0

Before passing the user’s inputs to your program, Gooey can optionally run a special pre-flight validation to check that all arguments pass your specified validations.

How does it work?

Gooey piggy backs on the type parameter available to most Argparse Argument types.

  1. parser.add_argument('--some-number', type=int)
  2. parser.add_argument('--some-number', type=float)

In addition to simple builtins like int and float, you can supply your own function to the type parameter to vet the incoming values.

  1. def must_be_exactly_ten(value):
  2. number = int(value)
  3. if number == 10:
  4. return number
  5. else:
  6. raise TypeError("Hey! you need to provide exactly the number 10!")
  7. def main():
  8. parser = ArgumentParser()
  9. parser.add_argument('--ten', type=must_be_exactly_ten)

How to enable the pre-flight validation

By default, Gooey won’t run the validation. Why? This feature is fairly experimental and does a lot of intense Monkey Patching behind the scenes. As such, it’s currently opt-in.

You enable to validation by telling Gooey you’d like to subscribe to the VALIDATE_FORM event.

  1. from gooey import Gooey, Events
  2. @Gooey(use_events=[Events.VALIDATE_FORM])
  3. def main():
  4. ...

GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图46

Now, when you run Gooey, before it invokes your main program, it’ll send a separate pre-validation check and record any issues raised from your type functions.

Full Code Example

  1. from gooey import Gooey, Events
  2. from argparse import ArgumentParser
  3. def must_be_exactly_ten(value):
  4. number = int(value)
  5. if number == 10:
  6. return number
  7. else:
  8. raise TypeError("Hey! you need to provide exactly the number 10!")
  9. @Gooey(program_name='Validation Example', use_events=[Events.VALIDATE_FORM])
  10. def main():
  11. parser = ArgumentParser(description="Checkout this validation!")
  12. parser.add_argument('--ten', metavar='This field should be 10', type=must_be_exactly_ten)
  13. args = parser.parse_args()
  14. print(args)

Lifecycle Events and UI control

⚠️ Note! This functionality is experimental. Its API may be changed or removed altogether. Feedback on this feature is welcome and encouraged!

As of 1.2.0, Gooey now exposes coarse grain lifecycle hooks to your program. This means you can now take additional follow-up actions in response to successful runs or failures and even control the current state of the UI itself!

Currently, two primary hooks are exposed:

  • on_success
  • on_error

These fire exactly when you’d expect: after your process has completed.

Anatomy of an lifecycle handler:

Both on_success and on_error have the same type signature.

  1. from typing import Mapping, Any, Optional
  2. from gooey.types import PublicGooeyState
  3. def on_success(args: Mapping[str, Any], state: PublicGooeyState) -> Optional[PublicGooeyState]:
  4. """
  5. You can do anything you want in the handler including
  6. returning an updated UI state for your next run!
  7. """
  8. return state
  9. def on_error(args: Mapping[str, Any], state: PublicGooeyState) -> Optional[PublicGooeyState]:
  10. """
  11. You can do anything you want in the handler including
  12. returning an updated UI state for your next run!
  13. """
  14. return state
  • args This is the parsed Argparse object (e.g. the output of parse_args()). This will be a mapping of the user’s arguments as existed when your program was invoked.
  • state This is the current state of Gooey’s UI. If your program uses subparsers, this currently just lists the state of the active parser/form. Whatever updated version of this state you return will be reflected in the UI!

Attaching the handlers:

Handlers are attached when instantiating the GooeyParser.

  1. parser = GooeyParser(
  2. on_success=my_success_handler,
  3. on_failure=my_failure_handler)

Subscribing to the lifecycle events

Just like Validation, these lifecycle events are opt-in. Pass the event you’d like to subscribe to into the use_events Gooey decorator argument.

  1. from gooey import Gooey, Events
  2. @Gooey(use_events=[Events.ON_SUCCESS, Events.ON_ERROR])
  3. def main():
  4. ...

Showing Progress

GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图47

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.

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+)%$")).

For more complicated outputs, you can pass in a custom evaluation expression (progress_expr) to transform regular expression matches as needed.

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).

Regex and Processing Expression

  1. @Gooey(progress_regex=r"^progress: (?P<current>\d+)/(?P<total>\d+)$",
  2. progress_expr="current / total * 100")

Program Output:

  1. progress: 1/100
  2. progress: 2/100
  3. progress: 3/100
  4. ...

There are lots of options for telling Gooey about progress as your program is running. Checkout the Gooey Examples repository for more detailed usage and examples!

Elapsed / Remaining Time

Gooey also supports tracking elapsed / remaining time when progress is used! This is done in a similar manner to that of the project tqdm. This can be enabled with timing_options, the timing_options argument takes in a dictionary with the keys show_time_remaining and hide_time_remaining_on_complete. The default behavior is True for show_time_remaining and False for hide_time_remaining_on_complete. This will only work when progress_regex and progress_expr are used.

  1. @Gooey(progress_regex=r"^progress: (?P<current>\d+)/(?P<total>\d+)$",
  2. progress_expr="current / total * 100",
  3. timing_options = {
  4. 'show_time_remaining':True,
  5. 'hide_time_remaining_on_complete':True,
  6. })

Customizing Icons

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 Gooey decorator.

  1. @Gooey(program_name='Custom icon demo', image_dir='/path/to/my/image/directory')
  2. def main():
  3. # rest of program

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:

  • program_icon.png
  • success_icon.png
  • running_icon.png
  • loading_icon.gif
  • config_icon.png
  • error_icon.png

Packaging

Thanks to some awesome contributors, packaging Gooey as an executable is super easy.

The tl;dr pyinstaller version is to drop this build.spec into the root directory of your application. Edit its contents so that the APPPNAME and name are relevant to your project and the pathex value points to your applications root, then execute pyinstaller -F --windowed build.spec to bundle your app into a ready-to-go executable.

Detailed step by step instructions can be found here.

Screenshots

Flat Layout Column Layout Success Screen Error Screen Warning Dialog

| GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图48
| GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图49
| GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图50
| GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图51
| GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图52
|
| Custom Groups | Tabbed Groups | Tabbed Navigation | Sidebar Navigation | Input Validation |
| —- | —- | —- | —- | —- |
| GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图53
| GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图54
| GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图55
| GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图56
| GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图57
|


Wanna help?

Code, translation, documentation, or graphics? All pull requests are welcome. Just make sure to checkout the contributing guidelines first.

About

Turn (almost) any Python command line program into a full GUI application with one line

Resources

Readme

License

MIT license

Stars

16.2k stars

Watchers

278 watching

Forks

876 forks

Releases 9

[

Gooey 1.0.8.1 Latest

on 13 Jun 2021

](/chriskiehl/Gooey/releases/tag/1.0.8.1)

+ 8 releases

Packages 0

No packages published

Used by 513

[

  • GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图58
  • GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图59
  • GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图60
  • GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图61
  • GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图62
  • GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图63
  • GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图64
  • GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图65
  • 505](/chriskiehl/Gooey/network/dependents?package_id=UGFja2FnZS01MjE4MTIxOQ%3D%3D)

Contributors 87

  • GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图66
  • GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图67
  • GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图68
  • GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图69
  • GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图70
  • GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图71
  • GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图72
  • GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图73
  • GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图74
  • GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图75
  • GitHub - chriskiehl/Gooey: Turn (almost) any Python command line program into a full GUI application with one line - 图76

+ 76 contributors

Languages

You can’t perform that action at this time.

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.

×

拖拽到此处

图片将完成下载

由 AIX 智能下载器 (图片 / 视频 / 音乐 / 文档) 提供
https://github.com/chriskiehl/Gooey#table-of-contents