Change filters

This commit is contained in:
Mauricio Baeza 2020-11-17 23:24:57 -06:00
parent c6ecd5a83f
commit 3d10072e9a
4 changed files with 9 additions and 15 deletions

View File

@ -50,7 +50,7 @@ from functools import wraps
from pathlib import Path
from pprint import pprint
from string import Template
from typing import Any
from typing import Any, Union
from urllib.request import Request, urlopen
from urllib.error import URLError, HTTPError
@ -4248,15 +4248,11 @@ class Paths(object):
return path
@classmethod
def get_file(cls, init_dir: str='', filters=(), multiple: bool=False):
def get_file(cls, init_dir: str='', filters: str='', multiple: bool=False):
"""
init_folder: folder default open
multiple: True for multiple selected
filters: Example
(
('XML', '*.xml'),
('TXT', '*.txt'),
)
filters: 'xml' or 'xml,txt'
"""
if not init_dir:
init_dir = cls.documents
@ -4268,6 +4264,7 @@ class Paths(object):
file_picker.setMultiSelectionMode(multiple)
if filters:
filters = [(f.upper(), f'*.{f.lower()}') for f in filters.split(',')]
file_picker.setCurrentFilter(filters[0][0])
for f in filters:
file_picker.appendFilter(f[0], f[1])

Binary file not shown.

View File

@ -50,7 +50,7 @@ from functools import wraps
from pathlib import Path
from pprint import pprint
from string import Template
from typing import Any
from typing import Any, Union
from urllib.request import Request, urlopen
from urllib.error import URLError, HTTPError
@ -4248,15 +4248,11 @@ class Paths(object):
return path
@classmethod
def get_file(cls, init_dir='', filters=(), multiple=False):
def get_file(cls, init_dir: str='', filters: str='', multiple: bool=False):
"""
init_folder: folder default open
multiple: True for multiple selected
filters: Example
(
('XML', '*.xml'),
('TXT', '*.txt'),
)
filters: 'xml' or 'xml,txt'
"""
if not init_dir:
init_dir = cls.documents
@ -4268,6 +4264,7 @@ class Paths(object):
file_picker.setMultiSelectionMode(multiple)
if filters:
filters = [(f.upper(), f'*.{f.lower()}') for f in filters.split(',')]
file_picker.setCurrentFilter(filters[0][0])
for f in filters:
file_picker.appendFilter(f[0], f[1])

View File

@ -285,7 +285,7 @@ class Controllers(object):
@app.catch_exception
def cmd_explore_action(self, event):
file_name = app.paths.get_file(filters=(('TXT', '*.txt'),))
file_name = app.paths.get_file(filters='txt')
self.d.txt_search.value = file_name
app.debug(file_name)
return