Skip to content

Commit

Permalink
Send new plot config options to IPython shells
Browse files Browse the repository at this point in the history
  • Loading branch information
jitseniesen committed Jan 2, 2024
1 parent 932db0f commit bbc058a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
16 changes: 16 additions & 0 deletions spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions spyder/plugins/ipythonconsole/widgets/main_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
14 changes: 14 additions & 0 deletions spyder/plugins/ipythonconsole/widgets/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit bbc058a

Please sign in to comment.