diff --git a/IPython/frontend/html/notebook/widgets/directview.js b/IPython/frontend/html/notebook/widgets/directview.js index 7489a96..7eed2ad 100644 --- a/IPython/frontend/html/notebook/widgets/directview.js +++ b/IPython/frontend/html/notebook/widgets/directview.js @@ -120,8 +120,6 @@ DirectViewWidget.prototype.execute = function () { target = '"all"'; } var code = '%(widget_var)s.execute("""'+this.get_text()+'""",targets='+target+')'; - console.log(code); - console.log(this.get_text()); var msg_id = this.kernel.execute(code, callbacks, {silent: false}); this.clear_input(); this.code_mirror.focus(); diff --git a/IPython/frontend/html/notebook/widgets/directview.py b/IPython/frontend/html/notebook/widgets/directview.py index b0c20c6..8a46c63 100644 --- a/IPython/frontend/html/notebook/widgets/directview.py +++ b/IPython/frontend/html/notebook/widgets/directview.py @@ -53,22 +53,9 @@ class DirectViewWidget(JavascriptWidget): def execute(self, code, targets='all'): if targets == 'all': targets = self.targets - ar = self.dv.execute(code,block=False,targets=targets) - ar.wait() - metadata = ar.metadata - if isinstance(metadata, (list,tuple)): - for md in metadata: - self.publish_md(md) - elif isinstance(metadata, dict): - self.publish_md(metadata) - - def publish_md(self, md): - if md['stdout']: - publish_pretty(md['stdout'],{'engine_id':md['engine_id']}) - if md['stderr']: - publish_pretty(md['stderr'],{'engine_id':md['engine_id']}) - if md['pyerr']: - publish_pretty(md['pyerr'],{'engine_id':md['engine_id']}) + result = self.dv.execute(code,silent=False,block=False,targets=targets) + result.wait() + result.display_outputs() def interact(dv): diff --git a/docs/examples/parallel/direct_view_widget.ipynb b/docs/examples/parallel/direct_view_widget.ipynb new file mode 100644 index 0000000..33e9631 --- /dev/null +++ b/docs/examples/parallel/direct_view_widget.ipynb @@ -0,0 +1,255 @@ +{ + "metadata": { + "name": "direct_view_widget" + }, + "nbformat": 3, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "source": [ + "Direct View Widget" + ] + }, + { + "cell_type": "markdown", + "source": [ + "IPython has a JavaScript widget for interacting with an IPython parallel engine interactively in the Notebook. This Notebook shows how this widget can be used." + ] + }, + { + "cell_type": "code", + "input": [ + "from IPython.frontend.html.notebook.widgets import directview", + "from IPython.parallel import Client" + ], + "language": "python", + "outputs": [], + "prompt_number": 4 + }, + { + "cell_type": "markdown", + "source": [ + "Let's create a `Client` and build a `DirectView` containing all of the engines:" + ] + }, + { + "cell_type": "code", + "input": [ + "c = Client()", + "dv = c[:]" + ], + "language": "python", + "outputs": [], + "prompt_number": 5 + }, + { + "cell_type": "markdown", + "source": [ + "To interact with the engines we simply pass the `DirectView` instance to the `interact` function. The resulting widget has an embedded notebook cell, but any code entered into the embedded cell is run on the engines you choose. The engines are now full blown IPython kernels so you can enter arbitrary Python/IPython code and even make plots on the engines." + ] + }, + { + "cell_type": "code", + "input": [ + "directview.interact(dv)" + ], + "language": "python", + "outputs": [ + { + "javascript": [ + "//----------------------------------------------------------------------------", + "// Copyright (C) 2008-2012 The IPython Development Team", + "//", + "// Distributed under the terms of the BSD License. The full license is in", + "// the file COPYING, distributed as part of this software.", + "//----------------------------------------------------------------------------", + "", + "//============================================================================", + "// EngineInteract", + "//============================================================================", + "", + "var key = IPython.utils.keycodes;", + "", + "", + "var DirectViewWidget = function (selector, kernel, targets) {", + " // The kernel doesn't have to be set at creation time, in that case", + " // it will be null and set_kernel has to be called later.", + " this.selector = selector;", + " this.element = $(selector);", + " this.kernel = kernel || null;", + " this.code_mirror = null;", + " this.targets = targets;", + " this.create_element();", + "};", + "", + "", + "DirectViewWidget.prototype.create_element = function () {", + " this.element.addClass('cell border-box-sizing code_cell vbox');", + " this.element.attr('tabindex','2');", + " this.element.css('padding-right',0);", + "", + " var control = $('
').addClass('dv_control').height('30px');", + " var control_label = $('').html('Select engine(s) to run code on interactively: ');", + " control_label.css('line-height','30px');", + " var select = $('