diff --git a/lib/matplotlib/backends/__init__.py b/lib/matplotlib/backends/__init__.py index f4ec9d91f919..62f15254ec3b 100644 --- a/lib/matplotlib/backends/__init__.py +++ b/lib/matplotlib/backends/__init__.py @@ -47,12 +47,8 @@ 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 '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 "