hesseflux.fgui

fgui : GUI dialogs to choose files and directories using Tkinter.

This module was written by Matthias Cuntz while at Department of Computational Hydrosystems, Helmholtz Centre for Environmental Research - UFZ, Leipzig, Germany, and continued while at Institut National de Recherche pour l’Agriculture, l’Alimentation et l’Environnement (INRAE), Nancy, France.

Copyright (c) 2015-2020 Matthias Cuntz - mc (at) macu (dot) de Released under the MIT License; see LICENSE file for details.

  • Written Jun 2014 by Matthias Cuntz (mc (at) macu (dot) de)
  • Added directories_from_gui, Oct 2015, Matthias Cuntz
  • Using numpy docstring format, May 2020, Matthias Cuntz

The following functions are provided

directory_from_gui([initialdir, title]) Opens dialog to select directory.
directories_from_gui([initialdir, title]) Open dialog to select several directories.
file_from_gui([initialdir, title, multiple]) Wrapper for files_from_gui() with multiple=False, i.e.
files_from_gui([initialdir, title, multiple]) Open dialog to select one or several files.
directory_from_gui(initialdir='.', title='Choose directory.')[source]

Opens dialog to select directory.

Parameters:
  • initialdir (str, optional) – Initial directory, in which opens GUI (default: ‘.’)
  • title (str, optional) – Title of GUI (default: ‘Choose directory.’)
Returns:

Selected directory.

Return type:

str

Examples

if not idir:
    idir = directory_from_gui()
    if not idir:
        raise ValueError('Error: no directory given.')
directories_from_gui(initialdir='.', title='Choose one or several directories.')[source]

Open dialog to select several directories.

Parameters:
  • initialdir (str, optional) – Initial directory, in which opens GUI (default: ‘.’)
  • title (str, optional) – Title of GUI (default: ‘Choose one or several directories.’
Returns:

Selected directories.

Return type:

list

Examples

if not dirs:
    dirs = directories_from_gui()
    if not dirs:
        raise ValueError('Error: no directories given.')
file_from_gui(initialdir='.', title='Choose file', multiple=False)[source]

Wrapper for files_from_gui() with multiple=False, i.e. open dialog to select one file.

Examples

if not file:
    file = file_from_gui()
    if not file:
        raise ValueError('Error: no input file given.')
files_from_gui(initialdir='.', title='Choose file(s).', multiple=True)[source]

Open dialog to select one or several files.

Parameters:
  • initialdir (str, optional) – Initial directory, in which opens GUI (default: ‘.’)
  • title (str, optional) – Title of GUI (default: ‘Choose file(s).’)
  • multiple (bool, optional) – True: allow selection of multiple files (default). False: only one single file possible to select.
Returns:

Selected files.

Return type:

list

Note

It always returns a list even with multiple=False.

Examples

if not files:
    files = files_from_gui()
    if not files:
        raise ValueError('Error: no input file(s) given.')