##// END OF EJS Templates
Added wait flag to clear_output.
Jonathan Frederic -
Show More
@@ -657,15 +657,19 b' class Image(DisplayObject):'
657 return unicode(s.split('.')[-1].lower())
657 return unicode(s.split('.')[-1].lower())
658
658
659
659
660 def clear_output():
660 def clear_output(wait=False):
661 """Clear the output of the current cell receiving output."""
661 """Clear the output of the current cell receiving output.
662
663 Parameters
664 ----------
665 wait : bool [default: false]
666 Wait to clear the output until new output is available to replace it."""
662 from IPython.core.interactiveshell import InteractiveShell
667 from IPython.core.interactiveshell import InteractiveShell
663 if InteractiveShell.initialized():
668 if InteractiveShell.initialized():
664 InteractiveShell.instance().display_pub.clear_output()
669 InteractiveShell.instance().display_pub.clear_output(wait)
665 else:
670 else:
666 from IPython.utils import io
671 from IPython.utils import io
667 print('\033[2K\r', file=io.stdout, end='')
672 print('\033[2K\r', file=io.stdout, end='')
668 io.stdout.flush()
673 io.stdout.flush()
669 print('\033[2K\r', file=io.stderr, end='')
674 print('\033[2K\r', file=io.stderr, end='')
670 io.stderr.flush()
675 io.stderr.flush()
671
@@ -108,7 +108,7 b' class DisplayPublisher(Configurable):'
108 if 'text/plain' in data:
108 if 'text/plain' in data:
109 print(data['text/plain'], file=io.stdout)
109 print(data['text/plain'], file=io.stdout)
110
110
111 def clear_output(self):
111 def clear_output(self, wait=False):
112 """Clear the output of the cell receiving output."""
112 """Clear the output of the cell receiving output."""
113 print('\033[2K\r', file=io.stdout, end='')
113 print('\033[2K\r', file=io.stdout, end='')
114 io.stdout.flush()
114 io.stdout.flush()
@@ -123,8 +123,8 b' class CapturingDisplayPublisher(DisplayPublisher):'
123 def publish(self, source, data, metadata=None):
123 def publish(self, source, data, metadata=None):
124 self.outputs.append((source, data, metadata))
124 self.outputs.append((source, data, metadata))
125
125
126 def clear_output(self):
126 def clear_output(self, wait=False):
127 super(CapturingDisplayPublisher, self).clear_output()
127 super(CapturingDisplayPublisher, self).clear_output(wait)
128 if other:
128 if other:
129 # empty the list, *do not* reassign a new list
129 # empty the list, *do not* reassign a new list
130 del self.outputs[:]
130 del self.outputs[:]
@@ -386,8 +386,8 b' var IPython = (function (IPython) {'
386 };
386 };
387
387
388
388
389 CodeCell.prototype.clear_output = function () {
389 CodeCell.prototype.clear_output = function (wait) {
390 this.output_area.clear_output();
390 this.output_area.clear_output(wait);
391 };
391 };
392
392
393
393
@@ -31,7 +31,7 b' var IPython = (function (IPython) {'
31 this.outputs = [];
31 this.outputs = [];
32 this.collapsed = false;
32 this.collapsed = false;
33 this.scrolled = false;
33 this.scrolled = false;
34 this.clear_out_timeout = null;
34 this.clear_queued = null;
35 if (prompt_area === undefined) {
35 if (prompt_area === undefined) {
36 this.prompt_area = true;
36 this.prompt_area = true;
37 } else {
37 } else {
@@ -289,6 +289,12 b' var IPython = (function (IPython) {'
289 OutputArea.prototype.append_output = function (json, dynamic) {
289 OutputArea.prototype.append_output = function (json, dynamic) {
290 // If dynamic is true, javascript output will be eval'd.
290 // If dynamic is true, javascript output will be eval'd.
291 this.expand();
291 this.expand();
292
293 // Clear the output if clear is queued.
294 if (this.clear_queued) {
295 this.clear_output(false);
296 }
297
292 if (json.output_type === 'pyout') {
298 if (json.output_type === 'pyout') {
293 this.append_pyout(json, dynamic);
299 this.append_pyout(json, dynamic);
294 } else if (json.output_type === 'pyerr') {
300 } else if (json.output_type === 'pyerr') {
@@ -605,21 +611,32 b' var IPython = (function (IPython) {'
605
611
606
612
607 OutputArea.prototype.handle_clear_output = function (content) {
613 OutputArea.prototype.handle_clear_output = function (content) {
608 this.clear_output();
614 this.clear_output(content.wait);
609 };
615 };
610
616
611
617
612 OutputArea.prototype.clear_output = function() {
618 OutputArea.prototype.clear_output = function(wait) {
613
619 if (wait) {
614 // Fix the output div's height
615 var height = this.element.height();
616 this.element.height(height);
617
620
618 // clear all, no need for logic
621 // If a clear is queued, clear before adding another to the queue.
619 this.element.html("");
622 if (this.clear_queued) {
620 this.outputs = [];
623 this.clear_output(false);
621 this.unscroll_area();
624 };
622 return;
625
626 this.clear_queued = true;
627 } else {
628 this.clear_queued = false;
629
630 // Fix the output div's height
631 var height = this.element.height();
632 this.element.height(height);
633
634 // clear all, no need for logic
635 this.element.html("");
636 this.outputs = [];
637 this.unscroll_area();
638 return;
639 };
623 };
640 };
624
641
625
642
@@ -86,8 +86,8 b' class ZMQDisplayPublisher(DisplayPublisher):'
86 parent=self.parent_header, ident=self.topic,
86 parent=self.parent_header, ident=self.topic,
87 )
87 )
88
88
89 def clear_output(self):
89 def clear_output(self, wait=False):
90 content = {}
90 content = dict(wait=wait)
91
91
92 print('\r', file=sys.stdout, end='')
92 print('\r', file=sys.stdout, end='')
93 print('\r', file=sys.stderr, end='')
93 print('\r', file=sys.stderr, end='')
@@ -984,6 +984,20 b' Message type: ``status``::'
984 execution_state : ('busy', 'idle', 'starting')
984 execution_state : ('busy', 'idle', 'starting')
985 }
985 }
986
986
987 Clear output
988 ------------
989
990 This message type is used to clear the output that is visible on the frontend.
991
992 Message type: ``clear_output``::
993
994 content = {
995
996 # Wait to clear the output until new output is available. Clears the
997 # existing output immediately before the new output is displayed.
998 # Useful for creating simple animations with minimal flickering.
999 'wait' : bool,
1000 }
987
1001
988 Messages on the stdin ROUTER/DEALER sockets
1002 Messages on the stdin ROUTER/DEALER sockets
989 ===========================================
1003 ===========================================
General Comments 0
You need to be logged in to leave comments. Login now