Skip to content

Commit

Permalink
Merge pull request #1449 from icmurray/master
Browse files Browse the repository at this point in the history
Fix for bug #735 : Images missing from XML/SVG export
  • Loading branch information
takluyver committed May 21, 2012
2 parents cffb287 + 78c047e commit b4a3ed4
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion IPython/frontend/qt/console/rich_ipython_widget.py
Expand Up @@ -29,6 +29,11 @@ class RichIPythonWidget(IPythonWidget):
# RichIPythonWidget protected class variables.
_payload_source_plot = 'IPython.zmq.pylab.backend_payload.add_plot_payload'
_jpg_supported = Bool(False)

# Used to determine whether a given html export attempt has already
# displayed a warning about being unable to convert a png to svg.
_svg_warning_displayed = False

#---------------------------------------------------------------------------
# 'object' interface
#---------------------------------------------------------------------------
Expand All @@ -52,6 +57,20 @@ def __init__(self, *args, **kw):
self._jpg_supported = 'jpeg' in _supported_format


#---------------------------------------------------------------------------
# 'ConsoleWidget' public interface overides
#---------------------------------------------------------------------------

def export_html(self):
""" Shows a dialog to export HTML/XML in various formats.
Overridden in order to reset the _svg_warning_displayed flag prior
to the export running.
"""
self._svg_warning_displayed = False
super(RichIPythonWidget, self).export_html()


#---------------------------------------------------------------------------
# 'ConsoleWidget' protected interface
#---------------------------------------------------------------------------
Expand Down Expand Up @@ -231,7 +250,18 @@ def _get_image_tag(self, match, path = None, format = "png"):
try:
svg = str(self._name_to_svg_map[match.group("name")])
except KeyError:
return "<b>Couldn't find image %s</b>" % match.group("name")
if not self._svg_warning_displayed:
QtGui.QMessageBox.warning(self, 'Error converting PNG to SVG.',
'Cannot convert a PNG to SVG. To fix this, add this '
'to your ipython config:\n\n'
'\tc.InlineBackendConfig.figure_format = \'svg\'\n\n'
'And regenerate the figures.',
QtGui.QMessageBox.Ok)
self._svg_warning_displayed = True
return ("<b>Cannot convert a PNG to SVG.</b> "
"To fix this, add this to your config: "
"<span>c.InlineBackendConfig.figure_format = 'svg'</span> "
"and regenerate the figures.")

# Not currently checking path, because it's tricky to find a
# cross-browser way to embed external SVG images (e.g., via
Expand Down

0 comments on commit b4a3ed4

Please sign in to comment.