diff options
-rw-r--r-- | source/blender/python/intern/bpy_interface.c | 16 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna.c | 61 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_PythonInit.cpp | 12 |
3 files changed, 79 insertions, 10 deletions
diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c index 62e374953b0..bc422e5a20c 100644 --- a/source/blender/python/intern/bpy_interface.c +++ b/source/blender/python/intern/bpy_interface.c @@ -187,7 +187,21 @@ void BPY_start_python( int argc, char **argv ) Py_Initialize( ); - //PySys_SetArgv( argc_copy, argv_copy ); +#if (PY_VERSION_HEX < 0x03000000) + PySys_SetArgv( argc, argv); +#else + /* sigh, why do python guys not have a char** version anymore? :( */ + { + int i; + PyObject *py_argv= PyList_New(argc); + + for (i=0; i<argc; i++) + PyList_SET_ITEM(py_argv, i, PyUnicode_FromString(argv[i])); + + PySys_SetObject("argv", py_argv); + Py_DECREF(py_argv); + } +#endif /* Initialize thread support (also acquires lock) */ PyEval_InitThreads(); diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index eff34b895da..5c8499b5280 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -40,6 +40,10 @@ #include "BKE_global.h" /* evil G.* */ #include "BKE_report.h" +/* only for keyframing */ +#include "DNA_scene_types.h" +#include "ED_keyframing.h" + #define USE_MATHUTILS #ifdef USE_MATHUTILS @@ -312,10 +316,17 @@ PyObject * pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop) /* don't throw error here, can't trust blender 100% to give the * right values, python code should not generate error for that */ RNA_property_enum_items(ptr, prop, &item, NULL); - if(item[0].identifier) - ret = PyUnicode_FromString( item[0].identifier ); - else + if(item->identifier) { + ret = PyUnicode_FromString( item->identifier ); + } + else { + /* prefer not fail silently incase of api errors, maybe disable it later */ + char error_str[128]; + sprintf(error_str, "RNA Warning: Current value \"%d\" matches no enum", val); + PyErr_Warn(PyExc_RuntimeWarning, error_str); + ret = PyUnicode_FromString( "" ); + } /*PyErr_Format(PyExc_AttributeError, "RNA Error: Current value \"%d\" matches no enum", val); ret = NULL;*/ @@ -913,8 +924,12 @@ static PyObject *prop_subscript_collection(BPy_PropertyRNA * self, PyObject *key if (PyUnicode_Check(key)) { return prop_subscript_collection_str(self, _PyUnicode_AsString(key)); } - else if (PyLong_Check(key)) { - return prop_subscript_collection_int(self, PyLong_AsSsize_t(key)); + else if (PyIndex_Check(key)) { + Py_ssize_t i = PyNumber_AsSsize_t(key, PyExc_IndexError); + if (i == -1 && PyErr_Occurred()) + return NULL; + + return prop_subscript_collection_int(self, i); } #if PY_VERSION_HEX >= 0x03000000 else if (PySlice_Check(key)) { @@ -947,7 +962,10 @@ static PyObject *prop_subscript_array(BPy_PropertyRNA * self, PyObject *key) /*if (PyUnicode_Check(key)) { return prop_subscript_array_str(self, _PyUnicode_AsString(key)); } else*/ - if (PyLong_Check(key)) { + if (PyIndex_Check(key)) { + Py_ssize_t i = PyNumber_AsSsize_t(key, PyExc_IndexError); + if (i == -1 && PyErr_Occurred()) + return NULL; return prop_subscript_array_int(self, PyLong_AsSsize_t(key)); } #if PY_VERSION_HEX >= 0x03000000 @@ -1037,8 +1055,12 @@ static int pyrna_prop_ass_subscript( BPy_PropertyRNA * self, PyObject *key, PyOb return -1; } - if (PyLong_Check(key)) { - return prop_subscript_ass_array_int(self, PyLong_AsSsize_t(key), value); + if (PyIndex_Check(key)) { + Py_ssize_t i = PyNumber_AsSsize_t(key, PyExc_IndexError); + if (i == -1 && PyErr_Occurred()) + return NULL; + + return prop_subscript_ass_array_int(self, i, value); } #if PY_VERSION_HEX >= 0x03000000 else if (PySlice_Check(key)) { @@ -1106,6 +1128,25 @@ static PySequenceMethods pyrna_prop_as_sequence = { (objobjproc)pyrna_prop_contains, /* sq_contains */ }; + +static PyObject *pyrna_struct_keyframe_insert(BPy_StructRNA * self, PyObject *args) +{ + char *path; + int index= 0; + float cfra = CTX_data_scene(BPy_GetContext())->r.cfra; + + if(!RNA_struct_is_ID(self->ptr.type)) { + PyErr_SetString( PyExc_TypeError, "StructRNA - keyframe_insert only for ID type"); + return NULL; + } + + if (!PyArg_ParseTuple(args, "s|if:keyframe_insert", &path, &index, &cfra)) + return NULL; + + return PyBool_FromLong( insert_keyframe((ID *)self->ptr.data, NULL, NULL, path, index, cfra, 0)); +} + + static PyObject *pyrna_struct_dir(BPy_StructRNA * self) { PyObject *ret, *dict; @@ -1645,6 +1686,10 @@ PyObject *pyrna_prop_iter(BPy_PropertyRNA *self) } static struct PyMethodDef pyrna_struct_methods[] = { + + /* maybe this become and ID function */ + {"keyframe_insert", (PyCFunction)pyrna_struct_keyframe_insert, METH_VARARGS, NULL}, + {"__dir__", (PyCFunction)pyrna_struct_dir, METH_NOARGS, NULL}, {NULL, NULL, 0, NULL} }; diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index eead7a51885..ac49b49c130 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -1622,10 +1622,20 @@ PyObject* initGamePlayerPythonScripting(const STR_String& progname, TPythonSecur Py_FrozenFlag=1; Py_Initialize(); + if(argv && first_time) { /* browser plugins dont currently set this */ #if (PY_VERSION_HEX < 0x03000000) - if(argv && first_time) /* browser plugins dont currently set this */ PySys_SetArgv(argc, argv); +#else + int i; + PyObject *py_argv= PyList_New(argc); + + for (i=0; i<argc; i++) + PyList_SET_ITEM(py_argv, i, PyUnicode_FromString(argv[i])); + + PySys_SetObject("argv", py_argv); + Py_DECREF(py_argv); #endif + } //importBlenderModules() setSandbox(level); |