diff --git a/doc/users/next_whats_new/macosx_windows_tabs.rst b/doc/users/next_whats_new/macosx_windows_tabs.rst new file mode 100644 index 000000000000..85fd76b6cb6d --- /dev/null +++ b/doc/users/next_whats_new/macosx_windows_tabs.rst @@ -0,0 +1,7 @@ +macosx: New figures can be opened in either windows or tabs +----------------------------------------------------------- + +There is a new :rc:`macosx.window_mode`` rcParam to control how +new figures are opened with the macosx backend. The default is +**system** which uses the system settings, or one can specify either +**tab** or **window** to explicitly choose the mode used to open new figures. diff --git a/lib/matplotlib/backends/backend_macosx.py b/lib/matplotlib/backends/backend_macosx.py index b4cfcd480250..695667dc48c3 100644 --- a/lib/matplotlib/backends/backend_macosx.py +++ b/lib/matplotlib/backends/backend_macosx.py @@ -145,6 +145,7 @@ def __init__(self, canvas, num): icon_path = str(cbook._get_data_path('images/matplotlib.pdf')) _macosx.FigureManager.set_icon(icon_path) FigureManagerBase.__init__(self, canvas, num) + self._set_window_mode(mpl.rcParams.get("macosx.window_mode", "system")) if self.toolbar is not None: self.toolbar.update() if mpl.is_interactive(): diff --git a/lib/matplotlib/mpl-data/matplotlibrc b/lib/matplotlib/mpl-data/matplotlibrc index d951bfca3dc3..7b1ee1467a2e 100644 --- a/lib/matplotlib/mpl-data/matplotlibrc +++ b/lib/matplotlib/mpl-data/matplotlibrc @@ -701,6 +701,10 @@ # background by default #savefig.orientation: portrait # orientation of saved figure, for PostScript output only +### macosx backend params +#macosx.window_mode : system # How to open new figures (system, tab, window) + # system uses the MacOS system preferences + ### tk backend params #tk.window_focus: False # Maintain shell focus for TkAgg diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index e628692eae8a..3a7fcbb15ab2 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -1214,6 +1214,7 @@ def _convert_validator_spec(key, conv): "figure.autolayout": validate_bool, "figure.max_open_warning": validate_int, "figure.raise_window": validate_bool, + "macosx.window_mode": ["system", "tab", "window"], "figure.subplot.left": validate_float, "figure.subplot.right": validate_float, diff --git a/src/_macosx.m b/src/_macosx.m index 0b9dc593e614..aa76b48edc41 100755 --- a/src/_macosx.m +++ b/src/_macosx.m @@ -689,6 +689,25 @@ int mpl_check_modifier( return 0; } +static PyObject* +FigureManager__set_window_mode(FigureManager* self, PyObject* args) +{ + const char* window_mode; + if (!PyArg_ParseTuple(args, "s", &window_mode) || !self->window) { + return NULL; + } + + NSString* window_mode_str = [NSString stringWithUTF8String: window_mode]; + if ([window_mode_str isEqualToString: @"tab"]) { + [self->window setTabbingMode: NSWindowTabbingModePreferred]; + } else if ([window_mode_str isEqualToString: @"window"]) { + [self->window setTabbingMode: NSWindowTabbingModeDisallowed]; + } else { // system settings + [self->window setTabbingMode: NSWindowTabbingModeAutomatic]; + } + Py_RETURN_NONE; +} + static PyObject* FigureManager_repr(FigureManager* self) { @@ -832,6 +851,10 @@ int mpl_check_modifier( {"destroy", (PyCFunction)FigureManager_destroy, METH_NOARGS}, + {"_set_window_mode", + (PyCFunction)FigureManager__set_window_mode, + METH_VARARGS, + "Set the window open mode (system, tab, window)"}, {"set_icon", (PyCFunction)FigureManager_set_icon, METH_STATIC | METH_VARARGS,