kopia lustrzana https://github.com/crahan/ipyfilechooser
Added support for multiple fnmatch filters
rodzic
09687ebfdb
commit
32ea5b05a8
|
@ -95,6 +95,10 @@ fc.selected_filename
|
|||
|
||||
## Release notes
|
||||
|
||||
### 0.4.2
|
||||
|
||||
- Added ability to specify a list of `fnmatch` pattern strings for `filter_pattern`
|
||||
|
||||
### 0.4.1
|
||||
|
||||
- Fixed issue with `select_default` not being applied on `reset`
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
from .filechooser import FileChooser
|
||||
|
||||
__version__ = '0.4.1'
|
||||
__version__ = '0.4.2'
|
||||
|
|
|
@ -32,6 +32,19 @@ def has_parent(path):
|
|||
return os.path.basename(path) != ''
|
||||
|
||||
|
||||
def match_item(item, filter_pattern):
|
||||
"""Check if a string matches one or more fnmatch patterns."""
|
||||
idx = 0
|
||||
found = False
|
||||
patterns = filter_pattern if isinstance(filter_pattern, list) else [filter_pattern]
|
||||
|
||||
while idx < len(patterns) and not found:
|
||||
found |= fnmatch.fnmatch(item, patterns[idx])
|
||||
idx += 1
|
||||
|
||||
return found
|
||||
|
||||
|
||||
def get_dir_contents(
|
||||
path,
|
||||
show_hidden=False,
|
||||
|
@ -52,7 +65,7 @@ def get_dir_contents(
|
|||
dirs.append(item)
|
||||
elif append and not show_only_dirs:
|
||||
if filter_pattern:
|
||||
if fnmatch.fnmatch(item, filter_pattern):
|
||||
if match_item(item, filter_pattern):
|
||||
files.append(item)
|
||||
else:
|
||||
files.append(item)
|
||||
|
|
|
@ -113,6 +113,16 @@
|
|||
"fdialog.filter_pattern = '*.txt'"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Set multiple file filter patterns (uses https://docs.python.org/3/library/fnmatch.html)\n",
|
||||
"fdialog.filter_pattern = ['*.jpg', '*.png']"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
|
|
2
setup.py
2
setup.py
|
@ -10,7 +10,7 @@ def read(fname):
|
|||
|
||||
setup(
|
||||
name='ipyfilechooser',
|
||||
version='0.4.1',
|
||||
version='0.4.2',
|
||||
author='Thomas Bouve (@crahan)',
|
||||
author_email='crahan@n00.be',
|
||||
description=(
|
||||
|
|
Ładowanie…
Reference in New Issue