diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-01-05 05:08:54 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-01-05 05:08:54 +0300 |
commit | 96b646c68dd9f62f7655b7eee902bddb908e12a5 (patch) | |
tree | 9ccc70ed2f3cdb9aeb60f5dbacc4d798ffa8223f /source/blender/python | |
parent | 8200e44c392f999efa6660f9f81af25792752bd4 (diff) |
edits for BPY_extern.h functions, no functional changes
- remove unused code.
- BPY_run_python_script() split in 2, BPY_filepath_exec, BPY_text_exec
- renamed funcs.
Diffstat (limited to 'source/blender/python')
-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 |
5 files changed, 64 insertions, 263 deletions
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) {} |