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

Skip to content

Commit c44b4c2

Browse files
author
Michiel de Hoon
committed
Reintroduce the verify_main_display function to check during runtime if Python was installed as a framework
1 parent 6586369 commit c44b4c2

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

lib/matplotlib/backends/backend_macosx.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@
2323
import matplotlib
2424
from matplotlib.backends import _macosx
2525

26+
if not _macosx.verify_main_display():
27+
import warnings
28+
warnings.warn("Python is not installed as a framework. The MacOSX "
29+
"backend may not work correctly if Python is not "
30+
"installed as a framework. Please see the Python "
31+
"documentation for more information on installing "
32+
"Python as a framework on Mac OS X.")
33+
2634

2735
class Show(ShowBase):
2836
def mainloop(self):

src/_macosx.m

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6208,7 +6208,24 @@ static void timer_callback(CFRunLoopTimerRef timer, void* info)
62086208
Timer_new, /* tp_new */
62096209
};
62106210

6211+
6212+
static PyObject*
6213+
verify_main_display(PyObject* self)
6214+
{
6215+
PyObject* result;
6216+
CGDirectDisplayID display = CGMainDisplayID();
6217+
if (display == 0) result = Py_False;
6218+
else result = Py_True;
6219+
Py_INCREF(result);
6220+
return result;
6221+
}
6222+
62116223
static struct PyMethodDef methods[] = {
6224+
{"verify_main_display",
6225+
(PyCFunction)verify_main_display,
6226+
METH_NOARGS,
6227+
"Verifies if the main display can be found. This function returns False if Python is not built as a framework."
6228+
},
62126229
{"show",
62136230
(PyCFunction)show,
62146231
METH_NOARGS,

0 commit comments

Comments
 (0)