I tried this calling the SVG backend directly and by
> switching to the SVG backend from the GTK backend and it
> works OK.
This gets back to our previous unresolved discussion on error handling
in the image backends. I think the way it is done now is a historical
accident. In the olden days, pre matplotlib-0.50, there was no
ability to switch backends, or to use an image backend within a GUI
(eg gtkcairo, gtkagg). So the image backends were free-standing and
their error handling didn't have much impact outside their own scope.
Now they clearly do.
The second design problem was that I preferred simple error messages
rather than exceptions with tracebacks. This grew out of my
experience with users of my GUIs who basically will not read a
traceback - they appear to have blinders on. However, they will read
a simple message like
Could not save file blah, blah, blah.
But as we are seeing, this approach (simple message, SystemExit)
doesn't scale well and isn't appropriate when GUIs are calling image
I suggest we rework the image backends to not define an error message
function at all, but simply to import and reuse the one from
backend_bases. This will make it easier to change the policy in a
single place. Secondly, an image backend should never call this
function, it should be reserved for the matlab interface simply to
insure a consistent interface between the various backends. Thirdly,
the image backends should verbose.report/report_error where
appropriate, and raise when indicated. GUI backends can catch these
exceptions and handle them how they want.
In the case at hand, it might be sensible for backend ps to catch an
IO Error, report to verbose report_error, and then rethrow the error
with the message. Something like
try : save_ps(fname)
except IOError, msg:
verbose.report_error('Backend PS failed to save %s'%fname)