Show More
@@ -657,35 +657,15 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(stdout=True, stderr=True, other=True): |
|
660 | def clear_output(): | |
661 | """Clear the output of the current cell receiving output. |
|
661 | """Clear the output of the current cell receiving output.""" | |
662 |
|
||||
663 | Optionally, each of stdout/stderr or other non-stream data (e.g. anything |
|
|||
664 | produced by display()) can be excluded from the clear event. |
|
|||
665 |
|
||||
666 | By default, everything is cleared. |
|
|||
667 |
|
||||
668 | Parameters |
|
|||
669 | ---------- |
|
|||
670 | stdout : bool [default: True] |
|
|||
671 | Whether to clear stdout. |
|
|||
672 | stderr : bool [default: True] |
|
|||
673 | Whether to clear stderr. |
|
|||
674 | other : bool [default: True] |
|
|||
675 | Whether to clear everything else that is not stdout/stderr |
|
|||
676 | (e.g. figures,images,HTML, any result of display()). |
|
|||
677 | """ |
|
|||
678 | from IPython.core.interactiveshell import InteractiveShell |
|
662 | from IPython.core.interactiveshell import InteractiveShell | |
679 | if InteractiveShell.initialized(): |
|
663 | if InteractiveShell.initialized(): | |
680 | InteractiveShell.instance().display_pub.clear_output( |
|
664 | InteractiveShell.instance().display_pub.clear_output() | |
681 | stdout=stdout, stderr=stderr, other=other, |
|
|||
682 | ) |
|
|||
683 | else: |
|
665 | else: | |
684 | from IPython.utils import io |
|
666 | from IPython.utils import io | |
685 | if stdout: |
|
667 | print('\033[2K\r', file=io.stdout, end='') | |
686 | print('\033[2K\r', file=io.stdout, end='') |
|
668 | io.stdout.flush() | |
687 | io.stdout.flush() |
|
669 | print('\033[2K\r', file=io.stderr, end='') | |
688 |
i |
|
670 | io.stderr.flush() | |
689 | print('\033[2K\r', file=io.stderr, end='') |
|
|||
690 | io.stderr.flush() |
|
|||
691 |
|
671 |
@@ -108,14 +108,12 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, stdout=True, stderr=True, other=True): |
|
111 | def clear_output(self): | |
112 | """Clear the output of the cell receiving output.""" |
|
112 | """Clear the output of the cell receiving output.""" | |
113 | if stdout: |
|
113 | print('\033[2K\r', file=io.stdout, end='') | |
114 | print('\033[2K\r', file=io.stdout, end='') |
|
114 | io.stdout.flush() | |
115 | io.stdout.flush() |
|
115 | print('\033[2K\r', file=io.stderr, end='') | |
116 |
i |
|
116 | io.stderr.flush() | |
117 | print('\033[2K\r', file=io.stderr, end='') |
|
|||
118 | io.stderr.flush() |
|
|||
119 |
|
117 | |||
120 |
|
118 | |||
121 | class CapturingDisplayPublisher(DisplayPublisher): |
|
119 | class CapturingDisplayPublisher(DisplayPublisher): | |
@@ -125,8 +123,8 b' class CapturingDisplayPublisher(DisplayPublisher):' | |||||
125 | def publish(self, source, data, metadata=None): |
|
123 | def publish(self, source, data, metadata=None): | |
126 | self.outputs.append((source, data, metadata)) |
|
124 | self.outputs.append((source, data, metadata)) | |
127 |
|
125 | |||
128 | def clear_output(self, stdout=True, stderr=True, other=True): |
|
126 | def clear_output(self): | |
129 |
super(CapturingDisplayPublisher, self).clear_output( |
|
127 | super(CapturingDisplayPublisher, self).clear_output() | |
130 | if other: |
|
128 | if other: | |
131 | # empty the list, *do not* reassign a new list |
|
129 | # empty the list, *do not* reassign a new list | |
132 | del self.outputs[:] |
|
130 | del self.outputs[:] |
@@ -240,7 +240,7 b' var IPython = (function (IPython) {' | |||||
240 | * @method execute |
|
240 | * @method execute | |
241 | */ |
|
241 | */ | |
242 | CodeCell.prototype.execute = function () { |
|
242 | CodeCell.prototype.execute = function () { | |
243 |
this.output_area.clear_output( |
|
243 | this.output_area.clear_output(); | |
244 | this.set_input_prompt('*'); |
|
244 | this.set_input_prompt('*'); | |
245 | this.element.addClass("running"); |
|
245 | this.element.addClass("running"); | |
246 | var callbacks = { |
|
246 | var callbacks = { | |
@@ -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 () { | |
390 |
this.output_area.clear_output( |
|
390 | this.output_area.clear_output(); | |
391 | }; |
|
391 | }; | |
392 |
|
392 | |||
393 |
|
393 |
@@ -1339,7 +1339,7 b' var IPython = (function (IPython) {' | |||||
1339 | var cells = this.get_cells(); |
|
1339 | var cells = this.get_cells(); | |
1340 | for (var i=0; i<ncells; i++) { |
|
1340 | for (var i=0; i<ncells; i++) { | |
1341 | if (cells[i] instanceof IPython.CodeCell) { |
|
1341 | if (cells[i] instanceof IPython.CodeCell) { | |
1342 |
cells[i].clear_output( |
|
1342 | cells[i].clear_output(); | |
1343 | // Make all In[] prompts blank, as well |
|
1343 | // Make all In[] prompts blank, as well | |
1344 | // TODO: make this configurable (via checkbox?) |
|
1344 | // TODO: make this configurable (via checkbox?) | |
1345 | cells[i].set_input_prompt(); |
|
1345 | cells[i].set_input_prompt(); |
@@ -605,52 +605,21 b' var IPython = (function (IPython) {' | |||||
605 |
|
605 | |||
606 |
|
606 | |||
607 | OutputArea.prototype.handle_clear_output = function (content) { |
|
607 | OutputArea.prototype.handle_clear_output = function (content) { | |
608 | this.clear_output(content.stdout, content.stderr, content.other); |
|
608 | this.clear_output(); | |
609 | }; |
|
609 | }; | |
610 |
|
610 | |||
611 |
|
611 | |||
612 |
OutputArea.prototype.clear_output = function |
|
612 | OutputArea.prototype.clear_output = function() { | |
613 | var output_div = this.element; |
|
613 | ||
614 |
|
||||
615 | // Fix the output div's height |
|
614 | // Fix the output div's height | |
616 |
var height = |
|
615 | var height = this.element.height(); | |
617 |
|
|
616 | this.element.height(height); | |
618 |
|
617 | |||
619 | if (stdout && stderr && other){ |
|
618 | // clear all, no need for logic | |
620 | // clear all, no need for logic |
|
619 | this.element.html(""); | |
621 | output_div.html(""); |
|
620 | this.outputs = []; | |
622 | this.outputs = []; |
|
|||
623 | this.unscroll_area(); |
|
|||
624 | return; |
|
|||
625 | } |
|
|||
626 | // remove html output |
|
|||
627 | // each output_subarea that has an identifying class is in an output_area |
|
|||
628 | // which is the element to be removed. |
|
|||
629 | if (stdout) { |
|
|||
630 | output_div.find("div.output_stdout").parent().remove(); |
|
|||
631 | } |
|
|||
632 | if (stderr) { |
|
|||
633 | output_div.find("div.output_stderr").parent().remove(); |
|
|||
634 | } |
|
|||
635 | if (other) { |
|
|||
636 | output_div.find("div.output_subarea").not("div.output_stderr").not("div.output_stdout").parent().remove(); |
|
|||
637 | } |
|
|||
638 | this.unscroll_area(); |
|
621 | this.unscroll_area(); | |
639 |
|
622 | return; | ||
640 | // remove cleared outputs from JSON list: |
|
|||
641 | for (var i = this.outputs.length - 1; i >= 0; i--) { |
|
|||
642 | var out = this.outputs[i]; |
|
|||
643 | var output_type = out.output_type; |
|
|||
644 | if (output_type == "display_data" && other) { |
|
|||
645 | this.outputs.splice(i,1); |
|
|||
646 | } else if (output_type == "stream") { |
|
|||
647 | if (stdout && out.stream == "stdout") { |
|
|||
648 | this.outputs.splice(i,1); |
|
|||
649 | } else if (stderr && out.stream == "stderr") { |
|
|||
650 | this.outputs.splice(i,1); |
|
|||
651 | } |
|
|||
652 | } |
|
|||
653 | } |
|
|||
654 | }; |
|
623 | }; | |
655 |
|
624 | |||
656 |
|
625 |
@@ -86,14 +86,11 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, stdout=True, stderr=True, other=True): |
|
89 | def clear_output(self): | |
90 | content = dict(stdout=stdout, stderr=stderr, other=other) |
|
90 | content = {} | |
91 |
|
91 | |||
92 | if stdout: |
|
92 | print('\r', file=sys.stdout, end='') | |
93 |
|
|
93 | print('\r', file=sys.stderr, end='') | |
94 | if stderr: |
|
|||
95 | print('\r', file=sys.stderr, end='') |
|
|||
96 |
|
||||
97 | self._flush_streams() |
|
94 | self._flush_streams() | |
98 |
|
95 | |||
99 | self.session.send( |
|
96 | self.session.send( |
@@ -108,7 +108,7 b' DirectViewWidget.prototype.set_kernel = function (kernel) {' | |||||
108 |
|
108 | |||
109 |
|
109 | |||
110 | DirectViewWidget.prototype.execute = function () { |
|
110 | DirectViewWidget.prototype.execute = function () { | |
111 |
this.output_area.clear_output( |
|
111 | this.output_area.clear_output(); | |
112 | this.element.addClass("running"); |
|
112 | this.element.addClass("running"); | |
113 | var callbacks = { |
|
113 | var callbacks = { | |
114 | 'execute_reply': $.proxy(this._handle_execute_reply, this), |
|
114 | 'execute_reply': $.proxy(this._handle_execute_reply, this), |
General Comments 0
You need to be logged in to leave comments.
Login now