parent
4cd8ee3bb2
commit
a5779bcd0e
@ -0,0 +1,41 @@
|
||||
// Copyright (c) IPython Development Team.
|
||||
// Distributed under the terms of the Modified BSD License.
|
||||
|
||||
define([
|
||||
"widgets/js/widget",
|
||||
"jquery",
|
||||
'notebook/js/outputarea',
|
||||
], function(widget, $, outputarea){
|
||||
|
||||
var OutputView = widget.DOMWidgetView.extend({
|
||||
initialize: function (parameters) {
|
||||
// Public constructor
|
||||
OutputView.__super__.initialize.apply(this, [parameters]);
|
||||
this.model.on('msg:custom', this._handle_route_msg, this);
|
||||
},
|
||||
|
||||
render: function(){
|
||||
// Called when view is rendered.
|
||||
this.output_area = new outputarea.OutputArea({
|
||||
selector: this.$el,
|
||||
prompt_area: false,
|
||||
events: this.model.widget_manager.notebook.events,
|
||||
keyboard_manager: this.model.widget_manager.keyboard_manager });
|
||||
},
|
||||
|
||||
_handle_route_msg: function(content) {
|
||||
var cell = this.options.cell;
|
||||
if (content && cell) {
|
||||
if (content.method == 'push') {
|
||||
cell.push_output_area(this.output_area);
|
||||
} else if (content.method == 'pop') {
|
||||
cell.pop_output_area(this.output_area);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
'OutputView': OutputView,
|
||||
};
|
||||
});
|
||||
@ -0,0 +1,32 @@
|
||||
"""Output class.
|
||||
|
||||
Represents a widget that can be used to display output within the widget area.
|
||||
"""
|
||||
|
||||
# Copyright (c) IPython Development Team.
|
||||
# Distributed under the terms of the Modified BSD License.
|
||||
|
||||
from .widget import DOMWidget
|
||||
import sys
|
||||
from IPython.utils.traitlets import Unicode, List
|
||||
from IPython.display import clear_output
|
||||
|
||||
class Output(DOMWidget):
|
||||
"""Displays multiple widgets in a group."""
|
||||
_view_name = Unicode('OutputView', sync=True)
|
||||
|
||||
def clear_output(self, *pargs, **kwargs):
|
||||
with self:
|
||||
clear_output(*pargs, **kwargs)
|
||||
|
||||
def __enter__(self):
|
||||
self._flush()
|
||||
self.send({'method': 'push'})
|
||||
|
||||
def __exit__(self, exception_type, exception_value, traceback):
|
||||
self._flush()
|
||||
self.send({'method': 'pop'})
|
||||
|
||||
def _flush(self):
|
||||
sys.stdout.flush()
|
||||
sys.stderr.flush()
|
||||
Loading…
Reference in new issue