Gooey icon indicating copy to clipboard operation
Gooey copied to clipboard

Gooey DirChooser widget - spaces in filepaths cause values to be assigned to the wrong args in namespace

Open GenevieveBuckley opened this issue 6 years ago • 4 comments

Hello There, Future Issue Creator!

If you've found a bug, make sure to include the following:

  • [x] OS: Mac High Sierra 10.13.5
  • [x] Python Version: Python 3.6.5 |Anaconda, Inc.| (default, Apr 26 2018, 08:42:37)
  • [x] Gooey Version: Gooey current master branch installed from source
git clone https://github.com/chriskiehl/Gooey.git
python setup.py install
  • [x] Thorough description of problem If you include two DirChooser widgets in a Gooey interface and select some directory paths containing spaces, this will cause parts of the directory path that should be assigned to the second variable to get shifted into the variable from the first DirChooser widget.

For example, if I select these two directories from Gooey: input_directory = "\path with spaces one\subdir with spaces one\" output_directory = "\path with spaces two\subdir with spaces two\" - [x] Expected Behavior I expect this namespace to be returned from the parsed arguments:

Namespace(input_directory=['/path', 'with', 'spaces', 'one/subdir with spaces one', '/path', 'with', 'spaces', 'two/subdir', 'with', 'spaces', 'two'], output_directory=['two'])

but I'd settle for this type of expected behaviour: Namespace(input_directory=['/path', 'with', 'spaces', 'one/subdir with spaces one'], output_directory=['/path', 'with', 'spaces', 'two/subdir', 'with', 'spaces', 'two'])

[x] Actual Behavior Instead, I get this. You can see that parts of the output directory filepath have been shifted into the input directory argument namespace.

Namespace(input_directory=['/path', 'with', 'spaces', 'one/subdir with spaces one', '/path', 'with', 'spaces', 'two/subdir', 'with', 'spaces'], output_directory=['two'])
  • [x] A minimal code example -- preferably copy/pastable in the issue itself (less time figuring out how to run your code == more time debugging!) minimal_example.py
from gooey.python_bindings.gooey_decorator import Gooey as gooey
from gooey.python_bindings.gooey_parser import GooeyParser

__DESCR__ = ('Some description.')

@gooey(default_size=(700, 400), navigation='TABBED')
def main():
    parser = GooeyParser(prog='Podocyte Profiler', description=__DESCR__)
    parser.add_argument('input_directory', widget='DirChooser', nargs='+',
                        help='Folder containing files for processing.')
    parser.add_argument('output_directory', widget='DirChooser', nargs='+',
                        help='Folder to save output analysis files.')
    args = parser.parse_args()
    print(args)
    joined_input_directory = ' '.join(args.input_directory)
    joined_output_directory = ' '.join(args.output_directory)
    print(joined_input_directory)
    print(joined_output_directory)


if __name__ == '__main__':
    main()
  • [x] Anything else you may think will be helpful Example directory tree structure shown here:
├── path\ with\ spaces\ one
│   ├── subdir\ with\ spaces\ one
│   └── subdir_without_spaces_one
├── path\ with\ spaces\ two
│   ├── subdir\ with\ spaces\ two
│   └── subdir_without_spaces_two
├── path_without_spaces_one
│   ├── subdir\ with\ spaces\ one
│   └── subdir_without_spaces_one
└── path_without_spaces_two
    ├── subdir\ with\ spaces\ two
    └── subdir_without_spaces_two

Thanks! ^_^

GenevieveBuckley avatar Jun 28 '18 04:06 GenevieveBuckley

I haven't run into this problem, despite having several DirChooser widgets in my app. But in my case, I'm using type=pathlib.Path kwarg which automatically casts the resulting string to a Path object.

PeterKucirek avatar Feb 26 '19 16:02 PeterKucirek

For people experiencing this issue, the way I got around it was by passing gooey_options validator into the GooeyParser's add_argument method. I feel like there should be a better solution than this. It forces the user to wrap their input with single or double quotations, which isn't an ideal user experience in my opinion. To the best of my knowledge there is no other way to deal with spaces in directory/file names which is unfortunate. Wish it was better documented.


gooey_options={
        'validator': {
            'test': 'not re.findall(r\"\\s\", user_input) or re.findall(r"^\\\'[^\\"\\\']+\\\'$", user_input) or re.findall(r"^\\\"[^\\\"\\\']+\\\"$", user_input)',
            'message': 'Input contains spaces and must be surrounded by quotation marks'
        }
    }

parser.add_argument('path', metavar='Output Path', nargs=1, type=str,
                        help='Path of the output file',
                        gooey_options=gooey_options, widget="DirChooser")

spl85 avatar May 08 '21 02:05 spl85

I ran into this issue as well with the "FileChooser." It took me a while to track down what was going on, but it seems that using the FileChooser Gooey only passed the part of my path before the space as the argument value.

harrislapiroff avatar Sep 25 '22 05:09 harrislapiroff