crahan / ipyfilechooser

Python file chooser widget for use in Jupyter/IPython in conjunction with ipywidgets
MIT License
103 stars 20 forks source link

Can not change path up hierarchy levels, if default_path is set with trailing '/' #59

Closed tombelpasso closed 3 years ago

tombelpasso commented 3 years ago

I am running on Windows 10 and Python 3.8.6.

If I set the default_path that has trailing '/' on a chooser, the listbox only shows the default path and not the paths above.

If I remove the trailing '/' it allows changing to full hierarchy .

Please document this behavior.

crahan commented 3 years ago

Thanks for reporting. On initialization I strip any trailing OS separators using path.rstrip(os.path.sep). On Windows os.path.sep only matches a backslash and so defining your path on Windows with forward slashes will fail to remove any trailing path separators.

I'll treat this as a bug and will update the code to use os.path.normpath to normalize the path which will also remove any trailing path separators (instead of using path.rstrip(os.path.sep)).

As a workaround until I get the fix pushed out, simply wrap the path in os.path.normpath:

fdialog = FileChooser(
    os.path.normpath("c:/users/crahan/Documents/"),
    filename='test.txt',
)
crahan commented 3 years ago

https://github.com/crahan/ipyfilechooser/tree/width_and_fixes now has the updated code. Feel free to use that branch in your project until I push out a new build to pypi.org and Condaforge.

crahan commented 3 years ago

v0.5.0 has now been published to PyPi. Conda-forge feedstock release will follow shortly. Thanks again for reporting this issue and helping to make the project better!