From 5d0be585fb4760a827b4a0c35df1647b3fafc48b Mon Sep 17 00:00:00 2001 From: Dmitry Mottl Date: Fri, 26 Oct 2018 03:09:58 +0200 Subject: [PATCH 1/2] Added support for MacOSX backend for PyPy --- doc/users/next_whats_new/2018-10-26-DM.rst | 5 +++++ src/_macosx.m | 1 + 2 files changed, 6 insertions(+) create mode 100644 doc/users/next_whats_new/2018-10-26-DM.rst diff --git a/doc/users/next_whats_new/2018-10-26-DM.rst b/doc/users/next_whats_new/2018-10-26-DM.rst new file mode 100644 index 000000000000..da119065fdee --- /dev/null +++ b/doc/users/next_whats_new/2018-10-26-DM.rst @@ -0,0 +1,5 @@ +Added support for MacOSX backend for PyPy +----------------------------------------- + +Fixed issue with MacOSX backend for PyPy and also for non-framework Python +installations. diff --git a/src/_macosx.m b/src/_macosx.m index 8ec3ebfae01d..69c80449e3c3 100644 --- a/src/_macosx.m +++ b/src/_macosx.m @@ -2586,6 +2586,7 @@ static bool verify_framework(void) have started */ #ifdef COMPILING_FOR_10_6 NSApp = [NSApplication sharedApplication]; + [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; NSApplicationActivationPolicy activationPolicy = [NSApp activationPolicy]; switch (activationPolicy) { case NSApplicationActivationPolicyRegular: From db6c8e8375a738206068d45d5be8d85a32f17940 Mon Sep 17 00:00:00 2001 From: Dmitry Mottl Date: Fri, 26 Oct 2018 22:25:31 +0200 Subject: [PATCH 2/2] setActivationPolicy is moved to lazy_init() for 10.6 --- src/_macosx.m | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/_macosx.m b/src/_macosx.m index 69c80449e3c3..958ca9e675d8 100644 --- a/src/_macosx.m +++ b/src/_macosx.m @@ -278,8 +278,11 @@ static void lazy_init(void) { backend_inited = true; NSApp = [NSApplication sharedApplication]; + [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; #ifndef PYPY + /* TODO: remove ifndef after the new PyPy with the PyOS_InputHook implementation + get released: https://bitbucket.org/pypy/pypy/commits/caaf91a */ PyOS_InputHook = wait_for_stdin; #endif @@ -2579,27 +2582,13 @@ static void context_cleanup(const void* info) Timer_new, /* tp_new */ }; +#ifndef COMPILING_FOR_10_6 static bool verify_framework(void) { ProcessSerialNumber psn; - /* These methods are deprecated, but they don't require the app to - have started */ -#ifdef COMPILING_FOR_10_6 - NSApp = [NSApplication sharedApplication]; - [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; - NSApplicationActivationPolicy activationPolicy = [NSApp activationPolicy]; - switch (activationPolicy) { - case NSApplicationActivationPolicyRegular: - case NSApplicationActivationPolicyAccessory: - return true; - case NSApplicationActivationPolicyProhibited: - break; - } -#else if (CGMainDisplayID()!=0 && GetCurrentProcess(&psn)==noErr && SetFrontProcess(&psn)==noErr) return true; -#endif PyErr_SetString(PyExc_ImportError, "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 " @@ -2611,6 +2600,7 @@ static bool verify_framework(void) "Matplotlib FAQ for more information."); return false; } +#endif static struct PyMethodDef methods[] = { {"event_loop_is_running", @@ -2661,8 +2651,11 @@ static bool verify_framework(void) || PyType_Ready(&TimerType) < 0) return NULL; +#ifndef COMPILING_FOR_10_6 + /* if >=10.6 invoke setActivationPolicy in lazy_init */ if (!verify_framework()) return NULL; +#endif module = PyModule_Create(&moduledef); if (!module)