Skip to main content

No project description provided

Project description

CrossFileDialog

A Python wrapper for opening files and folders with the native file dialog.

Makes it easy to prompt the user with a native filepicker on all supported platforms.

Currently supports:

  • GTK (via PyGObject, Zenity)
  • KDE (via KDialog)
  • Qt5/6 (via pyqt5/pyqt6)
  • Windows 2000 and newer (via PyWin32)

Note

Guys, I really don't know why, but why does QT and Kdialog have the same UI in my computer? Can someone who knows open an issue and explain it to me? Thank you!

Edit: The explanation has been provided in this issue comment.

If you know how to add the file picker for MacOS, please consider doing so and make a pull request for it.

Basic API usage

from crossfiledialog import file_dialog

CrossFileDialog = file_dialog(["zenity"])

filename = CrossFileDialog.open_file()
multiple_filenames = CrossFileDialog.open_multiple()
save_filename = CrossFileDialog.save_file()
foldername = CrossFileDialog.choose_folder()

Documentation

file_dialog(picker_preference: Optional[list[str]] = None) -> BaseFileDialog

From a list of (optional) file picker preferences, return the first available implementation.

Args:

  • picker_preference (Optional[list[str]], optional): Order of precedence for picking the file picker implementations. Defaults to None.

Raises:

  • NoImplementationFoundException: Raise when no implementation is found from the list of preferences
  • NoImplementationFoundException: Raise when no implementation is found for the current platform

Returns: BaseFileDialog: File picker class.


CrossFileDialog.open_file(title, start_dir, filter) -> str

Open a file selection dialog for selecting a file.

Args:

  • title (str, optional): The title of the file selection dialog. Default is 'Choose a file'
  • start_dir (str, optional): The starting directory for the dialog.
  • filter (str | list[str | list[str] | dict[str, str]] | dict[str, str | list[str]], optional): The filter for file types to display. For an example, head to documentation the of crossfiledialog.utils.filter_processor.

Returns: Optional[str]: The selected file's path.

Example: result = open_file(title="Select a file", start_dir="/path/to/starting/directory", filter="*.txt")


CrossFileDialog.open_multiple(title, start_dir, filter) -> list[str]

Open a file selection dialog for selecting multiple files.

Parameters:

  • title (str, optional) — The title of the file selection dialog. Default is 'Choose one or more files'
  • start_dir (str, optional) — The starting directory for the dialog.
  • filter (str, list, dict, optional) — The filter for file types to display. It can be either:
    • a single wildcard (e.g.: "*.py", all files are displayed ending .py)
    • a list of wildcards (e.g.: ["*.py" "*.md"], all files are displayed ending either .py or .md)
    • a list of list optional one or more wildcards (e.g.: [["*.py", "*.md"], ["*.txt"]], user can switch between (.py, .md) and (.txt))
    • a dictionary mapping descriptions to wildcards (e.g.: {"PDF-Files": "*.pdf", "Python Project": ["\*.py", "*.md"]})

Returns:

  • list[str]: A list of selected file paths.

CrossFileDialog.save_file(title, start_dir) -> str

Open a save file dialog.

Parameters:

  • title (str, optional) — The title of the file selection dialog. Default is 'Enter the name of the file to save to'
  • start_dir (str, optional) — The starting directory for the dialog.

Returns:

  • str: The selected file's path for saving.

CrossFileDialog.save_file(title, start_dir) -> str

Open a folder selection dialog.

Parameters:

  • title (str, optional) — The title of the file selection dialog. Default is 'Choose a folder'
  • start_dir (str, optional) — The starting directory for the dialog.

Returns:

  • str: The selected folder's path.

Getting Started

Install the following dependencies

In Linux, run the following command:

just bootstrap

or:

python3.12 -m venv --system-site-packages .venv
source .venv/bin/activate
rm -rf poetry.lock
poetry install --no-root --with dev

Linting

In any platform, run the following command:

just lint

or:

python -m no_implicit_optional crossfiledialog
python -m black -q school
python -m ruff check crossfiledialog --fix

Attribution

Thank you so much to Maikel Wever and 3ricsonn for allowing their Github repository to be relicensed to LGPL 3.0 so that I can use this library in my own proprietary projects.

My deepest gratitude also goes to Benjamin Auquite for letting me use snippets of their code from a pull request they made to the Toga repository, and to Russell Keith-Magee (the owner of said repository) and Malcolm Smith for the advice regarding using BSD 3-Clause licensed code to an LGPL licensed codebase.

Thank you so much!

License

This software is licensed under the GNU LGPL 3.0.

Copyright (c) 2020-2025 Maikel Wever
Copyright (c) 2024-2025 whinee

Portions of this codebase, specifically crossfiledialog/file_pickers/win32.py, are derived from Toga, which is licensed under the BSD 3-Clause License.

Copyright (c) 2014 Russell Keith-Magee.

See LICENSE.md for full details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

whines_crossfiledialog-1.0.0.tar.gz (24.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

whines_crossfiledialog-1.0.0-py3-none-any.whl (23.4 kB view details)

Uploaded Python 3

File details

Details for the file whines_crossfiledialog-1.0.0.tar.gz.

File metadata

  • Download URL: whines_crossfiledialog-1.0.0.tar.gz
  • Upload date:
  • Size: 24.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.8 Linux/6.12.11-100.fc40.x86_64

File hashes

Hashes for whines_crossfiledialog-1.0.0.tar.gz
Algorithm Hash digest
SHA256 43875a93656fe1f0355cace33acd76a955c7fe725debabe06c2241a08f311396
MD5 f70302045be4b967f5aee4c3728b1cf5
BLAKE2b-256 8e60f9f6520c7d3108589fab2a80bd213af01bac2b10a7b4a7ee871bbaf97f1f

See more details on using hashes here.

File details

Details for the file whines_crossfiledialog-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: whines_crossfiledialog-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 23.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.8 Linux/6.12.11-100.fc40.x86_64

File hashes

Hashes for whines_crossfiledialog-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4ceefbbdf776b45e4fb34a3b75686f3de7d0499aab2ef1a39177caabdda59e27
MD5 fd82892e75e5245dcc7bfd56acdb1c5b
BLAKE2b-256 ea4711feda313be7056991387b3ba726a218932f29ace2eefabf5aca6e0d7480

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page