Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitc745e17

Browse files
committed
Add detection of OSX NSApp event loop.
1 parentc14a754 commitc745e17

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

‎lib/matplotlib/backends/__init__.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ 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
"""
30-
# FIXME Add detection of OSX event loop.
3131
QtWidgets=sys.modules.get("PyQt5.QtWidgets")
3232
ifQtWidgetsandQtWidgets.QApplication.instance():
3333
return"qt5"
@@ -46,6 +46,16 @@ def _get_current_event_loop():
4646
andframe.f_code.co_name=="mainloop"
4747
forframeinsys._current_frames().values()):
4848
return"tk"
49+
try:
50+
frommatplotlib.backendsimport_macosx
51+
exceptImportError:
52+
pass
53+
else:
54+
# Note that the NSApp event loop is also running when a non-native
55+
# toolkit (e.g. Qt5) is active, but in that case we want to report the
56+
# other toolkit; thus, this check comes after the other toolkits.
57+
if_macosx.event_loop_is_running():
58+
return"macosx"
4959
ifsys.platform.startswith("linux")andnotos.environ.get("DISPLAY"):
5060
return"headless"
5161

‎src/_macosx.m

Lines 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 ([NSAppisRunning]) {
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
staticstruct 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)

[8]ページ先頭

©2009-2025 Movatter.jp