@@ -3950,7 +3950,6 @@ static void _data_provider_release(void* info, const void* data, size_t size)
3950
3950
rect.size .height = height;
3951
3951
rect.size .width = width;
3952
3952
3953
- NSApp = [NSApplication sharedApplication];
3954
3953
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc ] init ];
3955
3954
self->window = [self ->window initWithContentRect: rect
3956
3955
styleMask: NSTitledWindowMask
@@ -6208,32 +6207,34 @@ static void timer_callback(CFRunLoopTimerRef timer, void* info)
6208
6207
Timer_new, /* tp_new */
6209
6208
};
6210
6209
6211
-
6212
- static PyObject*
6213
- verify_main_display(PyObject* self)
6214
- /* Python2 contains a WMAvailable function in the MacOS module to check
6215
- * if python can interact with the display. This function calls
6216
- * CGMainDisplayID, which will return 0 if no window manager is available,
6217
- * or if we don't have permission to talk to it; this will happen if Python
6218
- * is not installed as a framework.
6219
- * The MacOS module was removed from Python3, so we need to provide a way
6220
- * to call CGMainDisplayID ourselves.
6221
- */
6210
+ static bool verify_framework (void )
6222
6211
{
6223
- PyObject* result;
6224
- CGDirectDisplayID display = CGMainDisplayID();
6225
- if (display == 0) result = Py_False;
6226
- else result = Py_True;
6227
- Py_INCREF(result);
6228
- return result;
6212
+ #ifdef COMPILING_FOR_10_6
6213
+ NSRunningApplication * app = [NSRunningApplication currentApplication ];
6214
+ NSApplicationActivationPolicy activationPolicy = [app activationPolicy ];
6215
+ switch (activationPolicy) {
6216
+ case NSApplicationActivationPolicyRegular:
6217
+ case NSApplicationActivationPolicyAccessory:
6218
+ return true ;
6219
+ case NSApplicationActivationPolicyProhibited:
6220
+ break ;
6221
+ }
6222
+ #else
6223
+ ProcessSerialNumber psn;
6224
+ if (CGMainDisplayID ()!=0
6225
+ && GetCurrentProcess (&psn)==noErr
6226
+ && SetFrontProcess (&psn)==noErr ) return true ;
6227
+ #endif
6228
+ PyErr_SetString (PyExc_RuntimeError,
6229
+ " Python is not installed as a framework. The Mac OS X backend will "
6230
+ " not be able to function correctly if Python is not installed as a "
6231
+ " framework. See the Python documentation for more information on "
6232
+ " installing Python as a framework on Mac OS X. Please either reinstall "
6233
+ " Python as a framework, or try one of the other backends." );
6234
+ return false ;
6229
6235
}
6230
6236
6231
6237
static struct PyMethodDef methods[] = {
6232
- {"verify_main_display",
6233
- (PyCFunction)verify_main_display,
6234
- METH_NOARGS,
6235
- "Verifies if the main display can be found. This function returns False if Python is not built as a framework."
6236
- },
6237
6238
{" show" ,
6238
6239
(PyCFunction)show,
6239
6240
METH_NOARGS,
@@ -6273,7 +6274,6 @@ static void timer_callback(CFRunLoopTimerRef timer, void* info)
6273
6274
void init_macosx (void )
6274
6275
#endif
6275
6276
{
6276
- #ifdef WITH_NEXT_FRAMEWORK
6277
6277
PyObject *module;
6278
6278
import_array ();
6279
6279
@@ -6289,6 +6289,15 @@ void init_macosx(void)
6289
6289
return ;
6290
6290
#endif
6291
6291
6292
+ NSApp = [NSApplication sharedApplication ];
6293
+
6294
+ if (!verify_framework ())
6295
+ #if PY3K
6296
+ return NULL ;
6297
+ #else
6298
+ return ;
6299
+ #endif
6300
+
6292
6301
#if PY3K
6293
6302
module = PyModule_Create (&moduledef);
6294
6303
if (module==NULL ) return NULL ;
@@ -6325,21 +6334,4 @@ void init_macosx(void)
6325
6334
#if PY3K
6326
6335
return module;
6327
6336
#endif
6328
- #else
6329
- /* WITH_NEXT_FRAMEWORK is not defined. This means that Python is not
6330
- * installed as a framework, and therefore the Mac OS X backend will
6331
- * not interact properly with the window manager.
6332
- */
6333
- PyErr_SetString(PyExc_RuntimeError,
6334
- "Python is not installed as a framework. The Mac OS X backend will "
6335
- "not be able to function correctly if Python is not installed as a "
6336
- "framework. See the Python documentation for more information on "
6337
- "installing Python as a framework on Mac OS X. Please either reinstall "
6338
- "Python as a framework, or try one of the other backends.");
6339
- #if PY3K
6340
- return NULL;
6341
- #else
6342
- return;
6343
- #endif
6344
- #endif
6345
6337
}
0 commit comments