From bf8bb77abc3f48ab808d76863c653856a9a08507 Mon Sep 17 00:00:00 2001 From: Ken Hughes Date: Sat, 31 Mar 2007 15:31:37 +0000 Subject: [PATCH] Python API ---------- Change deprecation printfs to print warning once instead of everytime the deprecated method is called. Also commented out deprecation warnings for code which will eventually be replaced by experimental Blender.Main/bpy module. --- source/blender/python/api2_2x/Image.c | 8 ++- source/blender/python/api2_2x/Mathutils.c | 49 ++++++++++++++--- source/blender/python/api2_2x/Scene.c | 67 ++++++++++++++++++----- source/blender/python/api2_2x/World.c | 20 +++++-- 4 files changed, 117 insertions(+), 27 deletions(-) diff --git a/source/blender/python/api2_2x/Image.c b/source/blender/python/api2_2x/Image.c index fed54aaed5b..06a9c8db1de 100644 --- a/source/blender/python/api2_2x/Image.c +++ b/source/blender/python/api2_2x/Image.c @@ -689,7 +689,13 @@ static PyObject *Image_pack( BPy_Image * self ) static PyObject *Image_makeCurrent( BPy_Image * self ) { - printf("deprecated! use Blender.Main.images.active = image instead\n"); +#if 0 /* add back in when bpy becomes "official" */ + static char warning = 1; + if( warning ) { + printf("image.makeCurrent() deprecated!\n\t use 'bpy.images.active = image instead'\n"); + --warning; + } +#endif if (!G.sima) Py_RETURN_FALSE; diff --git a/source/blender/python/api2_2x/Mathutils.c b/source/blender/python/api2_2x/Mathutils.c index 3aac1d3ddde..4b42ec94ae1 100644 --- a/source/blender/python/api2_2x/Mathutils.c +++ b/source/blender/python/api2_2x/Mathutils.c @@ -1672,8 +1672,13 @@ PyObject *M_Mathutils_TriangleArea( PyObject * self, PyObject * args ) PyObject *M_Mathutils_CopyMat(PyObject * self, PyObject * args) { PyObject *matrix = NULL; + static char warning = 1; + + if( warning ) { + printf("Mathutils.CopyMat(): deprecated :use Mathutils.Matrix() to copy matrices\n"); + --warning; + } - printf("Mathutils.CopyMat(): Deprecated :use Mathutils.Matrix() to copy matrices\n"); matrix = M_Mathutils_Matrix(self, args); if(matrix == NULL) return NULL; //error string already set if we get here @@ -1685,8 +1690,13 @@ PyObject *M_Mathutils_CopyMat(PyObject * self, PyObject * args) PyObject *M_Mathutils_CopyVec(PyObject * self, PyObject * args) { PyObject *vec = NULL; + static char warning = 1; + + if( warning ) { + printf("Mathutils.CopyVec(): Deprecated: use Mathutils.Vector() to copy vectors\n"); + --warning; + } - printf("Mathutils.CopyVec(): Deprecated: use Mathutils.Vector() to copy vectors\n"); vec = M_Mathutils_Vector(self, args); if(vec == NULL) return NULL; //error string already set if we get here @@ -1698,8 +1708,13 @@ PyObject *M_Mathutils_CopyVec(PyObject * self, PyObject * args) PyObject *M_Mathutils_CopyQuat(PyObject * self, PyObject * args) { PyObject *quat = NULL; + static char warning = 1; + + if( warning ) { + printf("Mathutils.CopyQuat(): Deprecated: use Mathutils.Quaternion() to copy vectors\n"); + --warning; + } - printf("Mathutils.CopyQuat(): Deprecated:use Mathutils.Quaternion() to copy vectors\n"); quat = M_Mathutils_Quaternion(self, args); if(quat == NULL) return NULL; //error string already set if we get here @@ -1711,8 +1726,13 @@ PyObject *M_Mathutils_CopyQuat(PyObject * self, PyObject * args) PyObject *M_Mathutils_CopyEuler(PyObject * self, PyObject * args) { PyObject *eul = NULL; + static char warning = 1; + + if( warning ) { + printf("Mathutils.CopyEuler(): deprecated:use Mathutils.Euler() to copy vectors\n"); + --warning; + } - printf("Mathutils.CopyEuler(): Deprecated:use Mathutils.Euler() to copy vectors\n"); eul = M_Mathutils_Euler(self, args); if(eul == NULL) return NULL; //error string already set if we get here @@ -1727,12 +1747,17 @@ PyObject *M_Mathutils_RotateEuler(PyObject * self, PyObject * args) EulerObject *Eul = NULL; float angle; char *axis; + static char warning = 1; + + if( warning ) { + printf("Mathutils.RotateEuler(): Deprecated:use Euler.rotate() to rotate a euler\n"); + --warning; + } if(!PyArg_ParseTuple(args, "O!fs", &euler_Type, &Eul, &angle, &axis)) return EXPP_ReturnPyObjError(PyExc_TypeError, "Mathutils.RotateEuler(): expected euler type & float & string"); - printf("Mathutils.RotateEuler(): Deprecated:use Euler.rotate() to rotate a euler\n"); Euler_Rotate(Eul, Py_BuildValue("fs", angle, axis)); return EXPP_incr_ret(Py_None); } @@ -1742,13 +1767,18 @@ PyObject *M_Mathutils_MatMultVec(PyObject * self, PyObject * args) { MatrixObject *mat = NULL; VectorObject *vec = NULL; + static char warning = 1; + + if( warning ) { + printf("Mathutils.MatMultVec(): Deprecated: use matrix * vec to perform column vector multiplication\n"); + --warning; + } //get pyObjects if(!PyArg_ParseTuple(args, "O!O!", &matrix_Type, &mat, &vector_Type, &vec)) return EXPP_ReturnPyObjError(PyExc_TypeError, "Mathutils.MatMultVec(): MatMultVec() expects a matrix and a vector object - in that order\n"); - printf("Mathutils.MatMultVec(): Deprecated: use matrix * vec to perform column vector multiplication\n"); return column_vector_multiplication(mat, vec); } //----------------------------------Mathutils.VecMultMat() --------------- @@ -1757,13 +1787,18 @@ PyObject *M_Mathutils_VecMultMat(PyObject * self, PyObject * args) { MatrixObject *mat = NULL; VectorObject *vec = NULL; + static char warning = 1; + + if( warning ) { + printf("Mathutils.VecMultMat(): Deprecated: use vec * matrix to perform row vector multiplication\n"); + --warning; + } //get pyObjects if(!PyArg_ParseTuple(args, "O!O!", &vector_Type, &vec, &matrix_Type, &mat)) return EXPP_ReturnPyObjError(PyExc_TypeError, "Mathutils.VecMultMat(): VecMultMat() expects a vector and matrix object - in that order\n"); - printf("Mathutils.VecMultMat(): Deprecated: use vec * matrix to perform row vector multiplication\n"); return row_vector_multiplication(vec, mat); } //####################################################################### diff --git a/source/blender/python/api2_2x/Scene.c b/source/blender/python/api2_2x/Scene.c index bacc747ecf8..883133d33a9 100644 --- a/source/blender/python/api2_2x/Scene.c +++ b/source/blender/python/api2_2x/Scene.c @@ -1,4 +1,5 @@ /* + * * $Id$ * * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** @@ -696,9 +697,15 @@ static PyObject *M_Scene_GetCurrent( PyObject * self ) { return Scene_CreatePyObject( ( Scene * ) G.scene ); } + static PyObject *M_Scene_getCurrent_deprecated( PyObject * self ) { - printf("Blender.Scene.getCurrent() is deprecated,\n\tuse Blender.Scene.GetCurrent() instead.\n"); + static char warning = 1; + if( warning ) { + printf("Blender.Scene.getCurrent() is deprecated,\n\tuse Blender.Scene.GetCurrent() instead.\n"); + --warning; + } + return Scene_CreatePyObject( ( Scene * ) G.scene ); } @@ -759,11 +766,16 @@ static PyObject *Scene_copy( BPy_Scene * self, PyObject * args ) static PyObject *Scene_makeCurrent( BPy_Scene * self ) { Scene *scene = self->scene; - +#if 0 /* add back in when bpy becomes "official" */ + static char warning = 1; + if( warning ) { + printf("scene.makeCurrent() deprecated!\n\tuse bpy.scenes.active = scene instead\n"); + --warning; + } +#endif + SCENE_DEL_CHECK_PY(self); - printf("scene.makeCurrent() deprecated!\n\tuse Blender.Main.scenes.active = scene instead\n"); - if( scene && scene != G.scene) { set_scene( scene ); scene_update_for_newframe(scene, scene->lay); @@ -808,10 +820,14 @@ static PyObject *Scene_link( BPy_Scene * self, PyObject * args ) Scene *scene = self->scene; BPy_Object *bpy_obj; Object *object = NULL; + static char warning = 1; + + if( warning ) { + printf("scene.link(ob) deprecated!\n\tuse scene.objects.link(ob) instead\n"); + --warning; + } SCENE_DEL_CHECK_PY(self); - - printf("scene.link(ob) deprecated!\n\tuse scene.objects.link(ob) instead\n"); if( !PyArg_ParseTuple( args, "O!", &Object_Type, &bpy_obj ) ) return EXPP_ReturnPyObjError( PyExc_TypeError, @@ -880,10 +896,14 @@ static PyObject *Scene_unlink( BPy_Scene * self, PyObject * args ) BPy_Object *bpy_obj = NULL; Scene *scene = self->scene; Base *base; + static char warning = 1; + + if( warning ) { + printf("scene.unlink(ob) deprecated!\n\tuse scene.objects.unlink(ob) instead\n"); + --warning; + } SCENE_DEL_CHECK_PY(self); - - printf("scene.unlink(ob) deprecated!\n\tuse scene.objects.unlink(ob) instead\n"); if( !PyArg_ParseTuple( args, "O!", &Object_Type, &bpy_obj ) ) return EXPP_ReturnPyObjError( PyExc_TypeError, @@ -911,10 +931,15 @@ static PyObject *Scene_getChildren( BPy_Scene * self ) PyObject *bpy_obj; Object *object; Base *base; + static char warning = 1; + + if( warning ) { + printf("scene.getChildren() deprecated!\n\tuse scene.objects instead\n"); + --warning; + } SCENE_DEL_CHECK_PY(self); - printf("scene.getChildren() deprecated!\n\tuse scene.objects instead\n"); base = scene->base.first; @@ -942,10 +967,14 @@ static PyObject *Scene_getActiveObject(BPy_Scene *self) Scene *scene = self->scene; PyObject *pyob; Object *ob; + static char warning = 1; + + if( warning ) { + printf("scene.getActiveObject() deprecated!\n\tuse scene.objects.active instead\n"); + --warning; + } SCENE_DEL_CHECK_PY(self); - - printf("scene.getActiveObject() deprecated!\n\tuse scene.objects.active instead\n"); ob = ((scene->basact) ? (scene->basact->object) : 0); @@ -968,10 +997,14 @@ static PyObject *Scene_getCurrentCamera( BPy_Scene * self ) Object *cam_obj; PyObject *pyob; Scene *scene = self->scene; + static char warning = 1; + if( warning ) { + printf("scene.getCurrentCamera() deprecated!\n\tuse scene.objects.camera instead\n"); + --warning; + } + SCENE_DEL_CHECK_PY(self); - - printf("scene.getCurrentCamera() deprecated!\n\tGet scene.objects.camera instead\n"); cam_obj = scene->camera; @@ -992,10 +1025,14 @@ static PyObject *Scene_setCurrentCamera( BPy_Scene * self, PyObject * args ) Object *object; BPy_Object *cam_obj; Scene *scene = self->scene; + static char warning = 1; + + if( warning ) { + printf("scene.setCurrentCamera(ob) deprecated!\n\tSet scene.objects.camera = ob instead\n"); + --warning; + } SCENE_DEL_CHECK_PY(self); - - printf("scene.setCurrentCamera(ob) deprecated!\n\tSet scene.objects.camera = ob instead\n"); if( !PyArg_ParseTuple( args, "O!", &Object_Type, &cam_obj ) ) return EXPP_ReturnPyObjError( PyExc_TypeError, diff --git a/source/blender/python/api2_2x/World.c b/source/blender/python/api2_2x/World.c index 580bb3efcc3..c321fccb044 100644 --- a/source/blender/python/api2_2x/World.c +++ b/source/blender/python/api2_2x/World.c @@ -450,9 +450,14 @@ static PyObject *M_World_Get( PyObject * self, PyObject * args ) static PyObject *M_World_GetCurrent( PyObject * self ) { BPy_World *w = NULL; - - printf("Blender.World.GetCurrent() deprecated!\n\tuse Blender.Main.scenes.world instead\n"); - +#if 0 /* add back in when bpy becomes "official" */ + static char warning = 1; + if( warning ) { + printf("Blender.World.GetCurrent() deprecated!\n\tuse bpy.scenes.world instead\n"); + --warning; + } +#endif + if( !G.scene->world ) Py_RETURN_NONE; @@ -890,8 +895,15 @@ static PyObject *World_getScriptLinks( BPy_World * self, PyObject * args ) static PyObject *World_setCurrent( BPy_World * self ) { World *world = self->world; +#if 0 /* add back in when bpy becomes "official" */ + static char warning = 1; + if( warning ) { + printf("world.setCurrent() deprecated!\n\tuse bpy.scenes.world=world instead\n"); + --warning; + } +#endif + /* If there is a world then it now has one less user */ - printf("world.setCurrent() deprecated!\n\tuse Blender.Main.scenes.world=world instead\n"); if( G.scene->world ) G.scene->world->id.us--; world->id.us++;