From 2b6add80f125c703a958a543f62fea321fbc44ac Mon Sep 17 00:00:00 2001 From: Jonathan Frederic Date: Wed, 18 Sep 2013 18:11:45 +0000 Subject: [PATCH 1/4] Remove clear_output timeout callback in favor of fixed height --- IPython/html/static/notebook/js/outputarea.js | 40 +++---------------- 1 file changed, 5 insertions(+), 35 deletions(-) diff --git a/IPython/html/static/notebook/js/outputarea.js b/IPython/html/static/notebook/js/outputarea.js index 08f40bfa1..72140ad96 100644 --- a/IPython/html/static/notebook/js/outputarea.js +++ b/IPython/html/static/notebook/js/outputarea.js @@ -289,7 +289,6 @@ 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(); if (json.output_type === 'pyout') { this.append_pyout(json, dynamic); } else if (json.output_type === 'pyerr') { @@ -300,6 +299,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 +553,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 @@ -611,31 +610,12 @@ var IPython = (function (IPython) { 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); - } - // 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; + // Fix the output div's height + var height = output_div.height(); + output_div.height(height); + if (stdout && stderr && other){ // clear all, no need for logic output_div.html(""); @@ -674,16 +654,6 @@ var IPython = (function (IPython) { }; - 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); - } - }; - - // JSON serialization OutputArea.prototype.fromJSON = function (outputs) { From 00f0c827e9cd221afc2ee1cff544a7df3f10960e Mon Sep 17 00:00:00 2001 From: Jonathan Frederic Date: Wed, 18 Sep 2013 22:56:31 +0000 Subject: [PATCH 2/4] Removed ability to clear stdout and stderr individually. --- IPython/html/static/notebook/js/codecell.js | 6 +-- IPython/html/static/notebook/js/notebook.js | 2 +- IPython/html/static/notebook/js/outputarea.js | 53 ++++--------------- 3 files changed, 15 insertions(+), 46 deletions(-) diff --git a/IPython/html/static/notebook/js/codecell.js b/IPython/html/static/notebook/js/codecell.js index 492b902f2..3ccc9f8db 100644 --- a/IPython/html/static/notebook/js/codecell.js +++ b/IPython/html/static/notebook/js/codecell.js @@ -240,7 +240,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"); var callbacks = { @@ -386,8 +386,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 () { + this.output_area.clear_output(); }; diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js index e4be4dd2b..88891ac52 100644 --- a/IPython/html/static/notebook/js/notebook.js +++ b/IPython/html/static/notebook/js/notebook.js @@ -1339,7 +1339,7 @@ var IPython = (function (IPython) { var cells = this.get_cells(); for (var i=0; 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); - } - } - } + // Fix the output div's height + var height = this.element.height(); + this.element.height(height); + + // clear all, no need for logic + this.element.html(""); + this.outputs = []; + this.unscroll_area(); + return; }; From 6bfd28b91dbccc00f3d16e2a78515abd37db9241 Mon Sep 17 00:00:00 2001 From: Jonathan Frederic Date: Thu, 19 Sep 2013 00:37:37 +0000 Subject: [PATCH 3/4] Added wait flag to clear_output. --- IPython/html/static/notebook/js/codecell.js | 4 +- IPython/html/static/notebook/js/outputarea.js | 41 +++++++++++++------ 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/IPython/html/static/notebook/js/codecell.js b/IPython/html/static/notebook/js/codecell.js index 3ccc9f8db..a23094f31 100644 --- a/IPython/html/static/notebook/js/codecell.js +++ b/IPython/html/static/notebook/js/codecell.js @@ -386,8 +386,8 @@ var IPython = (function (IPython) { }; - CodeCell.prototype.clear_output = function () { - this.output_area.clear_output(); + CodeCell.prototype.clear_output = function (wait) { + this.output_area.clear_output(wait); }; diff --git a/IPython/html/static/notebook/js/outputarea.js b/IPython/html/static/notebook/js/outputarea.js index d6b6fd091..9e6ddf31a 100644 --- a/IPython/html/static/notebook/js/outputarea.js +++ b/IPython/html/static/notebook/js/outputarea.js @@ -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,6 +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(); + + // 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') { @@ -605,21 +611,32 @@ var IPython = (function (IPython) { OutputArea.prototype.handle_clear_output = function (content) { - this.clear_output(); + this.clear_output(content.wait); }; - OutputArea.prototype.clear_output = function() { - - // Fix the output div's height - var height = this.element.height(); - this.element.height(height); + OutputArea.prototype.clear_output = function(wait) { + if (wait) { - // clear all, no need for logic - this.element.html(""); - this.outputs = []; - this.unscroll_area(); - return; + // 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 { + this.clear_queued = false; + + // Fix the output div's height + var height = this.element.height(); + this.element.height(height); + + // clear all, no need for logic + this.element.html(""); + this.outputs = []; + this.unscroll_area(); + return; + }; }; From b8d7197ec66d91b566c1282808202f2305fc15fa Mon Sep 17 00:00:00 2001 From: Jonathan Frederic Date: Thu, 19 Sep 2013 11:12:12 -0700 Subject: [PATCH 4/4] Don't preserve height when clear_output(wait=False) is called --- IPython/html/static/notebook/js/outputarea.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/IPython/html/static/notebook/js/outputarea.js b/IPython/html/static/notebook/js/outputarea.js index 9e6ddf31a..3fea91a33 100644 --- a/IPython/html/static/notebook/js/outputarea.js +++ b/IPython/html/static/notebook/js/outputarea.js @@ -625,12 +625,15 @@ var IPython = (function (IPython) { this.clear_queued = true; } else { - this.clear_queued = false; - - // Fix the output div's height - var height = this.element.height(); - this.element.height(height); + // 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; + } + // clear all, no need for logic this.element.html(""); this.outputs = [];