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

Skip to content

Commit c345f0c

Browse files
committed
ENH: macosx allow figures can be opened in tabs or windows
Allow users to select how new figures are created when opening new windows. The default is to keep using the system preferences, but one can also select "tab" or "window" to override the default system preferences.
1 parent fa21b42 commit c345f0c

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

lib/matplotlib/backends/backend_macosx.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ def __init__(self, canvas, num):
144144
icon_path = str(cbook._get_data_path('images/matplotlib.pdf'))
145145
_macosx.FigureManager.set_icon(icon_path)
146146
FigureManagerBase.__init__(self, canvas, num)
147+
self._set_window_mode(mpl.rcParams.get("macosx.window_mode", "auto"))
147148
if self.toolbar is not None:
148149
self.toolbar.update()
149150
if mpl.is_interactive():

lib/matplotlib/mpl-data/matplotlibrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,8 @@
569569
# the pyplot interface before emitting a warning.
570570
# If less than one this feature is disabled.
571571
#figure.raise_window : True # Raise the GUI window to front when show() is called.
572+
#macosx.window_mode : auto # How to open new figures (auto, tab, window)
573+
# auto uses system preferences
572574

573575
## The figure subplot parameters. All dimensions are a fraction of the figure width and height.
574576
#figure.subplot.left: 0.125 # the left side of the subplots of the figure

lib/matplotlib/rcsetup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,7 @@ def _convert_validator_spec(key, conv):
11731173
"figure.autolayout": validate_bool,
11741174
"figure.max_open_warning": validate_int,
11751175
"figure.raise_window": validate_bool,
1176+
"macosx.window_mode": ["auto", "tab", "window"],
11761177

11771178
"figure.subplot.left": validate_float,
11781179
"figure.subplot.right": validate_float,

src/_macosx.m

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,25 @@ int mpl_check_modifier(
681681
return 0;
682682
}
683683

684+
static PyObject*
685+
FigureManager__set_window_mode(FigureManager* self, PyObject* args)
686+
{
687+
const char* window_mode;
688+
if (!PyArg_ParseTuple(args, "s", &window_mode) || !self->window) {
689+
return NULL;
690+
}
691+
692+
NSString* window_mode_str = [NSString stringWithUTF8String: window_mode];
693+
if ([window_mode_str isEqualToString: @"tab"]) {
694+
[self->window setTabbingMode: NSWindowTabbingModePreferred];
695+
} else if ([window_mode_str isEqualToString: @"window"]) {
696+
[self->window setTabbingMode: NSWindowTabbingModeDisallowed];
697+
} else { // auto
698+
[self->window setTabbingMode: NSWindowTabbingModeAutomatic];
699+
}
700+
Py_RETURN_NONE;
701+
}
702+
684703
static PyObject*
685704
FigureManager_repr(FigureManager* self)
686705
{
@@ -824,6 +843,10 @@ int mpl_check_modifier(
824843
{"destroy",
825844
(PyCFunction)FigureManager_destroy,
826845
METH_NOARGS},
846+
{"_set_window_mode",
847+
(PyCFunction)FigureManager__set_window_mode,
848+
METH_VARARGS,
849+
"Set the window open mode (auto, tab, window)"},
827850
{"set_icon",
828851
(PyCFunction)FigureManager_set_icon,
829852
METH_STATIC | METH_VARARGS,

0 commit comments

Comments
 (0)