Skip to content

key_press_handler captures number keys and 'a'? #2699

Closed

Description

@eyurtsev

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)

Activity

  1. tacaswell commented on Dec 31, 2013

    @tacaswell
    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.

  2. fariza commented on Jan 22, 2014

    @fariza
    Member

    @tacaswell please add MEP22 label

  3. fariza commented on Aug 7, 2015

    @fariza
    Member

    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

  4. npmurphy commented on Oct 20, 2016

    @npmurphy

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions