From 4f5c9b055f20f36faac0c6bd1d3e72f5135b3687 Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Thu, 20 Sep 2018 18:54:05 -0500 Subject: [PATCH] IPdb: Pass metadata to inline figures This was causing a crash in qtconsole but we discovered the problem was a bug in MetaKernel. --- spyder_kernels/ipdb/backend_inline.py | 9 +++++---- spyder_kernels/ipdb/tests/test_matplotlib.py | 4 ++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/spyder_kernels/ipdb/backend_inline.py b/spyder_kernels/ipdb/backend_inline.py index a0ded823..3b8670d1 100644 --- a/spyder_kernels/ipdb/backend_inline.py +++ b/spyder_kernels/ipdb/backend_inline.py @@ -26,16 +26,17 @@ def get_image(figure): The idea to get png/svg from a figure was taken from https://stackoverflow.com/a/12145161/438386 """ + # Print figure to a bytes stream if PY2: data = io.StringIO() else: data = io.BytesIO() - figure.canvas.print_figure(data, bbox_inches='tight') - metadata=_fetch_figure_metadata(figure) - # TODO: Passing metadata is making qtconsole crash - img = Image(data=data.getvalue()) + # Get figure metadata + metadata = _fetch_figure_metadata(figure) + + img = Image(data=data.getvalue(), metadata=metadata) return img diff --git a/spyder_kernels/ipdb/tests/test_matplotlib.py b/spyder_kernels/ipdb/tests/test_matplotlib.py index 02b51482..40f731e6 100644 --- a/spyder_kernels/ipdb/tests/test_matplotlib.py +++ b/spyder_kernels/ipdb/tests/test_matplotlib.py @@ -75,3 +75,7 @@ def test_matplotlib_qt(qtconsole, qtbot): # Assert the previous command returns the object assert 'PyQt5.QtWidgets.QApplication object' in shell._control.toPlainText() + + +if __name__ == "__main__": + pytest.main()