Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/users/next_whats_new/macosx_windows_tabs.rst
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions lib/matplotlib/backends/backend_macosx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
4 changes: 4 additions & 0 deletions lib/matplotlib/mpl-data/matplotlibrc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
23 changes: 23 additions & 0 deletions src/_macosx.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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 (auto, tab, window)"},
Comment thread
greglucas marked this conversation as resolved.
Outdated
{"set_icon",
(PyCFunction)FigureManager_set_icon,
METH_STATIC | METH_VARARGS,
Expand Down