urifilebrowser package

This package allows to select files and directories in a cross-platform way. It has been tested on Android and Windows, but should also work on Linux and macOS.

Example:

from tatogalib.uri_io.urifilebrowser import UriFileBrowser
from tatogalib.uri_io.urifile import UriFile

fb = UriFileBrowser()
initial = "content://com.android.externalstorage.documents/document/primary%3ADaten"
urilist = await fb.open_file_dialog(
    "Choose a file",
    file_types=["xlsx","pdf","rar"],
    multiselect=True,
    initial_uri=initial
)
if len(urilist) > 0:
    urifile = UriFile(urilist[0])

UriFileBrowser class

class tatogalib.uri_io.urifilebrowser.UriFileBrowser(fnLog=None)

Creates a UriFileBrowser which allows to browse for files and folders

Parameters:

fnLog (callable) – The callable which is called from the log method It expects a string parameter

log(message)

Logs a message to the user code if fnLog was passed to the constructor

Parameters:

message (str) – The message to be logged

async open_file_dialog(title, initial_uri=None, file_types=None, multiselect=False)

Opens an open file dialog and returns the chosen files as a list of URI-strings. Returns [] if nothing has been chosen

Parameters:
  • title (str) – The title is ignored on Android

  • initial_uri (str or None) – The initial location shown in the file chooser. On Android, this must be a content URI-string. On desktops, it must be a file URI-string

  • file_types (list[str] or None) – The file types allowed to select. Must be file extensions e.g. [“doc”, “pdf”].

  • multiselect (bool) – If True, then several files can be selected

Returns:

the URI-strings of the selected files

Return type:

list[str]

async save_file_dialog(title, suggested_filename, file_types=None)

Opens a file save dialog and returns the chosen file as a URI-string. Returns None if nothing has been chosen

Parameters:
  • title (str) – The title for the dialog On Android, this is ignored

  • suggested_filename (str) – The filename to suggest

  • file_types (list[str] or None) – The file types allowed to select. Must be file extensions e.g. [“doc”, “pdf”].

Returns:

the URI-string of the selected file or None

Return type:

str or None

async select_folder_dialog(title, initial_uri=None)

Opens a select folder dialog and returns the chosen folder as a URI-string. Returns None if nothing has been chosen

Parameters:
  • title (str) – The title is ignored on Android

  • initial_uri (str or None) – The initial location shown in the file chooser. On Android, this must be a content URI-string. On desktops, it must be a file URI-string

Returns:

the URI-string of the selected folder

Return type:

str or None