Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
j4321 committed Dec 18, 2018
2 parents 0dfaf6b + ae7e851 commit 1de86d8
Show file tree
Hide file tree
Showing 13 changed files with 199 additions and 98 deletions.
14 changes: 14 additions & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
environment:
matrix:
- PYTHON: "C:\\PYTHON27"
- PYTHON: "C:\\PYTHON35"
- PYTHON: "C:\\PYTHON36"
install:
- "%PYTHON%\\python.exe -m pip install -U pip"
- "%PYTHON%\\python.exe -m pip install nose coverage codecov psutil pynput babel pillow pypiwin32"
build: off
test_script:
- "%PYTHON%\\python.exe -m pip install ."
- "%PYTHON%\\python.exe -m nose --with-coverage"
after_test:
- "%PYTHON%\\Scripts\\codecov.exe"
1 change: 1 addition & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
coverage:
ci:
- travis
- appveyor
status:
patch: false
changes: false
Expand Down
23 changes: 19 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
tkfilebrowser
=============

|Release|_ |Linux| |Travis| |Codecov| |License| |Doc|
|Release|_ |Linux| |Windows| |Travis| |Codecov| |License| |Doc|

tkfilebrowser is an alternative to tkinter.filedialog that allows the
user to select files or directories. The GUI is written with tkinter but
Expand Down Expand Up @@ -31,8 +31,16 @@ The documentation is also available here: https://tkfilebrowser.readthedocs.io
Requirements
------------

- Linux
- Python 2.7 or 3.x with tkinter + ttk, python-psutil and python-babel
- Linux or Windows
- Python 2.7 or 3.x

And the python packages:

- tkinter (included in the python distribution for Windows)
- psutil
- babel
- pywin32 (Windows only)
- pillow (only if tkinter.TkVersion < 8.6)


Installation
Expand Down Expand Up @@ -117,12 +125,17 @@ Documentation
is asked to confirm its replacement.

Additional option:

- defaultext: extension added to filename if none is given (default is none)


Changelog
---------

- tkfilebrowser 2.3.0
* Make package compatible with Windows
* Set initial focus on entry in save mode

- tkfilebrowser 2.2.6
* No longer reset path bar when clicking on a path button
* Fix bug caused by broken links
Expand Down Expand Up @@ -271,7 +284,9 @@ Example
:alt: Latest Release
.. _Release: https://pypi.org/project/tkfilebrowser/
.. |Linux| image:: https://img.shields.io/badge/platform-Linux-blue.svg
:alt: Platform
:alt: Platform Linux
.. |Windows| image:: https://img.shields.io/badge/platform-Windows-blue.svg
:alt: Platform Windows
.. |Travis| image:: https://travis-ci.org/j4321/tkFileBrowser.svg?branch=master
:target: https://travis-ci.org/j4321/tkFileBrowser
:alt: Travis CI Build Status
Expand Down
10 changes: 8 additions & 2 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
=========

tkfilebrowser 2.3.0
-------------------

* Make package compatible with Windows
* Set initial focus on entry in save mode

tkfilebrowser 2.2.6
-------------------

Expand All @@ -22,7 +28,7 @@ tkfilebrowser 2.2.4
tkfilebrowser 2.2.3
-------------------

* Fix FileNotFoundError if initialdir does not exist
* Fix :obj:`FileNotFoundError` if initialdir does not exist
* Add Desktop in shortcuts (if found)
* Improve filetype filtering

Expand Down Expand Up @@ -54,7 +60,7 @@ tkfilebrowser 2.1.1
tkfilebrowser 2.1.0
-------------------

* Add compatibility with tkinter.filedialog keywords 'master' and 'defaultextension'
* Add compatibility with :mod:`tkinter.filedialog` keywords 'master' and 'defaultextension'
* Change look of filetype selector
* Fix bugs when navigating without displaying hidden files
* Fix color alternance bug when hiding hidden files
Expand Down
14 changes: 7 additions & 7 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ the look is closer to GTK and the application uses GTK bookmarks (the
one displayed in nautilus or thunar for instance). This filebrowser
supports new directory creation and filtype filtering.

This module contains a general ``FileBrowser`` class which implements the
This module contains a general :class:`~tkfilebrowser.FileBrowser` class which implements the
filebrowser and the following functions, similar to the one in filedialog:

* ``askopenfilename`` that allow the selection of a single file
* :func:`~tkfilebrowser.askopenfilename` that allow the selection of a single file

* ``askopenfilenames`` that allow the selection of multiple files
* :func:`~tkfilebrowser.askopenfilenames` that allow the selection of multiple files

* ``askopendirname`` that allow the selection a single folder
* :func:`~tkfilebrowser.askopendirname` that allow the selection a single folder

* ``askopendirnames`` that allow the selection of multiple folders
* :func:`~tkfilebrowser.askopendirnames` that allow the selection of multiple folders

* ``asksaveasfilename`` that returns a single filename and give a warning if the file already exists
* :func:`~tkfilebrowser.asksaveasfilename` that returns a single filename and give a warning if the file already exists

Project page: https://github.com/j4321/tkFileBrowser

.. toctree::
:maxdepth: 4
:maxdepth: 1
:caption: Contents:

installation
Expand Down
11 changes: 9 additions & 2 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ Installation
Requirements
------------

- Linux
- Python 2.7 or 3.x with tkinter + ttk (and PIL if tk < 8.6.0), python-psutil and python-babel
- Linux or Windows
- Python 2.7 or 3.x

And the python packages:

- tkinter (included in the python distribution for Windows)
- psutil
- babel
- pywin32 (Windows only)
- pillow (only if tkinter.TkVersion < 8.6)

Install
-------
Expand Down
11 changes: 7 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
from setuptools import setup

from codecs import open
from os import path
from os import path, name

here = path.abspath(path.dirname(__file__))

with open(path.join(here, 'README.rst'), encoding='utf-8') as f:
long_description = f.read()



setup(name='tkfilebrowser',
version='2.2.6',
version='2.3.0',
description='File browser for Tkinter, alternative to tkinter.filedialog in linux with GTK bookmarks support.',
long_description=long_description,
url='https://github.com/j4321/tkFileBrowser',
Expand All @@ -32,7 +34,8 @@
'Programming Language :: Python :: 3.7',
'Natural Language :: English',
'Natural Language :: French',
'Operating System :: POSIX :: Linux'],
'Operating System :: POSIX :: Linux',
'Operating System :: Microsoft :: Windows'],
py_modules=["tkfilebrowser.autoscrollbar",
"tkfilebrowser.constants",
"tkfilebrowser.filebrowser",
Expand All @@ -43,5 +46,5 @@
keywords=['tkinter', 'filedialog', 'filebrowser'],
packages=["tkfilebrowser"],
package_data={"tkfilebrowser": ["images/*"]},
install_requires=["psutil", "babel"],
install_requires=["psutil", "babel"] + (['pypiwin32'] if name == 'nt' else []),
extras_require={'tk<8.6.0': 'Pillow'})
74 changes: 46 additions & 28 deletions tests/test_filebrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
except ImportError:
from tkinter import ttk
import os
from pynput.keyboard import Key, Controller


class TestFileBrowser(BaseWidgetTest):
Expand Down Expand Up @@ -104,7 +105,8 @@ def test_filebrowser_save(self):
foldercreation=True)
self.window.update()
fb.validate()
self.assertEqual(fb.get_result(), '/test.png')
self.assertEqual(os.path.abspath(fb.get_result()),
os.path.abspath('/test.png'))
fb = FileBrowser(self.window, initialdir="/", initialfile="test.png", mode="save",
filetypes=[("PNG", '*.png|*.PNG'), ("JPG", '*.jpg|*.JPG'),
('ALL', '*')])
Expand Down Expand Up @@ -134,26 +136,31 @@ def test_filebrowser_keybrowse(self):
self.window.update()
fb.right_tree.focus_force()
self.window.update()
ch = fb.right_tree.tag_has('file')
letters = [fb.right_tree.item(c, 'text')[0] for c in ch]
ch = fb.right_tree.get_children('')
letters = [fb.right_tree.item(c, 'text')[0].lower() for c in ch]
i = 65
while chr(i) in letters:
while chr(i).lower() in letters:
i += 1
letter = chr(i)
letter = chr(i).lower()
keyboard = Controller()
if letter.isalnum():
fb.right_tree.event_generate('<%s>' % letter)
fb.right_tree.focus_force()
keyboard.press(letter)
keyboard.release(letter)
self.window.update()
self.assertTrue(fb.key_browse_entry.winfo_ismapped())
self.assertEqual(fb.key_browse_entry.get(), letter)
fb.right_tree.event_generate('<Return>')
self.assertEqual(fb.key_browse_entry.get().lower(), letter)
fb.right_tree.event_generate('<Escape>')
self.window.update()
self.assertFalse(fb.key_browse_entry.winfo_ismapped())
if ch:
fb.right_tree.focus_force()
letter = fb.right_tree.item(ch[0], 'text')[0]
fb.right_tree.event_generate('<%s>' % letter)
keyboard.press(letter)
keyboard.release(letter)
self.window.update()
self.assertTrue(fb.key_browse_entry.winfo_ismapped())
self.assertEqual(fb.key_browse_entry.get(), letter)
self.assertEqual(fb.key_browse_entry.get().lower(), letter)
self.assertEqual(fb.right_tree.selection(), (ch[0],))
l = [c for c in ch if fb.right_tree.item(c, 'text')[0] == letter]
fb.key_browse_entry.focus_force()
Expand All @@ -172,11 +179,16 @@ def test_filebrowser_keybrowse(self):
self.window.update()
self.assertFalse(fb.key_browse_entry.winfo_ismapped())
fb.right_tree.focus_force()
fb.right_tree.event_generate('<%s>' % letter)
keyboard.press(letter)
keyboard.release(letter)
self.window.update()
fb.right_tree.event_generate('<Return>')
self.window.update()
self.assertEqual(fb.get_result(), (ch[0],))
item = os.path.realpath(ch[0])
if os.path.isdir(item):
self.assertEqual(fb.history[-1], ch[0])
else:
self.assertEqual(fb.get_result(), (item,))

# --- opendir
fb = FileBrowser(self.window, initialdir="/", mode="opendir",
Expand All @@ -185,27 +197,31 @@ def test_filebrowser_keybrowse(self):
fb.right_tree.focus_force()
self.window.update()
ch = fb.right_tree.tag_has('folder')
letters = [fb.right_tree.item(c, 'text')[0] for c in ch]
letters = [fb.right_tree.item(c, 'text')[0].lower() for c in ch]
i = 65
while chr(i) in letters:
while chr(i).lower() in letters:
i += 1
letter = chr(i)
letter = chr(i).lower()
if letter.isalnum():
fb.right_tree.event_generate('<%s>' % letter)
fb.right_tree.focus_force()
keyboard.press(letter)
keyboard.release(letter)
self.window.update()
self.assertTrue(fb.key_browse_entry.winfo_ismapped())
self.assertEqual(fb.key_browse_entry.get(), letter)
fb.right_tree.event_generate('<Return>')
self.window.update()
self.assertEqual(fb.get_result(), ('/',))
self.assertEqual(fb.get_result(), (os.path.abspath('/'),))
fb = FileBrowser(self.window, initialdir="/", mode="opendir",
multiple_selection=True)
self.window.update()
fb.right_tree.focus_force()
if ch:
letter = fb.right_tree.item(ch[-1], 'text')[0]
l = [c for c in ch if fb.right_tree.item(c, 'text')[0] == letter]
fb.right_tree.event_generate('<%s>' % letter)
letter = fb.right_tree.item(ch[-1], 'text')[0].lower()
l = [c for c in ch if fb.right_tree.item(c, 'text')[0].lower() == letter]
fb.right_tree.focus_force()
keyboard.press(letter)
keyboard.release(letter)
self.window.update()
self.assertTrue(fb.key_browse_entry.winfo_ismapped())
self.assertEqual(fb.key_browse_entry.get(), letter)
Expand All @@ -226,7 +242,8 @@ def test_filebrowser_keybrowse(self):
self.window.update()
self.assertFalse(fb.key_browse_entry.winfo_ismapped())
fb.right_tree.focus_force()
fb.right_tree.event_generate('<%s>' % letter)
keyboard.press(letter)
keyboard.release(letter)
self.window.update()
fb.right_tree.event_generate('<Return>')
self.window.update()
Expand Down Expand Up @@ -266,11 +283,12 @@ def test_filebrowser_keybrowse(self):
self.window.update()

def test_filebowser_foldercreation(self):
fb = FileBrowser(self.window, initialdir="/",
initdir = os.path.abspath('/')
fb = FileBrowser(self.window, initialdir=initdir,
foldercreation=True)
self.window.update()
self.assertTrue(fb.b_new_folder.winfo_ismapped())
self.assertTrue('disabled' in fb.b_new_folder.state())
self.assertIs('disabled' not in fb.b_new_folder.state(), os.access(initdir, os.W_OK))
fb.display_folder(os.path.expanduser('~'))
self.window.update()
self.assertTrue(fb.b_new_folder.winfo_ismapped())
Expand All @@ -287,7 +305,7 @@ def test_filebrowser_sorting(self):
okbuttontext=None, cancelbuttontext="Cancel",
foldercreation=True)
self.window.update()
walk = os.walk('/')
walk = os.walk(os.path.abspath('/'))
root, dirs, files = walk.send(None)
dirs = [os.path.join(root, d) for d in dirs]
files = [os.path.join(root, f) for f in files]
Expand Down Expand Up @@ -363,8 +381,8 @@ def test_filebrowser_on_selection(self):
fb.right_tree.selection_clear()
fb.right_tree.selection_set(ch[0])
self.window.update()
self.assertEqual(fb.entry.get(),
os.path.join(fb.right_tree.item(ch[0], 'text'), ''))
self.assertEqual(os.path.abspath(fb.entry.get()),
os.path.abspath(os.path.join(fb.right_tree.item(ch[0], 'text'), '')))
fb.focus_force()
fb.event_generate("<Control-l>")
self.window.update()
Expand All @@ -390,8 +408,8 @@ def test_filebrowser_on_selection(self):
fb.right_tree.selection_clear()
fb.right_tree.selection_set(ch[0])
self.window.update()
self.assertEqual(fb.entry.get(),
os.path.join(fb.right_tree.item(ch[0], 'text'), ''))
self.assertEqual(os.path.abspath(fb.entry.get()),
os.path.abspath(os.path.join(fb.right_tree.item(ch[0], 'text'), '')))
ch = fb.right_tree.tag_has('file')
if ch:
fb.right_tree.selection_clear()
Expand Down
1 change: 0 additions & 1 deletion tkfilebrowser/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
IM_RECENT = os.path.join(PATH, "images", "recent.png")
IM_RECENT_24 = os.path.join(PATH, "images", "recent_24.png")


# --- translation
try:
LANG = locale.getdefaultlocale()[0]
Expand Down
Loading

0 comments on commit 1de86d8

Please sign in to comment.