* Small changes in many files:

-  Trying to fix linking problems in OSX;
-  Making module .Get functions behave like the ones in Blender 2.25 - 2.27
   (Guignot pointed the incompatibility);
-  Included more types to Blender.Types;
-  Found by luck and corrected two bugs that were making Blender crash;
-  Added/updated some simple functions.
This commit is contained in:
2003-06-12 04:51:50 +00:00
parent ed6885d728
commit 6cc45538ef
24 changed files with 579 additions and 479 deletions

View File

@@ -451,7 +451,7 @@ PyObject * RunPython(Text *text, PyObject *globaldict)
/*#ifdef BLENDER_SANDBOX_MODE
// IGNORE THIS ALL FOR A WHILE, IT'S VERY INCOMPLETE AND WILL CHANGE
// CONSIDERABLY IN THE NEXT COMMIT. THE ifdef won't stay, either.
// CONSIDERABLY, SOON. The #ifdef won't stay, either.
// The import statement is a security risk, so we don't allow it in
// SANDBOX MODE. Instead, we import all needed modules ourselves and

View File

@@ -121,9 +121,9 @@ static PyObject *M_Armature_Get(PyObject *self, PyObject *args)
else
{
/* Return a list of all armatures in the scene */
/* Return a list of with armatures in the scene */
int index = 0;
PyObject *armlist, *pystr;
PyObject *armlist, *pyobj;
armlist = PyList_New (BLI_countlist (&(G.main->armature)));
@@ -132,13 +132,13 @@ static PyObject *M_Armature_Get(PyObject *self, PyObject *args)
"couldn't create PyList"));
while (armature_iter) {
pystr = PyString_FromString (armature_iter->id.name+2);
pyobj = M_ArmatureCreatePyObject (armature_iter);
if (!pystr)
if (!pyobj)
return (PythonReturnErrorObject (PyExc_MemoryError,
"couldn't create PyString"));
PyList_SET_ITEM (armlist, index, pystr);
PyList_SET_ITEM (armlist, index, pyobj);
armature_iter = armature_iter->id.next;
index++;
@@ -345,12 +345,10 @@ static PyObject *ArmatureRepr (C_Armature *self)
/*****************************************************************************/
static int ArmatureCmp (C_Armature *a, C_Armature *b)
{
if (a<b) return -1;
else if (a==b) return 0;
else return 1;
bArmature *pa = a->armature, *pb = b->armature;
return (pa == pb) ? 0:-1;
}
/*****************************************************************************/
/* Function: M_ArmatureCreatePyObject */
/* Description: This function will create a new BlenArmature from an */

View File

@@ -137,7 +137,7 @@ static int ArmaturePrint (C_Armature *armature, FILE *fp, int flags);
/*****************************************************************************/
/* Python TypeArmature structure definition: */
/*****************************************************************************/
static PyTypeObject Armature_Type =
PyTypeObject Armature_Type =
{
PyObject_HEAD_INIT(NULL)
0, /* ob_size */

View File

@@ -283,14 +283,14 @@ static int Buffer_ass_slice(PyObject *self, int begin, int end, PyObject *seq)
static void Buffer_dealloc(PyObject *self)
{
Buffer *buf= (Buffer *) self;
Buffer *buf = (Buffer *)self;
if (buf->parent) Py_DECREF(buf->parent);
else MEM_freeN(buf->buf.asvoid);
if (buf->parent) Py_DECREF (buf->parent);
else MEM_freeN (buf->buf.asvoid);
MEM_freeN(buf->dimensions);
MEM_freeN (buf->dimensions);
PyMem_DEL(self);
PyObject_DEL (self);
}
static PyObject *Buffer_tolist(PyObject *self)

View File

@@ -138,7 +138,7 @@ static PyObject *Buffer_repr(PyObject *self);
PyTypeObject buffer_Type = {
PyObject_HEAD_INIT(NULL)
0, /*ob_size*/
"Buffer", /*tp_name*/
"buffer", /*tp_name*/
sizeof(Buffer), /*tp_basicsize*/
0, /*tp_itemsize*/
(destructor) Buffer_dealloc, /*tp_dealloc*/

View File

@@ -146,7 +146,7 @@ static int BonePrint (C_Bone *bone, FILE *fp, int flags);
/*****************************************************************************/
/* Python TypeBone structure definition: */
/*****************************************************************************/
static PyTypeObject Bone_Type =
PyTypeObject Bone_Type =
{
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
@@ -680,9 +680,8 @@ static PyObject *BoneRepr (C_Bone *self)
/**************************************************************************/
static int BoneCmp (C_Bone *a, C_Bone *b)
{
if (a<b) return -1;
else if (a==b) return 0;
else return 1;
Bone *pa = a->bone, *pb = b->bone;
return (pa == pb) ? 0:-1;
}

View File

@@ -34,12 +34,6 @@
* \ingroup scripts
* \brief Blender.Camera Module and Camera Data PyObject implementation.
*
* Note: Parameters between "<" and ">" are optional. But if one of them is
* given, all preceding ones must be given, too. Of course, this only relates
* to the Python functions and methods described here and only inside Python
* code. [ This will go to another file later, probably the main exppython
* doc file]. XXX Better: put optional args with their default value:
* (self, name = "MyName")
*/
#include <BKE_main.h>
@@ -88,9 +82,12 @@ static PyObject *M_Camera_Get (PyObject *self, PyObject *args);
/* Blender.Camera.__doc__ */
/*****************************************************************************/
static char M_Camera_doc[] =
"The Blender Camera module\n\n\
This module provides access to **Camera Data** objects in Blender\n\n\
Example::\n\n\
"The Blender Camera module\n\
\n\
This module provides access to **Camera Data** objects in Blender\n\
\n\
Example::\n\
\n\
from Blender import Camera, Object, Scene\n\
c = Camera.New('ortho') # create new ortho camera data\n\
c.lens = 35.0 # set lens value\n\
@@ -101,14 +98,18 @@ Example::\n\n\
cur.setCurrentCamera(ob) # make this camera the active\n";
static char M_Camera_New_doc[] =
"(type) - return a new Camera object of type \"type\", \
which can be 'persp' or 'ortho'.\n\
() - return a new Camera object of type 'persp'.";
"Blender.Camera.New (type = 'persp', name = 'CamData'):\n\
\n\
(type) - Return a new Camera Data object of type \"type\",\n\
which can be 'persp' or 'ortho';\n\
() - Return a new Camera Data object of type 'persp'.";
static char M_Camera_Get_doc[] =
"(name) - return the camera with the name 'name', \
returns None if not found.\n If 'name' is not specified, \
it returns a list of all cameras in the\ncurrent scene.";
"Blender.Camera.Get (name = None):\n\
\n\
(name) - Return the Camera Data object with the given 'name',\n\
None if not found;\n\
() - Return a list with all Camera Data objects in the current scene.";
/*****************************************************************************/
/* Python method structure definition for Blender.Camera module: */
@@ -120,6 +121,7 @@ struct PyMethodDef M_Camera_methods[] = {
{"get", M_Camera_Get, METH_VARARGS, M_Camera_Get_doc},
{NULL, NULL, 0, NULL}
};
/*****************************************************************************/
/* Python BPy_Camera methods declarations: */
/*****************************************************************************/
@@ -150,8 +152,8 @@ static PyMethodDef BPy_Camera_methods[] = {
{"getType", (PyCFunction)Camera_getType, METH_NOARGS,
"() - Return Camera type - 'persp':0, 'ortho':1"},
{"getMode", (PyCFunction)Camera_getMode, METH_NOARGS,
"() - Return Camera mode flags (or'ed value) -\n\t"
"'showLimits':1, 'showMist':2"},
"() - Return Camera mode flags (or'ed value) -\n"
" 'showLimits':1, 'showMist':2"},
{"getLens", (PyCFunction)Camera_getLens, METH_NOARGS,
"() - Return Camera lens value"},
{"getClipStart", (PyCFunction)Camera_getClipStart, METH_NOARGS,
@@ -161,19 +163,19 @@ static PyMethodDef BPy_Camera_methods[] = {
{"getDrawSize", (PyCFunction)Camera_getDrawSize, METH_NOARGS,
"() - Return Camera draw size value"},
{"setName", (PyCFunction)Camera_setName, METH_VARARGS,
"(str) - Change Camera Data name"},
"(s) - Set Camera Data name"},
{"setType", (PyCFunction)Camera_setType, METH_VARARGS,
"(str) - Change Camera type, which can be 'persp' or 'ortho'"},
"(s) - Set Camera type, which can be 'persp' or 'ortho'"},
{"setMode", (PyCFunction)Camera_setMode, METH_VARARGS,
"([str[,str]]) - Set Camera mode flag(s): 'showLimits' and 'showMist'"},
"(<s<,s>>) - Set Camera mode flag(s): 'showLimits' and 'showMist'"},
{"setLens", (PyCFunction)Camera_setLens, METH_VARARGS,
"(float) - Change Camera lens value"},
"(f) - Set Camera lens value"},
{"setClipStart", (PyCFunction)Camera_setClipStart, METH_VARARGS,
"(float) - Change Camera clip start value"},
"(f) - Set Camera clip start value"},
{"setClipEnd", (PyCFunction)Camera_setClipEnd, METH_VARARGS,
"(float) - Change Camera clip end value"},
"(f) - Set Camera clip end value"},
{"setDrawSize", (PyCFunction)Camera_setDrawSize, METH_VARARGS,
"(float) - Change Camera draw size value"},
"(f) - Set Camera draw size value"},
{0}
};
@@ -238,52 +240,50 @@ static PyObject *M_Camera_New(PyObject *self, PyObject *args, PyObject *kwords)
char *type_str = "persp"; /* "persp" is type 0, "ortho" is type 1 */
char *name_str = "CamData";
static char *kwlist[] = {"type_str", "name_str", NULL};
BPy_Camera *pycam; /* for Camera Data object wrapper in Python */
PyObject *pycam; /* for Camera Data object wrapper in Python */
Camera *blcam; /* for actual Camera Data we create in Blender */
char buf[21];
printf ("In Camera_New()\n");
/* Parse the arguments passed in by the Python interpreter */
if (!PyArg_ParseTupleAndKeywords(args, kwords, "|ss", kwlist,
&type_str, &name_str))
/* We expected string(s) (or nothing) as argument, but we didn't get that. */
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
"expected zero, one or two strings as arguments"));
return EXPP_ReturnPyObjError (PyExc_AttributeError,
"expected zero, one or two strings as arguments");
blcam = add_camera(); /* first create the Camera Data in Blender */
if (blcam) /* now create the wrapper obj in Python */
pycam = (BPy_Camera *)PyObject_NEW(BPy_Camera, &Camera_Type);
pycam = Camera_CreatePyObject (blcam);
else
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't create Camera Data in Blender"));
return EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't create Camera Data in Blender");
/* let's return user count to zero, because ... */
blcam->id.us = 0; /* ... add_camera() right above incref'ed it */
blcam->id.us = 0; /* ... add_camera() incref'ed it */
/* XXX XXX Do this in other modules, too */
if (pycam == NULL)
return (EXPP_ReturnPyObjError (PyExc_MemoryError,
"couldn't create Camera Data object"));
pycam->camera = blcam; /* link Python camera wrapper to Blender Camera */
return EXPP_ReturnPyObjError (PyExc_MemoryError,
"couldn't create Camera PyObject");
if (strcmp (type_str, "persp") == 0) /* default, no need to set, so */
/*blcam->type = (short)EXPP_CAM_TYPE_PERSP*/; /* we comment this line */
else if (strcmp (type_str, "ortho") == 0)
blcam->type = (short)EXPP_CAM_TYPE_ORTHO;
else
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
"unknown camera type"));
return EXPP_ReturnPyObjError (PyExc_AttributeError,
"unknown camera type");
if (strcmp(name_str, "CamData") == 0)
return (PyObject *)pycam;
if (strcmp (name_str, "CamData") == 0)
return pycam;
else { /* user gave us a name for the camera, use it */
PyOS_snprintf(buf, sizeof(buf), "%s", name_str);
rename_id(&blcam->id, buf); /* proper way in Blender */
PyOS_snprintf (buf, sizeof(buf), "%s", name_str);
rename_id (&blcam->id, buf); /* proper way in Blender */
}
return (PyObject *)pycam;
return pycam;
}
/**
@@ -292,11 +292,11 @@ static PyObject *M_Camera_New(PyObject *self, PyObject *args, PyObject *kwords)
* This is the .Get() function of the Blender.Camera submodule. It searches
* the list of current Camera Data objects and returns a Python wrapper for
* the one with the name provided by the user. If called with no arguments,
* it returns a list of all current Camera Data object names in Blender.
* \param <name> - string: The name of an existing Blender Camera Data object.
* \return () - A list with the names of all current Camera Data objects;\n
* \return (name) - A Python wrapper for the Camera Data called 'name'
* it returns a list with Python wrappers for all current Camera Data objects
* in Blender.
* \param <name> - string: The name of an existing Blender Camera Data object.
* \return () - A list with wrappers for all current Camera Data objects;\n
* \return (name) - A wrapper for the Camera Data called 'name' in Blender.
*/
static PyObject *M_Camera_Get(PyObject *self, PyObject *args)
@@ -305,59 +305,62 @@ static PyObject *M_Camera_Get(PyObject *self, PyObject *args)
Camera *cam_iter;
if (!PyArg_ParseTuple(args, "|s", &name))
return (EXPP_ReturnPyObjError (PyExc_TypeError,
"expected string argument (or nothing)"));
return EXPP_ReturnPyObjError (PyExc_TypeError,
"expected string argument (or nothing)");
cam_iter = G.main->camera.first;
if (name) { /* (name) - Search camera by name */
BPy_Camera *wanted_cam = NULL;
PyObject *wanted_cam = NULL;
while (cam_iter && !wanted_cam) {
while ((cam_iter) && (wanted_cam == NULL)) {
if (strcmp (name, cam_iter->id.name+2) == 0) {
wanted_cam = (BPy_Camera *)PyObject_NEW(BPy_Camera, &Camera_Type);
if (wanted_cam) wanted_cam->camera = cam_iter;
wanted_cam = Camera_CreatePyObject (cam_iter);
break;
}
cam_iter = cam_iter->id.next;
}
if (wanted_cam == NULL) { /* Requested camera doesn't exist */
if (!wanted_cam) { /* Requested camera doesn't exist */
char error_msg[64];
PyOS_snprintf(error_msg, sizeof(error_msg),
"Camera \"%s\" not found", name);
return (EXPP_ReturnPyObjError (PyExc_NameError, error_msg));
return EXPP_ReturnPyObjError (PyExc_NameError, error_msg);
}
return (PyObject *)wanted_cam;
return wanted_cam;
}
else { /* () - return a list of all cameras in the scene */
else { /* () - return a list of wrappers for all cameras in the scene */
int index = 0;
PyObject *camlist, *pystr;
PyObject *cam_pylist, *pyobj;
camlist = PyList_New (BLI_countlist (&(G.main->camera)));
cam_pylist = PyList_New (BLI_countlist (&(G.main->camera)));
if (camlist == NULL)
return (PythonReturnErrorObject (PyExc_MemoryError,
"couldn't create PyList"));
if (!cam_pylist)
return PythonReturnErrorObject (PyExc_MemoryError,
"couldn't create PyList");
while (cam_iter) {
pystr = PyString_FromString (cam_iter->id.name+2);
pyobj = Camera_CreatePyObject (cam_iter);
if (!pystr)
return (PythonReturnErrorObject (PyExc_MemoryError,
"couldn't create PyString"));
if (!pyobj)
return PythonReturnErrorObject (PyExc_MemoryError,
"couldn't create Camera PyObject");
PyList_SET_ITEM (camlist, index, pystr);
PyList_SET_ITEM (cam_pylist, index, pyobj);
cam_iter = cam_iter->id.next;
index++;
}
return (camlist);
return cam_pylist;
}
}
/*@}*/
/**
@@ -365,7 +368,7 @@ static PyObject *M_Camera_Get(PyObject *self, PyObject *args)
*
* This function is used by Blender_Init() in Blender.c to register the
* Blender.Camera submodule in the main Blender module.
* \return PyObject*: The initialized submodule.
* \return The initialized submodule.
*/
PyObject *M_Camera_Init (void)
@@ -379,7 +382,7 @@ PyObject *M_Camera_Init (void)
submodule = Py_InitModule3("Blender.Camera",
M_Camera_methods, M_Camera_doc);
return (submodule);
return submodule;
}
/* Three Python Camera_Type helper functions needed by the Object module: */
@@ -389,8 +392,8 @@ PyObject *M_Camera_Init (void)
*
* This is also used in Object.c when defining the object.data member variable
* for an Object of type 'Camera'.
* \param cam - Camera*: A pointer to an existing Blender Camera Data object.
* \return PyObject*: The Camera Data wrapper created.
* \param cam - A pointer to an existing Blender Camera Data object.
* \return The Camera Data wrapper created.
*/
PyObject *Camera_CreatePyObject (Camera *cam)
@@ -401,7 +404,7 @@ PyObject *Camera_CreatePyObject (Camera *cam)
if (!pycam)
return EXPP_ReturnPyObjError (PyExc_MemoryError,
"couldn't create BPy_Camera object");
"couldn't create BPy_Camera PyObject");
pycam->camera = cam;
@@ -413,8 +416,8 @@ PyObject *Camera_CreatePyObject (Camera *cam)
*
* This is also used in Object.c when handling the object.data member variable
* for an object of type 'Camera'.
* \param pyobj - PyObject*: A pointer to a Camera PyObject.
* \return int: True or false.
* \param pyobj - A pointer to a Camera PyObject.
* \return True or false.
*/
int Camera_CheckPyObject (PyObject *pyobj)
@@ -427,8 +430,8 @@ int Camera_CheckPyObject (PyObject *pyobj)
*
* This is also used in Object.c when handling the object.data member variable
* for an object of type 'Camera'.
* \param pyobj - PyObject*: A pointer to a Camera PyObject.
* \return Camera*: A pointer to the wrapped Blender Camera Data object.
* \param pyobj - A pointer to a Camera PyObject.
* \return A pointer to the wrapped Blender Camera Data object.
*/
Camera *Camera_FromPyObject (PyObject *pyobj)
@@ -461,8 +464,8 @@ static PyObject *Camera_getName(BPy_Camera *self)
if (attr) return attr;
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't get Camera.name attribute"));
return EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't get Camera.name attribute");
}
/**
@@ -477,8 +480,8 @@ static PyObject *Camera_getType(BPy_Camera *self)
if (attr) return attr;
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't get Camera.type attribute"));
return EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't get Camera.type attribute");
}
/**
@@ -493,8 +496,8 @@ static PyObject *Camera_getMode(BPy_Camera *self)
if (attr) return attr;
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't get Camera.Mode attribute"));
return EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't get Camera.Mode attribute");
}
/**
@@ -509,8 +512,8 @@ static PyObject *Camera_getLens(BPy_Camera *self)
if (attr) return attr;
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't get Camera.lens attribute"));
return EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't get Camera.lens attribute");
}
/**
@@ -525,8 +528,8 @@ static PyObject *Camera_getClipStart(BPy_Camera *self)
if (attr) return attr;
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't get Camera.clipStart attribute"));
return EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't get Camera.clipStart attribute");
}
/**
@@ -540,8 +543,8 @@ static PyObject *Camera_getClipEnd(BPy_Camera *self)
if (attr) return attr;
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't get Camera.clipEnd attribute"));
return EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't get Camera.clipEnd attribute");
}
/**
@@ -555,8 +558,8 @@ static PyObject *Camera_getDrawSize(BPy_Camera *self)
if (attr) return attr;
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't get Camera.drawSize attribute"));
return EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't get Camera.drawSize attribute");
}
/**
@@ -570,8 +573,8 @@ static PyObject *Camera_setName(BPy_Camera *self, PyObject *args)
char buf[21];
if (!PyArg_ParseTuple(args, "s", &name))
return (EXPP_ReturnPyObjError (PyExc_TypeError,
"expected string argument"));
return EXPP_ReturnPyObjError (PyExc_TypeError,
"expected string argument");
PyOS_snprintf(buf, sizeof(buf), "%s", name);
@@ -591,16 +594,16 @@ static PyObject *Camera_setType(BPy_Camera *self, PyObject *args)
char *type;
if (!PyArg_ParseTuple(args, "s", &type))
return (EXPP_ReturnPyObjError (PyExc_TypeError,
"expected string argument"));
return EXPP_ReturnPyObjError (PyExc_TypeError,
"expected string argument");
if (strcmp (type, "persp") == 0)
self->camera->type = (short)EXPP_CAM_TYPE_PERSP;
else if (strcmp (type, "ortho") == 0)
self->camera->type = (short)EXPP_CAM_TYPE_ORTHO;
else
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
"unknown camera type"));
return EXPP_ReturnPyObjError (PyExc_AttributeError,
"unknown camera type");
Py_INCREF(Py_None);
return Py_None;
@@ -624,14 +627,14 @@ static PyObject *Camera_setIntType(BPy_Camera *self, PyObject *args)
short value;
if (!PyArg_ParseTuple(args, "h", &value))
return (EXPP_ReturnPyObjError (PyExc_TypeError,
"expected int argument: 0 or 1"));
return EXPP_ReturnPyObjError (PyExc_TypeError,
"expected int argument: 0 or 1");
if (value == 0 || value == 1)
self->camera->type = value;
else
return (EXPP_ReturnPyObjError (PyExc_ValueError,
"expected int argument: 0 or 1"));
return EXPP_ReturnPyObjError (PyExc_ValueError,
"expected int argument: 0 or 1");
Py_INCREF(Py_None);
return Py_None;
@@ -654,8 +657,8 @@ static PyObject *Camera_setMode(BPy_Camera *self, PyObject *args)
short flag = 0;
if (!PyArg_ParseTuple(args, "|ss", &mode_str1, &mode_str2))
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
"expected one or two strings as arguments"));
return EXPP_ReturnPyObjError (PyExc_AttributeError,
"expected one or two strings as arguments");
if (mode_str1 != NULL) {
if (strcmp(mode_str1, "showLimits") == 0)
@@ -663,8 +666,8 @@ static PyObject *Camera_setMode(BPy_Camera *self, PyObject *args)
else if (strcmp(mode_str1, "showMist") == 0)
flag |= (short)EXPP_CAM_MODE_SHOWMIST;
else
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
"first argument is an unknown camera flag"));
return EXPP_ReturnPyObjError (PyExc_AttributeError,
"first argument is an unknown camera flag");
if (mode_str2 != NULL) {
if (strcmp(mode_str2, "showLimits") == 0)
@@ -672,8 +675,8 @@ static PyObject *Camera_setMode(BPy_Camera *self, PyObject *args)
else if (strcmp(mode_str2, "showMist") == 0)
flag |= (short)EXPP_CAM_MODE_SHOWMIST;
else
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
"second argument is an unknown camera flag"));
return EXPP_ReturnPyObjError (PyExc_AttributeError,
"second argument is an unknown camera flag");
}
}
@@ -698,14 +701,14 @@ static PyObject *Camera_setIntMode(BPy_Camera *self, PyObject *args)
short value;
if (!PyArg_ParseTuple(args, "h", &value))
return (EXPP_ReturnPyObjError (PyExc_TypeError,
"expected int argument in [0,3]"));
return EXPP_ReturnPyObjError (PyExc_TypeError,
"expected int argument in [0,3]");
if (value >= 0 && value <= 3)
self->camera->flag = value;
else
return (EXPP_ReturnPyObjError (PyExc_ValueError,
"expected int argument in [0,3]"));
return EXPP_ReturnPyObjError (PyExc_ValueError,
"expected int argument in [0,3]");
Py_INCREF(Py_None);
return Py_None;
@@ -721,8 +724,8 @@ static PyObject *Camera_setLens(BPy_Camera *self, PyObject *args)
float value;
if (!PyArg_ParseTuple(args, "f", &value))
return (EXPP_ReturnPyObjError (PyExc_TypeError,
"expected float argument"));
return EXPP_ReturnPyObjError (PyExc_TypeError,
"expected float argument");
self->camera->lens = EXPP_ClampFloat (value,
EXPP_CAM_LENS_MIN, EXPP_CAM_LENS_MAX);
@@ -741,8 +744,8 @@ static PyObject *Camera_setClipStart(BPy_Camera *self, PyObject *args)
float value;
if (!PyArg_ParseTuple(args, "f", &value))
return (EXPP_ReturnPyObjError (PyExc_TypeError,
"expected float argument"));
return EXPP_ReturnPyObjError (PyExc_TypeError,
"expected float argument");
self->camera->clipsta = EXPP_ClampFloat (value,
EXPP_CAM_CLIPSTART_MIN, EXPP_CAM_CLIPSTART_MAX);
@@ -761,8 +764,8 @@ static PyObject *Camera_setClipEnd(BPy_Camera *self, PyObject *args)
float value;
if (!PyArg_ParseTuple(args, "f", &value))
return (EXPP_ReturnPyObjError (PyExc_TypeError,
"expected float argument"));
return EXPP_ReturnPyObjError (PyExc_TypeError,
"expected float argument");
self->camera->clipend = EXPP_ClampFloat (value,
EXPP_CAM_CLIPEND_MIN, EXPP_CAM_CLIPEND_MAX);
@@ -781,8 +784,8 @@ static PyObject *Camera_setDrawSize(BPy_Camera *self, PyObject *args)
float value;
if (!PyArg_ParseTuple(args, "f", &value))
return (EXPP_ReturnPyObjError (PyExc_TypeError,
"expected a float number as argument"));
return EXPP_ReturnPyObjError (PyExc_TypeError,
"expected a float number as argument");
self->camera->drawsize = EXPP_ClampFloat (value,
EXPP_CAM_DRAWSIZE_MIN, EXPP_CAM_DRAWSIZE_MAX);
@@ -854,8 +857,8 @@ static PyObject *Camera_GetAttr (BPy_Camera *self, char *name)
}
if (!attr)
return (EXPP_ReturnPyObjError (PyExc_MemoryError,
"couldn't create PyObject"));
return EXPP_ReturnPyObjError (PyExc_MemoryError,
"couldn't create PyObject");
if (attr != Py_None) return attr; /* member attribute found, return it */
@@ -909,23 +912,23 @@ static int Camera_SetAttr (BPy_Camera *self, char *name, PyObject *value)
if ((strcmp (name, "Types") == 0) || /* user tried to change a */
(strcmp (name, "Modes") == 0)) /* constant dict type ... */
return (EXPP_ReturnIntError (PyExc_AttributeError,
"constant dictionary -- cannot be changed"));
return EXPP_ReturnIntError (PyExc_AttributeError,
"constant dictionary -- cannot be changed");
else /* ... or no member with the given name was found */
return (EXPP_ReturnIntError (PyExc_KeyError,
"attribute not found"));
return EXPP_ReturnIntError (PyExc_KeyError,
"attribute not found");
}
/* valtuple won't be returned to the caller, so we need to DECREF it */
Py_DECREF(valtuple);
Py_DECREF (valtuple);
if (error != Py_None) return -1;
/* Py_None was incref'ed by the called Camera_set* function. We probably
* don't need to decref Py_None (!), but since Python/C API manual tells us
* to treat it like any other PyObject regarding ref counting ... */
Py_DECREF(Py_None);
Py_DECREF (Py_None);
return 0; /* normal exit */
}

View File

@@ -33,9 +33,7 @@
#define EXPP_CAMERA_H
#include <Python.h>
#include <DNA_camera_types.h>
#include "constant.h"
#include "gen_utils.h"

View File

@@ -109,10 +109,10 @@ static PyObject *M_Curve_Get(PyObject *self, PyObject *args)
return (PyObject*)wanted_curv;
}//if(name)
else{//no name has been given; return a list of all curves by name.
}/*if(name)*/
else{/*no name has been given; return a list with all curves in the scene */
int index = 0;
PyObject *curvlist, *pystr;
PyObject *curvlist, *pyobj;
curv_iter = G.main->curve.first;
curvlist = PyList_New (BLI_countlist (&(G.main->curve)));
@@ -122,20 +122,20 @@ static PyObject *M_Curve_Get(PyObject *self, PyObject *args)
"couldn't create PyList"));
while (curv_iter) {
pystr = PyString_FromString (curv_iter->id.name+2);
pyobj = CurveCreatePyObject (curv_iter);
if (!pystr)
if (!pyobj)
return (PythonReturnErrorObject (PyExc_MemoryError,
"couldn't create PyString"));
PyList_SET_ITEM (curvlist, index, pystr);
PyList_SET_ITEM (curvlist, index, pyobj);
curv_iter = curv_iter->id.next;
index++;
}
return (curvlist);
}//else
}/*else*/
}
/*****************************************************************************/

View File

@@ -198,7 +198,7 @@ struct Curve* CurveFromPyObject (PyObject *py_obj);
/*****************************************************************************/
/* Python Curve_Type structure definition: */
/*****************************************************************************/
static PyTypeObject Curve_Type =
PyTypeObject Curve_Type =
{
PyObject_HEAD_INIT(NULL)
0, /* ob_size */

View File

@@ -38,16 +38,16 @@
static void Button_dealloc(PyObject *self)
{
Button *but= (Button*) self;
Button *but = (Button*)self;
if(but->type==3) MEM_freeN(but->val.asstr);
if(but->type == 3) MEM_freeN (but->val.asstr);
PyMem_DEL(self);
PyObject_DEL (self);
}
static PyObject *Button_getattr(PyObject *self, char *name)
{
Button *but= (Button*) self;
Button *but = (Button*)self;
if(strcmp(name, "val") == 0) {
if (but->type==1)

View File

@@ -77,7 +77,7 @@ static PyObject *M_Ipo_Get(PyObject *self, PyObject *args)
{
char *name = NULL;
Ipo *ipo_iter;
PyObject *ipolist, *pystr;
PyObject *ipolist, *pyobj;
C_Ipo *wanted_ipo = NULL;
char error_msg[64];
@@ -105,7 +105,7 @@ static PyObject *M_Ipo_Get(PyObject *self, PyObject *args)
return (PyObject *)wanted_ipo;
}
else { /* () - return a list of all ipos in the scene */
else { /* () - return a list with all ipos in the scene */
int index = 0;
ipolist = PyList_New (BLI_countlist (&(G.main->ipo)));
@@ -115,13 +115,13 @@ static PyObject *M_Ipo_Get(PyObject *self, PyObject *args)
"couldn't create PyList"));
while (ipo_iter) {
pystr = PyString_FromString (ipo_iter->id.name+2);
pyobj = Ipo_CreatePyObject (ipo_iter);
if (!pystr)
if (!pyobj)
return (PythonReturnErrorObject (PyExc_MemoryError,
"couldn't create PyString"));
PyList_SET_ITEM (ipolist, index, pystr);
PyList_SET_ITEM (ipolist, index, pyobj);
ipo_iter = ipo_iter->id.next;
index++;
@@ -138,9 +138,10 @@ PyObject *M_Ipo_Init (void)
{
PyObject *submodule;
Ipo_Type.ob_type = &PyType_Type;
printf ("In M_Ipo_Init()\n");
submodule = Py_InitModule3("Blender.Ipo",
M_Ipo_methods, M_Ipo_doc);
submodule = Py_InitModule3("Blender.Ipo", M_Ipo_methods, M_Ipo_doc);
return (submodule);
}
@@ -458,3 +459,44 @@ static PyObject *IpoRepr (C_Ipo *self)
return PyString_FromString(self->ipo->id.name+2);
}
/* Three Python Ipo_Type helper functions needed by the Object module: */
/*****************************************************************************/
/* Function: Ipo_CreatePyObject */
/* Description: This function will create a new C_Ipo from an existing */
/* Blender ipo structure. */
/*****************************************************************************/
PyObject *Ipo_CreatePyObject (Ipo *ipo)
{
C_Ipo *pyipo;
pyipo = (C_Ipo *)PyObject_NEW (C_Ipo, &Ipo_Type);
if (!pyipo)
return EXPP_ReturnPyObjError (PyExc_MemoryError,
"couldn't create C_Ipo object");
pyipo->ipo = ipo;
return (PyObject *)pyipo;
}
/*****************************************************************************/
/* Function: Ipo_CheckPyObject */
/* Description: This function returns true when the given PyObject is of the */
/* type Ipo. Otherwise it will return false. */
/*****************************************************************************/
int Ipo_CheckPyObject (PyObject *pyobj)
{
return (pyobj->ob_type == &Ipo_Type);
}
/*****************************************************************************/
/* Function: Ipo_FromPyObject */
/* Description: This function returns the Blender ipo from the given */
/* PyObject. */
/*****************************************************************************/
Ipo *Ipo_FromPyObject (PyObject *pyobj)
{
return ((C_Ipo *)pyobj)->ipo;
}

View File

@@ -152,9 +152,9 @@ static PyObject *IpoRepr (C_Ipo *self);
/*****************************************************************************/
/* Python Ipo_Type structure definition: */
/*****************************************************************************/
static PyTypeObject Ipo_Type =
PyTypeObject Ipo_Type =
{
PyObject_HEAD_INIT(&PyType_Type)
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
"Ipo", /* tp_name */
sizeof (C_Ipo), /* tp_basicsize */

View File

@@ -129,7 +129,7 @@ static PyObject *M_Lamp_Get(PyObject *self, PyObject *args)
else { /* () - return a list of all lamps in the scene */
int index = 0;
PyObject *lamplist, *pystr;
PyObject *lamplist, *pyobj;
lamplist = PyList_New (BLI_countlist (&(G.main->lamp)));
@@ -138,19 +138,19 @@ static PyObject *M_Lamp_Get(PyObject *self, PyObject *args)
"couldn't create PyList"));
while (lamp_iter) {
pystr = PyString_FromString (lamp_iter->id.name+2);
pyobj = Lamp_CreatePyObject (lamp_iter);
if (!pystr)
if (!pyobj)
return (PythonReturnErrorObject (PyExc_MemoryError,
"couldn't create PyString"));
PyList_SET_ITEM (lamplist, index, pystr);
PyList_SET_ITEM (lamplist, index, pyobj);
lamp_iter = lamp_iter->id.next;
index++;
}
return (lamplist);
return lamplist;
}
}

View File

@@ -111,7 +111,7 @@ static PyObject *M_Metaball_Get(PyObject *self, PyObject *args)
else { /* () - return a list of all mballs in the scene */
int index = 0;
PyObject *mballlist, *pystr;
PyObject *mballlist, *pyobj;
mballlist = PyList_New (BLI_countlist (&(G.main->mball)));
@@ -120,13 +120,13 @@ static PyObject *M_Metaball_Get(PyObject *self, PyObject *args)
"couldn't create PyList"));
while (mball_iter) {
pystr = PyString_FromString (mball_iter->id.name+2);
pyobj = Metaball_CreatePyObject (mball_iter);
if (!pystr)
if (!pyobj)
return (PythonReturnErrorObject (PyExc_MemoryError,
"couldn't create PyString"));
PyList_SET_ITEM (mballlist, index, pystr);
PyList_SET_ITEM (mballlist, index, pyobj);
mball_iter = mball_iter->id.next;
index++;
@@ -1039,3 +1039,44 @@ static PyObject *MetaballRepr (C_Metaball *self)
return PyString_FromString(self->metaball->id.name+2);
}
/* Three Python Metaball_Type helper functions needed by the Object module: */
/*****************************************************************************/
/* Function: Metaball_CreatePyObject */
/* Description: This function will create a new C_Metaball from an existing */
/* Blender metaball structure. */
/*****************************************************************************/
PyObject *Metaball_CreatePyObject (MetaBall *metaball)
{
C_Metaball *pymetaball;
pymetaball = (C_Metaball *)PyObject_NEW (C_Metaball, &Metaball_Type);
if (!pymetaball)
return EXPP_ReturnPyObjError (PyExc_MemoryError,
"couldn't create C_Metaball object");
pymetaball->metaball = metaball;
return (PyObject *)pymetaball;
}
/*****************************************************************************/
/* Function: Metaball_CheckPyObject */
/* Description: This function returns true when the given PyObject is of the */
/* type Metaball. Otherwise it will return false. */
/*****************************************************************************/
int Metaball_CheckPyObject (PyObject *pyobj)
{
return (pyobj->ob_type == &Metaball_Type);
}
/*****************************************************************************/
/* Function: Metaball_FromPyObject */
/* Description: This function returns the Blender metaball from the given */
/* PyObject. */
/*****************************************************************************/
MetaBall *Metaball_FromPyObject (PyObject *pyobj)
{
return ((C_Metaball *)pyobj)->metaball;
}

View File

@@ -278,7 +278,7 @@ static PyObject *MetaballRepr (C_Metaball *self);
/*****************************************************************************/
/* Python Metaball_Type structure definition: */
/*****************************************************************************/
static PyTypeObject Metaball_Type =
PyTypeObject Metaball_Type =
{
PyObject_HEAD_INIT(&PyType_Type)
0, /* ob_size */

View File

@@ -46,7 +46,7 @@ void mesh_update(Mesh *mesh)
static void NMCol_dealloc(PyObject *self)
{
PyMem_DEL(self); /* XXX PyObject_Del ?*/
PyObject_DEL(self); /* XXX PyObject_Del ?*/
}
static C_NMCol *newcol (char r, char g, char b, char a)
@@ -144,7 +144,7 @@ static void NMFace_dealloc (PyObject *self)
Py_DECREF(mf->col);
Py_XDECREF(mf->image);
PyMem_DEL(self);
PyObject_DEL(self);
}
static C_NMFace *new_NMFace(PyObject *vertexlist)
@@ -393,7 +393,7 @@ static PyObject *M_NMesh_Vert(PyObject *self, PyObject *args)
static void NMVert_dealloc(PyObject *self)
{
PyMem_DEL(self);
PyObject_DEL(self);
}
static PyObject *NMVert_getattr(PyObject *self, char *name)
@@ -545,7 +545,7 @@ static void NMesh_dealloc(PyObject *self)
Py_DECREF(me->verts);
Py_DECREF(me->faces);
PyMem_DEL(self);
PyObject_DEL(self);
}
static PyObject *NMesh_getSelectedFaces(PyObject *self, PyObject *args)

View File

@@ -73,7 +73,7 @@ PyTypeObject NMFace_Type;
PyTypeObject NMVert_Type;
PyTypeObject NMCol_Type;
PyTypeObject Image_Type;
extern PyTypeObject Image_Type;
/* Globals */

View File

@@ -567,13 +567,13 @@ static PyObject *Object_getData (C_Object *self)
//#obj_id = MAKE_ID2 (id->name[0], id->name[1]);
switch (self->object->type)//#obj_id)
{
case ID_AR:
case OB_ARMATURE://#ID_AR:
data_object = M_ArmatureCreatePyObject (self->object->data);
break;
case OB_CAMERA://#ID_CA:
data_object = Camera_CreatePyObject (self->object->data);
break;
case ID_CU:
case OB_CURVE://#ID_CU:
data_object = CurveCreatePyObject (self->object->data);
break;
case ID_IM:
@@ -581,12 +581,13 @@ static PyObject *Object_getData (C_Object *self)
break;
case ID_IP:
break;
case ID_LA:
case OB_LAMP://#ID_LA:
data_object = Lamp_CreatePyObject (self->object->data);
break;
case ID_MA:
break;
case ID_ME:
case OB_MESH://#ID_ME:
data_object = NMesh_CreatePyObject (self->object->data);
break;
case ID_OB:
data_object = M_ObjectCreatePyObject (self->object->data);

View File

@@ -295,30 +295,30 @@ static PyObject *M_Scene_Get(PyObject *self, PyObject *args)
return wanted_scene;
}
else { /* () - return a list of all scenes in Blender */
else { /* () - return a list with wrappers for all scenes in Blender */
int index = 0;
PyObject *scenelist, *pystr;
PyObject *sce_pylist, *pyobj;
scenelist = PyList_New (BLI_countlist (&(G.main->scene)));
sce_pylist = PyList_New (BLI_countlist (&(G.main->scene)));
if (scenelist == NULL)
if (sce_pylist == NULL)
return (PythonReturnErrorObject (PyExc_MemoryError,
"couldn't create PyList"));
while (scene_iter) {
pystr = PyString_FromString (scene_iter->id.name+2);
pyobj = Scene_CreatePyObject (scene_iter);
if (!pystr)
if (!pyobj)
return (PythonReturnErrorObject (PyExc_MemoryError,
"couldn't create PyString"));
PyList_SET_ITEM (scenelist, index, pystr);
PyList_SET_ITEM (sce_pylist, index, pyobj);
scene_iter = scene_iter->id.next;
index++;
}
return scenelist;
return sce_pylist;
}
}

View File

@@ -101,6 +101,7 @@ struct PyMethodDef M_Text_methods[] = {
typedef struct {
PyObject_HEAD
Text *text;
} C_Text;
/*****************************************************************************/

View File

@@ -40,7 +40,15 @@ PyObject *M_Types_Init (void)
{
PyObject *submodule, *dict;
submodule = Py_InitModule3("Blender.Types", Null_methods, M_Types_doc);
/* These are only set when some object initializes them. But unless we
* do it now, we get two easy ways to crash Blender. Maybe we'd better
* have an Init function for all these internal types that more than one
* module can use. We could call it after setting the Blender dictionary */
vector_Type.ob_type = &PyType_Type;
rgbTuple_Type.ob_type = &PyType_Type;
constant_Type.ob_type = &PyType_Type;
submodule = Py_InitModule3 ("Blender.Types", Null_methods, M_Types_doc);
dict = PyModule_GetDict(submodule);
@@ -55,13 +63,20 @@ PyObject *M_Types_Init (void)
PyDict_SetItemString(dict, "NMVertType", (PyObject *)&NMVert_Type);
PyDict_SetItemString(dict, "NMColType", (PyObject *)&NMCol_Type);
PyDict_SetItemString(dict, "ArmatureType", (PyObject *)&Armature_Type);
PyDict_SetItemString(dict, "BoneType", (PyObject *)&Bone_Type);
PyDict_SetItemString(dict, "CurveType", (PyObject *)&Curve_Type);
PyDict_SetItemString(dict, "IpoType", (PyObject *)&Ipo_Type);
PyDict_SetItemString(dict, "MetaballType", (PyObject *)&Metaball_Type);
PyDict_SetItemString(dict, "CameraType", (PyObject *)&Camera_Type);
PyDict_SetItemString(dict, "ImageType", (PyObject *)&Image_Type);
PyDict_SetItemString(dict, "LampType", (PyObject *)&Lamp_Type);
PyDict_SetItemString(dict, "TextType", (PyObject *)&Text_Type);
PyDict_SetItemString(dict, "MaterialType", (PyObject *)&Material_Type);
PyDict_SetItemString(dict, "ButtonType", (PyObject *)&Button_Type);
PyDict_SetItemString(dict, "MaterialType",(PyObject *)&Material_Type);
/* External helper Types available to the main ones above */
@@ -70,5 +85,5 @@ PyObject *M_Types_Init (void)
PyDict_SetItemString(dict, "constantType", (PyObject *)&constant_Type);
PyDict_SetItemString(dict, "rgbTupleType", (PyObject *)&rgbTuple_Type);
return (submodule);
return submodule;
}

View File

@@ -39,6 +39,8 @@ extern PyTypeObject Button_Type, Material_Type;
extern PyTypeObject Object_Type;
extern PyTypeObject NMesh_Type, NMFace_Type, NMVert_Type, NMCol_Type;
extern PyTypeObject Camera_Type, Lamp_Type, Image_Type, Text_Type;
extern PyTypeObject Armature_Type, Bone_Type;
extern PyTypeObject Curve_Type, Ipo_Type, Metaball_Type;
extern PyTypeObject vector_Type, buffer_Type, rgbTuple_Type,
constant_Type;

View File

@@ -39,7 +39,7 @@
static void Vector_dealloc(VectorObject *self)
{
PyMem_DEL(self);
PyObject_DEL (self);
}
static PyObject *Vector_getattr(VectorObject *self, char *name)
@@ -195,7 +195,7 @@ PyTypeObject vector_Type =
{
PyObject_HEAD_INIT(NULL)
0, /*ob_size*/
"Vector", /*tp_name*/
"vector", /*tp_name*/
sizeof(VectorObject), /*tp_basicsize*/
0, /*tp_itemsize*/
/* methods */