Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f865c09

Browse filesBrowse files
committed
Add detection of OSX NSApp event loop.
1 parent 63df186 commit f865c09
Copy full SHA for f865c09

File tree

Expand file treeCollapse file tree

2 files changed

+31
-3
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+31
-3
lines changed

‎lib/matplotlib/backends/__init__.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/__init__.py
+12-1Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ def _get_current_event_loop():
2525
Returns
2626
-------
2727
Optional[str]
28-
A value in {"qt5", "qt4", "gtk3", "gtk2", "tk", "headless", None}
28+
One of the following values: "qt5", "qt4", "gtk3", "gtk2", "tk",
29+
"macosx", "headless", ``None``.
2930
"""
3031
QtWidgets = (sys.modules.get("PyQt5.QtWidgets")
3132
or sys.modules.get("PySide2.QtWidgets"))
@@ -48,6 +49,16 @@ def _get_current_event_loop():
4849
and frame.f_code.co_name == "mainloop"
4950
for frame in sys._current_frames().values()):
5051
return "tk"
52+
try:
53+
from matplotlib.backends import _macosx
54+
except ImportError:
55+
pass
56+
else:
57+
# Note that the NSApp event loop is also running when a non-native
58+
# toolkit (e.g. Qt5) is active, but in that case we want to report the
59+
# other toolkit; thus, this check comes after the other toolkits.
60+
if _macosx.event_loop_is_running():
61+
return "macosx"
5162
if sys.platform.startswith("linux") and not os.environ.get("DISPLAY"):
5263
return "headless"
5364

‎src/_macosx.m

Copy file name to clipboardExpand all lines: src/_macosx.m
+19-2Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2818,6 +2818,16 @@ - (int)index
28182818
}
28192819
@end
28202820

2821+
static PyObject*
2822+
event_loop_is_running(PyObject* self)
2823+
{
2824+
if ([NSApp isRunning]) {
2825+
Py_RETURN_TRUE;
2826+
} else {
2827+
Py_RETURN_FALSE;
2828+
}
2829+
}
2830+
28212831
static PyObject*
28222832
show(PyObject* self)
28232833
{
@@ -3072,10 +3082,17 @@ static bool verify_framework(void)
30723082
}
30733083

30743084
static struct PyMethodDef methods[] = {
3085+
{"event_loop_is_running",
3086+
(PyCFunction)event_loop_is_running,
3087+
METH_NOARGS,
3088+
"Return whether the NSApp main event loop is currently running."
3089+
},
30753090
{"show",
30763091
(PyCFunction)show,
30773092
METH_NOARGS,
3078-
"Show all the figures and enter the main loop.\nThis function does not return until all Matplotlib windows are closed,\nand is normally not needed in interactive sessions."
3093+
"Show all the figures and enter the main loop.\n"
3094+
"This function does not return until all Matplotlib windows are closed,\n"
3095+
"and is normally not needed in interactive sessions."
30793096
},
30803097
{"choose_save_file",
30813098
(PyCFunction)choose_save_file,
@@ -3087,7 +3104,7 @@ static bool verify_framework(void)
30873104
METH_VARARGS,
30883105
"Sets the active cursor."
30893106
},
3090-
{NULL, NULL, 0, NULL}/* sentinel */
3107+
{NULL, NULL, 0, NULL} /* sentinel */
30913108
};
30923109

30933110
#if PY3K

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.