Skip to content

Commit d0a307d

Browse files
committed
The MacOS module will disappear in Python 3. Implement the WMAvailable()
check in the C code in src/_macosx.m, so we won't rely on the MacOS module. svn path=/trunk/matplotlib/; revision=8625
1 parent f118949 commit d0a307d

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-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.get_main_display_id():
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: 27 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,31 @@ - (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+
get_main_display_id(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+
return PyInt_FromLong(display);
5150+
}
5151+
51425152
static struct PyMethodDef methods[] = {
51435153
{"show",
51445154
(PyCFunction)show,
51455155
METH_NOARGS,
5146-
show__doc__
5156+
"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."
51475157
},
51485158
{"choose_save_file",
51495159
(PyCFunction)choose_save_file,
@@ -5155,11 +5165,17 @@ - (int)index
51555165
METH_VARARGS,
51565166
"Sets the active cursor."
51575167
},
5168+
{"get_main_display_id",
5169+
(PyCFunction)get_main_display_id,
5170+
METH_NOARGS,
5171+
"Returns the display ID of the main display. This function fails if Python is not built as a framework."
5172+
},
51585173
{NULL, NULL, 0, NULL}/* sentinel */
51595174
};
51605175

51615176
void init_macosx(void)
51625177
{ PyObject *m;
5178+
51635179
import_array();
51645180

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

0 commit comments

Comments
 (0)