##// END OF EJS Templates
Adding clear_output to kernel and HTML notebook.
Brian Granger -
Show More
@@ -0,0 +1,56 b''
1 {
2 "worksheets": [
3 {
4 "cells": [
5 {
6 "source": "A demonstration of the ability to clear the output of a cell during execution.",
7 "cell_type": "markdown"
8 },
9 {
10 "cell_type": "code",
11 "language": "python",
12 "outputs": [],
13 "collapsed": true,
14 "prompt_number": 8,
15 "input": "from IPython.core.display import clear_output, display"
16 },
17 {
18 "cell_type": "code",
19 "language": "python",
20 "outputs": [],
21 "collapsed": false,
22 "prompt_number": 4,
23 "input": "import time"
24 },
25 {
26 "source": "First we show how this works with ``display``:",
27 "cell_type": "markdown"
28 },
29 {
30 "cell_type": "code",
31 "language": "python",
32 "outputs": [],
33 "collapsed": false,
34 "prompt_number": 17,
35 "input": "for i in range(10):\n display(\"Time step: %i\" % i)\n time.sleep(0.5)\n clear_output()"
36 },
37 {
38 "source": "Next, we show that ``clear_output`` can also be used to create a primitive form of animation using\nmatplotlib:",
39 "cell_type": "markdown"
40 },
41 {
42 "cell_type": "code",
43 "language": "python",
44 "outputs": [],
45 "collapsed": false,
46 "prompt_number": 20,
47 "input": "for i in range(10):\n figure()\n plot(rand(100))\n show()\n time.sleep(0.1)\n clear_output()"
48 }
49 ]
50 }
51 ],
52 "metadata": {
53 "name": "clear_output"
54 },
55 "nbformat": 2
56 } No newline at end of file
@@ -381,3 +381,9 b' class Image(DisplayObject):'
381
381
382 def _find_ext(self, s):
382 def _find_ext(self, s):
383 return unicode(s.split('.')[-1].lower())
383 return unicode(s.split('.')[-1].lower())
384
385
386 def clear_output():
387 """Clear the output of the current cell receiving output."""
388 from IPython.core.interactiveshell import InteractiveShell
389 InteractiveShell.instance().display_pub.clear_output()
@@ -104,6 +104,10 b' class DisplayPublisher(Configurable):'
104 if data.has_key('text/plain'):
104 if data.has_key('text/plain'):
105 print(data['text/plain'], file=io.stdout)
105 print(data['text/plain'], file=io.stdout)
106
106
107 def clear_output(self):
108 """Clear the output of the cell receiving output."""
109 pass
110
107
111
108 def publish_display_data(source, data, metadata=None):
112 def publish_display_data(source, data, metadata=None):
109 """Publish data and metadata to all frontends.
113 """Publish data and metadata to all frontends.
@@ -733,7 +733,9 b' var IPython = (function (IPython) {'
733 } else if (content.execution_state === 'dead') {
733 } else if (content.execution_state === 'dead') {
734 this.handle_status_dead();
734 this.handle_status_dead();
735 };
735 };
736 }
736 } else if (msg_type === 'clear_output') {
737 cell.clear_output();
738 };
737 };
739 };
738
740
739
741
@@ -80,6 +80,11 b' class ZMQDisplayPublisher(DisplayPublisher):'
80 parent=self.parent_header
80 parent=self.parent_header
81 )
81 )
82
82
83 def clear_output(self):
84 self.session.send(
85 self.pub_socket, u'clear_output', {},
86 parent=self.parent_header
87 )
83
88
84 class ZMQInteractiveShell(InteractiveShell):
89 class ZMQInteractiveShell(InteractiveShell):
85 """A subclass of InteractiveShell for ZMQ."""
90 """A subclass of InteractiveShell for ZMQ."""
General Comments 0
You need to be logged in to leave comments. Login now