@@ -3950,7 +3950,6 @@ static void _data_provider_release(void* info, const void* data, size_t size)
39503950 rect.size .height = height;
39513951 rect.size .width = width;
39523952
3953- NSApp = [NSApplication sharedApplication ];
39543953 NSAutoreleasePool * pool = [[NSAutoreleasePool alloc ] init ];
39553954 self->window = [self ->window initWithContentRect: rect
39563955 styleMask: NSTitledWindowMask
@@ -6208,6 +6207,33 @@ static void timer_callback(CFRunLoopTimerRef timer, void* info)
62086207 Timer_new, /* tp_new */
62096208};
62106209
6210+ static bool verify_framework (void )
6211+ {
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 ;
6235+ }
6236+
62116237static struct PyMethodDef methods[] = {
62126238 {" show" ,
62136239 (PyCFunction)show,
@@ -6248,7 +6274,6 @@ static void timer_callback(CFRunLoopTimerRef timer, void* info)
62486274void init_macosx (void )
62496275#endif
62506276{
6251- #ifdef WITH_NEXT_FRAMEWORK
62526277 PyObject *module;
62536278 import_array ();
62546279
@@ -6264,6 +6289,15 @@ void init_macosx(void)
62646289 return ;
62656290#endif
62666291
6292+ NSApp = [NSApplication sharedApplication ];
6293+
6294+ if (!verify_framework ())
6295+ #if PY3K
6296+ return NULL ;
6297+ #else
6298+ return ;
6299+ #endif
6300+
62676301#if PY3K
62686302 module = PyModule_Create (&moduledef);
62696303 if (module==NULL ) return NULL ;
@@ -6300,21 +6334,4 @@ void init_macosx(void)
63006334#if PY3K
63016335 return module;
63026336#endif
6303- #else
6304- /* WITH_NEXT_FRAMEWORK is not defined. This means that Python is not
6305- * installed as a framework, and therefore the Mac OS X backend will
6306- * not interact properly with the window manager.
6307- */
6308- PyErr_SetString (PyExc_RuntimeError,
6309- " Python is not installed as a framework. The Mac OS X backend will "
6310- " not be able to function correctly if Python is not installed as a "
6311- " framework. See the Python documentation for more information on "
6312- " installing Python as a framework on Mac OS X. Please either reinstall "
6313- " Python as a framework, or try one of the other backends." );
6314- #if PY3K
6315- return NULL ;
6316- #else
6317- return ;
6318- #endif
6319- #endif
63206337}
0 commit comments