Show More
@@ -115,10 +115,11 b' class CapturingDisplayPublisher(DisplayPublisher):' | |||||
115 | outputs = List() |
|
115 | outputs = List() | |
116 |
|
116 | |||
117 | def publish(self, data, metadata=None, source=None, *, transient=None, update=False): |
|
117 | def publish(self, data, metadata=None, source=None, *, transient=None, update=False): | |
118 |
self.outputs.append( |
|
118 | self.outputs.append({'data':data, 'metadata':metadata, | |
|
119 | 'transient':transient, 'update':update}) | |||
119 |
|
120 | |||
120 | def clear_output(self, wait=False): |
|
121 | def clear_output(self, wait=False): | |
121 | super(CapturingDisplayPublisher, self).clear_output(wait) |
|
122 | super(CapturingDisplayPublisher, self).clear_output(wait) | |
122 |
|
123 | |||
123 | # empty the list, *do not* reassign a new list |
|
124 | # empty the list, *do not* reassign a new list | |
124 |
|
|
125 | self.outputs.clear() |
@@ -14,13 +14,16 b' from io import StringIO' | |||||
14 |
|
14 | |||
15 |
|
15 | |||
16 | class RichOutput(object): |
|
16 | class RichOutput(object): | |
17 | def __init__(self, data=None, metadata=None): |
|
17 | def __init__(self, data=None, metadata=None, transient=None, update=False): | |
18 | self.data = data or {} |
|
18 | self.data = data or {} | |
19 | self.metadata = metadata or {} |
|
19 | self.metadata = metadata or {} | |
|
20 | self.transient = transient or {} | |||
|
21 | self.update = update | |||
20 |
|
22 | |||
21 | def display(self): |
|
23 | def display(self): | |
22 | from IPython.display import publish_display_data |
|
24 | from IPython.display import publish_display_data | |
23 |
publish_display_data(data=self.data, metadata=self.metadata |
|
25 | publish_display_data(data=self.data, metadata=self.metadata, | |
|
26 | transient=self.transient, update=self.update) | |||
24 |
|
27 | |||
25 | def _repr_mime_(self, mime): |
|
28 | def _repr_mime_(self, mime): | |
26 | if mime not in self.data: |
|
29 | if mime not in self.data: | |
@@ -104,7 +107,7 b' class CapturedIO(object):' | |||||
104 | for o in c.outputs: |
|
107 | for o in c.outputs: | |
105 | display(o) |
|
108 | display(o) | |
106 | """ |
|
109 | """ | |
107 |
return [ RichOutput( |
|
110 | return [ RichOutput(**kargs) for kargs in self._outputs ] | |
108 |
|
111 | |||
109 | def show(self): |
|
112 | def show(self): | |
110 | """write my output to sys.stdout/err as appropriate""" |
|
113 | """write my output to sys.stdout/err as appropriate""" | |
@@ -112,8 +115,8 b' class CapturedIO(object):' | |||||
112 | sys.stderr.write(self.stderr) |
|
115 | sys.stderr.write(self.stderr) | |
113 | sys.stdout.flush() |
|
116 | sys.stdout.flush() | |
114 | sys.stderr.flush() |
|
117 | sys.stderr.flush() | |
115 |
for |
|
118 | for kargs in self._outputs: | |
116 |
RichOutput( |
|
119 | RichOutput(**kargs).display() | |
117 |
|
120 | |||
118 | __call__ = show |
|
121 | __call__ = show | |
119 |
|
122 |
General Comments 0
You need to be logged in to leave comments.
Login now