Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updating the notebook to work with the latex master.

* PNG figures are now used for matplotlib.
* NEW msg format is used where msg_type is in the header.
* Session is used for sending/recving.
  • Loading branch information...
commit 97f1ce7d726070cf8e0c7fedc7504c32cadea1ef 1 parent fd1d84c
@ellisonbg ellisonbg authored
View
7 IPython/frontend/html/notebook/kernelmanager.py
@@ -1,6 +1,13 @@
"""A kernel manager for multiple kernels."""
#-----------------------------------------------------------------------------
+# Copyright (C) 2011 The IPython Development Team
+#
+# Distributed under the terms of the BSD License. The full license is in
+# the file COPYING.txt, distributed as part of this software.
+#-----------------------------------------------------------------------------
+
+#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
View
7 IPython/frontend/html/notebook/notebookapp.py
@@ -1,6 +1,13 @@
"""A tornado based IPython notebook server."""
#-----------------------------------------------------------------------------
+# Copyright (C) 2011 The IPython Development Team
+#
+# Distributed under the terms of the BSD License. The full license is in
+# the file COPYING.txt, distributed as part of this software.
+#-----------------------------------------------------------------------------
+
+#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
View
47 IPython/frontend/html/notebook/routers.py
@@ -1,3 +1,16 @@
+"""Routers that connect WebSockets to ZMQ sockets."""
+
+#-----------------------------------------------------------------------------
+# Copyright (C) 2011 The IPython Development Team
+#
+# Distributed under the terms of the BSD License. The full license is in
+# the file COPYING.txt, distributed as part of this software.
+#-----------------------------------------------------------------------------
+
+#-----------------------------------------------------------------------------
+# Imports
+#-----------------------------------------------------------------------------
+
import uuid
from Queue import Queue
import json
@@ -5,6 +18,10 @@
from IPython.config.configurable import Configurable
from IPython.utils.traitlets import Instance, Int, Dict
+#-----------------------------------------------------------------------------
+# Classes
+#-----------------------------------------------------------------------------
+
class ZMQStreamRouter(Configurable):
zmq_stream = Instance('zmq.eventloop.zmqstream.ZMQStream')
@@ -58,15 +75,26 @@ def _on_zmq_reply(self, msg_list):
"""
pass
+ def _reserialize_reply(self, msg_list):
+ """Reserialize a reply message using JSON.
+
+ This takes the msg list from the ZMQ socket, unserializes it using
+ self.session and then serializes the result using JSON. This method
+ should be used by self._on_zmq_reply to build messages that can
+ be sent back to the browser.
+ """
+ idents, msg_list = self.session.feed_identities(msg_list)
+ msg = self.session.unpack_message(msg_list)
+ msg['header'].pop('date')
+ return json.dumps(msg)
+
class IOPubStreamRouter(ZMQStreamRouter):
def _on_zmq_reply(self, msg_list):
- msg = self.session.unpack_message(msg_list)
- msg = json.dumps(msg)
+ msg = self._reserialize_reply(msg_list)
for client_id, client in self._clients.items():
- for msg in msg_list:
- client.write_message(msg)
+ client.write_message(msg)
class ShellStreamRouter(ZMQStreamRouter):
@@ -74,21 +102,16 @@ class ShellStreamRouter(ZMQStreamRouter):
_request_queue = Instance(Queue,(),{})
def _on_zmq_reply(self, msg_list):
- msg = self.session.unpack_message(msg_list)
- msg = json.dumps(msg)
- print "Reply: ", msg_list
+ msg = self._reserialize_reply(msg_list)
client_id = self._request_queue.get(block=False)
client = self._clients.get(client_id)
if client is not None:
- for msg in msg_list:
- client.write_message(msg)
+ client.write_message(msg)
def forward_msg(self, client_id, msg):
if len(msg) < self.max_msg_size:
msg = json.loads(msg)
- print "Raw msg: ", msg
to_send = self.session.serialize(msg)
- print "to_send: ", to_send, to_send[-3:]
self._request_queue.put(client_id)
- self.session.send_raw(self.zmq_stream, to_send[-3:])
+ self.session.send(self.zmq_stream, msg)
View
7 IPython/frontend/html/notebook/sessionmanager.py
@@ -1,6 +1,13 @@
"""A manager for session and channels for a single kernel."""
#-----------------------------------------------------------------------------
+# Copyright (C) 2011 The IPython Development Team
+#
+# Distributed under the terms of the BSD License. The full license is in
+# the file COPYING.txt, distributed as part of this software.
+#-----------------------------------------------------------------------------
+
+#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
View
2  IPython/frontend/html/notebook/static/css/notebook.css
@@ -166,6 +166,8 @@ div.output_latex {
font-size: 13pt;
}
+div.output_png {
+}
div.text_cell {
background-color: white;
View
25 IPython/frontend/html/notebook/static/js/notebook.js
@@ -441,7 +441,7 @@ Notebook.prototype._kernel_started = function () {
this.kernel.shell_channel.onmessage = function (e) {
reply = $.parseJSON(e.data);
// console.log(reply);
- var msg_type = reply.msg_type;
+ var msg_type = reply.header.msg_type;
var cell = that.cell_for_msg(reply.parent_header.msg_id);
if (msg_type === "execute_reply") {
cell.set_input_prompt(reply.content.execution_count);
@@ -451,8 +451,8 @@ Notebook.prototype._kernel_started = function () {
this.kernel.iopub_channel.onmessage = function (e) {
reply = $.parseJSON(e.data);
var content = reply.content;
- // console.log(reply);
- var msg_type = reply.msg_type;
+ console.log(reply);
+ var msg_type = reply.header.msg_type;
var cell = that.cell_for_msg(reply.parent_header.msg_id);
if (msg_type === "stream") {
cell.expand();
@@ -709,6 +709,7 @@ CodeCell.prototype.append_pyerr = function (ename, evalue, tb) {
CodeCell.prototype.append_display_data = function (data, element) {
+ console.log(data);
if (data["text/latex"] !== undefined) {
this.append_latex(data["text/latex"], element);
// If it is undefined, then we just appended to div.output, which
@@ -719,6 +720,8 @@ CodeCell.prototype.append_display_data = function (data, element) {
};
} else if (data["image/svg+xml"] !== undefined) {
this.append_svg(data["image/svg+xml"], element);
+ } else if (data["image/png"] !== undefined) {
+ this.append_png(data["image/png"], element);
} else if (data["text/plain"] !== undefined) {
this.append_stream(data["text/plain"], element);
};
@@ -744,6 +747,15 @@ CodeCell.prototype.append_svg = function (svg, element) {
};
+CodeCell.prototype.append_png = function (png, element) {
+ element = element || this.element.find("div.output");
+ var toinsert = $("<div/>").addClass("output_area output_png");
+ toinsert.append($("<img/>").attr('src','data:image/png;base64,'+png));
+ element.append(toinsert);
+ return element;
+};
+
+
CodeCell.prototype.append_latex = function (latex, element) {
// This method cannot do the typesetting because the latex first has to
// be on the page.
@@ -982,9 +994,9 @@ Kernel.prototype.get_msg = function (msg_type, content) {
header : {
msg_id : uuid(),
username : "bgranger",
- session: this.session_id
+ session: this.session_id,
+ msg_type : msg_type
},
- msg_type : msg_type,
content : content,
parent_header : {}
};
@@ -1129,4 +1141,5 @@ $(document).ready(function () {
$("#collapse").click(function () {IPYTHON.notebook.collapse();});
$("#expand").click(function () {IPYTHON.notebook.expand();});
-});
+});
+
Please sign in to comment.
Something went wrong with that request. Please try again.