| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -269,9 +269,41 @@ - (int)index; | |||
| 269 | 269 | ||
| 270 | 270 | static bool backend_inited = false; | |
| 271 | 271 | ||
| 272 | - static void lazy_init(void) { | ||
| 272 | + static bool verify_framework(void) | ||
| 273 | + { | ||
| 274 | + #ifdef COMPILING_FOR_10_6 | ||
| 275 | + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; | ||
| 276 | + NSRunningApplication* app = [NSRunningApplication currentApplication]; | ||
| 277 | + NSApplicationActivationPolicy activationPolicy = [app activationPolicy]; | ||
| 278 | + [pool release]; | ||
| 279 | + switch (activationPolicy) { | ||
| 280 | + case NSApplicationActivationPolicyRegular: | ||
| 281 | + case NSApplicationActivationPolicyAccessory: | ||
| 282 | + return true; | ||
| 283 | + case NSApplicationActivationPolicyProhibited: | ||
| 284 | + break; | ||
| 285 | + } | ||
| 286 | + #else | ||
| 287 | + ProcessSerialNumber psn; | ||
| 288 | + if (CGMainDisplayID()!=0 | ||
| 289 | + && GetCurrentProcess(&psn)==noErr | ||
| 290 | + && SetFrontProcess(&psn)==noErr) return true; | ||
| 291 | + #endif | ||
| 292 | + PyErr_SetString(PyExc_ImportError, | ||
| 293 | + "Python is not installed as a framework. The Mac OS X backend will " | ||
| 294 | + "not be able to function correctly if Python is not installed as a " | ||
| 295 | + "framework. See the Python documentation for more information on " | ||
| 296 | + "installing Python as a framework on Mac OS X. Please either reinstall " | ||
| 297 | + "Python as a framework, or try one of the other backends. If you are " | ||
| 298 | + "using (Ana)Conda please install python.app and replace the use of " | ||
| 299 | + "'python' with 'pythonw'. See 'Working with Matplotlib on OSX' in the " | ||
| 300 | + "Matplotlib FAQ for more information."); | ||
| 301 | + return false; | ||
| 302 | + } | ||
| 303 | + | ||
| 304 | + static bool lazy_init(void) { | ||
| 273 | 305 | if (backend_inited) { | |
| 274 | - return; | ||
| 306 | + return true; | ||
| 275 | 307 | } | |
| 276 | 308 | backend_inited = true; | |
| 277 | 309 | ||
@@ -288,6 +320,10 @@ static void lazy_init(void) { | |||
| 288 | 320 | name: NSWorkspaceDidLaunchApplicationNotification | |
| 289 | 321 | object: nil]; | |
| 290 | 322 | [pool release]; | |
| 323 | + | ||
| 324 | + if (!verify_framework()) return false; | ||
| 325 | + | ||
| 326 | + return true; | ||
| 291 | 327 | } | |
| 292 | 328 | ||
| 293 | 329 | static PyObject* | |
@@ -314,7 +350,7 @@ static CGFloat _get_device_scale(CGContextRef cr) | |||
| 314 | 350 | static PyObject* | |
| 315 | 351 | FigureCanvas_new(PyTypeObject *type, PyObject *args, PyObject *kwds) | |
| 316 | 352 | { | |
| 317 | - lazy_init(); | ||
| 353 | + if (!lazy_init()) return NULL; | ||
| 318 | 354 | FigureCanvas *self = (FigureCanvas*)type->tp_alloc(type, 0); | |
| 319 | 355 | if (!self) return NULL; | |
| 320 | 356 | self->view = [View alloc]; | |
@@ -675,7 +711,7 @@ static CGFloat _get_device_scale(CGContextRef cr) | |||
| 675 | 711 | static PyObject* | |
| 676 | 712 | FigureManager_new(PyTypeObject *type, PyObject *args, PyObject *kwds) | |
| 677 | 713 | { | |
| 678 | - lazy_init(); | ||
| 714 | + if (!lazy_init()) return NULL; | ||
| 679 | 715 | Window* window = [Window alloc]; | |
| 680 | 716 | if (!window) return NULL; | |
| 681 | 717 | FigureManager *self = (FigureManager*)type->tp_alloc(type, 0); | |
@@ -1111,7 +1147,7 @@ -(void)save_figure:(id)sender | |||
| 1111 | 1147 | static PyObject* | |
| 1112 | 1148 | NavigationToolbar2_new(PyTypeObject *type, PyObject *args, PyObject *kwds) | |
| 1113 | 1149 | { | |
| 1114 | - lazy_init(); | ||
| 1150 | + if (!lazy_init()) return NULL; | ||
| 1115 | 1151 | NavigationToolbar2Handler* handler = [NavigationToolbar2Handler alloc]; | |
| 1116 | 1152 | if (!handler) return NULL; | |
| 1117 | 1153 | NavigationToolbar2 *self = (NavigationToolbar2*)type->tp_alloc(type, 0); | |
@@ -2372,7 +2408,7 @@ - (int)index | |||
| 2372 | 2408 | static PyObject* | |
| 2373 | 2409 | Timer_new(PyTypeObject* type, PyObject *args, PyObject *kwds) | |
| 2374 | 2410 | { | |
| 2375 | - lazy_init(); | ||
| 2411 | + if (!lazy_init()) return NULL; | ||
| 2376 | 2412 | Timer* self = (Timer*)type->tp_alloc(type, 0); | |
| 2377 | 2413 | if (!self) return NULL; | |
| 2378 | 2414 | self->timer = NULL; | |
@@ -2563,38 +2599,6 @@ static void context_cleanup(const void* info) | |||
| 2563 | 2599 | Timer_new, /* tp_new */ | |
| 2564 | 2600 | }; | |
| 2565 | 2601 | ||
| 2566 | - static bool verify_framework(void) | ||
| 2567 | - { | ||
| 2568 | - #ifdef COMPILING_FOR_10_6 | ||
| 2569 | - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; | ||
| 2570 | - NSRunningApplication* app = [NSRunningApplication currentApplication]; | ||
| 2571 | - NSApplicationActivationPolicy activationPolicy = [app activationPolicy]; | ||
| 2572 | - [pool release]; | ||
| 2573 | - switch (activationPolicy) { | ||
| 2574 | - case NSApplicationActivationPolicyRegular: | ||
| 2575 | - case NSApplicationActivationPolicyAccessory: | ||
| 2576 | - return true; | ||
| 2577 | - case NSApplicationActivationPolicyProhibited: | ||
| 2578 | - break; | ||
| 2579 | - } | ||
| 2580 | - #else | ||
| 2581 | - ProcessSerialNumber psn; | ||
| 2582 | - if (CGMainDisplayID()!=0 | ||
| 2583 | - && GetCurrentProcess(&psn)==noErr | ||
| 2584 | - && SetFrontProcess(&psn)==noErr) return true; | ||
| 2585 | - #endif | ||
| 2586 | - PyErr_SetString(PyExc_ImportError, | ||
| 2587 | - "Python is not installed as a framework. The Mac OS X backend will " | ||
| 2588 | - "not be able to function correctly if Python is not installed as a " | ||
| 2589 | - "framework. See the Python documentation for more information on " | ||
| 2590 | - "installing Python as a framework on Mac OS X. Please either reinstall " | ||
| 2591 | - "Python as a framework, or try one of the other backends. If you are " | ||
| 2592 | - "using (Ana)Conda please install python.app and replace the use of " | ||
| 2593 | - "'python' with 'pythonw'. See 'Working with Matplotlib on OSX' in the " | ||
| 2594 | - "Matplotlib FAQ for more information."); | ||
| 2595 | - return false; | ||
| 2596 | - } | ||
| 2597 | - | ||
| 2598 | 2602 | static struct PyMethodDef methods[] = { | |
| 2599 | 2603 | {"event_loop_is_running", | |
| 2600 | 2604 | (PyCFunction)event_loop_is_running, | |
@@ -2644,9 +2648,6 @@ static bool verify_framework(void) | |||
| 2644 | 2648 | || PyType_Ready(&TimerType) < 0) | |
| 2645 | 2649 | return NULL; | |
| 2646 | 2650 | ||
| 2647 | - if (!verify_framework()) | ||
| 2648 | - return NULL; | ||
| 2649 | - | ||
| 2650 | 2651 | module = PyModule_Create(&moduledef); | |
| 2651 | 2652 | if (!module) | |
| 2652 | 2653 | return NULL; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments