##// END OF EJS Templates
Output Widget
Jonathan Frederic -
Show More
@@ -0,0 +1,41 b''
1 // Copyright (c) IPython Development Team.
2 // Distributed under the terms of the Modified BSD License.
3
4 define([
5 "widgets/js/widget",
6 "jquery",
7 'notebook/js/outputarea',
8 ], function(widget, $, outputarea){
9
10 var OutputView = widget.DOMWidgetView.extend({
11 initialize: function (parameters) {
12 // Public constructor
13 OutputView.__super__.initialize.apply(this, [parameters]);
14 this.model.on('msg:custom', this._handle_route_msg, this);
15 },
16
17 render: function(){
18 // Called when view is rendered.
19 this.output_area = new outputarea.OutputArea({
20 selector: this.$el,
21 prompt_area: false,
22 events: this.model.widget_manager.notebook.events,
23 keyboard_manager: this.model.widget_manager.keyboard_manager });
24 },
25
26 _handle_route_msg: function(content) {
27 var cell = this.options.cell;
28 if (content && cell) {
29 if (content.method == 'push') {
30 cell.push_output_area(this.output_area);
31 } else if (content.method == 'pop') {
32 cell.pop_output_area(this.output_area);
33 }
34 }
35 },
36 });
37
38 return {
39 'OutputView': OutputView,
40 };
41 });
@@ -0,0 +1,32 b''
1 """Output class.
2
3 Represents a widget that can be used to display output within the widget area.
4 """
5
6 # Copyright (c) IPython Development Team.
7 # Distributed under the terms of the Modified BSD License.
8
9 from .widget import DOMWidget
10 import sys
11 from IPython.utils.traitlets import Unicode, List
12 from IPython.display import clear_output
13
14 class Output(DOMWidget):
15 """Displays multiple widgets in a group."""
16 _view_name = Unicode('OutputView', sync=True)
17
18 def clear_output(self, *pargs, **kwargs):
19 with self:
20 clear_output(*pargs, **kwargs)
21
22 def __enter__(self):
23 self._flush()
24 self.send({'method': 'push'})
25
26 def __exit__(self, exception_type, exception_value, traceback):
27 self._flush()
28 self.send({'method': 'pop'})
29
30 def _flush(self):
31 sys.stdout.flush()
32 sys.stderr.flush()
@@ -23,6 +23,7 b' define(['
23 'notebook/js/codemirror-ipython'
23 'notebook/js/codemirror-ipython'
24 ], function(IPython, $, utils, keyboard, cell, outputarea, completer, celltoolbar, CodeMirror, cmpython, cmip) {
24 ], function(IPython, $, utils, keyboard, cell, outputarea, completer, celltoolbar, CodeMirror, cmpython, cmip) {
25 "use strict";
25 "use strict";
26
26 var Cell = cell.Cell;
27 var Cell = cell.Cell;
27
28
28 /* local util for codemirror */
29 /* local util for codemirror */
@@ -79,6 +80,7 b' define(['
79 this.input_prompt_number = null;
80 this.input_prompt_number = null;
80 this.celltoolbar = null;
81 this.celltoolbar = null;
81 this.output_area = null;
82 this.output_area = null;
83 this.active_output_area = [];
82 this.last_msg_id = null;
84 this.last_msg_id = null;
83 this.completer = null;
85 this.completer = null;
84
86
@@ -118,6 +120,31 b' define(['
118 CodeCell.prototype = Object.create(Cell.prototype);
120 CodeCell.prototype = Object.create(Cell.prototype);
119
121
120 /**
122 /**
123 * @method get_output_area
124 */
125 CodeCell.prototype.get_output_area = function () {
126 if (this.active_output_area && this.active_output_area.length > 0) {
127 return this.active_output_area[this.active_output_area.length-1];
128 } else {
129 return this.output_area;
130 }
131 };
132
133 /**
134 * @method push_output_area
135 */
136 CodeCell.prototype.push_output_area = function (output_area) {
137 this.active_output_area.push(output_area);
138 };
139
140 /**
141 * @method pop_output_area
142 */
143 CodeCell.prototype.pop_output_area = function () {
144 this.active_output_area.pop();
145 };
146
147 /**
121 * @method auto_highlight
148 * @method auto_highlight
122 */
149 */
123 CodeCell.prototype.auto_highlight = function () {
150 CodeCell.prototype.auto_highlight = function () {
@@ -282,8 +309,8 b' define(['
282 console.log("Can't execute, kernel is not connected.");
309 console.log("Can't execute, kernel is not connected.");
283 return;
310 return;
284 }
311 }
285
312
286 this.output_area.clear_output();
313 this.get_output_area().clear_output();
287
314
288 // Clear widget area
315 // Clear widget area
289 this.widget_subarea.html('');
316 this.widget_subarea.html('');
@@ -312,6 +339,7 b' define(['
312 * @method get_callbacks
339 * @method get_callbacks
313 */
340 */
314 CodeCell.prototype.get_callbacks = function () {
341 CodeCell.prototype.get_callbacks = function () {
342 var that = this;
315 return {
343 return {
316 shell : {
344 shell : {
317 reply : $.proxy(this._handle_execute_reply, this),
345 reply : $.proxy(this._handle_execute_reply, this),
@@ -321,8 +349,14 b' define(['
321 }
349 }
322 },
350 },
323 iopub : {
351 iopub : {
324 output : $.proxy(this.output_area.handle_output, this.output_area),
352 output : function() {
325 clear_output : $.proxy(this.output_area.handle_clear_output, this.output_area),
353 var output_area = that.get_output_area();
354 output_area.handle_output.apply(output_area, arguments);
355 },
356 clear_output : function() {
357 var output_area = that.get_output_area();
358 output_area.handle_clear_output.apply(output_area, arguments);
359 },
326 },
360 },
327 input : $.proxy(this._handle_input_request, this)
361 input : $.proxy(this._handle_input_request, this)
328 };
362 };
@@ -356,7 +390,7 b' define(['
356 * @private
390 * @private
357 */
391 */
358 CodeCell.prototype._handle_input_request = function (msg) {
392 CodeCell.prototype._handle_input_request = function (msg) {
359 this.output_area.append_raw_input(msg);
393 this.get_output_area().append_raw_input(msg);
360 };
394 };
361
395
362
396
@@ -459,7 +493,7 b' define(['
459
493
460
494
461 CodeCell.prototype.clear_output = function (wait) {
495 CodeCell.prototype.clear_output = function (wait) {
462 this.output_area.clear_output(wait);
496 this.get_output_area().clear_output(wait);
463 this.set_input_prompt();
497 this.set_input_prompt();
464 };
498 };
465
499
@@ -9,6 +9,7 b' define(['
9 "widgets/js/widget_float",
9 "widgets/js/widget_float",
10 "widgets/js/widget_image",
10 "widgets/js/widget_image",
11 "widgets/js/widget_int",
11 "widgets/js/widget_int",
12 "widgets/js/widget_output",
12 "widgets/js/widget_selection",
13 "widgets/js/widget_selection",
13 "widgets/js/widget_selectioncontainer",
14 "widgets/js/widget_selectioncontainer",
14 "widgets/js/widget_string",
15 "widgets/js/widget_string",
@@ -6,6 +6,7 b' from .widget_box import Box, Popup, FlexBox, HBox, VBox'
6 from .widget_float import FloatText, BoundedFloatText, FloatSlider, FloatProgress, FloatRangeSlider
6 from .widget_float import FloatText, BoundedFloatText, FloatSlider, FloatProgress, FloatRangeSlider
7 from .widget_image import Image
7 from .widget_image import Image
8 from .widget_int import IntText, BoundedIntText, IntSlider, IntProgress, IntRangeSlider
8 from .widget_int import IntText, BoundedIntText, IntSlider, IntProgress, IntRangeSlider
9 from .widget_output import Output
9 from .widget_selection import RadioButtons, ToggleButtons, Dropdown, Select
10 from .widget_selection import RadioButtons, ToggleButtons, Dropdown, Select
10 from .widget_selectioncontainer import Tab, Accordion
11 from .widget_selectioncontainer import Tab, Accordion
11 from .widget_string import HTML, Latex, Text, Textarea
12 from .widget_string import HTML, Latex, Text, Textarea
General Comments 0
You need to be logged in to leave comments. Login now