##// END OF EJS Templates
Adding engine selection UI control to DirectViewWidget.
Brian Granger -
Show More
@@ -28,6 +28,19 b' DirectViewWidget.prototype.create_element = function () {'
28 this.element.addClass('cell border-box-sizing code_cell vbox');
28 this.element.addClass('cell border-box-sizing code_cell vbox');
29 this.element.attr('tabindex','2');
29 this.element.attr('tabindex','2');
30 this.element.css('padding-right',0);
30 this.element.css('padding-right',0);
31
32 var control = $('<div/>').addClass('dv_control').height('30px');
33 var control_label = $('<span/>').html('Select engine(s) to run code on interactively: ');
34 control_label.css('line-height','30px');
35 var select = $('<select/>').addClass('dv_select ui-widget ui-widget-content');
36 select.css('font-size','85%%').css('margin-bottom','5px');
37 var n = this.targets.length;
38 select.append($('<option/>').html('all').attr('value','all'));
39 for (var i=0; i<n; i++) {
40 select.append($('<option/>').html(this.targets[i]).attr('value',this.targets[i]))
41 }
42 control.append(control_label).append(select);
43
31 var input = $('<div></div>').addClass('input hbox');
44 var input = $('<div></div>').addClass('input hbox');
32 var input_area = $('<div/>').addClass('input_area box-flex1');
45 var input_area = $('<div/>').addClass('input_area box-flex1');
33 this.code_mirror = CodeMirror(input_area.get(0), {
46 this.code_mirror = CodeMirror(input_area.get(0), {
@@ -38,7 +51,9 b' DirectViewWidget.prototype.create_element = function () {'
38 });
51 });
39 input.append(input_area);
52 input.append(input_area);
40 var output = $('<div></div>');
53 var output = $('<div></div>');
41 this.element.append(input).append(output);
54
55
56 this.element.append(control).append(input).append(output);
42 this.output_area = new IPython.OutputArea(output, false);
57 this.output_area = new IPython.OutputArea(output, false);
43
58
44 };
59 };
@@ -100,7 +115,11 b' DirectViewWidget.prototype.execute = function () {'
100 'output': $.proxy(this.output_area.handle_output, this.output_area),
115 'output': $.proxy(this.output_area.handle_output, this.output_area),
101 'clear_output': $.proxy(this.output_area.handle_clear_output, this.output_area),
116 'clear_output': $.proxy(this.output_area.handle_clear_output, this.output_area),
102 };
117 };
103 var code = '%(widget_var)s.execute("""'+this.get_text()+'""")';
118 var target = this.element.find('.dv_select option:selected').attr('value');
119 if (target === 'all') {
120 target = '"all"';
121 }
122 var code = '%(widget_var)s.execute("""'+this.get_text()+'""",targets='+target+')';
104 console.log(code);
123 console.log(code);
105 console.log(this.get_text());
124 console.log(this.get_text());
106 var msg_id = this.kernel.execute(code, callbacks, {silent: false});
125 var msg_id = this.kernel.execute(code, callbacks, {silent: false});
@@ -50,18 +50,25 b' class DirectViewWidget(JavascriptWidget):'
50 jscode = jscode % data
50 jscode = jscode % data
51 return jscode
51 return jscode
52
52
53 def execute(self,code):
53 def execute(self, code, targets='all'):
54 ar = self.dv.execute(code,block=False,targets='all')
54 if targets == 'all':
55 targets = self.targets
56 ar = self.dv.execute(code,block=False,targets=targets)
55 ar.wait()
57 ar.wait()
56 metadata = ar.metadata
58 metadata = ar.metadata
57 for md in metadata:
59 if isinstance(metadata, (list,tuple)):
58 if md['stdout']:
60 for md in metadata:
59 publish_pretty(md['stdout'],{'engine_id':md['engine_id']})
61 self.publish_md(md)
60 if md['stderr']:
62 elif isinstance(metadata, dict):
61 publish_pretty(md['stderr'],{'engine_id':md['engine_id']})
63 self.publish_md(metadata)
62 if md['pyerr']:
64
63 publish_pretty(md['pyerr'],{'engine_id':md['engine_id']})
65 def publish_md(self, md):
64
66 if md['stdout']:
67 publish_pretty(md['stdout'],{'engine_id':md['engine_id']})
68 if md['stderr']:
69 publish_pretty(md['stderr'],{'engine_id':md['engine_id']})
70 if md['pyerr']:
71 publish_pretty(md['pyerr'],{'engine_id':md['engine_id']})
65
72
66
73
67 def interact(dv):
74 def interact(dv):
General Comments 0
You need to be logged in to leave comments. Login now