chriskiehl / Gooey

Turn (almost) any Python command line program into a full GUI application with one line
MIT License
20.5k stars 1.01k forks source link

Mutually exclusive radio buttons require double click on Mac to trigger #272

Closed abulka closed 5 years ago

abulka commented 6 years ago

Mutually exclusive radio option buttons don't trigger when clicked - they need to be double clicked (weird, I know) to work.

Mac High Sierra, Python 3.6.4 python.org, Gooey Version 1.0.0

Expected Behaviour

When I create two mutual exclusive options, the Gooey UI correctly displays two radio buttons. I expect that clicking on a radio button will select it and deselect the other (mutually exclusive behaviour).

Actual Behaviour

Nothing happens when I click on either radio button. I need to double click on a radio button for the state to change. The mutual exclusive behaviour works ok - its the need to double click that is not right.

Actual full runnable example:

    import argparse
    from gooey import Gooey
    from gooey import GooeyParser

    @Gooey
    def main():
        parser = GooeyParser(description="Convert python to rpn for hp41s/free42/dm42")

        group = parser.add_mutually_exclusive_group()
        group.add_argument("-v", "--verbose", action="store_true")
        group.add_argument("-q", "--quiet", action="store_true")

        parser.add_argument('filename', help="name of the file to process", widget='FileChooser')
        parser.add_argument("-n", "--nolinenum", action='store_true', help="do not generate line numbers")
        parser.add_argument("-c", "--comments", action='store_true', help="generate commants")
        args = parser.parse_args()

        def run():
            print('work done here...')

            if args.quiet:
                print(rpn)
            elif args.verbose:
                print('source is', source)
                print('rpn is', rpn)
            else:
                line_count = len(rpn.split('\n'))
                print(f'Generated {line_count} lines.')
                print(rpn)

        run()

    main()

Perhaps not a Gooey bug otherwise it would have been noticed. Maybe a weird interaction with Mac wxPython? Installing Gooey installed wxPython (4.0.0b1). Apologies if I'm doing something wrong with driving argparse, but it seems to work ok on the command line.

chriskiehl commented 6 years ago

Perhaps not a Gooey bug otherwise it would have been noticed.

Ha! If only...

Give this branch a quick run and let me know if it fixes your issue? It was an issue with the select/deselect logic when the Mutex groups were in an optional section.

pip install -U git+https://github.com/chriskiehl/Gooey/@issue-272-optional-radio-group-behavior

bradc commented 6 years ago

@chriskiehl I had a similar problem only the double clicking did nothing for me. I could only choose one radio widget and sometimes toggle it on or off.

I installed your patch and it seems to be working as expected now. Thank you.