diff --git a/IPython/frontend/qt/console/rich_ipython_widget.py b/IPython/frontend/qt/console/rich_ipython_widget.py index 9570f01..06172d9 100644 --- a/IPython/frontend/qt/console/rich_ipython_widget.py +++ b/IPython/frontend/qt/console/rich_ipython_widget.py @@ -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 #--------------------------------------------------------------------------- @@ -53,6 +58,20 @@ class RichIPythonWidget(IPythonWidget): #--------------------------------------------------------------------------- + # '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 #--------------------------------------------------------------------------- @@ -231,7 +250,18 @@ class RichIPythonWidget(IPythonWidget): try: svg = str(self._name_to_svg_map[match.group("name")]) except KeyError: - return "Couldn't find image %s" % 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 ("Cannot convert a PNG to SVG. " + "To fix this, add this to your config: " + "c.InlineBackendConfig.figure_format = 'svg' " + "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