Thanks to visit codestin.com
Credit goes to github.com

Skip to content

key_press_handler captures number keys and 'a'? #2699

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
eyurtsev opened this issue Dec 30, 2013 · 4 comments
Closed

key_press_handler captures number keys and 'a'? #2699

eyurtsev opened this issue Dec 30, 2013 · 4 comments
Labels
MEP: MEP22 tool manager
Milestone

Comments

@eyurtsev
Copy link
Contributor

I was developing a simple GUI and ran into unexpected behaviour when pressing the number keys 1-9, which disable/enable panning.

Based on the online documentation I was using (http://matplotlib.org/users/navigation_toolbar.html), I wasn't expecting any of the number keys to be used as keyboard shortcuts. However, the key_press_handler method defined in backend_bases.py uses the number keys 1-9 to enable/disable panning on axes (I attached excerpt code below).

I think it would be nice to have these features documented on the webpage, so other developers know that the number keys are used by matplotlib.

Also, here are two thoughts:

  1. Is the ability to toggle navigation actually needed? (I am not sure what the use-case would be.)
  2. Assuming the ability to toggle navigation is indeed needed, wouldn't a single button that toggles navigation on given subplot (the one under the cursor) be better? It would (A) free up keyboard shortcuts for other uses and (B) would work when more than 10 subplots are present.

Here's the code from key_press_handler (here's a link https://github.com/matplotlib/matplotlib/blob/v1.3.x/lib/matplotlib/backend_bases.py#L2523)

    elif (event.key.isdigit() and event.key != '0') or event.key in all:
        # keys in list 'all' enables all axes (default key 'a'),
        # otherwise if key is a number only enable this particular axes
        # if it was the axes, where the event was raised
        if not (event.key in all):
            n = int(event.key) - 1
        for i, a in enumerate(canvas.figure.get_axes()):
            # consider axes, in which the event was raised
            # FIXME: Why only this axes?
            if event.x is not None and event.y is not None \
                    and a.in_axes(event):
                if event.key in all:
                    a.set_navigate(True)
                else:
                    a.set_navigate(i == n)
@tacaswell
Copy link
Member

This should be addressed by #2624 as it will expose a set of classes that do not have the default callbacks registered.

If you are embedding, can you add any comments to that PR?

@fariza I think this should also be folded into the toolbar refactor.

@fariza
Copy link
Member

fariza commented Jan 22, 2014

@tacaswell please add MEP22 label

@fariza
Copy link
Member

fariza commented Aug 7, 2015

This was handled in MEP22.
These keys 1-9 are captured by the tool ToolEnableNavigation that can be disabled by calling fig.canvas.manager.toolmanager.remove_tool('nav')
I'm closing the issue because there is a working solution now. Please reopen if necessary

@fariza fariza closed this as completed Aug 7, 2015
@npmurphy
Copy link

This quirk is still not noted in the documentation.
As a work around I re-enable navigation after pressing a digit.
ax.set_navigate(True)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
MEP: MEP22 tool manager
Projects
None yet
Development

No branches or pull requests

4 participants