chriskiehl / Gooey

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

MultiFileChooser/MultiDirChooser don't handle list default values correctly #758

Open JozsefKutas opened 2 years ago

JozsefKutas commented 2 years ago

This is a seperate issue to the one I previously raised (#756), but it also concerns the handling of list default/initial values.

When paths are selected MultiFileChooser and MultiDirChooser, the selected paths are separated using the OS path separator in the input box. This concatenated string is split by formatter.multiFileChooser before being passed back to the client program, so the client program receives a list of paths. If a list of paths is used as a default value/initial value for the field, then I'd expect the inverse transformation to be applied: the paths should be joined by the OS path separator.

At the moment, argparse_to_json.textinput_with_nargs_and_list_default only handles vanilla text inputs, and so the default list of paths is shown as a list in the input box. If the value isn't changed, it is passed back to the program as a singleton list with the only element being a stringified list of paths.

from gooey import Gooey, GooeyParser

@Gooey
def main():
    parser = GooeyParser(description='Test')
    parser.add_argument('multi_file_choice', nargs='+', default=['a.txt', 'b.txt'],
                        widget='MultiFileChooser')
    args = parser.parse_args()
    print(args.multi_file_choice)

main()

image

image

ChenglongMa commented 9 months ago

Using 'initial_value' can solve this problem.

gooey_options={
  'initial_value': os.getcwd(),
}