Show More
@@ -217,12 +217,12 b' class IPythonWidget(FrontendWidget):' | |||
|
217 | 217 | # representation. |
|
218 | 218 | if data.has_key('text/html'): |
|
219 | 219 | html = data['text/html'] |
|
220 |
self._append_html(html, |
|
|
220 | self._append_html(html, True) | |
|
221 | 221 | elif data.has_key('text/plain'): |
|
222 | 222 | text = data['text/plain'] |
|
223 |
self._append_plain_text(text, |
|
|
223 | self._append_plain_text(text, True) | |
|
224 | 224 | # This newline seems to be needed for text and html output. |
|
225 |
self._append_plain_text(u'\n', |
|
|
225 | self._append_plain_text(u'\n', True) | |
|
226 | 226 | |
|
227 | 227 | def _started_channels(self): |
|
228 | 228 | """ Reimplemented to make a history request. |
@@ -74,20 +74,17 b' class RichIPythonWidget(IPythonWidget):' | |||
|
74 | 74 | prompt_number = content['execution_count'] |
|
75 | 75 | data = content['data'] |
|
76 | 76 | if data.has_key('image/svg+xml'): |
|
77 | self._append_plain_text(self.output_sep) | |
|
78 | self._append_html(self._make_out_prompt(prompt_number)) | |
|
79 | # TODO: try/except this call. | |
|
80 | self._append_svg(data['image/svg+xml']) | |
|
81 | self._append_html(self.output_sep2) | |
|
77 | self._append_plain_text(self.output_sep, True) | |
|
78 | self._append_html(self._make_out_prompt(prompt_number), True) | |
|
79 | self._append_svg(data['image/svg+xml'], True) | |
|
80 | self._append_html(self.output_sep2, True) | |
|
82 | 81 | elif data.has_key('image/png'): |
|
83 | self._append_plain_text(self.output_sep) | |
|
84 | self._append_html(self._make_out_prompt(prompt_number)) | |
|
82 | self._append_plain_text(self.output_sep, True) | |
|
83 | self._append_html(self._make_out_prompt(prompt_number), True) | |
|
85 | 84 | # This helps the output to look nice. |
|
86 | self._append_plain_text('\n') | |
|
87 | # TODO: try/except these calls | |
|
88 | png = decodestring(data['image/png']) | |
|
89 | self._append_png(png) | |
|
90 | self._append_html(self.output_sep2) | |
|
85 | self._append_plain_text('\n', True) | |
|
86 | self._append_png(decodestring(data['image/png']), True) | |
|
87 | self._append_html(self.output_sep2, True) | |
|
91 | 88 | else: |
|
92 | 89 | # Default back to the plain text representation. |
|
93 | 90 | return super(RichIPythonWidget, self)._handle_pyout(msg) |
@@ -103,14 +100,12 b' class RichIPythonWidget(IPythonWidget):' | |||
|
103 | 100 | # FIXME: Is this the right ordering of things to try? |
|
104 | 101 | if data.has_key('image/svg+xml'): |
|
105 | 102 | svg = data['image/svg+xml'] |
|
106 | # TODO: try/except this call. | |
|
107 | self._append_svg(svg) | |
|
103 | self._append_svg(svg, True) | |
|
108 | 104 | elif data.has_key('image/png'): |
|
109 | # TODO: try/except these calls | |
|
110 | 105 | # PNG data is base64 encoded as it passes over the network |
|
111 | 106 | # in a JSON structure so we decode it. |
|
112 | 107 | png = decodestring(data['image/png']) |
|
113 | self._append_png(png) | |
|
108 | self._append_png(png, True) | |
|
114 | 109 | else: |
|
115 | 110 | # Default back to the plain text representation. |
|
116 | 111 | return super(RichIPythonWidget, self)._handle_display_data(msg) |
@@ -119,35 +114,15 b' class RichIPythonWidget(IPythonWidget):' | |||
|
119 | 114 | # 'RichIPythonWidget' protected interface |
|
120 | 115 | #--------------------------------------------------------------------------- |
|
121 | 116 | |
|
122 |
def _append_ |
|
|
123 |
""" Append raw |
|
|
117 | def _append_png(self, png, before_prompt=False): | |
|
118 | """ Append raw PNG data to the widget. | |
|
124 | 119 | """ |
|
125 | try: | |
|
126 | image = svg_to_image(svg) | |
|
127 | except ValueError: | |
|
128 | self._append_plain_text('Received invalid plot data.') | |
|
129 | else: | |
|
130 | format = self._add_image(image) | |
|
131 | self._name_to_svg_map[format.name()] = svg | |
|
132 | cursor = self._get_end_cursor() | |
|
133 | cursor.insertBlock() | |
|
134 | cursor.insertImage(format) | |
|
135 | cursor.insertBlock() | |
|
120 | self._append_custom(self._insert_png, png, before_prompt) | |
|
136 | 121 | |
|
137 |
def _append_ |
|
|
138 |
""" Append raw |
|
|
122 | def _append_svg(self, svg, before_prompt=False): | |
|
123 | """ Append raw SVG data to the widget. | |
|
139 | 124 | """ |
|
140 | try: | |
|
141 | image = QtGui.QImage() | |
|
142 | image.loadFromData(png, 'PNG') | |
|
143 | except ValueError: | |
|
144 | self._append_plain_text('Received invalid plot data.') | |
|
145 | else: | |
|
146 | format = self._add_image(image) | |
|
147 | cursor = self._get_end_cursor() | |
|
148 | cursor.insertBlock() | |
|
149 | cursor.insertImage(format) | |
|
150 | cursor.insertBlock() | |
|
125 | self._append_custom(self._insert_svg, svg, before_prompt) | |
|
151 | 126 | |
|
152 | 127 | def _add_image(self, image): |
|
153 | 128 | """ Adds the specified QImage to the document and returns a |
@@ -236,6 +211,34 b' class RichIPythonWidget(IPythonWidget):' | |||
|
236 | 211 | else: |
|
237 | 212 | return '<b>Unrecognized image format</b>' |
|
238 | 213 | |
|
214 | def _insert_png(self, cursor, png): | |
|
215 | """ Insert raw PNG data into the widget. | |
|
216 | """ | |
|
217 | try: | |
|
218 | image = QtGui.QImage() | |
|
219 | image.loadFromData(png, 'PNG') | |
|
220 | except ValueError: | |
|
221 | self._insert_plain_text(cursor, 'Received invalid PNG data.') | |
|
222 | else: | |
|
223 | format = self._add_image(image) | |
|
224 | cursor.insertBlock() | |
|
225 | cursor.insertImage(format) | |
|
226 | cursor.insertBlock() | |
|
227 | ||
|
228 | def _insert_svg(self, cursor, svg): | |
|
229 | """ Insert raw SVG data into the widet. | |
|
230 | """ | |
|
231 | try: | |
|
232 | image = svg_to_image(svg) | |
|
233 | except ValueError: | |
|
234 | self._insert_plain_text(cursor, 'Received invalid SVG data.') | |
|
235 | else: | |
|
236 | format = self._add_image(image) | |
|
237 | self._name_to_svg_map[format.name()] = svg | |
|
238 | cursor.insertBlock() | |
|
239 | cursor.insertImage(format) | |
|
240 | cursor.insertBlock() | |
|
241 | ||
|
239 | 242 | def _save_image(self, name, format='PNG'): |
|
240 | 243 | """ Shows a save dialog for the ImageResource with 'name'. |
|
241 | 244 | """ |
General Comments 0
You need to be logged in to leave comments.
Login now