Keybinding doc & close window

29/10/11 21:20, Benjamin Root

···

On Saturday, October 29, 2011, Antoine Levitt > <antoine.levitt@...149...> wrote:

29/10/11 19:39, Benjamin Root

I don't think there is a document for the default keymaps, and

there

has been some talk about redoing default keybindings, because they

are

so hidden and varies from backend to backend.

In the meantime, I would suggest checking out the "event handeling"
section of the examples page. You can have a function that you

attach

to the "key_press_event", which takes an "event" object as an
argument. That event object has the key that was pressed. You can
then have an if...elif...else statement for all the keys and

actions,

or have a dictionary of key-action pairs.

Hope that helps!
Ben Root

That's pretty cool! However, I have to do it for every figure I

create,

there doesn't seem to be a way to tell matplotlib : "whenever a

figure

is created, associate this handler to this event".

I think I'll just wait for the keybinding stuff to get refactored,

which

would definitely be a good idea (I only found out via very indirect
means, and had to change backend to get them working). It seems
worthwhile to have a "q" default binding to exit the plot.

The basic event handling isn't going to be refactored. I was merely
speaking of how the default keymaps are set. Yes, you will need to
mpl_connect for each figure object. This is standard for any GUI
control system. What you can do is make a function that produces a
figure for you as well as perform any event connections for you.

Ben Root

The problem is that I don't usually invoke figure(), I just do
plot(x,y), which will presumably call figure for me. So unless there's
some kind of event that's run after figure is called, I can't have a
generic way of adding my bindings.

Try

gcf().canvas.mpl_connect(…)

Before any show() calls or after any particular plotting commands.

Ben Root

···

On Saturday, October 29, 2011, Antoine Levitt <antoine.levitt@…149…> wrote:

29/10/11 21:20, Benjamin Root

On Saturday, October 29, 2011, Antoine Levitt >> <antoine.levitt@…552…149…> wrote:

29/10/11 19:39, Benjamin Root

I don’t think there is a document for the default keymaps, and

there

has been some talk about redoing default keybindings, because they
are

so hidden and varies from backend to backend.

In the meantime, I would suggest checking out the “event handeling”

section of the examples page. You can have a function that you
attach

to the “key_press_event”, which takes an “event” object as an
argument. That event object has the key that was pressed. You can

then have an if…elif…else statement for all the keys and
actions,

or have a dictionary of key-action pairs.

Hope that helps!

Ben Root

That’s pretty cool! However, I have to do it for every figure I
create,
there doesn’t seem to be a way to tell matplotlib : "whenever a

figure

is created, associate this handler to this event".

I think I’ll just wait for the keybinding stuff to get refactored,
which
would definitely be a good idea (I only found out via very indirect

means, and had to change backend to get them working). It seems
worthwhile to have a “q” default binding to exit the plot.

The basic event handling isn’t going to be refactored. I was merely

speaking of how the default keymaps are set. Yes, you will need to
mpl_connect for each figure object. This is standard for any GUI
control system. What you can do is make a function that produces a

figure for you as well as perform any event connections for you.

Ben Root

The problem is that I don’t usually invoke figure(), I just do
plot(x,y), which will presumably call figure for me. So unless there’s

some kind of event that’s run after figure is called, I can’t have a
generic way of adding my bindings.