From 489db9994df0bd95ac595922b38391ee68c3088f Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 17 Jun 2009 20:33:34 +0000 Subject: Some generic modules from blender 2.4x building with py3k and mostly working. * Mathutils, Geometry, BGL, Mostly working, some //XXX comments for things to fix with py3 python import override (bpy_internal_import.c) so you can import python internal scripts from the BGE and running blender normally. --- source/blender/python/intern/bpy_interface.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'source/blender/python/intern/bpy_interface.c') diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c index 22336bd4f71..0c063c0192b 100644 --- a/source/blender/python/intern/bpy_interface.c +++ b/source/blender/python/intern/bpy_interface.c @@ -36,6 +36,9 @@ #include "BPY_extern.h" +#include "../generic/bpy_internal_import.h" // our own imports + + void BPY_free_compiled_text( struct Text *text ) { if( text->compiled ) { @@ -131,10 +134,17 @@ void BPY_start_python( int argc, char **argv ) /* bpy.* and lets us import it */ bpy_init_modules(); + { /* our own import and reload functions */ + PyObject *item; + //PyObject *m = PyImport_AddModule("__builtin__"); + //PyObject *d = PyModule_GetDict(m); + PyObject *d = PyEval_GetBuiltins( ); + PyDict_SetItemString(d, "reload", item=PyCFunction_New(bpy_reload_meth, NULL)); Py_DECREF(item); + PyDict_SetItemString(d, "__import__", item=PyCFunction_New(bpy_import_meth, NULL)); Py_DECREF(item); + } py_tstate = PyGILState_GetThisThreadState(); PyEval_ReleaseThread(py_tstate); - } void BPY_end_python( void ) @@ -164,6 +174,7 @@ int BPY_run_python_script( bContext *C, const char *fn, struct Text *text, struc gilstate = PyGILState_Ensure(); BPY_update_modules(); /* can give really bad results if this isnt here */ + bpy_import_main_set(CTX_data_main(C)); py_dict = CreateGlobalDictionary(C); @@ -201,6 +212,7 @@ int BPY_run_python_script( bContext *C, const char *fn, struct Text *text, struc Py_DECREF(py_dict); PyGILState_Release(gilstate); + bpy_import_main_set(NULL); //BPY_end_python(); return py_result ? 1:0; @@ -387,6 +399,7 @@ void BPY_run_ui_scripts(bContext *C, int reload) // XXX - evil, need to access context BPy_SetContext(C); + bpy_import_main_set(CTX_data_main(C)); while((de = readdir(dir)) != NULL) { /* We could stat the file but easier just to let python @@ -421,6 +434,8 @@ void BPY_run_ui_scripts(bContext *C, int reload) PySys_SetObject("path", sys_path_orig); Py_DECREF(sys_path_orig); + bpy_import_main_set(NULL); + PyGILState_Release(gilstate); #ifdef TIME_REGISTRATION printf("script time %f\n", (PIL_check_seconds_timer()-time)); -- cgit v1.2.3