diff options
Diffstat (limited to 'source/blender/python/intern/bpy_driver.c')
-rw-r--r-- | source/blender/python/intern/bpy_driver.c | 60 |
1 files changed, 14 insertions, 46 deletions
diff --git a/source/blender/python/intern/bpy_driver.c b/source/blender/python/intern/bpy_driver.c index e5719a84fdd..7072fbc09a7 100644 --- a/source/blender/python/intern/bpy_driver.c +++ b/source/blender/python/intern/bpy_driver.c @@ -1,4 +1,4 @@ -/** +/* * $Id$ * * ***** BEGIN GPL LICENSE BLOCK ***** @@ -34,13 +34,15 @@ #include "BKE_fcurve.h" #include "BKE_global.h" +#include "bpy_driver.h" + /* for pydrivers (drivers using one-line Python expressions to express relationships between targets) */ PyObject *bpy_pydriver_Dict = NULL; /* For faster execution we keep a special dictionary for pydrivers, with * the needed modules and aliases. */ -static int bpy_pydriver_create_dict(void) +int bpy_pydriver_create_dict(void) { PyObject *d, *mod; @@ -63,47 +65,21 @@ static int bpy_pydriver_create_dict(void) } /* add bpy to global namespace */ - mod= PyImport_ImportModuleLevel("bpy", NULL, NULL, NULL, 0); + mod= PyImport_ImportModuleLevel((char *)"bpy", NULL, NULL, NULL, 0); if (mod) { PyDict_SetItemString(bpy_pydriver_Dict, "bpy", mod); 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_pydriver_update(void) +void BPY_driver_reset(void) { PyGILState_STATE gilstate; int use_gil= 1; // (PyThreadState_Get()==NULL); @@ -124,22 +100,14 @@ void BPY_pydriver_update(void) } /* error return function for BPY_eval_pydriver */ -static float pydriver_error(ChannelDriver *driver) +static void pydriver_error(ChannelDriver *driver) { - if (bpy_pydriver_Dict) { /* free the global dict used by pydrivers */ - PyDict_Clear(bpy_pydriver_Dict); - Py_DECREF(bpy_pydriver_Dict); - bpy_pydriver_Dict = NULL; - } - driver->flag |= DRIVER_FLAG_INVALID; /* py expression failed */ fprintf(stderr, "\nError in Driver: The following Python expression failed:\n\t'%s'\n\n", driver->expression); // BPy_errors_to_report(NULL); // TODO - reports PyErr_Print(); PyErr_Clear(); - - return 0.0f; } /* This evals py driver expressions, 'expr' is a Python expression that @@ -149,7 +117,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_eval_driver (ChannelDriver *driver) +float BPY_driver_exec(ChannelDriver *driver) { PyObject *driver_vars=NULL; PyObject *retval= NULL; @@ -238,15 +206,15 @@ float BPY_eval_driver (ChannelDriver *driver) /* try to add to dictionary */ /* if (PyDict_SetItemString(driver_vars, dvar->name, driver_arg)) { */ - if (PyDict_SetItem(driver_vars, PyTuple_GET_ITEM(expr_vars, i++), driver_arg)) { /* use string interning for faster namespace creation */ + if (PyDict_SetItem(driver_vars, PyTuple_GET_ITEM(expr_vars, i++), driver_arg) < 0) { /* use string interning for faster namespace creation */ /* 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(); @@ -259,7 +227,7 @@ float BPY_eval_driver (ChannelDriver *driver) #else /* evaluate the compiled expression */ if (expr_code) - retval= PyEval_EvalCode((PyCodeObject *)expr_code, bpy_pydriver_Dict, driver_vars); + retval= PyEval_EvalCode((void *)expr_code, bpy_pydriver_Dict, driver_vars); #endif /* decref the driver vars first... */ @@ -286,7 +254,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; } } |