Skip to content

Commit 42b8388

Browse files
committed
Replace MacOS.WMAvailable, as the MacOS module is not available with 64-bit Pythons, and deprecated for Python 3.
svn path=/branches/v1_0_maint/; revision=8886
1 parent ea7344e commit 42b8388

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

lib/matplotlib/backends/backend_macosx.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import os
44
import numpy
5-
import MacOS
65

76
from matplotlib._pylab_helpers import Gcf
87
from matplotlib.backend_bases import RendererBase, GraphicsContextBase,\
@@ -229,7 +228,7 @@ def new_figure_manager(num, *args, **kwargs):
229228
"""
230229
Create a new figure manager instance
231230
"""
232-
if not MacOS.WMAvailable():
231+
if not _macosx.verify_main_display():
233232
import warnings
234233
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")
235234
FigureClass = kwargs.pop('FigureClass', Figure)

src/_macosx.m

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4399,16 +4399,6 @@ -(void)save_figure:(id)sender
43994399
return Py_None;
44004400
}
44014401

4402-
static char show__doc__[] = "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.";
4403-
4404-
static PyObject*
4405-
show(PyObject* self)
4406-
{
4407-
if(nwin > 0) [NSApp run];
4408-
Py_INCREF(Py_None);
4409-
return Py_None;
4410-
}
4411-
44124402
@implementation Window
44134403
- (Window*)initWithContentRect:(NSRect)rect styleMask:(unsigned int)mask backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation withManager: (PyObject*)theManager
44144404
{
@@ -5139,11 +5129,32 @@ - (int)index
51395129
}
51405130
@end
51415131

5132+
5133+
static PyObject*
5134+
show(PyObject* self)
5135+
{
5136+
if(nwin > 0) [NSApp run];
5137+
Py_INCREF(Py_None);
5138+
return Py_None;
5139+
}
5140+
5141+
static PyObject*
5142+
verify_main_display(PyObject* self)
5143+
{
5144+
CGDirectDisplayID display = CGMainDisplayID();
5145+
if (display == 0) {
5146+
PyErr_SetString(PyExc_RuntimeError, "Failed to obtain the display ID of the main display");
5147+
return NULL;
5148+
}
5149+
Py_INCREF(Py_True);
5150+
return Py_True;
5151+
}
5152+
51425153
static struct PyMethodDef methods[] = {
51435154
{"show",
51445155
(PyCFunction)show,
51455156
METH_NOARGS,
5146-
show__doc__
5157+
"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."
51475158
},
51485159
{"choose_save_file",
51495160
(PyCFunction)choose_save_file,
@@ -5155,11 +5166,17 @@ - (int)index
51555166
METH_VARARGS,
51565167
"Sets the active cursor."
51575168
},
5169+
{"verify_main_display",
5170+
(PyCFunction)verify_main_display,
5171+
METH_NOARGS,
5172+
"Verifies if the main display can be found. This function fails if Python is not built as a framework."
5173+
},
51585174
{NULL, NULL, 0, NULL}/* sentinel */
51595175
};
51605176

51615177
void init_macosx(void)
51625178
{ PyObject *m;
5179+
51635180
import_array();
51645181

51655182
if (PyType_Ready(&GraphicsContextType) < 0) return;

0 commit comments

Comments
 (0)