mirror of
https://github.com/jupyter/notebook.git
synced 2024-12-27 04:20:22 +08:00
Merge pull request #4229 from jdfreder/clearoutput
Clear_output: Animation & widget related changes.
This commit is contained in:
commit
54c751ce50
@ -241,7 +241,7 @@ var IPython = (function (IPython) {
|
||||
* @method execute
|
||||
*/
|
||||
CodeCell.prototype.execute = function () {
|
||||
this.output_area.clear_output(true, true, true);
|
||||
this.output_area.clear_output();
|
||||
this.set_input_prompt('*');
|
||||
this.element.addClass("running");
|
||||
if (this.last_msg_id) {
|
||||
@ -390,8 +390,8 @@ var IPython = (function (IPython) {
|
||||
};
|
||||
|
||||
|
||||
CodeCell.prototype.clear_output = function (stdout, stderr, other) {
|
||||
this.output_area.clear_output(stdout, stderr, other);
|
||||
CodeCell.prototype.clear_output = function (wait) {
|
||||
this.output_area.clear_output(wait);
|
||||
};
|
||||
|
||||
|
||||
|
@ -1339,7 +1339,7 @@ var IPython = (function (IPython) {
|
||||
var cells = this.get_cells();
|
||||
for (var i=0; i<ncells; i++) {
|
||||
if (cells[i] instanceof IPython.CodeCell) {
|
||||
cells[i].clear_output(true,true,true);
|
||||
cells[i].clear_output();
|
||||
// Make all In[] prompts blank, as well
|
||||
// TODO: make this configurable (via checkbox?)
|
||||
cells[i].set_input_prompt();
|
||||
|
@ -31,7 +31,7 @@ var IPython = (function (IPython) {
|
||||
this.outputs = [];
|
||||
this.collapsed = false;
|
||||
this.scrolled = false;
|
||||
this.clear_out_timeout = null;
|
||||
this.clear_queued = null;
|
||||
if (prompt_area === undefined) {
|
||||
this.prompt_area = true;
|
||||
} else {
|
||||
@ -289,7 +289,12 @@ var IPython = (function (IPython) {
|
||||
OutputArea.prototype.append_output = function (json, dynamic) {
|
||||
// If dynamic is true, javascript output will be eval'd.
|
||||
this.expand();
|
||||
this.flush_clear_timeout();
|
||||
|
||||
// Clear the output if clear is queued.
|
||||
if (this.clear_queued) {
|
||||
this.clear_output(false);
|
||||
}
|
||||
|
||||
if (json.output_type === 'pyout') {
|
||||
this.append_pyout(json, dynamic);
|
||||
} else if (json.output_type === 'pyerr') {
|
||||
@ -300,6 +305,7 @@ var IPython = (function (IPython) {
|
||||
this.append_stream(json);
|
||||
}
|
||||
this.outputs.push(json);
|
||||
this.element.height('auto');
|
||||
var that = this;
|
||||
setTimeout(function(){that.element.trigger('resize');}, 100);
|
||||
};
|
||||
@ -553,7 +559,6 @@ var IPython = (function (IPython) {
|
||||
OutputArea.prototype.append_raw_input = function (content) {
|
||||
var that = this;
|
||||
this.expand();
|
||||
this.flush_clear_timeout();
|
||||
var area = this.create_output_area();
|
||||
|
||||
// disable any other raw_inputs, if they are left around
|
||||
@ -606,81 +611,35 @@ var IPython = (function (IPython) {
|
||||
|
||||
|
||||
OutputArea.prototype.handle_clear_output = function (content) {
|
||||
this.clear_output(content.stdout, content.stderr, content.other);
|
||||
this.clear_output(content.wait);
|
||||
};
|
||||
|
||||
|
||||
OutputArea.prototype.clear_output = function (stdout, stderr, other) {
|
||||
var that = this;
|
||||
if (this.clear_out_timeout != null){
|
||||
// fire previous pending clear *immediately*
|
||||
clearTimeout(this.clear_out_timeout);
|
||||
this.clear_out_timeout = null;
|
||||
this.clear_output_callback(this._clear_stdout, this._clear_stderr, this._clear_other);
|
||||
OutputArea.prototype.clear_output = function(wait) {
|
||||
if (wait) {
|
||||
|
||||
// If a clear is queued, clear before adding another to the queue.
|
||||
if (this.clear_queued) {
|
||||
this.clear_output(false);
|
||||
};
|
||||
|
||||
this.clear_queued = true;
|
||||
} else {
|
||||
|
||||
// Fix the output div's height if the clear_output is waiting for
|
||||
// new output (it is being used in an animation).
|
||||
if (this.clear_queued) {
|
||||
var height = this.element.height();
|
||||
this.element.height(height);
|
||||
this.clear_queued = false;
|
||||
}
|
||||
// store flags for flushing the timeout
|
||||
this._clear_stdout = stdout;
|
||||
this._clear_stderr = stderr;
|
||||
this._clear_other = other;
|
||||
this.clear_out_timeout = setTimeout(function() {
|
||||
// really clear timeout only after a short delay
|
||||
// this reduces flicker in 'clear_output; print' cases
|
||||
that.clear_out_timeout = null;
|
||||
that._clear_stdout = that._clear_stderr = that._clear_other = null;
|
||||
that.clear_output_callback(stdout, stderr, other);
|
||||
}, 500
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
OutputArea.prototype.clear_output_callback = function (stdout, stderr, other) {
|
||||
var output_div = this.element;
|
||||
|
||||
if (stdout && stderr && other){
|
||||
// clear all, no need for logic
|
||||
output_div.html("");
|
||||
this.element.html("");
|
||||
this.outputs = [];
|
||||
this.unscroll_area();
|
||||
return;
|
||||
}
|
||||
// remove html output
|
||||
// each output_subarea that has an identifying class is in an output_area
|
||||
// which is the element to be removed.
|
||||
if (stdout) {
|
||||
output_div.find("div.output_stdout").parent().remove();
|
||||
}
|
||||
if (stderr) {
|
||||
output_div.find("div.output_stderr").parent().remove();
|
||||
}
|
||||
if (other) {
|
||||
output_div.find("div.output_subarea").not("div.output_stderr").not("div.output_stdout").parent().remove();
|
||||
}
|
||||
this.unscroll_area();
|
||||
|
||||
// remove cleared outputs from JSON list:
|
||||
for (var i = this.outputs.length - 1; i >= 0; i--) {
|
||||
var out = this.outputs[i];
|
||||
var output_type = out.output_type;
|
||||
if (output_type == "display_data" && other) {
|
||||
this.outputs.splice(i,1);
|
||||
} else if (output_type == "stream") {
|
||||
if (stdout && out.stream == "stdout") {
|
||||
this.outputs.splice(i,1);
|
||||
} else if (stderr && out.stream == "stderr") {
|
||||
this.outputs.splice(i,1);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
OutputArea.prototype.flush_clear_timeout = function() {
|
||||
var output_div = this.element;
|
||||
if (this.clear_out_timeout){
|
||||
clearTimeout(this.clear_out_timeout);
|
||||
this.clear_out_timeout = null;
|
||||
this.clear_output_callback(this._clear_stdout, this._clear_stderr, this._clear_other);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user