X Tutup
Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 36 additions & 19 deletions src/_macosx.m
Original file line number Diff line number Diff line change
Expand Up @@ -3950,7 +3950,6 @@ static void _data_provider_release(void* info, const void* data, size_t size)
rect.size.height = height;
rect.size.width = width;

NSApp = [NSApplication sharedApplication];
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
self->window = [self->window initWithContentRect: rect
styleMask: NSTitledWindowMask
Expand Down Expand Up @@ -6208,6 +6207,33 @@ static void timer_callback(CFRunLoopTimerRef timer, void* info)
Timer_new, /* tp_new */
};

static bool verify_framework(void)
{
#ifdef COMPILING_FOR_10_6
NSRunningApplication* app = [NSRunningApplication currentApplication];
NSApplicationActivationPolicy activationPolicy = [app activationPolicy];
switch (activationPolicy) {
case NSApplicationActivationPolicyRegular:
case NSApplicationActivationPolicyAccessory:
return true;
case NSApplicationActivationPolicyProhibited:
break;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a default case handling -1? I.e. when this is called without an NSApplication? Perhaps raising a warning that the check will not work? Alternatively I think that we should at least document that this will not work without an NSApplication

}
#else
ProcessSerialNumber psn;
if (CGMainDisplayID()!=0
&& GetCurrentProcess(&psn)==noErr
&& SetFrontProcess(&psn)==noErr) return true;
#endif
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.");
return false;
}

static struct PyMethodDef methods[] = {
{"show",
(PyCFunction)show,
Expand Down Expand Up @@ -6248,7 +6274,6 @@ static void timer_callback(CFRunLoopTimerRef timer, void* info)
void init_macosx(void)
#endif
{
#ifdef WITH_NEXT_FRAMEWORK
PyObject *module;
import_array();

Expand All @@ -6264,6 +6289,15 @@ void init_macosx(void)
return;
#endif

NSApp = [NSApplication sharedApplication];

if (!verify_framework())
#if PY3K
return NULL;
#else
return;
#endif

#if PY3K
module = PyModule_Create(&moduledef);
if (module==NULL) return NULL;
Expand Down Expand Up @@ -6300,21 +6334,4 @@ 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
}
X Tutup