Package: tooey
TooeyTurn any python console script into an interactive TUI application.
Tooey is similar to (and inspired by)Gooey, but keeps you in the terminal.Without Tooey 😕With Tooey 🎉InstallationInstall Tooey fromPyPiviapip:python -m pip install tooeyGetting startedDecorate your script'sargparsefunction with@Tooey, then run the script with or without any of its arguments.
You'll be prompted interactively in the terminal to enter each argument.
After this the script will continue as normal.ExampleThe following python script requests and then prints three arguments.
The method that handles command line arguments is decorated with@Tooey.importargparsefromtooeyimportTooey@Tooeydefmain():parser=argparse.ArgumentParser()parser.add_argument('positional',nargs=1,help='A positional argument requiring one value')parser.add_argument('--named-choices',nargs=2,type=int,choices=range(1,5),help='A named argument requiring two integers from a given list of choices')parser.add_argument('--store-true',action='store_true',help='A store_true argument')print(parser.parse_args())main()Tooey automatically turns this into an interactive prompt for each argument.ConfigurationTooey will automatically inject itself into any decorated functions wheneversys.isatty()isTrue.If you would like to override this behaviour and disable Tooey when running a script, add the additional parameter--ignore-tooeywhen running, or set an environment variableIGNORE_TOOEY.
For example, Tooey will ignore any decorated methods in this script:$pythontooey_example.pyval1--named-choices13--ignore-tooeyConversely, if you would like to force Tooey to inject itself into decorated functions even when it does not detect a terminal-like environment, add the additional parameter--force-tooeywhen running, or set an environment variableFORCE_TOOEY.
For example, Tooey will still run in the following script:$FORCE_TOOEY=1pythontooey_example.pyval1--named-choices13|sortUsing alongside GooeyIt can be useful to decorate methods with both@Tooeyand@Gooeyso that scripts can be run flexibly depending on context.
To avoid conflicts, if both decorators are present for a single method, Tooey makes sure that only one of them is active.
Which one is chosen depends on the order in which you add their decorators, with the decorator closest to the function taking priority:@Gooey@Tooeydefmain_tooey():# Here Tooey is activated and Gooey is ignored# To force Gooey to be used instead, pass the `--ignore-tooey` command line option[...]@Tooey@Gooeydefmain_gooey():# Here Gooey is activated and Tooey is ignored# To force Tooey to be used instead, pass the `--ignore-gooey` command line option[...]Regardless of decorator order, you can always use the command line parameters--ignore-tooeyand--ignore-gooeyto switch behaviour, as outlined in the example above.
If Gooey is present (and not ignored) it will take precedence over the the--force-tooeyparameter.
Please note that due to the nature of Gooey's interaction with command line arguments, complex scripts with multiple Gooey decorators or unusual configurations may not be fully compatibile with this approach, and it is advisable to test your script when using both Tooey and Gooey simultaneously.TestingTo run the Tooey tests and generate a coverage report, first clone this repository and open thetestsdirectory in a terminal, then:python -m pip install gooeypython -m coverage run -m unittestpython -m coverage html --include '*/tooey/*' --omit '*test*'Inspirations and alternativesGooeyadds a GUI interface to (almost) any scriptGooeyWrapperextends Gooey to make switching between the command line and Gooey a little more seamlessClicksupports command line options that auto-prompt when missingLicenseApache 2.0