diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/intern/constraint.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/context.c | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/exotic.c | 7 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/fcurve.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/text.c | 4 | ||||
-rw-r--r-- | source/blender/editors/interface/interface.c | 2 | ||||
-rw-r--r-- | source/blender/editors/space_script/script_edit.c | 6 | ||||
-rw-r--r-- | source/blender/editors/space_script/space_script.c | 5 | ||||
-rw-r--r-- | source/blender/editors/space_text/text_ops.c | 4 | ||||
-rw-r--r-- | source/blender/python/BPY_extern.h | 95 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_driver.c | 38 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_interface.c | 183 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna.c | 2 | ||||
-rw-r--r-- | source/blender/python/intern/stubs.c | 9 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_files.c | 10 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_init_exit.c | 12 | ||||
-rw-r--r-- | source/creator/CMakeLists.txt | 2 | ||||
-rw-r--r-- | source/creator/creator.c | 13 |
18 files changed, 97 insertions, 303 deletions
diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index b0932533ea6..b6e68a71bc9 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -2033,7 +2033,7 @@ static void pycon_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *targ #endif /* Now, run the actual 'constraint' function, which should only access the matrices */ - BPY_pyconstraint_eval(data, cob, targets); + BPY_pyconstraint_exec(data, cob, targets); #endif /* WITH_PYTHON */ } diff --git a/source/blender/blenkernel/intern/context.c b/source/blender/blenkernel/intern/context.c index 9740c969ec7..09321ddea81 100644 --- a/source/blender/blenkernel/intern/context.c +++ b/source/blender/blenkernel/intern/context.c @@ -427,8 +427,8 @@ static int ctx_data_get(bContext *C, const char *member, bContextDataResult *res memset(result, 0, sizeof(bContextDataResult)); #ifdef WITH_PYTHON if(CTX_py_dict_get(C)) { - return BPY_context_get(C, member, result); -// if (BPY_context_get(C, member, result)) + return BPY_context_member_get(C, member, result); +// if (BPY_context_member_get(C, member, result)) // return 1; } #endif diff --git a/source/blender/blenkernel/intern/exotic.c b/source/blender/blenkernel/intern/exotic.c index 53c3534bce3..e695c40401a 100644 --- a/source/blender/blenkernel/intern/exotic.c +++ b/source/blender/blenkernel/intern/exotic.c @@ -492,12 +492,7 @@ int BKE_read_exotic(Scene *scene, const char *name) #ifdef WITH_PYTHON // TODO: this should not be in the kernel... else { // unknown format, call Python importloader - if (BPY_call_importloader(name)) { - retval = 1; - } else { - //XXX error("Unknown file type or error, check console"); - } - + /* pass */ } #endif /* WITH_PYTHON */ //XXX waitcursor(0); diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c index f2bc586f15c..4a596b079cf 100644 --- a/source/blender/blenkernel/intern/fcurve.c +++ b/source/blender/blenkernel/intern/fcurve.c @@ -1514,7 +1514,7 @@ static float evaluate_driver (ChannelDriver *driver, float UNUSED(evaltime)) /* this evaluates the expression using Python,and returns its result: * - on errors it reports, then returns 0.0f */ - driver->curval= BPY_eval_driver(driver); + driver->curval= BPY_driver_exec(driver); } #endif /* WITH_PYTHON*/ } diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index bb3a31a0977..44a8141adff 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -168,7 +168,7 @@ void free_text(Text *text) if(text->name) MEM_freeN(text->name); MEM_freeN(text->undo_buf); #ifdef WITH_PYTHON - if (text->compiled) BPY_free_compiled_text(text); + if (text->compiled) BPY_text_free_code(text); #endif } @@ -684,7 +684,7 @@ static void txt_make_dirty (Text *text) { text->flags |= TXT_ISDIRTY; #ifdef WITH_PYTHON - if (text->compiled) BPY_free_compiled_text(text); + if (text->compiled) BPY_text_free_code(text); #endif } diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 4e3e9786a5a..5860bdaed2f 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -1734,7 +1734,7 @@ int ui_set_but_string(bContext *C, uiBut *but, const char *str) bUnit_ReplaceString(str_unit_convert, sizeof(str_unit_convert), but->drawstr, ui_get_but_scale_unit(but, 1.0), scene->unit.system, unit_type>>16); } - if(BPY_eval_button(C, str_unit_convert, &value)) { + if(BPY_button_exec(C, str_unit_convert, &value)) { value = ui_get_but_val(but); /* use its original value */ if(str[0]) diff --git a/source/blender/editors/space_script/script_edit.c b/source/blender/editors/space_script/script_edit.c index 4e65c216cd3..ba51fd93f92 100644 --- a/source/blender/editors/space_script/script_edit.c +++ b/source/blender/editors/space_script/script_edit.c @@ -47,7 +47,7 @@ #include "script_intern.h" // own include #ifdef WITH_PYTHON -#include "BPY_extern.h" /* BPY_run_python_script */ +#include "BPY_extern.h" /* BPY_script_exec */ #endif static int run_pyfile_exec(bContext *C, wmOperator *op) @@ -55,7 +55,7 @@ static int run_pyfile_exec(bContext *C, wmOperator *op) char path[512]; RNA_string_get(op->ptr, "filepath", path); #ifdef WITH_PYTHON - if(BPY_run_python_script(C, path, NULL, op->reports)) { + if(BPY_filepath_exec(C, path, op->reports)) { ARegion *ar= CTX_wm_region(C); ED_region_tag_redraw(ar); return OPERATOR_FINISHED; @@ -88,7 +88,7 @@ static int script_reload_exec(bContext *C, wmOperator *UNUSED(op)) /* TODO, this crashes on netrender and keying sets, need to look into why * disable for now unless running in debug mode */ WM_cursor_wait(1); - BPY_eval_string(C, "__import__('bpy').utils.load_scripts(reload_scripts=True)"); + BPY_string_exec(C, "__import__('bpy').utils.load_scripts(reload_scripts=True)"); WM_cursor_wait(0); WM_event_add_notifier(C, NC_WINDOW, NULL); return OPERATOR_FINISHED; diff --git a/source/blender/editors/space_script/space_script.c b/source/blender/editors/space_script/space_script.c index 57d7bba8e3b..106c79f8fd0 100644 --- a/source/blender/editors/space_script/space_script.c +++ b/source/blender/editors/space_script/space_script.c @@ -148,12 +148,11 @@ static void script_main_area_draw(const bContext *C, ARegion *ar) UI_view2d_view_ortho(v2d); /* data... */ - // BPY_run_python_script(C, "/root/blender-svn/blender25/test.py", NULL); + // BPY_script_exec(C, "/root/blender-svn/blender25/test.py", NULL); #ifdef WITH_PYTHON if (sscript->script) { - //BPY_run_python_script_space(scpt->script.filename, NULL); - BPY_run_script_space_draw(C, sscript); + // BPY_run_script_space_draw(C, sscript); } #else (void)sscript; diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c index 8dc67ca4774..e3ac59861bf 100644 --- a/source/blender/editors/space_text/text_ops.c +++ b/source/blender/editors/space_text/text_ops.c @@ -314,7 +314,7 @@ static int reload_exec(bContext *C, wmOperator *op) #ifdef WITH_PYTHON if(text->compiled) - BPY_free_compiled_text(text); + BPY_text_free_code(text); #endif text_update_edited(text); @@ -569,7 +569,7 @@ static int run_script_exec(bContext *C, wmOperator *op) Text *text= CTX_data_edit_text(C); SpaceText *st= CTX_wm_space_text(C); - if (BPY_run_python_script(C, NULL, text, op->reports)) + if (BPY_text_exec(C, text, op->reports)) return OPERATOR_FINISHED; /* Dont report error messages while live editing */ diff --git a/source/blender/python/BPY_extern.h b/source/blender/python/BPY_extern.h index 98e160525f8..5ee4664fd57 100644 --- a/source/blender/python/BPY_extern.h +++ b/source/blender/python/BPY_extern.h @@ -38,14 +38,12 @@ struct Object; /* DNA_object_types.h */ struct ChannelDriver; /* DNA_anim_types.h */ struct ListBase; /* DNA_listBase.h */ struct SpaceText; /* DNA_space_types.h */ -struct SpaceScript; /* DNA_space_types.h */ struct ScrArea; /* DNA_screen_types.h */ struct bScreen; /* DNA_screen_types.h */ struct bConstraint; /* DNA_constraint_types.h */ struct bPythonConstraint; /* DNA_constraint_types.h */ struct bConstraintOb; /* DNA_constraint_types.h */ struct bConstraintTarget; /* DNA_constraint_types.h*/ -struct Script; /* DNA_screen_types.h */ struct BPyMenu; struct bContext; struct bContextDataResult; @@ -55,34 +53,15 @@ struct ReportList; extern "C" { #endif - /*These two next functions are important for making sure the Draw module - works correctly. Before calling any gui callback using the Draw module, - the following code must be executed: - - if (some_drawspace_pylist) { - BPy_Set_DrawButtonsList(some_drawspace_pylist->but_refs); - BPy_Free_DrawButtonsList(); - } - some_drawspace_pylist = PyList_New(0); - BPy_Set_DrawButtonsList(some_drawspace_pylist); - - Also, BPy_Free_DrawButtonsList() must be called as necassary when a drawspace - with python callbacks is destroyed. - - This is necassary to avoid blender buttons storing invalid pointers to freed - python data.*/ -// void BPy_Set_DrawButtonsList(void *list); -// void BPy_Free_DrawButtonsList(void); -// - void BPY_pyconstraint_eval(struct bPythonConstraint *con, struct bConstraintOb *cob, struct ListBase *targets); +void BPY_pyconstraint_exec(struct bPythonConstraint *con, struct bConstraintOb *cob, struct ListBase *targets); // void BPY_pyconstraint_settings(void *arg1, void *arg2); - void BPY_pyconstraint_target(struct bPythonConstraint *con, struct bConstraintTarget *ct); - void BPY_pyconstraint_update(struct Object *owner, struct bConstraint *con); - int BPY_is_pyconstraint(struct Text *text); +void BPY_pyconstraint_target(struct bPythonConstraint *con, struct bConstraintTarget *ct); +void BPY_pyconstraint_update(struct Object *owner, struct bConstraint *con); +int BPY_is_pyconstraint(struct Text *text); // void BPY_free_pyconstraint_links(struct Text *text); // - void BPY_start_python( int argc, char **argv ); - void BPY_end_python( void ); +void BPY_python_start( int argc, char **argv ); +void BPY_python_end( void ); // void init_syspath( int first_time ); // void syspath_append( char *dir ); // void BPY_rebuild_syspath( void ); @@ -90,55 +69,23 @@ extern "C" { // // int BPY_Err_getLinenumber( void ); // const char *BPY_Err_getFilename( void ); -// -// int BPY_txt_do_python_Text( struct Text *text ); -// int BPY_menu_do_python( short menutype, int event ); -// int BPY_menu_do_shortcut( short menutype, unsigned short key, unsigned short modifiers ); -// int BPY_menu_invoke( struct BPyMenu *pym, short menutype ); - - /* 2.5 UI Scripts */ - int BPY_run_python_script( struct bContext *C, const char *filename, struct Text *text, struct ReportList *reports ); // 2.5 working - int BPY_run_script_space_draw(const struct bContext *C, struct SpaceScript * sc); // 2.5 working -// int BPY_run_script_space_listener(struct bContext *C, struct SpaceScript * sc, struct ARegion *ar, struct wmNotifier *wmn); // 2.5 working - void BPY_update_modules(struct bContext *C); // XXX - annoying, need this for pointers that get out of date -// - int BPY_context_get(struct bContext *C, const char *member, struct bContextDataResult *result); -// -// int BPY_run_script(struct Script *script); - void BPY_free_compiled_text( struct Text *text ); -// -// int BPY_has_onload_script( void ); -// -// int BPY_is_spacehandler(struct Text *text, char spacetype); -// int BPY_del_spacehandler(struct Text *text, struct ScrArea *sa); -// int BPY_add_spacehandler(struct Text *txt, struct ScrArea *sa,char spacetype); -// int BPY_has_spacehandler(struct Text *text, struct ScrArea *sa); -// void BPY_screen_free_spacehandlers(struct bScreen *sc); -// int BPY_do_spacehandlers(struct ScrArea *sa, unsigned short event, -// short eventValue, unsigned short space_event); -// - void BPY_reset_driver(void); - float BPY_eval_driver(struct ChannelDriver *driver); -// - int BPY_eval_button(struct bContext *C, const char *expr, double *value); - int BPY_eval_string(struct bContext *C, const char *expr); +/* 2.5 UI Scripts */ +int BPY_filepath_exec(struct bContext *C, const char *filepath, struct ReportList *reports); +int BPY_text_exec(struct bContext *C, struct Text *text, struct ReportList *reports); +void BPY_text_free_code(struct Text *text); +void BPY_modules_update(struct bContext *C); // XXX - annoying, need this for pointers that get out of date +void BPY_modules_load_user(struct bContext *C); -/* format importer hook */ - int BPY_call_importloader(const char *name); -// -// void BPY_spacescript_do_pywin_draw( struct SpaceScript *sc ); -// void BPY_spacescript_do_pywin_event( struct SpaceScript *sc, -// unsigned short event, short val, char ascii ); -// void BPY_free_finished_script( struct Script *script ); -// void BPY_scripts_clear_pyobjects( void ); -// -// void error_pyscript( void ); - void BPY_DECREF(void *pyob_ptr); /* Py_DECREF() */ - void BPY_set_context(struct bContext *C); -/* void BPY_Err_Handle(struct Text *text); */ -/* int BPY_spacetext_is_pywin(struct SpaceText *st); */ - void BPY_load_user_modules(struct bContext *C); +void BPY_driver_reset(void); +float BPY_driver_exec(struct ChannelDriver *driver); + +int BPY_button_exec(struct bContext *C, const char *expr, double *value); +int BPY_string_exec(struct bContext *C, const char *expr); + +void BPY_DECREF(void *pyob_ptr); /* Py_DECREF() */ +int BPY_context_member_get(struct bContext *C, const char *member, struct bContextDataResult *result); +void BPY_context_set(struct bContext *C); #ifdef __cplusplus } /* extern "C" */ diff --git a/source/blender/python/intern/bpy_driver.c b/source/blender/python/intern/bpy_driver.c index 7ca7604e938..59f762a0658 100644 --- a/source/blender/python/intern/bpy_driver.c +++ b/source/blender/python/intern/bpy_driver.c @@ -69,41 +69,15 @@ int bpy_pydriver_create_dict(void) Py_DECREF(mod); } - -#if 0 // non existant yet - mod = PyImport_ImportModule("Blender.Noise"); - if (mod) { - PyDict_SetItemString(d, "noise", mod); - PyDict_SetItemString(d, "n", mod); - Py_DECREF(mod); - } else { - PyErr_Clear(); - } - - /* If there's a Blender text called pydrivers.py, import it. - * Users can add their own functions to this module. - */ - if (G.f & G_SCRIPT_AUTOEXEC) { - mod = importText("pydrivers"); /* can also use PyImport_Import() */ - if (mod) { - PyDict_SetItemString(d, "pydrivers", mod); - PyDict_SetItemString(d, "p", mod); - Py_DECREF(mod); - } else { - PyErr_Clear(); - } - } -#endif // non existant yet - return 0; } /* Update function, it gets rid of pydrivers global dictionary, forcing - * BPY_eval_driver to recreate it. This function is used to force + * BPY_driver_exec to recreate it. This function is used to force * reloading the Blender text module "pydrivers.py", if available, so * updates in it reach pydriver evaluation. */ -void BPY_reset_driver(void) +void BPY_driver_reset(void) { PyGILState_STATE gilstate; int use_gil= 1; // (PyThreadState_Get()==NULL); @@ -141,7 +115,7 @@ static void pydriver_error(ChannelDriver *driver) * bake operator which intern starts a thread which calls scene update which * does a driver update. to avoid a deadlock check PyThreadState_Get() if PyGILState_Ensure() is needed. */ -float BPY_eval_driver (ChannelDriver *driver) +float BPY_driver_exec(ChannelDriver *driver) { PyObject *driver_vars=NULL; PyObject *retval= NULL; @@ -234,11 +208,11 @@ float BPY_eval_driver (ChannelDriver *driver) /* this target failed - bad name */ if (targets_ok) { /* first one - print some extra info for easier identification */ - fprintf(stderr, "\nBPY_eval_driver() - Error while evaluating PyDriver:\n"); + fprintf(stderr, "\nBPY_driver_eval() - Error while evaluating PyDriver:\n"); targets_ok= 0; } - fprintf(stderr, "\tBPY_eval_driver() - couldn't add variable '%s' to namespace\n", dvar->name); + fprintf(stderr, "\tBPY_driver_eval() - couldn't add variable '%s' to namespace\n", dvar->name); // BPy_errors_to_report(NULL); // TODO - reports PyErr_Print(); PyErr_Clear(); @@ -278,7 +252,7 @@ float BPY_eval_driver (ChannelDriver *driver) return (float)result; } else { - fprintf(stderr, "\tBPY_eval_driver() - driver '%s' evaluates to '%f'\n", dvar->name, result); + fprintf(stderr, "\tBPY_driver_eval() - driver '%s' evaluates to '%f'\n", dvar->name, result); return 0.0f; } } diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c index 2c615a52860..3e3e946ae86 100644 --- a/source/blender/python/intern/bpy_interface.c +++ b/source/blender/python/intern/bpy_interface.c @@ -88,7 +88,7 @@ void bpy_context_set(bContext *C, PyGILState_STATE *gilstate) fprintf(stderr, "ERROR: Python context called with a NULL Context. this should not happen!\n"); } - BPY_update_modules(C); /* can give really bad results if this isnt here */ + BPY_modules_update(C); /* can give really bad results if this isnt here */ #ifdef TIME_PY_RUN if(bpy_timer_count==0) { @@ -128,7 +128,7 @@ void bpy_context_clear(bContext *UNUSED(C), PyGILState_STATE *gilstate) } } -void BPY_free_compiled_text( struct Text *text ) +void BPY_text_free_code(Text *text) { if( text->compiled ) { Py_DECREF( ( PyObject * ) text->compiled ); @@ -136,7 +136,7 @@ void BPY_free_compiled_text( struct Text *text ) } } -void BPY_update_modules(bContext *C) +void BPY_modules_update(bContext *C) { #if 0 // slow, this runs all the time poll, draw etc 100's of time a sec. PyObject *mod= PyImport_ImportModuleLevel("bpy", NULL, NULL, NULL, 0); @@ -150,7 +150,7 @@ void BPY_update_modules(bContext *C) } /* must be called before Py_Initialize */ -void BPY_start_python_path(void) +void BPY_python_start_path(void) { char *py_path_bundle= BLI_get_folder(BLENDER_PYTHON, NULL); @@ -191,7 +191,7 @@ void BPY_start_python_path(void) -void BPY_set_context(bContext *C) +void BPY_context_set(bContext *C) { BPy_SetContext(C); } @@ -214,8 +214,8 @@ static struct _inittab bpy_internal_modules[]= { {NULL, NULL} }; -/* call BPY_set_context first */ -void BPY_start_python( int argc, char **argv ) +/* call BPY_context_set first */ +void BPY_python_start( int argc, char **argv ) { PyThreadState *py_tstate = NULL; @@ -227,7 +227,7 @@ void BPY_start_python( int argc, char **argv ) /* builtin modules */ PyImport_ExtendInittab(bpy_internal_modules); - BPY_start_python_path(); /* allow to use our own included python */ + BPY_python_start_path(); /* allow to use our own included python */ Py_Initialize( ); @@ -278,7 +278,7 @@ void BPY_start_python( int argc, char **argv ) PyEval_ReleaseThread(py_tstate); } -void BPY_end_python( void ) +void BPY_python_end(void) { // fprintf(stderr, "Ending Python!\n"); @@ -312,12 +312,13 @@ void BPY_end_python( void ) } -/* Can run a file or text block */ -int BPY_run_python_script( bContext *C, const char *fn, struct Text *text, struct ReportList *reports) +static int python_script_exec(bContext *C, const char *fn, struct Text *text, struct ReportList *reports) { PyObject *py_dict= NULL, *py_result= NULL; PyGILState_STATE gilstate; - + + BKE_assert(fn || text); + if (fn==NULL && text==NULL) { return 0; } @@ -327,7 +328,7 @@ int BPY_run_python_script( bContext *C, const char *fn, struct Text *text, struc if (text) { char fn_dummy[FILE_MAXDIR]; bpy_text_filename_get(fn_dummy, text); - + if( !text->compiled ) { /* if it wasn't already compiled, do it now */ char *buf = txt_to_buf( text ); @@ -336,8 +337,8 @@ int BPY_run_python_script( bContext *C, const char *fn, struct Text *text, struc MEM_freeN( buf ); - if( PyErr_Occurred( ) ) { - BPY_free_compiled_text( text ); + if(PyErr_Occurred()) { + BPY_text_free_code(text); } } @@ -345,7 +346,7 @@ int BPY_run_python_script( bContext *C, const char *fn, struct Text *text, struc py_dict = PyC_DefaultNameSpace(fn_dummy); py_result = PyEval_EvalCode(text->compiled, py_dict, py_dict); } - + } else { FILE *fp= fopen(fn, "r"); @@ -354,9 +355,9 @@ int BPY_run_python_script( bContext *C, const char *fn, struct Text *text, struc py_dict = PyC_DefaultNameSpace(fn); #ifdef _WIN32 - /* Previously we used PyRun_File to run directly the code on a FILE + /* Previously we used PyRun_File to run directly the code on a FILE * object, but as written in the Python/C API Ref Manual, chapter 2, - * 'FILE structs for different C libraries can be different and + * 'FILE structs for different C libraries can be different and * incompatible'. * So now we load the script file data to a buffer */ { @@ -380,14 +381,14 @@ int BPY_run_python_script( bContext *C, const char *fn, struct Text *text, struc py_result= NULL; } } - + if (!py_result) { BPy_errors_to_report(reports); } else { Py_DECREF( py_result ); } -/* super annoying, undo _PyModule_Clear() */ +/* super annoying, undo _PyModule_Clear() */ #define PYMODULE_CLEAR_WORKAROUND if(py_dict) { @@ -405,92 +406,22 @@ int BPY_run_python_script( bContext *C, const char *fn, struct Text *text, struc #endif #undef PYMODULE_CLEAR_WORKAROUND } - + bpy_context_clear(C, &gilstate); - return py_result ? 1:0; + return (py_result != NULL); } - -/* TODO - move into bpy_space.c ? */ -/* GUI interface routines */ - -/* Copied from Draw.c */ -static void exit_pydraw( SpaceScript * sc, short err ) +/* Can run a file or text block */ +int BPY_filepath_exec(bContext *C, const char *filepath, struct ReportList *reports) { - Script *script = NULL; - - if( !sc || !sc->script ) - return; - - script = sc->script; - - if( err ) { - BPy_errors_to_report(NULL); // TODO, reports - script->flags = 0; /* mark script struct for deletion */ - SCRIPT_SET_NULL(script); - script->scriptname[0] = '\0'; - script->scriptarg[0] = '\0'; -// XXX 2.5 error_pyscript(); -// XXX 2.5 scrarea_queue_redraw( sc->area ); - } - -#if 0 // XXX 2.5 - BPy_Set_DrawButtonsList(sc->but_refs); - BPy_Free_DrawButtonsList(); /*clear all temp button references*/ -#endif - - sc->but_refs = NULL; - - Py_XDECREF( ( PyObject * ) script->py_draw ); - Py_XDECREF( ( PyObject * ) script->py_event ); - Py_XDECREF( ( PyObject * ) script->py_button ); - - script->py_draw = script->py_event = script->py_button = NULL; + return python_script_exec(C, filepath, NULL, reports); } -static int bpy_run_script_init(bContext *C, SpaceScript * sc) -{ - if (sc->script==NULL) - return 0; - - if (sc->script->py_draw==NULL && sc->script->scriptname[0] != '\0') - BPY_run_python_script(C, sc->script->scriptname, NULL, NULL); - - if (sc->script->py_draw==NULL) - return 0; - - return 1; -} -int BPY_run_script_space_draw(const struct bContext *C, SpaceScript * sc) +int BPY_text_exec(bContext *C, struct Text *text, struct ReportList *reports) { - if (bpy_run_script_init( (bContext *)C, sc)) { - PyGILState_STATE gilstate = PyGILState_Ensure(); - PyObject *result = PyObject_CallObject( sc->script->py_draw, NULL ); - - if (result==NULL) - exit_pydraw(sc, 1); - - PyGILState_Release(gilstate); - } - return 1; -} - -// XXX - not used yet, listeners dont get a context -int BPY_run_script_space_listener(bContext *C, SpaceScript * sc) -{ - if (bpy_run_script_init(C, sc)) { - PyGILState_STATE gilstate = PyGILState_Ensure(); - - PyObject *result = PyObject_CallObject( sc->script->py_draw, NULL ); - - if (result==NULL) - exit_pydraw(sc, 1); - - PyGILState_Release(gilstate); - } - return 1; + return python_script_exec(C, NULL, text, reports); } void BPY_DECREF(void *pyob_ptr) @@ -500,57 +431,7 @@ void BPY_DECREF(void *pyob_ptr) PyGILState_Release(gilstate); } -#if 0 -/* called from the the scripts window, assume context is ok */ -int BPY_run_python_script_space(const char *modulename, const char *func) -{ - PyObject *py_dict, *py_result= NULL; - char pystring[512]; - PyGILState_STATE gilstate; - - /* for calling the module function */ - PyObject *py_func, - - gilstate = PyGILState_Ensure(); - - py_dict = PyC_DefaultNameSpace("<dummy>"); - - PyObject *module = PyImport_ImportModule(scpt->script.filename); - if (module==NULL) { - PyErr_SetFormat(PyExc_SystemError, "could not import '%s'", scpt->script.filename); - } - else { - py_func = PyObject_GetAttrString(modulename, func); - if (py_func==NULL) { - PyErr_SetFormat(PyExc_SystemError, "module has no function '%s.%s'\n", scpt->script.filename, func); - } - else { - Py_DECREF(py_func); - if (!PyCallable_Check(py_func)) { - PyErr_SetFormat(PyExc_SystemError, "module item is not callable '%s.%s'\n", scpt->script.filename, func); - } - else { - py_result= PyObject_CallObject(py_func, NULL); // XXX will need args eventually - } - } - } - - if (!py_result) { - BPy_errors_to_report(NULL); // TODO - reports - } else - Py_DECREF( py_result ); - - Py_XDECREF(module); - - PyDict_SetItemString(PyThreadState_GET()->interp->modules, "__main__", Py_None); - - PyGILState_Release(gilstate); - return 1; -} -#endif - - -int BPY_eval_button(bContext *C, const char *expr, double *value) +int BPY_button_exec(bContext *C, const char *expr, double *value) { PyGILState_STATE gilstate; PyObject *py_dict, *mod, *retval; @@ -622,7 +503,7 @@ int BPY_eval_button(bContext *C, const char *expr, double *value) return error_ret; } -int BPY_eval_string(bContext *C, const char *expr) +int BPY_string_exec(bContext *C, const char *expr) { PyGILState_STATE gilstate; PyObject *py_dict, *retval; @@ -657,7 +538,7 @@ int BPY_eval_string(bContext *C, const char *expr) } -void BPY_load_user_modules(bContext *C) +void BPY_modules_load_user(bContext *C) { PyGILState_STATE gilstate; Main *bmain= CTX_data_main(C); @@ -690,7 +571,7 @@ void BPY_load_user_modules(bContext *C) bpy_context_clear(C, &gilstate); } -int BPY_context_get(bContext *C, const char *member, bContextDataResult *result) +int BPY_context_member_get(bContext *C, const char *member, bContextDataResult *result) { PyObject *pyctx= (PyObject *)CTX_py_dict_get(C); PyObject *item= PyDict_GetItemString(pyctx, member); diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index e6becc6f6be..123091cf6df 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -5176,7 +5176,7 @@ static int bpy_class_validate(PointerRNA *dummyptr, void *py_data, int *have_fun return 0; } -extern void BPY_update_modules(bContext *C); //XXX temp solution +extern void BPY_modules_update(bContext *C); //XXX temp solution /* TODO - multiple return values like with rna functions */ static int bpy_class_call(bContext *C, PointerRNA *ptr, FunctionRNA *func, ParameterList *parms) diff --git a/source/blender/python/intern/stubs.c b/source/blender/python/intern/stubs.c index abf329b5fd0..c766e802dd0 100644 --- a/source/blender/python/intern/stubs.c +++ b/source/blender/python/intern/stubs.c @@ -27,11 +27,10 @@ */ /* python, will come back */ -//void BPY_run_python_script(void) {} -//void BPY_start_python(void) {} -void BPY_call_importloader(const char *filepath) {(void)filepath;} -//void BPY_free_compiled_text(void) {} -void BPY_pyconstraint_eval(void) {} +//void BPY_script_exec(void) {} +//void BPY_python_start(void) {} +//void BPY_text_free_code(void) {} +void BPY_pyconstraint_exec(void) {} void BPY_pyconstraint_target(void) {} int BPY_is_pyconstraint(void) {return 0;} void BPY_pyconstraint_update(void) {} diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index 5403699a0b3..b5601f60bee 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -316,8 +316,8 @@ void WM_read_file(bContext *C, const char *name, ReportList *reports) #ifdef WITH_PYTHON /* run any texts that were loaded in and flagged as modules */ - BPY_reset_driver(); - BPY_load_user_modules(C); + BPY_driver_reset(); + BPY_modules_load_user(C); #endif CTX_wm_window_set(C, NULL); /* exits queues */ @@ -415,10 +415,10 @@ int WM_read_homefile(bContext *C, wmOperator *op) #ifdef WITH_PYTHON if(CTX_py_init_get(C)) { /* sync addons, these may have changed from the defaults */ - BPY_eval_string(C, "__import__('bpy').utils.addon_reset_all()"); + BPY_string_exec(C, "__import__('bpy').utils.addon_reset_all()"); - BPY_reset_driver(); - BPY_load_user_modules(C); + BPY_driver_reset(); + BPY_modules_load_user(C); } #endif diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c index 181ae62af17..7eefacca2c6 100644 --- a/source/blender/windowmanager/intern/wm_init_exit.c +++ b/source/blender/windowmanager/intern/wm_init_exit.c @@ -144,11 +144,11 @@ void WM_init(bContext *C, int argc, char **argv) * Will try fix when the crash can be repeated. - campbell. */ #ifdef WITH_PYTHON - BPY_set_context(C); /* necessary evil */ - BPY_start_python(argc, argv); + BPY_context_set(C); /* necessary evil */ + BPY_python_start(argc, argv); - BPY_reset_driver(); - BPY_load_user_modules(C); + BPY_driver_reset(); + BPY_modules_load_user(C); #else (void)argc; /* unused */ (void)argv; /* unused */ @@ -412,7 +412,7 @@ void WM_exit(bContext *C) /* Update for blender 2.5, move after free_blender because blender now holds references to PyObject's * so decref'ing them after python ends causes bad problems every time * the pyDriver bug can be fixed if it happens again we can deal with it then */ - BPY_end_python(); + BPY_python_end(); #endif if (!G.background) { @@ -435,7 +435,7 @@ void WM_exit(bContext *C) UI_exit(); BKE_userdef_free(); - RNA_exit(); /* should be after BPY_end_python so struct python slots are cleared */ + RNA_exit(); /* should be after BPY_python_end so struct python slots are cleared */ wm_ghost_exit(); diff --git a/source/creator/CMakeLists.txt b/source/creator/CMakeLists.txt index 78aa98cb7f5..8db4954d876 100644 --- a/source/creator/CMakeLists.txt +++ b/source/creator/CMakeLists.txt @@ -556,7 +556,7 @@ endif() ge_scenegraph ge_logic_network bf_gen_system - bf_python # duplicate for BPY_eval_driver + bf_python # duplicate for BPY_driver_exec ge_logic_ngnetwork extern_bullet ge_logic_loopbacknetwork diff --git a/source/creator/creator.c b/source/creator/creator.c index aaa96752cc3..92da0fe5beb 100644 --- a/source/creator/creator.c +++ b/source/creator/creator.c @@ -861,7 +861,7 @@ static int run_python(int argc, char **argv, void *data) BLI_strncpy(filename, argv[1], sizeof(filename)); BLI_path_cwd(filename); - BPY_CTX_SETUP( BPY_run_python_script(C, filename, NULL, NULL) ) + BPY_CTX_SETUP(BPY_filepath_exec(C, filename, NULL)) return 1; } else { @@ -878,10 +878,9 @@ static int run_python(int argc, char **argv, void *data) static int run_python_console(int UNUSED(argc), char **argv, void *data) { #ifdef WITH_PYTHON - bContext *C = data; - const char *expr= "__import__('code').interact()"; + bContext *C = data; - BPY_CTX_SETUP( BPY_eval_string(C, expr) ) + BPY_CTX_SETUP(BPY_string_exec(C, "__import__('code').interact()")) return 0; #else @@ -926,8 +925,8 @@ static int load_file(int UNUSED(argc), char **argv, void *data) /* WM_read_file() runs normally but since we're in background mode do here */ #ifdef WITH_PYTHON /* run any texts that were loaded in and flagged as modules */ - BPY_reset_driver(); - BPY_load_user_modules(C); + BPY_driver_reset(); + BPY_modules_load_user(C); #endif /* happens for the UI on file reading too (huh? (ton))*/ @@ -1159,7 +1158,7 @@ int main(int argc, char **argv) * NOTE: the U.pythondir string is NULL until WM_init() is executed, * so we provide the BPY_ function below to append the user defined * pythondir to Python's sys.path at this point. Simply putting - * WM_init() before BPY_start_python() crashes Blender at startup. + * WM_init() before BPY_python_start() crashes Blender at startup. * Update: now this function also inits the bpymenus, which also depend * on U.pythondir. */ |