Repository: ipython/ipython

Issue:
Images missing from XML/SVG export (for me)
When I use --pylab=inline and produce a very simple notebook with one image, both forms of HTML output work fine. But in the generated XML/SVG I get a message "Couldn't find image 8538394984452". I would guess that the backend is generating PNGs and not SVGs, and that the "Save as XML/HTML" function is not going back and regenerating them all. Asking matplotlib to generate an SVG and save it to disk yields a perfectly good SVG.

Further details: OS is Ubuntu Natty, ipython is 0.11, zeromq is 2.1.7, pyzmq is 2.1.7, all compiled and installed in my user environment. All other software is Natty standard. Machine is a core i3 laptop, ipython was run as "ipython qtconsole --pylab=inline".

ETA: I can't figure out how to either attach the broken XML notebook or get github to quote it (in spite of github's claim to use markdown). But there's not much to see; just some imports and a plot(arange(10),arange(10)), followed by the above message.

Images missing from XML/SVG export (for me)
When I use --pylab=inline and produce a very simple notebook with one image, both forms of HTML output work fine. But in the generated XML/SVG I get a message "Couldn't find image 8538394984452". I would guess that the backend is generating PNGs and not SVGs, and that the "Save as XML/HTML" function is not going back and regenerating them all. Asking matplotlib to generate an SVG and save it to disk yields a perfectly good SVG.

Further details: OS is Ubuntu Natty, ipython is 0.11, zeromq is 2.1.7, pyzmq is 2.1.7, all compiled and installed in my user environment. All other software is Natty standard. Machine is a core i3 laptop, ipython was run as "ipython qtconsole --pylab=inline".

ETA: I can't figure out how to either attach the broken XML notebook or get github to quote it (in spite of github's claim to use markdown). But there's not much to see; just some imports and a plot(arange(10),arange(10)), followed by the above message.



Discussion:
Yes, I believe you have to already be using SVG figures for XML+SVG export to work (SVG -> PNG conversion works, but not PNG->SVG).

To switch the qtconsole to svg figures, add:

``` python
c.InlineBackendConfig.figure_format = 'svg'
```

in your config file.

Or switch at runtime with:

``` python
from IPython.zmq.pylab import backend_inline
cfg = backend_inline.InlineBackendConfig.instance()
backend_inline.figure_format = 'svg'
```

Marking this as a quickfix, as the real fix in IPython should be to make the 'Couldn't find image' message describe the cause/solution more clearly, probably popping up in a dialog box after the failed export.

Yes, I believe you have to already be using SVG figures for XML+SVG export to work (SVG -> PNG conversion works, but not PNG->SVG).

To switch the qtconsole to svg figures, add:

``` python
c.InlineBackendConfig.figure_format = 'svg'
```

in your config file.

Or switch at runtime with:

``` python
from IPython.zmq.pylab import backend_inline
cfg = backend_inline.InlineBackendConfig.instance()
backend_inline.figure_format = 'svg'
```

Marking this as a quickfix, as the real fix in IPython should be to make the 'Couldn't find image' message describe the cause/solution more clearly, probably popping up in a dialog box after the failed export.


Resolving patch:
diff --git a/IPython/frontend/qt/console/rich_ipython_widget.py b/IPython/frontend/qt/console/rich_ipython_widget.py
--- 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
     #---------------------------------------------------------------------------
@@ -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
     #---------------------------------------------------------------------------
@@ -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


Test patch: