static int pyLeafController_setKeys(pyLeafController* self, PyObject* value, void*) { if (value == NULL || !PySequence_Check(value) || PySequence_Size(value) != 2) { PyErr_SetString(PyExc_TypeError, "keys should be a sequence of: sequence (keyframes), int"); return -1; } PyObject* keySeq = PySequence_GetItem(value, 0); PyObject* keyTypeObj = PySequence_GetItem(value, 1); if (!PySequence_Check(keySeq) || !PyInt_Check(keyTypeObj)) { PyErr_SetString(PyExc_TypeError, "keys should be a sequence of: sequence (keyframes), int"); return -1; } std::vector<hsKeyFrame*> keyframes; keyframes.reserve(PySequence_Size(keySeq)); unsigned int keyType = PyInt_AsLong(keyTypeObj); for (Py_ssize_t i = 0; i < PySequence_Size(keySeq); ++i) { PyObject* key = PySequence_GetItem(keySeq, i); if (!pyKeyFrame_Check(key)) { PyErr_SetString(PyExc_TypeError, "keys should be a sequence of: sequence (keyframes), int"); return -1; } hsKeyFrame* keyframe = ((pyKeyFrame*)key)->fThis; if (keyframe->getType() != keyType) { PyErr_SetString(PyExc_TypeError, plString::Format("keys should be of type %s, not %s", hsKeyFrame::TypeNames[keyType], hsKeyFrame::TypeNames[keyframe->getType()] ).cstr()); return -1; } keyframes.push_back(keyframe); } IConvertController(self)->setKeys(keyframes, keyType); return 0; }
static PyObject* pyLeafController_setKeys(pyLeafController* self, PyObject* args) { PyObject* list; int type; if (!PyArg_ParseTuple(args, "Oi", &list, &type)) { PyErr_SetString(PyExc_TypeError, "setKeys expects a list of hsKeyFrames and an int"); return NULL; } if (!PyList_Check(list)) { PyErr_SetString(PyExc_TypeError, "setKeys expects a list of hsKeyFrames and an int"); return NULL; } std::vector<hsKeyFrame*> keys(PyList_Size(list)); for (size_t i=0; i<keys.size(); i++) { PyObject* itm = PyList_GetItem(list, i); if (!pyKeyFrame_Check(itm)) { PyErr_SetString(PyExc_TypeError, "setKeys expects a list of hsKeyFrames and an int"); return NULL; } ((pyKeyFrame*)itm)->fPyOwned = false; keys[i] = ((pyKeyFrame*)itm)->fThis; } self->fThis->setKeys(keys, type); Py_INCREF(Py_None); return Py_None; }