From f14f24191cb5ea843b2900ff447bee42bdffe135 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Tue, 23 Oct 2018 11:58:54 -0700 Subject: [PATCH 1/2] FIX: don't import macosx to check if eventloop running --- lib/matplotlib/backends/__init__.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/matplotlib/backends/__init__.py b/lib/matplotlib/backends/__init__.py index f4ec9d91f919..f91689c72d04 100644 --- a/lib/matplotlib/backends/__init__.py +++ b/lib/matplotlib/backends/__init__.py @@ -47,12 +47,7 @@ def _get_running_interactive_framework(): if frame.f_code == tkinter.mainloop.__code__: return "tk" frame = frame.f_back - try: - from matplotlib.backends import _macosx - except ImportError: - pass - else: - if _macosx.event_loop_is_running(): + if ('_macosx' in sys.modules) and (_macosx.event_loop_is_running()): return "macosx" if sys.platform.startswith("linux") and not os.environ.get("DISPLAY"): return "headless" From bc7059e619ff9878d33a8f28d77b83e9c7b271f8 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Tue, 23 Oct 2018 12:57:43 -0700 Subject: [PATCH 2/2] FIX: go back to non-deprecated methods --- lib/matplotlib/backends/__init__.py | 3 ++- src/_macosx.m | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/backends/__init__.py b/lib/matplotlib/backends/__init__.py index f91689c72d04..62f15254ec3b 100644 --- a/lib/matplotlib/backends/__init__.py +++ b/lib/matplotlib/backends/__init__.py @@ -47,7 +47,8 @@ def _get_running_interactive_framework(): if frame.f_code == tkinter.mainloop.__code__: return "tk" frame = frame.f_back - if ('_macosx' in sys.modules) and (_macosx.event_loop_is_running()): + if 'matplotlib.backends._macosx' in sys.modules: + if sys.modules["matplotlib.backends._macosx"].event_loop_is_running(): return "macosx" if sys.platform.startswith("linux") and not os.environ.get("DISPLAY"): return "headless" diff --git a/src/_macosx.m b/src/_macosx.m index ce791d1f9d21..4f025268ef8d 100644 --- a/src/_macosx.m +++ b/src/_macosx.m @@ -2580,9 +2580,21 @@ 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]; + 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 "