question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add --ignore-gooey option to README

See original GitHub issue

Hi!

Not a bug so much as an oversight in the readme perhaps?

I spent quite a long time agonising about how to make a CLI interface and a GUI option play nicely together. I knew there had to be an elegant solution somewhere (such as switching between framework/non-framework python.

I noticed in the STDOUT while the program ran however, that it spits out a verbose version of the full call to python which highlighted the --ignore-gooey option which suffices for this perfectly - but there is no mention of this in the README, or any docs I could find.

Could I suggest/request this be highlighted somewhere (and perhaps a more full guide with it if there are other things to consider when using --ignore-gooey that I’m not aware of).

Otherwise, love the package!

Joe

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
zertrincommented, Sep 23, 2019

I also have this, so if you run my app with no parameters you get the GUI, but if you run in with any parameters you can the CLI version; so this is backwards compatible with the tool before gooey

    if len(sys.argv)>=2:
        if not '--ignore-gooey' in sys.argv:
            sys.argv.append('--ignore-gooey')

This is exactly what I needed (only start Gooey if the script is started without argument, otherwise operate as CLI). It is very simple and straightforward, however there is a caveat that took me some time to understand:

⚠️ you need to place the code before the @Gooey() decorator.

So for example, you can do like this:

import sys
from gooey import Gooey, GooeyParser
# other imports...

# this needs to be *before* the @Gooey decorator!
# (this code allows to only use Gooey when no arguments are passed to the script)
if len(sys.argv) >= 2:
    if not '--ignore-gooey' in sys.argv:
        sys.argv.append('--ignore-gooey')

@Gooey(options=...)
def main():
    parser = ....
    # rest of your code


if __name__ == '__main__':
    main()

Initially I tried putting it in the if __name__ == '__main__' section, but that won’t work.

if __name__ == '__main__':
    # this does NOT work, it is executed too late
    if len(sys.argv) >= 2:
        if not '--ignore-gooey' in sys.argv:
            sys.argv.append('--ignore-gooey')
    main()
4reactions
eladeyal-intelcommented, Jun 19, 2019
  1. In Windows I was able to use sys.stdout.isatty().
import sys
def prompt_for_one_of(prompt_text, *args):
    if sys.stdout.isatty():
        while True:
            print(prompt_text)
            for i,s in enumerate(args): print(f'{i+1}. {s}')
            i=input()
            try:
                return args[int(i)-1]
            except:
                pass
        
    else:
        import PySimpleGUI as sg 
        window=sg.Window(Path(__file__).stem,
                         [ [sg.Text(prompt_text)],
                           [sg.Button(t) for t in args] ])
        event, values = window.Read()
        window.Close()
        return event

response=prompt_for_one_of('Would you like to save?', 'Yes', 'No')

  1. I also have this, so if you run my app with no parameters you get the GUI, but if you run in with any parameters you can the CLI version; so this is backwards compatible with the tool before gooey
    if len(sys.argv)>=2:
        if not '--ignore-gooey' in sys.argv:
            sys.argv.append('--ignore-gooey')
Read more comments on GitHub >

github_iconTop Results From Across the Web

User Data Options - ReadMe Documentation
isAdmin, Adds links to the dash, and allows access to disabled sections, No (default false). isReadOnly, Allows user to access project with "Project...
Read more >
How to add images to README.md on GitHub? - Stack Overflow
It can be a good alternative to GIF images. ![image description](relative/path/in/repository/to/image.svg) OR <img ...
Read more >
Github Readme Cheatsheet - Level Up Coding
To add a Horizontal Rule In Readme we can use --- or *** or <hr> . ... of their choice, letting them know...
Read more >
9.5 Setting up a project in RStudio - An Introduction to R
gitignore files have now been pushed to GitHub from your local repository. The last thing we need to do is create and add...
Read more >
How to Create an Impressive GitHub Profile README - SitePoint
We'll also add a style parameter to the above URL. There are various styling options available, the details of which you can find...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found