Backing out all changes to the UI and notebook.js.

Updated kernel.js to trigger the ``received_unsolicited_message.Kernel`` event instead. Notebook extensions can handle the event in whatever way they deem appropriate.

A notebook extension that takes advantage of this is available at https://github.com/nheijermans/nbexts.git.
This commit is contained in:
Nathan Heijermans 2014-12-12 17:09:44 -05:00
parent 4925ea3e44
commit 408e3fa557
5 changed files with 5 additions and 75 deletions

View File

@ -293,9 +293,6 @@ define([
});
// Kernel
this.element.find('#toggle_unsolicited').click(function() {
IPython.notebook.toggle_ignore_unsolicited_msgs();
});
this.element.find('#int_kernel').click(function () {
that.notebook.kernel.interrupt();
});

View File

@ -137,7 +137,6 @@ define([
this.undelete_below = false;
this.paste_enabled = false;
this.writable = false;
this.include_other_output = true;
// It is important to start out in command mode to match the intial mode
// of the KeyboardManager.
this.mode = 'command';
@ -1574,60 +1573,6 @@ define([
this.get_selected_cell().toggle_line_numbers();
};
// Support for displaying input and output messages from other iPy clients.
/**
* Toggles the ability to display input/output message events from
* externally connected clients (i.e. other iPython shells, vim-ipython,
* etc).
*
* @method toggle_ignore_unsolicited_msgs
*/
Notebook.prototype.toggle_ignore_unsolicited_msgs = function () {
this.include_other_output = !this.include_other_output;
this.events.trigger('toggle_other_client_output.Notebook',
[this.include_other_output]);
return this.include_other_output;
};
/**
* Handles the display of unsolicited messages, i.e. inputs or outputs that
* were generated by a client other than this notebook. New messages are
* displayed at the bottom of the notebook.
*
* @method handle_unsolicited_msg
*/
Notebook.prototype.handle_unsolicited_msg = function(msg) {
if (!this.include_other_output) {
return;
}
if (msg.msg_type == 'execute_input') {
var cell = this.insert_cell_at_bottom('code');
if (cell) {
var cell_index = this.ncells() - 1;
cell.last_msg_id = msg.parent_header.msg_id;
cell.set_text(msg.content.code);
cell._handle_execute_reply(msg);
this.scroll_to_cell(cell_index);
this.select(cell_index);
}
} else {
/* Find the input cell that corresponds with the output, then add
* the contents to the cell's output area.
*/
var count = this.ncells();
while (count--) {
var cell = this.get_cell(count);
if (cell && cell.last_msg_id == msg.parent_header.msg_id) {
cell.output_area.handle_output(msg);
this.scroll_to_cell(count);
this.select(count);
break;
}
}
}
};
/**
* Set the codemirror mode for all code cells, including the default for
* new code cells.
@ -1705,7 +1650,6 @@ define([
cell.set_kernel(this.session.kernel);
}
}
this.kernel.unsolicited_msg_callback = $.proxy(this.handle_unsolicited_msg, this);
};
Notebook.prototype._session_start_failed = function (jqxhr, status, error){
this._session_starting = false;

View File

@ -279,11 +279,6 @@ define([
nnw.warning(error.message || "Notebook copy failed");
});
this.events.on('toggle_other_client_output.Notebook', function(evt, include_output) {
var msg = (include_output? "Showing": "Ignoring") + " output from other clients";
nnw.set_message(msg, 2000);
});
// Checkpoint events
this.events.on('checkpoint_created.Notebook', function (evt, data) {
var msg = "Checkpoint created";

View File

@ -47,7 +47,6 @@ define([
this.session_id = utils.uuid();
this._msg_callbacks = {};
this.info_reply = {}; // kernel_info_reply stored here after starting
this.unsolicited_msg_callback = null;
if (typeof(WebSocket) !== 'undefined') {
this.WebSocket = WebSocket;
@ -1000,11 +999,9 @@ define([
Kernel.prototype._handle_output_message = function (msg) {
var callbacks = this.get_callbacks_for_msg(msg.parent_header.msg_id);
if (!callbacks || !callbacks.iopub) {
if (this.unsolicited_msg_callback) {
// The message came from another client. Let the UI decide what
// to do with it.
this.unsolicited_msg_callback(msg);
}
// The message came from another client. Let the UI decide what to
// do with it.
this.events.trigger('received_unsolicited_message.Kernel', msg);
return;
}
var callback = callbacks.iopub.output;
@ -1020,10 +1017,10 @@ define([
*/
Kernel.prototype._handle_input_message = function (msg) {
var callbacks = this.get_callbacks_for_msg(msg.parent_header.msg_id);
if (!callbacks && this.unsolicited_msg_callback) {
if (!callbacks) {
// The message came from another client. Let the UI decide what to
// do with it.
this.unsolicited_msg_callback(msg);
this.events.trigger('received_unsolicited_message.Kernel', msg);
}
};

View File

@ -226,9 +226,6 @@ class="notebook_app"
</li>
<li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">Kernel</a>
<ul id="kernel_menu" class="dropdown-menu">
<li id="toggle_unsolicited"
title="Toggles display of messages from clients other than this one sharing the same kernel.">
<a href="#">Show/ignore output from other clients.</a></li>
<li id="int_kernel"
title="Send KeyboardInterrupt (CTRL-C) to the Kernel">
<a href="#">Interrupt</a>