Skip to content

Commit

Permalink
Merge pull request #1613 from mdehoon/fix-for-framework-check
Browse files Browse the repository at this point in the history
Using a stricter check to see if Python was installed as a framework.
  • Loading branch information
efiring committed Jan 10, 2013
2 parents e4d4984 + 30a8bca commit 9f74de0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 25 deletions.
7 changes: 0 additions & 7 deletions lib/matplotlib/backends/backend_macosx.py
Expand Up @@ -231,13 +231,6 @@ def new_figure_manager(num, *args, **kwargs):
"""
Create a new figure manager instance
"""
if not _macosx.verify_main_display():
import warnings
warnings.warn("Python is not installed as a framework. The MacOSX "
"backend may not work correctly if Python is not "
"installed as a framework. Please see the Python "
"documentation for more information on installing "
"Python as a framework on Mac OS X")
FigureClass = kwargs.pop('FigureClass', Figure)
figure = FigureClass(*args, **kwargs)
return new_figure_manager_given_figure(num, figure)
Expand Down
38 changes: 20 additions & 18 deletions src/_macosx.m
Expand Up @@ -5707,18 +5707,6 @@ - (int)index
return Py_None;
}

static PyObject*
verify_main_display(PyObject* self)
{
CGDirectDisplayID display = CGMainDisplayID();
if (display == 0) {
PyErr_SetString(PyExc_RuntimeError, "Failed to obtain the display ID of the main display");
return NULL;
}
Py_INCREF(Py_True);
return Py_True;
}

typedef struct {
PyObject_HEAD
CFRunLoopTimerRef timer;
Expand Down Expand Up @@ -5928,11 +5916,6 @@ static void timer_callback(CFRunLoopTimerRef timer, void* info)
METH_VARARGS,
"Sets the active cursor."
},
{"verify_main_display",
(PyCFunction)verify_main_display,
METH_NOARGS,
"Verifies if the main display can be found. This function fails if Python is not built as a framework."
},
{NULL, NULL, 0, NULL}/* sentinel */
};

Expand All @@ -5956,8 +5939,10 @@ static void timer_callback(CFRunLoopTimerRef timer, void* info)

void init_macosx(void)
#endif
{ PyObject *module;
{

#ifdef WITH_NEXT_FRAMEWORK
PyObject *module;
import_array();

if (PyType_Ready(&GraphicsContextType) < 0
Expand Down Expand Up @@ -6001,4 +5986,21 @@ void init_macosx(void)
#if PY3K
return module;
#endif
#else
/* WITH_NEXT_FRAMEWORK is not defined. This means that Python is not
* installed as a framework, and therefore the Mac OS X backend will
* not interact properly with the window manager.
*/
PyErr_SetString(PyExc_RuntimeError,
"Python is not installed as a framework. The Mac OS X backend will "
"not be able to function correctly if Python is not installed as a "
"framework. See the Python documentation for more information on "
"installing Python as a framework on Mac OS X. Please either reinstall "
"Python as a framework, or try one of the other backends.");
#if PY3K
return NULL;
#else
return;
#endif
#endif
}

0 comments on commit 9f74de0

Please sign in to comment.