Dialogs
openseize.file_io.dialogs
A collection of dialogs and message boxes.
This module contains the following functions
standard:
A unified tkinter filedialog that gracefully destroys itself when
a selection is complete or the window is closed.
message:
A unified tkinter messagebox that gracefully destroys itself when the
window is closed.
matching:
A dialog that uses regex patterns to match file stems of two sets of
file paths selected by path selection dialogs, or a directory dialog or
by manually specifying a directory containing all paths to match.
openseize.file_io.dialogs.standard(kind, **options)
Opens a tkinter modal file dialog & returns a Path instance or list of Path instances.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kind |
str
|
Name of a tkinter file dialog. |
required |
options |
str
|
|
{}
|
Returns:
Type | Description |
---|---|
Union[Path, List[Path]]
|
A Path instance or list of Path instances. |
Source code in openseize/file_io/dialogs.py
openseize.file_io.dialogs.message(kind, **options)
Opens a tkinter modal message box & returns a string response.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kind |
str
|
Name of a tkinter messagebox (eg. 'askyesno') |
required |
options |
str
|
Any valid option for the message box except for 'parent'. |
{}
|
Returns:
Type | Description |
---|---|
A subset of (True, False, OK, None, Yes, No). |
Source code in openseize/file_io/dialogs.py
openseize.file_io.dialogs.matching(pattern, kind=None, dirpath=None, **options)
A dialog that regex pattern matches Path stems of two sets of files.
This dialog can match two sets of files from two separate dialogs or match two sets of files contained in a single directory specified by a single dialog or a manually supplied directory path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pattern |
str
|
A regex pattern raw string used to perform match. |
required |
kind |
Optional[str]
|
A string indicating if dialog should be of type 'askdirectory' or 'askopenfilenames'. If 'askdirectory' all the files to match must be in a single dir. If None a dirpath must be supplied. |
None
|
dirpath |
Optional[Union[str, Path]]
|
A optional path to a directory. If given, kind argument is ignored and no dialogs are opened. It is assumed that all paths to match are in the given dir. |
None
|
**options |
|
{}
|
Returns:
Type | Description |
---|---|
List[Tuple[Path, Path]]
|
A list of matched path instance tuples. |
Examples:
>>> # This example matches by directory without dialoging.
>>> import tempfile
>>> # make a temp dir containing 2 .edf & 2 .txt files
>>> tempdir = tempfile.mkdtemp()
>>> paths = [Path(tempdir).joinpath(x)
... for x in ['eeg_1.edf', 'eeg_2.edf']]
>>> others = [Path(tempdir).joinpath(x)
... for x in ['annotation_1.txt', 'annotation_2.txt']]
>>> x = [path.touch() for path in paths+others]
>>> # match the files stored in the dir
>>> result = matching(r'\d+', dirpath=Path(tempdir))
>>> # matching does not guarantee ordering so chk set equivalence
>>> set(result) == set(zip(paths, others))
True