8000 Js fixes for key events + ipython notebooks by tacaswell · Pull Request #3965 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Js fixes for key events + ipython notebooks #3965

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

Merged
merged 14 commits into from
Jan 11, 2015
Merged
Changes from 2 commits
Commits
File filter
8000

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions lib/matplotlib/backends/web_backend/mpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ mpl.figure.prototype._init_canvas = function() {

var canvas = $('<canvas/>');
canvas.addClass('mpl-canvas');
canvas.attr('style', "left: 0; top: 0; z-index: 0;")
canvas.attr('style', "left: 0; top: 0; z-index: 0; outline: 0")

this.canvas = canvas[0];
this.context = canvas[0].getContext("2d");
Expand All @@ -144,11 +144,6 @@ mpl.figure.prototype._init_canvas = function() {
canvas_div.append(canvas);
canvas_div.append(rubberband);

function mouse_out_fn(event) {
canvas_div.blur();
}
canvas_div.on("mouseout", mouse_out_fn);

this.rubberband = rubberband;
this.rubberband_canvas = rubberband[0];
this.rubberband_context = rubberband[0].getContext("2d");
Expand All @@ -170,6 +165,13 @@ mpl.figure.prototype._init_canvas = function() {
// Set the figure to an initial 600x600px, this will subsequently be updated
// upon first draw.
this._resize_canvas(600, 600);

function set_focus () {
canvas.focus();
canvas_div.focus();
}

window.setTimeout(set_focus, 100);
}

mpl.figure.prototype._init_toolbar = function() {
Expand Down Expand Up @@ -412,8 +414,9 @@ mpl.findpos = function(e) {
mpl.figure.prototype.mouse_event = function(event, name) {
var canvas_pos = mpl.findpos(event)

if (this.focus_on_mouseover && name === 'motion_notify')
if (name === 'button_press')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely certain why motion notify is no longer important. Would you mind talking me through it? Does the status bar (with the x and y coordinates) still work with this change?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My take: we switched to a more Qt-like focus policy, in that the figure takes focus immediately and upon clicking. When the figure has focus, the status bar receives updates.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I stand corrected, the motion_notify event is triggered regardless of focus, and the coordinates are updated (I just ran the example code).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mouse-move events fire independent of the focus state of the figure. The reason that we had to go through such contortions to get the key events to work is that IPython has a handler at the top of the document tree that eats all of the keyboard events and uses them for their own shortcuts.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

er, sorry, for the repeat, my gh got logged out due to having issues with ipython + js + clearing the cache and didn't see above until I had already posted.

{
this.canvas.focus();
this.canvas_div.focus();
}

Expand Down
0