Skip to content

Commit

Permalink
Merge branch 'fix_#9'
Browse files Browse the repository at this point in the history
Fix #9 by putting `after_cancel` in try/except block to catch the `ValueError` which is raised since Python 3.6.5 if there is nothing to cancel.
  • Loading branch information
j4321 committed Apr 18, 2018
2 parents 02170d7 + bff1b65 commit 3e7694b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ Documentation
Changelog
---------

- tkfilebrowser 2.2.2
* Fix ValueError in after_cancel with Python 3.6.5

- tkfilebrowser 2.2.1
* Fix __main__.py for python 2

Expand Down
4 changes: 4 additions & 0 deletions changelog
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ Copyright 2017 Juliette Monsel <j_4321@protonmail.com>

Changelog
---------

- tkfilebrowser 2.2.2
* Fix ValueError in after_cancel with Python 3.6.5

- tkfilebrowser 2.2.1
* Fix __main__.py for python 2

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
long_description = f.read()

setup(name='tkfilebrowser',
version='2.2.1',
version='2.2.2',
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 Down
15 changes: 13 additions & 2 deletions tkfilebrowser/tooltip.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,14 @@ def __init__(self, tree, delay=1500, **kwargs):
self.current_item = None

self.tree.bind('<Motion>', self._on_motion)
self.tree.bind('<Leave>', lambda e: self.tree.after_cancel(self._timer_id))
self.tree.bind('<Leave>', self._on_leave)

def _on_leave(self, event):
try:
self.tree.after_cancel(self._timer_id)
except ValueError:
# nothing to cancel
pass

def add_tooltip(self, item, text):
"""Add a tooltip with given text to the item."""
Expand All @@ -116,7 +123,11 @@ def _on_motion(self, event):
self.tooltip.withdraw()
self.current_item = None
else:
self.tree.after_cancel(self._timer_id)
try:
self.tree.after_cancel(self._timer_id)
except ValueError:
# nothing to cancel
pass
self._timer_id = self.tree.after(self.delay, self.display_tooltip)

def display_tooltip(self):
Expand Down

0 comments on commit 3e7694b

Please sign in to comment.