Fix pressing tab breaks keymap in CanvasTk #13739
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi, I'm opening this as part of coursework from University of Toronto Scarborough's CSCD01 taught by Dr. Anya Tafliovich @atafliovich. (https://www.utsc.utoronto.ca/~atafliovich/cscd01/index.html)
PR Summary
Closes #13484 - Matplotlib keymap stop working after pressing tab
Bug Analysis and Technical Commentary:
When using figureCanvas and NavigationToolBar embedded in Tkinter, Matplotlib has some key mappings to NavigationToolBar actions. However, if tab is pressed, none of the key mappings works and clicking in the figure/plot does not help. The methods to bring the key mappings back are to use either alt+tab or pressing tab for a few times.
The problem is with the default Tkinter tab action, it will move the focus around on different objects in the Tinkter canvas, in this case, buttons in the NavigationToolBar. The key mapping functions are set on figureCanvas so they work only when the focus in on the figure.
The fix is to add a tab_event to handle the case where tab is pressed on the Tkinter Canvas. The tab_event will set focus to the figureCanvas and call
key_press
fromFigureCanvasTk
, and uses return 'break' to disable the default Tkinter tab action. By binding the Tkinter tab pressed event "<tab>" to my customized tab_event fixes the misbehaviour when tab is pressed. I also added a default tab key recognition to theFigureCanvasTk
class since None was returned before when tab is pressed.Acceptance Test:
Result:
pressing tab behaves as expected
Example code:
see matplotlib embedded in tk example
PR Checklist