diff --git a/spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py b/spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py index 796dc3509da..6dafdfafec1 100644 --- a/spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py +++ b/spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py @@ -17,6 +17,7 @@ import shutil import sys from textwrap import dedent +from unittest.mock import patch # Third party imports from ipykernel._version import __version__ as ipykernel_version @@ -1914,6 +1915,21 @@ def test_restart_intertactive_backend(ipyconsole, qtbot): assert bool(os.environ.get('BACKEND_REQUIRE_RESTART')) +def test_mpl_conf(ipyconsole, qtbot): + """ + Test that after setting matplotlib-related config options, the member + function send_mpl_backend of the shellwidget is called with the new value. + """ + main_widget = ipyconsole.get_widget() + client = main_widget.get_current_client() + with patch.object(client.shellwidget, 'send_mpl_backend') as mock: + main_widget.set_conf('pylab/inline/fontsize', 20.5) + mock.assert_called_once_with({'pylab/inline/fontsize': 20.5}) + with patch.object(client.shellwidget, 'send_mpl_backend') as mock: + main_widget.set_conf('pylab/inline/bottom', 0.314) + mock.assert_called_once_with({'pylab/inline/bottom': 0.314}) + + @flaky(max_runs=3) @pytest.mark.no_web_widgets def test_no_infowidget(ipyconsole): diff --git a/spyder/plugins/ipythonconsole/widgets/main_widget.py b/spyder/plugins/ipythonconsole/widgets/main_widget.py index b362ce31926..0bb6165a4ab 100644 --- a/spyder/plugins/ipythonconsole/widgets/main_widget.py +++ b/spyder/plugins/ipythonconsole/widgets/main_widget.py @@ -871,6 +871,7 @@ def change_clients_autocall(self, value): 'pylab', 'pylab/backend', 'pylab/autoload', 'pylab/inline/figure_format', 'pylab/inline/resolution', 'pylab/inline/width', 'pylab/inline/height', + 'pylab/inline/fontsize', 'pylab/inline/bottom', 'pylab/inline/bbox_inches']) def change_possible_restart_and_mpl_conf(self, option, value): """ diff --git a/spyder/plugins/ipythonconsole/widgets/shell.py b/spyder/plugins/ipythonconsole/widgets/shell.py index c59b26ef32d..787b6ba7a69 100644 --- a/spyder/plugins/ipythonconsole/widgets/shell.py +++ b/spyder/plugins/ipythonconsole/widgets/shell.py @@ -564,6 +564,8 @@ def send_mpl_backend(self, option=None): resolution_n = 'pylab/inline/resolution' width_n = 'pylab/inline/width' height_n = 'pylab/inline/height' + fontsize_n = 'pylab/inline/fontsize' + bottom_n = 'pylab/inline/bottom' bbox_inches_n = 'pylab/inline/bbox_inches' backend_o = self.get_conf(pylab_backend_n) @@ -591,6 +593,18 @@ def send_mpl_backend(self, option=None): if height_o is not None: matplotlib_conf[height_n] = height_o + # Font size + fontsize_o = float(self.get_conf(fontsize_n)) + if fontsize_o is not None and ( + option is None or fontsize_n in option): + matplotlib_conf[fontsize_n] = fontsize_o + + # Bottom part + bottom_o = float(self.get_conf(bottom_n)) + if bottom_o is not None and ( + option is None or bottom_n in option): + matplotlib_conf[bottom_n] = bottom_o + # Print figure kwargs bbox_inches_o = self.get_conf(bbox_inches_n) if option is None or bbox_inches_n in option: