def _process_execute_payload(self, item): """ Reimplemented to handle matplotlib plot payloads. """ if item['source'] == self._payload_source_plot: if item['format'] == 'svg': svg = item['data'] try: image = svg_to_image(svg) except ValueError: self._append_plain_text('Received invalid plot data.') else: format = self._add_image(image) self._name_to_svg[str(format.name())] = svg format.setProperty(self._svg_text_format_property, svg) cursor = self._get_end_cursor() cursor.insertBlock() cursor.insertImage(format) cursor.insertBlock() return True else: # Add other plot formats here! return False else: return super(RichIPythonWidget, self)._process_execute_payload(item)
def _insert_svg(self, cursor, svg): """ Insert raw SVG data into the widet. """ try: image = svg_to_image(svg) except ValueError: self._insert_plain_text(cursor, 'Received invalid SVG data.') else: format = self._add_image(image) self._name_to_svg_map[format.name()] = svg cursor.insertBlock() cursor.insertImage(format) cursor.insertBlock()
def _insert_svg(self, cursor, svg): """ Insert raw SVG data into the widet. """ try: image = svg_to_image(svg) except ValueError: self._insert_plain_text(cursor, "Received invalid SVG data.") else: format = self._add_image(image) self._name_to_svg_map[format.name()] = svg cursor.insertBlock() cursor.insertImage(format) cursor.insertBlock()
def _append_svg(self, svg): """ Append raw svg data to the widget. """ try: image = svg_to_image(svg) except ValueError: self._append_plain_text('Received invalid plot data.') else: format = self._add_image(image) self._name_to_svg_map[format.name()] = svg cursor = self._get_end_cursor() cursor.insertBlock() cursor.insertImage(format) cursor.insertBlock()
def _process_execute_payload(self, item): """ Reimplemented to handle matplotlib plot payloads. """ if item['source'] == self._payload_source_plot: if item['format'] == 'svg': svg = item['data'] try: image = svg_to_image(svg) except ValueError: self._append_plain_text('Received invalid plot data.') else: format = self._add_image(image) format.setProperty(self._svg_text_format_property, svg) cursor = self._get_end_cursor() cursor.insertBlock() cursor.insertImage(format) cursor.insertBlock() return True else: # Add other plot formats here! return False else: return super(RichIPythonWidget, self)._process_execute_payload(item)