crahan / ipyfilechooser

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

Filter files by multiple file extensions #34

Closed giswqs closed 3 years ago

giswqs commented 3 years ago

Is it possible to filter files by multiple file extensions (e.g., .png, .jpg)? It seems fc.filter_pattern can only support one file extension.

crahan commented 3 years ago

For now it's based on fnmatch.fnmatch which has a limited matching capability. I'll put true regex support on the todo list.

giswqs commented 3 years ago

That would be awesome! Many thanks.

crahan commented 3 years ago

@giswqs question as I start to add this. I don't want to break the current implementation with fnmatch so I want to double check if you require any additional use cases beyond multiple file extensions or fnmatch patterns?

Adding regex support without breaking the current implementation would mean adding a new parameter, but if it's just a matter of supporting multiple fnmatch patterns, I can easily extend the current implementation of a single string by also allowing for a list of fnmatch patterns, like ['*.png', '*.gif', '*.jpg'].

giswqs commented 3 years ago

Allowing a list of fnmatch patterns should be sufficient. Thanks.

giswqs commented 3 years ago

My user case is to allow users to select files with specific file extensions to perform geospatial analysis. At the moment, I could not specify the file pattern if I want to allow multiple file extensions.

https://github.com/giswqs/whiteboxgui

https://user-images.githubusercontent.com/5016453/105920916-2f072600-6006-11eb-92e4-033f949701ba.mp4

crahan commented 3 years ago

Thanks for the quick response!

crahan commented 3 years ago

@giswqs apologies for the delay on this. Version 0.4.2 (https://github.com/crahan/ipyfilechooser/releases/tag/v0.4.2) has now been pushed to PyPi and conda-forge. You can still specify a single fnmatch string, but the filter_pattern parameter now also supports a list of multiple fnmatch strings.

giswqs commented 3 years ago

Fantastic! Will test it shortly. Thanks a lot for your efforts!