add channel-selection to clear_output

example notebook updated accordingly
This commit is contained in:
MinRK 2011-10-17 18:37:08 -07:00
parent 10deb3b744
commit 24d37b6bcc
2 changed files with 38 additions and 6 deletions

View File

@ -364,9 +364,41 @@ var IPython = (function (IPython) {
} }
CodeCell.prototype.clear_output = function () { CodeCell.prototype.clear_output = function (stdout, stderr, other) {
this.element.find("div.output").html(""); var output_div = this.element.find("div.output");
if (stdout && stderr && other){
// clear all, no need for logic
output_div.html("");
this.outputs = []; this.outputs = [];
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();
}
// 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);
}
}
}
}; };

View File

@ -627,7 +627,7 @@ var IPython = (function (IPython) {
var cells = this.cells(); var cells = this.cells();
for (var i=0; i<ncells; i++) { for (var i=0; i<ncells; i++) {
if (cells[i] instanceof IPython.CodeCell) { if (cells[i] instanceof IPython.CodeCell) {
cells[i].clear_output(); cells[i].clear_output(true,true,true);
} }
}; };
this.dirty = true; this.dirty = true;
@ -734,7 +734,7 @@ var IPython = (function (IPython) {
this.handle_status_dead(); this.handle_status_dead();
}; };
} else if (msg_type === 'clear_output') { } else if (msg_type === 'clear_output') {
cell.clear_output(); cell.clear_output(content.stdout, content.stderr, content.other);
}; };
}; };
@ -825,7 +825,7 @@ var IPython = (function (IPython) {
var cell = that.selected_cell(); var cell = that.selected_cell();
var cell_index = that.find_cell_index(cell); var cell_index = that.find_cell_index(cell);
if (cell instanceof IPython.CodeCell) { if (cell instanceof IPython.CodeCell) {
cell.clear_output(); cell.clear_output(true, true, true);
var code = cell.get_code(); var code = cell.get_code();
var msg_id = that.kernel.execute(cell.get_code()); var msg_id = that.kernel.execute(cell.get_code());
that.msg_cell_map[msg_id] = cell.cell_id; that.msg_cell_map[msg_id] = cell.cell_id;