Python API

made all libdata hashable - use the object type,name and lib for the hash.
added .tag to libdata so we can test if data's been processed without using dictionaries
added libdataseq.tag (write only) setting the tag flag (which can always be dirty)
This commit is contained in:
Campbell Barton 2007-03-26 02:10:24 +00:00
parent aba5557028
commit c97be098f7
26 changed files with 113 additions and 25 deletions

@ -1087,7 +1087,7 @@ PyTypeObject Armature_Type = {
0, //tp_as_number
0, //tp_as_sequence
0, //tp_as_mapping
0, //tp_hash
( hashfunc ) GenericLib_hash, //tp_hash
0, //tp_call
0, //tp_str
0, //tp_getattro

@ -1557,7 +1557,7 @@ PyTypeObject Curve_Type = {
/* More standard operations (here for binary compatibility) */
NULL, /* hashfunc tp_hash; */
( hashfunc ) GenericLib_hash, /* hashfunc tp_hash; */
NULL, /* ternaryfunc tp_call; */
NULL, /* reprfunc tp_str; */
NULL, /* getattrofunc tp_getattro; */

@ -288,7 +288,7 @@ PyTypeObject Font_Type = {
/* More standard operations (here for binary compatibility) */
NULL, /* hashfunc tp_hash; */
( hashfunc ) GenericLib_hash, /* hashfunc tp_hash; */
NULL, /* ternaryfunc tp_call; */
NULL, /* reprfunc tp_str; */
NULL, /* getattrofunc tp_getattro; */

@ -285,7 +285,7 @@ PyTypeObject Group_Type = {
/* More standard operations (here for binary compatibility) */
NULL, /* hashfunc tp_hash; */
( hashfunc ) GenericLib_hash, /* hashfunc tp_hash; */
NULL, /* ternaryfunc tp_call; */
NULL, /* reprfunc tp_str; */
NULL, /* getattrofunc tp_getattro; */

@ -1324,7 +1324,7 @@ PyTypeObject Image_Type = {
/* More standard operations (here for binary compatibility) */
NULL, /* hashfunc tp_hash; */
( hashfunc ) GenericLib_hash, /* hashfunc tp_hash; */
NULL, /* ternaryfunc tp_call; */
NULL, /* reprfunc tp_str; */
NULL, /* getattrofunc tp_getattro; */

@ -379,7 +379,7 @@ PyTypeObject Ipo_Type = {
/* More standard operations (here for binary compatibility) */
NULL, /* hashfunc tp_hash; */
( hashfunc ) GenericLib_hash, /* hashfunc tp_hash; */
NULL, /* ternaryfunc tp_call; */
NULL, /* reprfunc tp_str; */
#ifdef CURVEATTRS

@ -149,7 +149,7 @@ PyTypeObject Key_Type = {
/* More standard operations (here for binary compatibility) */
NULL, /* hashfunc tp_hash; */
( hashfunc ) GenericLib_hash, /* hashfunc tp_hash; */
NULL, /* ternaryfunc tp_call; */
NULL, /* reprfunc tp_str; */
NULL, /* getattrofunc tp_getattro; */

@ -538,7 +538,7 @@ PyTypeObject Lamp_Type = {
/* More standard operations (here for binary compatibility) */
NULL, /* hashfunc tp_hash; */
( hashfunc ) GenericLib_hash, /* hashfunc tp_hash; */
NULL, /* ternaryfunc tp_call; */
NULL, /* reprfunc tp_str; */
NULL, /* getattrofunc tp_getattro; */

@ -754,7 +754,7 @@ PyTypeObject Lattice_Type = {
/* More standard operations (here for binary compatibility) */
NULL, /* hashfunc tp_hash; */
( hashfunc ) GenericLib_hash, /* hashfunc tp_hash; */
NULL, /* ternaryfunc tp_call; */
NULL, /* reprfunc tp_str; */
NULL, /* getattrofunc tp_getattro; */

@ -350,6 +350,31 @@ static int MainSeq_setActive(BPy_MainSeq *self, PyObject *value)
"Only Scene and Image types have the active attribute" );
}
static int MainSeq_setTag(BPy_MainSeq *self, PyObject *value)
{
int param = PyObject_IsTrue( value );
ID *id;
if( param == -1 )
return EXPP_ReturnIntError( PyExc_TypeError,
"expected int argument in range [0,1]" );
id = (ID *)wich_libbase(G.main, self->type)->first;
if (param) {
for (; id; id = id->next) {
id->flag |= LIB_DOIT;
}
} else {
for (; id; id = id->next) {
id->flag &= ~LIB_DOIT;
}
}
return 0;
}
/* New Data, internal functions */
Mesh *add_mesh__internal(char *name)
{
@ -640,6 +665,10 @@ static PyGetSetDef MainSeq_getseters[] = {
(getter)MainSeq_getActive, (setter)MainSeq_setActive,
"active object",
NULL},
{"tag",
(getter)NULL, (setter)MainSeq_setTag,
"tag all data in True or False (write only)",
NULL},
{NULL,NULL,NULL,NULL,NULL} /* Sentinel */
};

@ -1102,7 +1102,7 @@ PyTypeObject Material_Type = {
/* More standard operations (here for binary compatibility) */
NULL, /* hashfunc tp_hash; */
( hashfunc ) GenericLib_hash, /* hashfunc tp_hash; */
NULL, /* ternaryfunc tp_call; */
NULL, /* reprfunc tp_str; */
NULL, /* getattrofunc tp_getattro; */

@ -7739,7 +7739,7 @@ PyTypeObject Mesh_Type = {
/* More standard operations (here for binary compatibility) */
NULL, /* hashfunc tp_hash; */
( hashfunc ) GenericLib_hash, /* hashfunc tp_hash; */
NULL, /* ternaryfunc tp_call; */
NULL, /* reprfunc tp_str; */
NULL, /* getattrofunc tp_getattro; */

@ -243,7 +243,7 @@ PyTypeObject Metaball_Type = {
/* More standard operations (here for binary compatibility) */
NULL, /* hashfunc tp_hash; */
( hashfunc ) GenericLib_hash, /* hashfunc tp_hash; */
NULL, /* ternaryfunc tp_call; */
NULL, /* reprfunc tp_str; */
NULL, /* getattrofunc tp_getattro; */

@ -439,7 +439,7 @@ PyTypeObject Action_Type = {
/* More standard operations (here for binary compatibility) */
NULL, /* hashfunc tp_hash; */
( hashfunc ) GenericLib_hash, /* hashfunc tp_hash; */
NULL, /* ternaryfunc tp_call; */
NULL, /* reprfunc tp_str; */
NULL, /* getattrofunc tp_getattro; */

@ -5027,7 +5027,7 @@ PyTypeObject Object_Type = {
/* More standard operations (here for binary compatibility) */
NULL, /* hashfunc tp_hash; */
( hashfunc ) GenericLib_hash, /* hashfunc tp_hash; */
NULL, /* ternaryfunc tp_call; */
NULL, /* reprfunc tp_str; */
NULL, /* getattrofunc tp_getattro; */

@ -474,7 +474,7 @@ PyTypeObject Scene_Type = {
/* More standard operations (here for binary compatibility) */
NULL, /* hashfunc tp_hash; */
( hashfunc ) GenericLib_hash, /* hashfunc tp_hash; */
NULL, /* ternaryfunc tp_call; */
NULL, /* reprfunc tp_str; */
NULL, /* getattrofunc tp_getattro; */

@ -563,7 +563,7 @@ PyTypeObject Sound_Type = {
/* More standard operations (here for binary compatibility) */
NULL, /* hashfunc tp_hash; */
( hashfunc ) GenericLib_hash, /* hashfunc tp_hash; */
NULL, /* ternaryfunc tp_call; */
NULL, /* reprfunc tp_str; */
NULL, /* getattrofunc tp_getattro; */

@ -762,7 +762,7 @@ PyTypeObject SurfNurb_Type = {
/* More standard operations (here for binary compatibility) */
NULL, /* hashfunc tp_hash; */
( hashfunc ) GenericLib_hash, /* hashfunc tp_hash; */
NULL, /* ternaryfunc tp_call; */
NULL, /* reprfunc tp_str; */
NULL, /* getattrofunc tp_getattro; */

@ -532,7 +532,7 @@ PyTypeObject Text_Type = {
/* More standard operations (here for binary compatibility) */
NULL, /* hashfunc tp_hash; */
( hashfunc ) GenericLib_hash, /* hashfunc tp_hash; */
NULL, /* ternaryfunc tp_call; */
NULL, /* reprfunc tp_str; */
NULL, /* getattrofunc tp_getattro; */
@ -540,7 +540,7 @@ PyTypeObject Text_Type = {
/* Functions to access object as input/output buffer */
NULL, /* PyBufferProcs *tp_as_buffer; */
/*** Flags to define presence of optional/expanded features ***/
Py_TPFLAGS_DEFAULT, /* long tp_flags; */

@ -31,7 +31,7 @@
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#include "Text3d.h" /*This must come first*/
#include "DNA_object_types.h"
@ -372,7 +372,7 @@ PyTypeObject Text3d_Type = {
/* More standard operations (here for binary compatibility) */
NULL, /* hashfunc tp_hash; */
( hashfunc ) GenericLib_hash, /* hashfunc tp_hash; */
NULL, /* ternaryfunc tp_call; */
NULL, /* reprfunc tp_str; */
NULL, /* getattrofunc tp_getattro; */

@ -811,7 +811,7 @@ PyTypeObject Texture_Type = {
/* More standard operations (here for binary compatibility) */
NULL, /* hashfunc tp_hash; */
( hashfunc ) GenericLib_hash, /* hashfunc tp_hash; */
NULL, /* ternaryfunc tp_call; */
NULL, /* reprfunc tp_str; */
NULL, /* getattrofunc tp_getattro; */

@ -281,7 +281,7 @@ PyTypeObject World_Type = {
/* More standard operations (here for binary compatibility) */
NULL, /* hashfunc tp_hash; */
( hashfunc ) GenericLib_hash, /* hashfunc tp_hash; */
NULL, /* ternaryfunc tp_call; */
NULL, /* reprfunc tp_str; */
NULL, /* getattrofunc tp_getattro; */

@ -188,6 +188,17 @@ class dataIterator:
>>> ipo_list = list(bpy.ipos)
@type tag: Bool
@ivar tag: A fast way to set the tag value of every member of the sequence to True or False
For example
>>> bpy.meshes.tag = True
Is the same as...
>>> for me in bpy.meshes: me.tag = True
@type active: Datablock or None
@ivar active: The active member of the datatype

@ -18,6 +18,9 @@ attributes = """
@ivar fakeUser: When set to True, this datablock wont be removed, even if nothing is using it.
All data has this disabled by default except for Actions.
@type fakeUser: bool
@ivar tag: A temporary tag that to flag data as being used within a loop.
always set all tags to True or False before using since blender uses this flag for its own internal operations.
@type tag: bool
@ivar users: The number of users this datablock has. (readonly)
Zero user datablocks are de-allocated after reloading and saving.
@type users: int

@ -91,6 +91,35 @@ int GenericLib_setFakeUser( void *self, PyObject *value )
return 0;
}
PyObject *GenericLib_getTag( void *self )
{
ID *id = ((BPy_GenericLib *)self)->id;
if (!id) return ( EXPP_ReturnPyObjError( PyExc_RuntimeError, "data has been removed" ) );
if (id->flag & LIB_DOIT)
Py_RETURN_TRUE;
else
Py_RETURN_FALSE;
}
int GenericLib_setTag( void *self, PyObject *value )
{
int param;
ID *id = ((BPy_GenericLib *)self)->id;
if (!id) return ( EXPP_ReturnIntError( PyExc_RuntimeError, "data has been removed" ) );
param = PyObject_IsTrue( value );
if( param == -1 )
return EXPP_ReturnIntError( PyExc_TypeError,
"expected int argument in range [0,1]" );
if (param)
id->flag |= LIB_DOIT;
else
id->flag &= ~LIB_DOIT;
return 0;
}
/* read only */
PyObject *GenericLib_getLib( void *self )
{
@ -306,3 +335,14 @@ PyObject *GetPyObjectFromID( ID * id )
Py_RETURN_NONE;
}
/* return a unique tuple for this libdata*/
long GenericLib_hash(PyObject * pydata)
{
ID *id = ((BPy_GenericLib *)pydata)->id;
PyObject *pyhash = PyTuple_New( 2 );
PyTuple_SetItem( pyhash, 0, PyString_FromString(id->name) );
if (id->lib) PyTuple_SetItem( pyhash, 0, PyString_FromString(id->lib->name) );
else PyTuple_SetItem( pyhash, 1, Py_None );
return PyObject_Hash(pyhash);
}

@ -59,9 +59,12 @@
{"properties",\
(getter)GenericLib_getProperties, (setter)NULL,\
"properties",\
NULL},\
{"tag",\
(getter)GenericLib_getTag, (setter)GenericLib_setTag,\
"temproary tag",\
NULL}
/* Dummy struct for getting the ID from a libdata BPyObject */
typedef struct {
PyObject_HEAD /* required python macro */
@ -72,6 +75,8 @@ int GenericLib_setName( void *self, PyObject *value );
PyObject *GenericLib_getName( void *self );
PyObject *GenericLib_getFakeUser( void *self );
int GenericLib_setFakeUser( void *self, PyObject *value );
PyObject *GenericLib_getTag( void *self );
int GenericLib_setTag( void *self, PyObject *value );
PyObject *GenericLib_getLib( void *self );
PyObject *GenericLib_getUsers( void *self );
PyObject *GenericLib_getProperties( void *self );
@ -85,5 +90,5 @@ short GenericLib_getType(PyObject * pydata);
/* Other ID functions */
ID *GetIdFromList( ListBase * list, char *name );
PyObject *GetPyObjectFromID( ID * id );
long GenericLib_hash(PyObject * pydata);
#endif /* EXPP_gen_library_h */