|
| 1 | +tkfilebrowser |
| 2 | +============= |
| 3 | + |
| 4 | +|Release|_ |Linux| |Travis| |Codecov| |License| |Doc| |
| 5 | + |
| 6 | +tkfilebrowser is an alternative to tkinter.filedialog that allows the |
| 7 | +user to select files or directories. The GUI is written with tkinter but |
| 8 | +the look is closer to GTK and the application uses GTK bookmarks (the |
| 9 | +one displayed in nautilus or thunar for instance). This filebrowser |
| 10 | +supports new directory creation and filtype filtering. |
| 11 | + |
| 12 | +This module contains a general ``FileBrowser`` class which implements the |
| 13 | +filebrowser and the following functions, similar to the one in filedialog: |
| 14 | + |
| 15 | + * ``askopenfilename`` that allow the selection of a single file |
| 16 | + |
| 17 | + * ``askopenfilenames`` that allow the selection of multiple files |
| 18 | + |
| 19 | + * ``askopendirname`` that allow the selection a single folder |
| 20 | + |
| 21 | + * ``askopendirnames`` that allow the selection of multiple folders |
| 22 | + |
| 23 | + * ``asksaveasfilename`` that returns a single filename and give a warning if the file already exists |
| 24 | + |
| 25 | + |
| 26 | +The documentation is also available here: https://tkfilebrowser.readthedocs.io |
| 27 | + |
| 28 | +.. contents:: Table of Contents |
| 29 | + |
| 30 | + |
| 31 | +Requirements |
| 32 | +------------ |
| 33 | + |
| 34 | +- Linux |
| 35 | +- Python 2.7 or 3.x with tkinter + ttk, python-psutil and python-babel |
| 36 | + |
| 37 | + |
| 38 | +Installation |
| 39 | +------------ |
| 40 | + |
| 41 | +- Ubuntu: use the PPA `ppa:j-4321-i/ppa <https://launchpad.net/~j-4321-i/+archive/ubuntu/ppa>`__ |
| 42 | + |
| 43 | + :: |
| 44 | + |
| 45 | + $ sudo add-apt-repository ppa:j-4321-i/ppa |
| 46 | + $ sudo apt-get update |
| 47 | + $ sudo apt-get install python(3)-tkfilebrowser |
| 48 | + |
| 49 | + |
| 50 | +- Archlinux: |
| 51 | + |
| 52 | + the package is available on `AUR <https://aur.archlinux.org/packages/python-tkfilebrowser>`__ |
| 53 | + |
| 54 | + |
| 55 | +- With pip: |
| 56 | + |
| 57 | + :: |
| 58 | + |
| 59 | + $ pip install tkfilebrowser |
| 60 | + |
| 61 | + |
| 62 | +Documentation |
| 63 | +------------- |
| 64 | + |
| 65 | +* Optional keywords arguments common to each function |
| 66 | + |
| 67 | + - parent: parent window |
| 68 | + |
| 69 | + - title: the title of the filebrowser window |
| 70 | + |
| 71 | + - initialdir: directory whose content is initially displayed |
| 72 | + |
| 73 | + - initialfile: initially selected item (just the name, not the full path) |
| 74 | + |
| 75 | + - filetypes list: [("name", "\*.ext1|\*.ext2|.."), ...] |
| 76 | + only the files of given filetype will be displayed, |
| 77 | + e.g. to allow the user to switch between displaying only PNG or JPG |
| 78 | + pictures or dispalying all files: |
| 79 | + filtypes=[("Pictures", "\*.png|\*.PNG|\*.jpg|\*.JPG'), ("All files", "\*")] |
| 80 | + |
| 81 | + - okbuttontext: text displayed on the validate button, if None, the |
| 82 | + default text corresponding to the mode is used (either "Open" or "Save") |
| 83 | + |
| 84 | + - cancelbuttontext: text displayed on the button that cancels the |
| 85 | + selection. |
| 86 | + |
| 87 | + - foldercreation: enable the user to create new folders if True (default) |
| 88 | + |
| 89 | +* askopendirname |
| 90 | + |
| 91 | + Allow the user to choose a single directory. The absolute path of the |
| 92 | + chosen directory is returned. If the user cancels, an empty string is |
| 93 | + returned. |
| 94 | + |
| 95 | +* askopendirnames |
| 96 | + |
| 97 | + Allow the user to choose multiple directories. A tuple containing the absolute |
| 98 | + path of the chosen directories is returned. If the user cancels, |
| 99 | + an empty tuple is returned. |
| 100 | + |
| 101 | +* askopenfilename |
| 102 | + |
| 103 | + Allow the user to choose a single file. The absolute path of the |
| 104 | + chosen file is returned. If the user cancels, an empty string is |
| 105 | + returned. |
| 106 | + |
| 107 | +* askopenfilenames |
| 108 | + |
| 109 | + Allow the user to choose multiple files. A tuple containing the absolute |
| 110 | + path of the chosen files is returned. If the user cancels, |
| 111 | + an empty tuple is returned. |
| 112 | + |
| 113 | +* asksaveasfilename |
| 114 | + |
| 115 | + Allow the user to choose a file path. The file may not exist but |
| 116 | + the path to its directory does. If the file already exists, the user |
| 117 | + is asked to confirm its replacement. |
| 118 | + |
| 119 | + Additional option: |
| 120 | + - defaultext: extension added to filename if none is given (default is none) |
| 121 | + |
| 122 | + |
| 123 | +Changelog |
| 124 | +--------- |
| 125 | + |
| 126 | +- tkfilebrowser 2.2.6 |
| 127 | +<<<<<<< HEAD |
| 128 | + * No longer reset path bar when clicking on a path button |
| 129 | +======= |
| 130 | + * Fix bug caused by broken links |
| 131 | +>>>>>>> master |
| 132 | + |
| 133 | +- tkfilebrowser 2.2.5 |
| 134 | + * Add compatibility with Tk < 8.6.0 (requires PIL.ImageTk) |
| 135 | + * Add desktop icon in shortcuts |
| 136 | + * Fix handling of spaces in bookmarks |
| 137 | + * Fix bug due to spaces in recent file names |
| 138 | + |
| 139 | +- tkfilebrowser 2.2.4 |
| 140 | + * Fix bug in desktop folder identification |
| 141 | + |
| 142 | +- tkfilebrowser 2.2.3 |
| 143 | + * Fix FileNotFoundError if initialdir does not exist |
| 144 | + * Add Desktop in shortcuts (if found) |
| 145 | + * Improve filetype filtering |
| 146 | + |
| 147 | +- tkfilebrowser 2.2.2 |
| 148 | + * Fix ValueError in after_cancel with Python 3.6.5 |
| 149 | + |
| 150 | +- tkfilebrowser 2.2.1 |
| 151 | + * Fix __main__.py for python 2 |
| 152 | + |
| 153 | +- tkfilebrowser 2.2.0 |
| 154 | + * Use babel instead of locale in order not to change the locale globally |
| 155 | + * Speed up (a little) folder content display |
| 156 | + * Improve example: add comparison with default dialogs |
| 157 | + * Add select all on Ctrl+A if multiple selection is enabled |
| 158 | + * Disable folder creation button if the user does not have write access |
| 159 | + * Improve extension management in save mode |
| 160 | + |
| 161 | +- tkfilebrowser 2.1.1 |
| 162 | + * Fix error if LOCAL_PATH does not exists or is not writtable |
| 163 | + |
| 164 | +- tkfilebrowser 2.1.0 |
| 165 | + * Add compatibility with tkinter.filedialog keywords 'master' and 'defaultextension' |
| 166 | + * Change look of filetype selector |
| 167 | + * Fix bugs when navigating without displaying hidden files |
| 168 | + * Fix color alternance bug when hiding hidden files |
| 169 | + * Fix setup.py |
| 170 | + * Hide suggestion drop-down when nothing matches anymore |
| 171 | + |
| 172 | +- tkfilebrowser 2.0.0 |
| 173 | + * Change package name to tkfilebrowser to respect PEP 8 |
| 174 | + * Display error message when an issue occurs during folder creation |
| 175 | + * Cycle only through folders with key browsing in "opendir" mode |
| 176 | + * Complete only with folder names in "opendir" mode |
| 177 | + * Fix bug: grey/white color alternance not always respected |
| 178 | + * Add __main__.py with an example |
| 179 | + * Add "Recent files" shortcut |
| 180 | + * Make the text of the validate and cancel buttons customizable |
| 181 | + * Add possibility to disable new folder creation |
| 182 | + * Add python 2 support |
| 183 | + * Add horizontal scrollbar |
| 184 | + |
| 185 | +- tkFileBrowser 1.1.2 |
| 186 | + * Add tooltips to display the full path of the shortcut if the mouse stays |
| 187 | + long enough over it. |
| 188 | + * Fix bug: style of browser treeview applied to parent |
| 189 | + |
| 190 | +- tkFileBrowser 1.1.1 |
| 191 | + * Fix bug: key browsing did not work with capital letters |
| 192 | + * Add specific icons for symlinks |
| 193 | + * Add handling of symlinks, the real path is returned instead of the link path |
| 194 | + |
| 195 | +- tkFileBrowser 1.1.0 |
| 196 | + * Fix bug concerning the initialfile argument |
| 197 | + * Add column sorting (by name, size, modification date) |
| 198 | + |
| 199 | +- tkFileBrowser 1.0.1 |
| 200 | + * Set default filebrowser parent to None as for the usual filedialogs and messageboxes. |
| 201 | + |
| 202 | +- tkFileBrowser 1.0.0 |
| 203 | + * Initial version |
| 204 | + |
| 205 | + |
| 206 | +Example |
| 207 | +======= |
| 208 | + |
| 209 | +.. code:: python |
| 210 | + |
| 211 | + try: |
| 212 | + import tkinter as tk |
| 213 | + import tkinter.ttk as ttk |
| 214 | + from tkinter import filedialog |
| 215 | + except ImportError: |
| 216 | + import Tkinter as tk |
| 217 | + import ttk |
| 218 | + import tkFileDialog as filedialog |
| 219 | + from tkfilebrowser import askopendirname, askopenfilenames, asksaveasfilename |
| 220 | + |
| 221 | + |
| 222 | + root = tk.Tk() |
| 223 | + |
| 224 | + style = ttk.Style(root) |
| 225 | + style.theme_use("clam") |
| 226 | + |
| 227 | + |
| 228 | + def c_open_file_old(): |
| 229 | + rep = filedialog.askopenfilenames(parent=root, initialdir='/', initialfile='tmp', |
| 230 | + filetypes=[("PNG", "*.png"), ("JPEG", "*.jpg"), ("All files", "*")]) |
| 231 | + print(rep) |
| 232 | + |
| 233 | + |
| 234 | + def c_open_dir_old(): |
| 235 | + rep = filedialog.askdirectory(parent=root, initialdir='/tmp') |
| 236 | + print(rep) |
| 237 | + |
| 238 | + |
| 239 | + def c_save_old(): |
| 240 | + rep = filedialog.asksaveasfilename(parent=root, defaultextension=".png", initialdir='/tmp', initialfile='image.png', |
| 241 | + filetypes=[("PNG", "*.png"), ("JPEG", "*.jpg"), ("All files", "*")]) |
| 242 | + print(rep) |
| 243 | + |
| 244 | + |
| 245 | + def c_open_file(): |
| 246 | + rep = askopenfilenames(parent=root, initialdir='/', initialfile='tmp', |
| 247 | + filetypes=[("Pictures", "*.png|*.jpg|*.JPG"), ("All files", "*")]) |
| 248 | + print(rep) |
| 249 | + |
| 250 | + |
| 251 | + def c_open_dir(): |
| 252 | + rep = askopendirname(parent=root, initialdir='/', initialfile='tmp') |
| 253 | + print(rep) |
| 254 | + |
| 255 | + |
| 256 | + def c_save(): |
| 257 | + rep = asksaveasfilename(parent=root, defaultext=".png", initialdir='/tmp', initialfile='image.png', |
| 258 | + filetypes=[("Pictures", "*.png|*.jpg|*.JPG"), ("All files", "*")]) |
| 259 | + print(rep) |
| 260 | + |
| 261 | + |
| 262 | + ttk.Label(root, text='Default dialogs').grid(row=0, column=0, padx=4, pady=4, sticky='ew') |
| 263 | + ttk.Label(root, text='tkfilebrowser dialogs').grid(row=0, column=1, padx=4, pady=4, sticky='ew') |
| 264 | + ttk.Button(root, text="Open files", command=c_open_file_old).grid(row=1, column=0, padx=4, pady=4, sticky='ew') |
| 265 | + ttk.Button(root, text="Open folder", command=c_open_dir_old).grid(row=2, column=0, padx=4, pady=4, sticky='ew') |
| 266 | + ttk.Button(root, text="Save file", command=c_save_old).grid(row=3, column=0, padx=4, pady=4, sticky='ew') |
| 267 | + ttk.Button(root, text="Open files", command=c_open_file).grid(row=1, column=1, padx=4, pady=4, sticky='ew') |
| 268 | + ttk.Button(root, text="Open folder", command=c_open_dir).grid(row=2, column=1, padx=4, pady=4, sticky='ew') |
| 269 | + ttk.Button(root, text="Save file", command=c_save).grid(row=3, column=1, padx=4, pady=4, sticky='ew') |
| 270 | + |
| 271 | + root.mainloop() |
| 272 | + |
| 273 | +.. |Release| image:: https://badge.fury.io/py/tkfilebrowser.svg |
| 274 | + :alt: Latest Release |
| 275 | +.. _Release: https://pypi.org/project/tkfilebrowser/ |
| 276 | +.. |Linux| image:: https://img.shields.io/badge/platform-Linux-blue.svg |
| 277 | + :alt: Platform |
| 278 | +.. |Travis| image:: https://travis-ci.org/j4321/tkFileBrowser.svg?branch=master |
| 279 | + :target: https://travis-ci.org/j4321/tkFileBrowser |
| 280 | + :alt: Travis CI Build Status |
| 281 | +.. |Codecov| image:: https://codecov.io/gh/j4321/tkFileBrowser/branch/master/graph/badge.svg |
| 282 | + :target: https://codecov.io/gh/j4321/tkFileBrowser |
| 283 | + :alt: Code coverage |
| 284 | +.. |License| image:: https://img.shields.io/github/license/j4321/tkFileBrowser.svg |
| 285 | + :target: https://www.gnu.org/licenses/gpl-3.0.en.html |
| 286 | + :alt: License |
| 287 | +.. |Doc| image:: https://readthedocs.org/projects/tkfilebrowser/badge/?version=latest |
| 288 | + :target: https://tkfilebrowser.readthedocs.io/en/latest/?badge=latest |
| 289 | + :alt: Documentation Status |
0 commit comments