Merged changes in the trunk up to revision 29184.

This commit is contained in:
2010-06-03 15:39:02 +00:00
154 changed files with 3596 additions and 1611 deletions

View File

@@ -103,7 +103,7 @@ static int bpy_pydriver_create_dict(void)
}
/* Update function, it gets rid of pydrivers global dictionary, forcing
* BPY_pydriver_eval to recreate it. This function is used to force
* BPY_eval_driver 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.
*/
@@ -153,7 +153,7 @@ static float 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_pydriver_eval (ChannelDriver *driver)
float BPY_eval_driver (ChannelDriver *driver)
{
PyObject *driver_vars=NULL;
PyObject *retval= NULL;
@@ -246,11 +246,11 @@ float BPY_pydriver_eval (ChannelDriver *driver)
/* this target failed - bad name */
if (targets_ok) {
/* first one - print some extra info for easier identification */
fprintf(stderr, "\nBPY_pydriver_eval() - Error while evaluating PyDriver:\n");
fprintf(stderr, "\nBPY_eval_driver() - Error while evaluating PyDriver:\n");
targets_ok= 0;
}
fprintf(stderr, "\tBPY_pydriver_eval() - couldn't add variable '%s' to namespace\n", dvar->name);
fprintf(stderr, "\tBPY_eval_driver() - couldn't add variable '%s' to namespace\n", dvar->name);
// BPy_errors_to_report(NULL); // TODO - reports
PyErr_Print();
PyErr_Clear();
@@ -290,7 +290,7 @@ float BPY_pydriver_eval (ChannelDriver *driver)
return (float)result;
}
else {
fprintf(stderr, "\tBPY_pydriver_eval() - driver '%s' evaluates to '%f'\n", dvar->name, result);
fprintf(stderr, "\tBPY_eval_driver() - driver '%s' evaluates to '%f'\n", dvar->name, result);
return 0.0f;
}
}

View File

@@ -327,16 +327,17 @@ int BPY_run_python_script( bContext *C, const char *fn, struct Text *text, struc
}
bpy_context_set(C, &gilstate);
py_dict = CreateGlobalDictionary(C, text?text->id.name+2:fn);
if (text) {
char fn_dummy[FILE_MAXDIR];
bpy_text_filename_get(fn_dummy, text);
py_dict = CreateGlobalDictionary(C, fn_dummy);
if( !text->compiled ) { /* if it wasn't already compiled, do it now */
char *buf = txt_to_buf( text );
text->compiled =
Py_CompileString( buf, text->id.name+2, Py_file_input );
Py_CompileString( buf, fn_dummy, Py_file_input );
MEM_freeN( buf );
@@ -347,8 +348,12 @@ int BPY_run_python_script( bContext *C, const char *fn, struct Text *text, struc
if(text->compiled)
py_result = PyEval_EvalCode( text->compiled, py_dict, py_dict );
} else {
FILE *fp= fopen(fn, "r");
}
else {
FILE *fp= fopen(fn, "r");
py_dict = CreateGlobalDictionary(C, fn);
if(fp) {
#ifdef _WIN32
/* Previously we used PyRun_File to run directly the code on a FILE
@@ -528,7 +533,7 @@ int BPY_run_python_script_space(const char *modulename, const char *func)
#endif
int BPY_button_eval(bContext *C, char *expr, double *value)
int BPY_eval_button(bContext *C, const char *expr, double *value)
{
PyGILState_STATE gilstate;
PyObject *dict, *mod, *retval;
@@ -599,6 +604,40 @@ int BPY_button_eval(bContext *C, char *expr, double *value)
return error_ret;
}
int BPY_eval_string(bContext *C, const char *expr)
{
PyGILState_STATE gilstate;
PyObject *dict, *retval;
int error_ret = 0;
if (!expr) return -1;
if(expr[0]=='\0') {
return error_ret;
}
bpy_context_set(C, &gilstate);
dict= CreateGlobalDictionary(C, NULL);
retval = PyRun_String(expr, Py_eval_input, dict, dict);
if (retval == NULL) {
error_ret= -1;
BPy_errors_to_report(CTX_wm_reports(C));
}
else {
Py_DECREF(retval);
}
Py_DECREF(dict);
bpy_context_clear(C, &gilstate);
return error_ret;
}
void BPY_load_user_modules(bContext *C)
{
PyGILState_STATE gilstate;