diff --git a/IPython/frontend/html/notebook/widgets/directview.js b/IPython/frontend/html/notebook/widgets/directview.js
index 14aa014..7489a96 100644
--- a/IPython/frontend/html/notebook/widgets/directview.js
+++ b/IPython/frontend/html/notebook/widgets/directview.js
@@ -28,6 +28,19 @@ 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 = $('').addClass('dv_select ui-widget ui-widget-content');
+ select.css('font-size','85%%').css('margin-bottom','5px');
+ var n = this.targets.length;
+ select.append($('').html('all').attr('value','all'));
+ for (var i=0; i').html(this.targets[i]).attr('value',this.targets[i]))
+ }
+ control.append(control_label).append(select);
+
var input = $('').addClass('input hbox');
var input_area = $('').addClass('input_area box-flex1');
this.code_mirror = CodeMirror(input_area.get(0), {
@@ -38,7 +51,9 @@ DirectViewWidget.prototype.create_element = function () {
});
input.append(input_area);
var output = $('');
- this.element.append(input).append(output);
+
+
+ this.element.append(control).append(input).append(output);
this.output_area = new IPython.OutputArea(output, false);
};
@@ -100,7 +115,11 @@ DirectViewWidget.prototype.execute = function () {
'output': $.proxy(this.output_area.handle_output, this.output_area),
'clear_output': $.proxy(this.output_area.handle_clear_output, this.output_area),
};
- var code = '%(widget_var)s.execute("""'+this.get_text()+'""")';
+ var target = this.element.find('.dv_select option:selected').attr('value');
+ if (target === 'all') {
+ 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});
diff --git a/IPython/frontend/html/notebook/widgets/directview.py b/IPython/frontend/html/notebook/widgets/directview.py
index c01b212..b0c20c6 100644
--- a/IPython/frontend/html/notebook/widgets/directview.py
+++ b/IPython/frontend/html/notebook/widgets/directview.py
@@ -50,18 +50,25 @@ class DirectViewWidget(JavascriptWidget):
jscode = jscode % data
return jscode
- def execute(self,code):
- ar = self.dv.execute(code,block=False,targets='all')
+ 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
- for md in metadata:
- 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']})
-
+ 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']})
def interact(dv):