Emulating keypress and mouse clicks

Hello,

I have some some matplotlib code that we use for interactive plotting, and I
want to do non-interactive unit testing. This means I need to emulate
keypresses and mouse clicks.

It is simple enough to do keypress unit testing by using:

fig.canvas.key_press_event('down')

This for example allows us to test that pressing "down" in a figure window
elicits the appropriate behavior.

However, I am having difficulty testing mouse clicks. We have behaviors
where users can click within an axis (e.g., fix.axes[1]) to elicit some
behavior. I have tried the following:

fig.canvas.button_press_event(0.5, 0.5, 1)

But within the event handler (which generally has structure
_mouse_click(event, params)), the "event" object does not have the
"event.inaxes" field populated correctly (it is always "None") despite my
emulated click @ (0.5, 0.5) sitting within one of the axes in the figure.

Does anyone know how to emulate either of these types of clicks?

···

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Emulating-keypress-and-mouse-clicks-tp42534.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

Just wanted to let people know that I chased down the problem I was having. The command I was using was working, but I wrongly assumed the coordinate system was normalized for some reason. Doing things like:

fig.canvas.button_press_event(110, 240, 1, False, None)

works great!

Cheers,

Eric

···

On Thu, Nov 21, 2013 at 9:52 AM, Eric89GXL <larson.eric.d@…287…> wrote:

Hello,

I have some some matplotlib code that we use for interactive plotting, and I

want to do non-interactive unit testing. This means I need to emulate

keypresses and mouse clicks.

It is simple enough to do keypress unit testing by using:

fig.canvas.key_press_event(‘down’)

This for example allows us to test that pressing “down” in a figure window

elicits the appropriate behavior.

However, I am having difficulty testing mouse clicks. We have behaviors

where users can click within an axis (e.g., fix.axes[1]) to elicit some

behavior. I have tried the following:

fig.canvas.button_press_event(0.5, 0.5, 1)

But within the event handler (which generally has structure

_mouse_click(event, params)), the “event” object does not have the

“event.inaxes” field populated correctly (it is always “None”) despite my

emulated click @ (0.5, 0.5) sitting within one of the axes in the figure.

Does anyone know how to emulate either of these types of clicks?

View this message in context: http://matplotlib.1069221.n5.nabble.com/Emulating-keypress-and-mouse-clicks-tp42534.html

Sent from the matplotlib - users mailing list archive at Nabble.com.


Shape the Mobile Experience: Free Subscription

Software experts and developers: Be at the forefront of tech innovation.

Intel® Software Adrenaline delivers strategic insight and game-changing

conversations that shape the rapidly evolving mobile landscape. Sign up now.

http://pubads.g.doubleclick.net/gampad/clk?id=63431311&iu=/4140/ostg.clktrk


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users