Show More
@@ -1,32 +1,50 b'' | |||
|
1 | 1 | """Output class. |
|
2 | 2 | |
|
3 | 3 | Represents a widget that can be used to display output within the widget area. |
|
4 | 4 | """ |
|
5 | 5 | |
|
6 | 6 | # Copyright (c) IPython Development Team. |
|
7 | 7 | # Distributed under the terms of the Modified BSD License. |
|
8 | 8 | |
|
9 | 9 | from .widget import DOMWidget |
|
10 | 10 | import sys |
|
11 | 11 | from IPython.utils.traitlets import Unicode, List |
|
12 | 12 | from IPython.display import clear_output |
|
13 | from IPython.testing.skipdoctest import skip_doctest | |
|
13 | 14 | |
|
15 | @skip_doctest | |
|
14 | 16 | class Output(DOMWidget): |
|
15 | """Displays multiple widgets in a group.""" | |
|
17 | """Widget used as a context manager to display output. | |
|
18 | ||
|
19 | This widget can capture and display stdout, stderr, and rich output. To use | |
|
20 | it, create an instance of it and display it. Then use it as a context | |
|
21 | manager. Any output produced while in it's context will be captured and | |
|
22 | displayed in it instead of the standard output area. | |
|
23 | ||
|
24 | Example | |
|
25 | from IPython.html import widgets | |
|
26 | from IPython.display import display | |
|
27 | out = widgets.Output() | |
|
28 | display(out) | |
|
29 | ||
|
30 | print('prints to output area') | |
|
31 | ||
|
32 | with out: | |
|
33 | print('prints to output widget')""" | |
|
16 | 34 | _view_name = Unicode('OutputView', sync=True) |
|
17 | 35 | |
|
18 | 36 | def clear_output(self, *pargs, **kwargs): |
|
19 | 37 | with self: |
|
20 | 38 | clear_output(*pargs, **kwargs) |
|
21 | 39 | |
|
22 | 40 | def __enter__(self): |
|
23 | 41 | self._flush() |
|
24 | 42 | self.send({'method': 'push'}) |
|
25 | 43 | |
|
26 | 44 | def __exit__(self, exception_type, exception_value, traceback): |
|
27 | 45 | self._flush() |
|
28 | 46 | self.send({'method': 'pop'}) |
|
29 | 47 | |
|
30 | 48 | def _flush(self): |
|
31 | 49 | sys.stdout.flush() |
|
32 | 50 | sys.stderr.flush() |
General Comments 0
You need to be logged in to leave comments.
Login now