##// END OF EJS Templates
Simplified the reset of the _svg_warning_displayed flag in RichIPythonWidget...
Ian Murray -
Show More
@@ -29,6 +29,8 b' class RichIPythonWidget(IPythonWidget):'
29 # RichIPythonWidget protected class variables.
29 # RichIPythonWidget protected class variables.
30 _payload_source_plot = 'IPython.zmq.pylab.backend_payload.add_plot_payload'
30 _payload_source_plot = 'IPython.zmq.pylab.backend_payload.add_plot_payload'
31 _jpg_supported = Bool(False)
31 _jpg_supported = Bool(False)
32 _svg_warning_displayed = False
33
32 #---------------------------------------------------------------------------
34 #---------------------------------------------------------------------------
33 # 'object' interface
35 # 'object' interface
34 #---------------------------------------------------------------------------
36 #---------------------------------------------------------------------------
@@ -53,6 +55,19 b' class RichIPythonWidget(IPythonWidget):'
53
55
54
56
55 #---------------------------------------------------------------------------
57 #---------------------------------------------------------------------------
58 # 'ConsoleWidget' public interface overides
59 #---------------------------------------------------------------------------
60
61 def export_html(self):
62 """ Shows a dialog to export HTML/XML in various formats.
63
64 Overridden in order to reset the _svg_warning_displayed flag.
65 """
66 self._svg_warning_displayed = False
67 super(RichIPythonWidget, self).export_html()
68
69
70 #---------------------------------------------------------------------------
56 # 'ConsoleWidget' protected interface
71 # 'ConsoleWidget' protected interface
57 #---------------------------------------------------------------------------
72 #---------------------------------------------------------------------------
58
73
@@ -231,24 +246,13 b' class RichIPythonWidget(IPythonWidget):'
231 try:
246 try:
232 svg = str(self._name_to_svg_map[match.group("name")])
247 svg = str(self._name_to_svg_map[match.group("name")])
233 except KeyError:
248 except KeyError:
234
249 if not self._svg_warning_displayed:
235 # Determine whether this is a new export by checking whether
236 # we've attempted to export this svg previously. If so, then
237 # reset the flag that determines whether the warning has been
238 # displayed or not.
239 if match.group("name") in getattr(self, '_svgs_processed', set()):
240 self._svg_warning_displayed = False
241
242 # Display this warning exactly once per export attempt.
243 if not getattr(self, '_svg_warning_displayed', False):
244 QtGui.QMessageBox.warning(self, 'Error converting PNG to SVG.',
250 QtGui.QMessageBox.warning(self, 'Error converting PNG to SVG.',
245 'Cannot convert a PNG to SVG. To fix this, add this to your ipython config:\n\n'
251 'Cannot convert a PNG to SVG. To fix this, add this to your ipython config:\n\n'
246 '\tc.InlineBackendConfig.figure_format = \'svg\'\n\n'
252 '\tc.InlineBackendConfig.figure_format = \'svg\'\n\n'
247 'And regenerate the figures.',
253 'And regenerate the figures.',
248 QtGui.QMessageBox.Ok)
254 QtGui.QMessageBox.Ok)
249 self._svg_warning_displayed = True
255 self._svg_warning_displayed = True
250 self._svgs_processed = set()
251 self._svgs_processed.add(match.group("name"))
252 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."
256 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."
253
257
254 # Not currently checking path, because it's tricky to find a
258 # Not currently checking path, because it's tricky to find a
General Comments 0
You need to be logged in to leave comments. Login now