Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for bug #735 : Images missing from XML/SVG export #1449

Merged
merged 5 commits into from
May 21, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion IPython/frontend/qt/console/rich_ipython_widget.py
Original file line number Diff line number Diff line change
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