From 30a8bcae4f6fbd976f18c1ebd3543407aa8f1342 Mon Sep 17 00:00:00 2001 From: Michiel de Hoon Date: Thu, 20 Dec 2012 14:03:14 +0900 Subject: [PATCH] Using a stricter check to see if Python was installed as a framework. Also, because of the recurring problems with non-framework Pythons, importing the Mac OS X backend will now fail (instead of just issuing a warning) if Python is not installed as a framework. --- lib/matplotlib/backends/backend_macosx.py | 7 ----- src/_macosx.m | 38 ++++++++++++----------- 2 files changed, 20 insertions(+), 25 deletions(-) diff --git a/lib/matplotlib/backends/backend_macosx.py b/lib/matplotlib/backends/backend_macosx.py index 3386b523f7e9..ed17506e4a79 100644 --- a/lib/matplotlib/backends/backend_macosx.py +++ b/lib/matplotlib/backends/backend_macosx.py @@ -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) diff --git a/src/_macosx.m b/src/_macosx.m index 55b0d4997e4a..fcd638aa95cf 100644 --- a/src/_macosx.m +++ b/src/_macosx.m @@ -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; @@ -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 */ }; @@ -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 @@ -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 }