diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-11-27 05:39:51 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-11-27 05:39:51 +0300 |
commit | 02cc80691d71ea305780655d3b0d4cd4530db9c7 (patch) | |
tree | f41d0aeb97e5667d4697c2a90b7fc2becc65ffa6 /source/blender/python/intern/bpy_app.c | |
parent | 4a804855b26bd764b7752e673052c0001dce32a1 (diff) |
python access to driver namespace, rather then have a textblock defined for drivers allow scripts to add functions directly.
- bpy.app.driver_namespace, read-only dictionary, edit in-place.
- reset on file load and new file.
- on errors the namespace used to be reset, this should not be needed.
simple example.
def driverFunc(val):
return val * val
bpy.app.driver_namespace['driverFunc'] = driverFunc
... now all drivers can access this function.
Diffstat (limited to 'source/blender/python/intern/bpy_app.c')
-rw-r--r-- | source/blender/python/intern/bpy_app.c | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/source/blender/python/intern/bpy_app.c b/source/blender/python/intern/bpy_app.c index b7a277c76b0..8977c82dc7c 100644 --- a/source/blender/python/intern/bpy_app.c +++ b/source/blender/python/intern/bpy_app.c @@ -159,15 +159,34 @@ static PyObject *bpy_app_tempdir_get(PyObject *UNUSED(self), void *UNUSED(closur return PyC_UnicodeFromByte(btempdir); } -PyGetSetDef bpy_app_debug_getset= {"debug", bpy_app_debug_get, bpy_app_debug_set, "Boolean, set when blender is running in debug mode (started with -d)", NULL}; -PyGetSetDef bpy_app_tempdir_getset= {"tempdir", bpy_app_tempdir_get, NULL, "String, the temp directory used by blender (read-only)", NULL}; +static PyObject *bpy_app_driver_dict_get(PyObject *UNUSED(self), void *UNUSED(closure)) +{ + if (bpy_pydriver_Dict == NULL) + if (bpy_pydriver_create_dict() != 0) { + PyErr_SetString(PyExc_RuntimeError, "bpy.app.driver_namespace failed to create dictionary"); + return NULL; + } + + Py_INCREF(bpy_pydriver_Dict); + return bpy_pydriver_Dict; +} + + +PyGetSetDef bpy_app_getsets[]= { + {"debug", bpy_app_debug_get, bpy_app_debug_set, "Boolean, set when blender is running in debug mode (started with -d)", NULL}, + {"tempdir", bpy_app_tempdir_get, NULL, "String, the temp directory used by blender (read-only)", NULL}, + {"driver_namespace", bpy_app_driver_dict_get, NULL, "Dictionary for drivers namespace, editable in-place, reset on file load (read-only)", NULL}, + {NULL, NULL, NULL, NULL, NULL} +}; static void py_struct_seq_getset_init(void) { /* tricky dynamic members, not to py-spec! */ - - PyDict_SetItemString(BlenderAppType.tp_dict, bpy_app_debug_getset.name, PyDescr_NewGetSet(&BlenderAppType, &bpy_app_debug_getset)); - PyDict_SetItemString(BlenderAppType.tp_dict, bpy_app_tempdir_getset.name, PyDescr_NewGetSet(&BlenderAppType, &bpy_app_tempdir_getset)); + PyGetSetDef *getset; + + for(getset= bpy_app_getsets; getset->name; getset++) { + PyDict_SetItemString(BlenderAppType.tp_dict, getset->name, PyDescr_NewGetSet(&BlenderAppType, getset)); + } } /* end dynamic bpy.app */ |