Changeset View
Changeset View
Standalone View
Standalone View
source/blender/python/intern/bpy_interface.c
| Show First 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | |||||
| #include "../gpu/gpu_py_api.h" | #include "../gpu/gpu_py_api.h" | ||||
| #include "../bmesh/bmesh_py_api.h" | #include "../bmesh/bmesh_py_api.h" | ||||
| #include "../mathutils/mathutils.h" | #include "../mathutils/mathutils.h" | ||||
| /* Logging types to use anywhere in the Python modules. */ | /* Logging types to use anywhere in the Python modules. */ | ||||
| CLG_LOGREF_DECLARE_GLOBAL(BPY_LOG_CONTEXT, "bpy.context"); | CLG_LOGREF_DECLARE_GLOBAL(BPY_LOG_CONTEXT, "bpy.context"); | ||||
| CLG_LOGREF_DECLARE_GLOBAL(BPY_LOG_RNA, "bpy.rna"); | CLG_LOGREF_DECLARE_GLOBAL(BPY_LOG_RNA, "bpy.rna"); | ||||
| static CLG_LogRef LOG = {"bpy.interface"}; | |||||
| /* for internal use, when starting and ending python scripts */ | /* for internal use, when starting and ending python scripts */ | ||||
| /* in case a python script triggers another python call, stop bpy_context_clear from invalidating */ | /* in case a python script triggers another python call, stop bpy_context_clear from invalidating */ | ||||
| static int py_call_level = 0; | static int py_call_level = 0; | ||||
| BPy_StructRNA *bpy_context_module = NULL; /* for fast access */ | BPy_StructRNA *bpy_context_module = NULL; /* for fast access */ | ||||
| // #define TIME_PY_RUN // simple python tests. prints on exit. | // #define TIME_PY_RUN // simple python tests. prints on exit. | ||||
| ▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | |||||
| void bpy_context_clear(bContext *UNUSED(C), PyGILState_STATE *gilstate) | void bpy_context_clear(bContext *UNUSED(C), PyGILState_STATE *gilstate) | ||||
| { | { | ||||
| py_call_level--; | py_call_level--; | ||||
| if (gilstate) | if (gilstate) | ||||
| PyGILState_Release(*gilstate); | PyGILState_Release(*gilstate); | ||||
| if (py_call_level < 0) { | if (py_call_level < 0) { | ||||
| fprintf(stderr, "ERROR: Python context internal state bug. this should not happen!\n"); | CLOG_ERROR(&LOG, "Python context internal state bug. this should not happen!"); | ||||
| } | } | ||||
| else if (py_call_level == 0) { | else if (py_call_level == 0) { | ||||
| /* XXX - Calling classes currently wont store the context :\, | /* XXX - Calling classes currently wont store the context :\, | ||||
| * cant set NULL because of this. but this is very flakey still. */ | * cant set NULL because of this. but this is very flakey still. */ | ||||
| #if 0 | #if 0 | ||||
| BPy_SetContext(NULL); | BPy_SetContext(NULL); | ||||
| bpy_import_main_set(NULL); | bpy_import_main_set(NULL); | ||||
| #endif | #endif | ||||
| ▲ Show 20 Lines • Show All 612 Lines • ▼ Show 20 Lines | void BPY_modules_load_user(bContext *C) | ||||
| for (text = bmain->text.first; text; text = text->id.next) { | for (text = bmain->text.first; text; text = text->id.next) { | ||||
| if (text->flags & TXT_ISSCRIPT && BLI_path_extension_check(text->id.name + 2, ".py")) { | if (text->flags & TXT_ISSCRIPT && BLI_path_extension_check(text->id.name + 2, ".py")) { | ||||
| if (!(G.f & G_SCRIPT_AUTOEXEC)) { | if (!(G.f & G_SCRIPT_AUTOEXEC)) { | ||||
| if (!(G.f & G_SCRIPT_AUTOEXEC_FAIL_QUIET)) { | if (!(G.f & G_SCRIPT_AUTOEXEC_FAIL_QUIET)) { | ||||
| G.f |= G_SCRIPT_AUTOEXEC_FAIL; | G.f |= G_SCRIPT_AUTOEXEC_FAIL; | ||||
| BLI_snprintf(G.autoexec_fail, sizeof(G.autoexec_fail), "Text '%s'", text->id.name + 2); | BLI_snprintf(G.autoexec_fail, sizeof(G.autoexec_fail), "Text '%s'", text->id.name + 2); | ||||
| printf("scripts disabled for \"%s\", skipping '%s'\n", BKE_main_blendfile_path(bmain), text->id.name + 2); | CLOG_INFO(&LOG, 1, "scripts disabled for \"%s\", skipping '%s'", BKE_main_blendfile_path(bmain), text->id.name + 2); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| PyObject *module = bpy_text_import(text); | PyObject *module = bpy_text_import(text); | ||||
| if (module == NULL) { | if (module == NULL) { | ||||
| PyErr_Print(); | PyErr_Print(); | ||||
| PyErr_Clear(); | PyErr_Clear(); | ||||
| ▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | #endif | ||||
| } | } | ||||
| } | } | ||||
| if (done == false) { | if (done == false) { | ||||
| if (item) { | if (item) { | ||||
| CLOG_INFO(BPY_LOG_CONTEXT, 1, "'%s' not a valid type", member); | CLOG_INFO(BPY_LOG_CONTEXT, 1, "'%s' not a valid type", member); | ||||
| } | } | ||||
| else { | else { | ||||
| CLOG_INFO(BPY_LOG_CONTEXT, 1, "'%s' not found\n", member); | CLOG_INFO(BPY_LOG_CONTEXT, 1, "'%s' not found", member); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| CLOG_INFO(BPY_LOG_CONTEXT, 2, "'%s' found", member); | CLOG_INFO(BPY_LOG_CONTEXT, 2, "'%s' found", member); | ||||
| } | } | ||||
| if (use_gil) | if (use_gil) | ||||
| PyGILState_Release(gilstate); | PyGILState_Release(gilstate); | ||||
| ▲ Show 20 Lines • Show All 154 Lines • Show Last 20 Lines | |||||