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

Skip to content

Commit ee2c848

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 eb33b94 commit ee2c848

File tree

5 files changed

+36
-0
lines changed

5 files changed

+36
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
macosx: New figures can be opened in either windows or tabs
2+
-----------------------------------------------------------
3+
4+
There is a new :rc:`macosx.window_mode`` rcParam to control how
5+
new figures are opened with the macosx backend. The default is
6+
**system** which uses the system settings, or one can specify either
7+
**tab** or **window** to explicitly choose the mode used to open new figures.

lib/matplotlib/backends/backend_macosx.py

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

lib/matplotlib/mpl-data/matplotlibrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,10 @@
701701
# background by default
702702
#savefig.orientation: portrait # orientation of saved figure, for PostScript output only
703703

704+
### macosx backend params
705+
#macosx.window_mode : system # How to open new figures (system, tab, window)
706+
# system uses the MacOS system preferences
707+
704708
### tk backend params
705709
#tk.window_focus: False # Maintain shell focus for TkAgg
706710

lib/matplotlib/rcsetup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,6 +1214,7 @@ def _convert_validator_spec(key, conv):
12141214
"figure.autolayout": validate_bool,
12151215
"figure.max_open_warning": validate_int,
12161216
"figure.raise_window": validate_bool,
1217+
"macosx.window_mode": ["system", "tab", "window"],
12171218

12181219
"figure.subplot.left": validate_float,
12191220
"figure.subplot.right": validate_float,

src/_macosx.m

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,25 @@ int mpl_check_modifier(
689689
return 0;
690690
}
691691

692+
static PyObject*
693+
FigureManager__set_window_mode(FigureManager* self, PyObject* args)
694+
{
695+
const char* window_mode;
696+
if (!PyArg_ParseTuple(args, "s", &window_mode) || !self->window) {
697+
return NULL;
698+
}
699+
700+
NSString* window_mode_str = [NSString stringWithUTF8String: window_mode];
701+
if ([window_mode_str isEqualToString: @"tab"]) {
702+
[self->window setTabbingMode: NSWindowTabbingModePreferred];
703+
} else if ([window_mode_str isEqualToString: @"window"]) {
704+
[self->window setTabbingMode: NSWindowTabbingModeDisallowed];
705+
} else { // system settings
706+
[self->window setTabbingMode: NSWindowTabbingModeAutomatic];
707+
}
708+
Py_RETURN_NONE;
709+
}
710+
692711
static PyObject*
693712
FigureManager_repr(FigureManager* self)
694713
{
@@ -832,6 +851,10 @@ int mpl_check_modifier(
832851
{"destroy",
833852
(PyCFunction)FigureManager_destroy,
834853
METH_NOARGS},
854+
{"_set_window_mode",
855+
(PyCFunction)FigureManager__set_window_mode,
856+
METH_VARARGS,
857+
"Set the window open mode (auto, tab, window)"},
835858
{"set_icon",
836859
(PyCFunction)FigureManager_set_icon,
837860
METH_STATIC | METH_VARARGS,

0 commit comments

Comments
 (0)