Skip to content

How do I disable the Esc key from closing raw.plot? #6425

Closed

Description

@cbrnr

In MNELAB, I would like my raw.plot window to not close if the user hits the Esc key. Previously, I used the following hack which worked for matplotlib < 3:

 try:
    key_events = fig.canvas.callbacks.callbacks["key_press_event"][8]
except KeyError:
    pass
else:  # this requires MNE >=0.15
    key_events.func.keywords["params"]["close_key"] = None

Of course this was bound to fail, and with matplotlib >= 3 key_events is now a matplotlib.cbook._StrongRef object, whereas previously it used to be a matplotlib.cbook._BoundMethodProxy object. Of course private methods can change at anytime, but does anyone know either how to make the old hack work again, or better yet how to modify/delete existing callbacks?

Activity

  1. larsoner commented on Jun 6, 2019

    @larsoner
    Member

    I wonder if we should just monkey patch to add an attribute to fig as fig._mne_params = params

  2. cbrnr commented on Jun 6, 2019

    @cbrnr
    ContributorAuthor

    Yes, why not? If this gives an interface where I can change/delete callbacks... But once a callback is set, would adding our params solve the issue? Isn't a matplotlib call necessary to change a callback? If so, which?

  3. larsoner commented on Jun 6, 2019

    @larsoner
    Member

    Isn't a matplotlib call necessary to change a callback? If so, which?

    It depends what you mean. If you mean removing or adding a callback function yes you have to use mpl. If you just want to make it so that the existing mne callback does nothing on esc, it should be enough to do fig._mne_params['close_key'] = None.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions