added comparison function to many python types so you can do == and =!

This commit is contained in:
2006-10-06 16:48:28 +00:00
parent aaaae78527
commit dda63a9dde
21 changed files with 122 additions and 41 deletions

View File

@@ -1060,13 +1060,21 @@ AttributeError:
return EXPP_intError(PyExc_AttributeError, "%s%s%s",
sArmatureBadArgs, " __init__: ", "Expects string(name)");
}
//------------------------tp_richcompare
//This method allows the object to use comparison operators
//TODO: We need some armature comparisons
static PyObject *Armature_richcmpr(BPy_Armature *self, PyObject *v, int op)
/*****************************************************************************/
/* Function: Armature_compare */
/* Description: This is a callback function for the BPy_Armature type. It */
/* compares two Armature_Type objects. Only the "==" and "!=" */
/* comparisons are meaninful. Returns 0 for equality and -1 if */
/* they don't point to the same Blender Object struct. */
/* In Python it becomes 1 if they are equal, 0 otherwise. */
/*****************************************************************************/
static int Armature_compare( BPy_Armature * a, BPy_Armature * b )
{
return EXPP_incr_ret(Py_None);
return ( a->armature == b->armature ) ? 0 : -1;
}
//------------------------tp_repr
//This is the string representation of the object
static PyObject *Armature_repr(BPy_Armature *self)
@@ -1093,7 +1101,7 @@ PyTypeObject Armature_Type = {
0, //tp_print
0, //tp_getattr
0, //tp_setattr
0, //tp_compare
(cmpfunc) Armature_compare, //tp_compare
(reprfunc) Armature_repr, //tp_repr
0, //tp_as_number
0, //tp_as_sequence
@@ -1108,7 +1116,7 @@ PyTypeObject Armature_Type = {
BPy_Armature_doc, //tp_doc
0, //tp_traverse
0, //tp_clear
(richcmpfunc)Armature_richcmpr, //tp_richcompare
0, //tp_richcompare
0, //tp_weaklistoffset
0, //tp_iter
0, //tp_iternext

View File

@@ -181,6 +181,7 @@ static PyMappingMethods Constraint_as_mapping = {
/*****************************************************************************/
static void Constraint_dealloc( BPy_Constraint * self );
static PyObject *Constraint_repr( BPy_Constraint * self );
static int Constraint_compare( BPy_Constraint * a, BPy_Constraint * b );
/*****************************************************************************/
/* Python Constraint_Type structure definition: */
@@ -199,7 +200,7 @@ PyTypeObject Constraint_Type = {
NULL, /* printfunc tp_print; */
NULL, /* getattrfunc tp_getattr; */
NULL, /* setattrfunc tp_setattr; */
NULL, /* cmpfunc tp_compare; */
( cmpfunc ) Constraint_compare, /* cmpfunc tp_compare; */
( reprfunc ) Constraint_repr, /* reprfunc tp_repr; */
/* Method suites for standard classes */
@@ -1276,6 +1277,16 @@ static void Constraint_dealloc( BPy_Constraint * self )
PyObject_DEL( self );
}
/*****************************************************************************/
/* Function: Constraint_compare */
/* Description: This compares 2 constraint python types, == or != only. */
/*****************************************************************************/
static int Constraint_compare( BPy_Constraint * a, BPy_Constraint * b )
{
return ( a->con == b->con ) ? 0 : -1;
}
/*****************************************************************************/
/* Function: Constraint_repr */
/* Description: This is a callback function for the BPy_Constraint type. It */

View File

@@ -241,6 +241,7 @@ static void CurveDeAlloc( BPy_Curve * msh );
/* static int CurvePrint (BPy_Curve *msh, FILE *fp, int flags); */
static int CurveSetAttr( BPy_Curve * msh, char *name, PyObject * v );
static PyObject *CurveGetAttr( BPy_Curve * msh, char *name );
static int CurveCopmpare( BPy_Curve * a, BPy_Curve * b );
static PyObject *CurveRepr( BPy_Curve * msh );
static PySequenceMethods Curve_as_sequence = {
@@ -271,7 +272,7 @@ PyTypeObject Curve_Type = {
0, /* tp_print */
( getattrfunc ) CurveGetAttr, /* tp_getattr */
( setattrfunc ) CurveSetAttr, /* tp_setattr */
0, /* tp_compare */
( cmpfunc ) CurveCopmpare, /* tp_compare */
( reprfunc ) CurveRepr, /* tp_repr */
/* methods for standard classes */
0, /* tp_as_number */
@@ -1662,6 +1663,16 @@ static int CurveSetAttr( BPy_Curve * self, char *name, PyObject * value )
}
/*****************************************************************************/
/* Function: CurveCopmpare */
/* Description: This compares 2 curve python types, == or != only. */
/*****************************************************************************/
static int CurveCopmpare( BPy_Curve * a, BPy_Curve * b )
{
return ( a->curve == b->curve ) ? 0 : -1;
}
/*****************************************************************************/
/* Function: CurveRepr */
/* Description: This is a callback function for the BPy_Curve type. It */

View File

@@ -435,8 +435,7 @@ static PyObject *Font_repr( BPy_Font * self )
/*--------------- compare------------------------------------------*/
static int Font_compare( BPy_Font * a, BPy_Font * b )
{
VFont *pa = a->font, *pb = b->font;
return ( pa == pb ) ? 0 : -1;
return ( a->font == b->font ) ? 0 : -1;
}
/*--------------- Font_CreatePyObject---------------------------------*/

View File

@@ -491,8 +491,7 @@ PyObject *M_Group_Unlink( PyObject * self, PyObject * args )
unlink_group(group);
group->id.us= 0;
free_libblock( &G.main->group, group );
Py_INCREF( Py_None );
return Py_None;
Py_RETURN_NONE;
}
@@ -527,7 +526,7 @@ PyObject *Group_CreatePyObject( struct Group * grp )
BPy_Group *pygrp;
if( !grp )
return EXPP_incr_ret( Py_None );
Py_RETURN_NONE;
pygrp =
( BPy_Group * ) PyObject_NEW( BPy_Group, &Group_Type );
@@ -746,7 +745,7 @@ static PyObject *GroupObSeq_add( BPy_GroupObSeq * self, PyObject *args )
add_to_group_wraper(self->bpygroup->group, blen_ob); /* this checks so as not to add the object into the group twice*/
return EXPP_incr_ret( Py_None );
Py_RETURN_NONE;
}
@@ -776,7 +775,7 @@ static PyObject *GroupObSeq_remove( BPy_GroupObSeq * self, PyObject *args )
if (base)
base->flag &= ~OB_FROMGROUP;
}
return EXPP_incr_ret( Py_None );
Py_RETURN_NONE;
}

View File

@@ -70,7 +70,6 @@ current image frame, some images change frame if they are a sequence */
static PyObject *M_Image_New( PyObject * self, PyObject * args );
static PyObject *M_Image_Get( PyObject * self, PyObject * args );
static PyObject *M_Image_GetCurrent( PyObject * self );
static PyObject *M_Image_SetCurrent( PyObject * self, PyObject * args );
static PyObject *M_Image_Load( PyObject * self, PyObject * args );
@@ -1261,8 +1260,7 @@ static int Image_setAttr( BPy_Image * self, char *name, PyObject * value )
/*****************************************************************************/
static int Image_compare( BPy_Image * a, BPy_Image * b )
{
Image *pa = a->image, *pb = b->image;
return ( pa == pb ) ? 0 : -1;
return ( a->image == b->image ) ? 0 : -1;
}
/*****************************************************************************/

View File

@@ -228,6 +228,7 @@ static PySequenceMethods Ipo_as_sequence = {
/*****************************************************************************/
static void Ipo_dealloc( BPy_Ipo * self );
//static int IpoPrint (BPy_Ipo *self, FILE *fp, int flags);
static int Ipo_compare( BPy_Ipo * a, BPy_Ipo * b );
static PyObject *Ipo_repr( BPy_Ipo * self );
static PyObject *Ipo_getIter( BPy_Ipo * self );
static PyObject *Ipo_nextIter( BPy_Ipo * self );
@@ -365,7 +366,7 @@ PyTypeObject Ipo_Type = {
NULL, /* printfunc tp_print; */
NULL, /* getattrfunc tp_getattr; */
NULL, /* setattrfunc tp_setattr; */
NULL, /* cmpfunc tp_compare; */
( reprfunc ) Ipo_compare, /* cmpfunc tp_compare; */
( reprfunc ) Ipo_repr, /* reprfunc tp_repr; */
/* Method suites for standard classes */
@@ -1302,6 +1303,15 @@ static void Ipo_dealloc( BPy_Ipo * self )
PyObject_DEL( self );
}
/*****************************************************************************/
/* Function: Ipo_compare */
/* Description: This compares 2 ipo python types, == or != only. */
/*****************************************************************************/
static int Ipo_compare( BPy_Ipo * a, BPy_Ipo * b )
{
return ( a->ipo == b->ipo ) ? 0 : -1;
}
/*****************************************************************************/
/* Function: Ipo_repr */
/* Description: This is a callback function for the BPy_Ipo type. It */

View File

@@ -175,6 +175,7 @@ static PyMappingMethods IpoCurve_as_mapping = {
/*****************************************************************************/
/* Python IpoCurve_Type callback function prototypes: */
/*****************************************************************************/
static int IpoCurve_compare( C_IpoCurve * a, C_IpoCurve * b );
static PyObject *IpoCurve_repr( C_IpoCurve * self );
static void IpoCurve_dealloc( C_IpoCurve * self );
@@ -192,7 +193,7 @@ PyTypeObject IpoCurve_Type = {
0, /* tp_print */
( getattrfunc ) NULL, /* tp_getattr */
( setattrfunc ) NULL, /* tp_setattr */
0, /* tp_compare */
( cmpfunc ) IpoCurve_compare, /* tp_compare */
( reprfunc ) IpoCurve_repr, /* tp_repr */
/* Method suites for standard classes */
@@ -646,6 +647,15 @@ static void IpoCurve_dealloc( C_IpoCurve * self )
PyObject_DEL( self );
}
/*****************************************************************************/
/* Function: IpoCurve_compare */
/* Description: This compares 2 python types, == or != only. */
/*****************************************************************************/
static int IpoCurve_compare( C_IpoCurve * a, C_IpoCurve * b )
{
return ( a->ipocurve == b->ipocurve ) ? 0 : -1;
}
/*****************************************************************************/
/* Function: IpoCurve_repr */
/* Description: This is a callback function for the C_IpoCurve type. It */

View File

@@ -61,6 +61,7 @@
static void Key_dealloc( PyObject * self );
static void KeyBlock_dealloc( PyObject * self );
static int Key_compare( BPy_Key * a, BPy_Key * b );
static PyObject *Key_repr( BPy_Key * self );
static PyObject *Key_getBlocks( PyObject * self );
@@ -138,7 +139,7 @@ PyTypeObject Key_Type = {
( printfunc ) 0, /*tp_print */
( getattrfunc ) 0, /*tp_getattr */
( setattrfunc ) 0, /*tp_setattr */
0, /*tp_compare*/
( cmpfunc) Key_compare, /*tp_compare*/
( reprfunc ) Key_repr, /* tp_repr */
/* Method suites for standard classes */
@@ -306,6 +307,12 @@ PyObject *Key_CreatePyObject( Key * k )
return ( PyObject * ) key;
}
static int Key_compare( BPy_Key * a, BPy_Key * b )
{
return ( a->key == b->key ) ? 0 : -1;
}
static PyObject *Key_repr( BPy_Key * self )
{
return PyString_FromFormat( "[Key \"%s\"]", self->key->id.name + 2 );

View File

@@ -1431,8 +1431,7 @@ static void Lamp_dealloc( BPy_Lamp * self )
/*****************************************************************************/
static int Lamp_compare( BPy_Lamp * a, BPy_Lamp * b )
{
Lamp *pa = a->lamp, *pb = b->lamp;
return ( pa == pb ) ? 0 : -1;
return ( a->lamp == b->lamp ) ? 0 : -1;
}
/*****************************************************************************/

View File

@@ -193,6 +193,7 @@ static void Lattice_dealloc( BPy_Lattice * self );
static int Lattice_setAttr( BPy_Lattice * self, char *name, PyObject * v );
static PyObject *Lattice_getAttr( BPy_Lattice * self, char *name );
static PyObject *Lattice_repr( BPy_Lattice * self );
static int Lattice_compare( BPy_Lattice * a, BPy_Lattice * b );
/*****************************************************************************/
/* Python Lattice_Type structure definition: */
@@ -208,7 +209,7 @@ PyTypeObject Lattice_Type = {
0, /* tp_print */
( getattrfunc ) Lattice_getAttr, /* tp_getattr */
( setattrfunc ) Lattice_setAttr, /* tp_setattr */
0, /* tp_compare */
( cmpfunc ) Lattice_compare, /* tp_compare */
( reprfunc ) Lattice_repr, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
@@ -927,6 +928,13 @@ static int Lattice_setAttr( BPy_Lattice * self, char *name, PyObject * value )
return 0; // normal exit
}
static int Lattice_compare( BPy_Lattice * a, BPy_Lattice * b )
{
return ( a->Lattice == b->Lattice ) ? 0 : -1;
}
//***************************************************************************
// Function: Lattice_repr
// Description: This is a callback function for the BPy_Lattice type. It

View File

@@ -1081,6 +1081,7 @@ static PyGetSetDef BPy_Material_getseters[] = {
/* Python Material_Type callback function prototypes: */
/*****************************************************************************/
static void Material_dealloc( BPy_Material * self );
static int Material_compare( BPy_Material * a, BPy_Material * b);
static PyObject *Material_repr( BPy_Material * self );
/*****************************************************************************/
@@ -1100,7 +1101,7 @@ PyTypeObject Material_Type = {
NULL, /* printfunc tp_print; */
NULL, /* getattrfunc tp_getattr; */
NULL, /* setattrfunc tp_setattr; */
NULL, /* cmpfunc tp_compare; */
( cmpfunc ) Material_compare,/* cmpfunc tp_compare; */
( reprfunc ) Material_repr, /* reprfunc tp_repr; */
/* Method suites for standard classes */
@@ -2501,6 +2502,12 @@ static PyObject *Material_copy( BPy_Material * self )
return ( PyObject * ) pymat;
}
/* mat_a==mat_b or mat_a!=mat_b*/
static int Material_compare( BPy_Material * a, BPy_Material * b )
{
return ( a->material == b->material) ? 0 : -1;
}
/*****************************************************************************/
/* Function: Material_repr */
/* Description: This is a callback function for the BPy_Material type. It */

View File

@@ -7361,6 +7361,11 @@ static void Mesh_dealloc( BPy_Mesh * self )
PyObject_DEL( self );
}
static int Mesh_compare( BPy_Mesh * a, BPy_Mesh * b )
{
return ( a->mesh == b->mesh ) ? 0 : -1;
}
static PyObject *Mesh_repr( BPy_Mesh * self )
{
return PyString_FromFormat( "[Mesh \"%s\"]",
@@ -7472,7 +7477,7 @@ PyTypeObject Mesh_Type = {
NULL, /* printfunc tp_print; */
NULL, /* getattrfunc tp_getattr; */
NULL, /* setattrfunc tp_setattr; */
NULL, /* cmpfunc tp_compare; */
( cmpfunc ) Mesh_compare, /* cmpfunc tp_compare; */
( reprfunc ) Mesh_repr, /* reprfunc tp_repr; */
/* Method suites for standard classes */

View File

@@ -124,8 +124,10 @@ static PyMethodDef BPy_Action_methods[] = {
static void Action_dealloc( BPy_Action * bone );
static PyObject *Action_getAttr( BPy_Action * bone, char *name );
static int Action_setAttr( BPy_Action * bone, char *name, PyObject * v );
static int Action_compare( BPy_Action * a, BPy_Action * b );
static PyObject *Action_repr( BPy_Action * bone );
/*****************************************************************************/
/* Python TypeAction structure definition: */
/*****************************************************************************/
@@ -140,7 +142,7 @@ PyTypeObject Action_Type = {
0, /* tp_print */
( getattrfunc ) Action_getAttr, /* tp_getattr */
( setattrfunc ) Action_setAttr, /* tp_setattr */
0, /* tp_compare */
( cmpfunc ) Action_compare, /* tp_compare */
( reprfunc ) Action_repr, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
@@ -495,6 +497,13 @@ static int Action_setAttr( BPy_Action * self, char *name, PyObject * value )
return 0; /* normal exit */
}
/*----------------------------------------------------------------------*/
static int Action_compare( BPy_Action * a, BPy_Action * b )
{
return ( a->action == b->action ) ? 0 : -1;
}
/*----------------------------------------------------------------------*/
static PyObject *Action_repr( BPy_Action * self )
{

View File

@@ -3061,8 +3061,7 @@ static void Object_dealloc( BPy_Object * obj )
/*****************************************************************************/
static int Object_compare( BPy_Object * a, BPy_Object * b )
{
Object *pa = a->object, *pb = b->object;
return ( pa == pb ) ? 0 : -1;
return ( a->object == b->object ) ? 0 : -1;
}
/*****************************************************************************/

View File

@@ -332,6 +332,12 @@ static void Pose_dealloc(BPy_Pose *self)
Pose_Type.tp_free(self);
return;
}
//------------------------tp_cmp
//This compares 2 pose types
static int Pose_compare(BPy_Pose *a, BPy_Pose *b )
{
return ( a->pose== b->pose ) ? 0 : -1;
}
//------------------------tp_repr
//This is the string representation of the object
static PyObject *Pose_repr(BPy_Pose *self)

View File

@@ -356,8 +356,7 @@ static int Scene_setAttr( BPy_Scene * self, char *name, PyObject * value )
/*-----------------------compare----------------------------------------*/
static int Scene_compare( BPy_Scene * a, BPy_Scene * b )
{
Scene *pa = a->scene, *pb = b->scene;
return ( pa == pb ) ? 0 : -1;
return ( a->scene == b->scene ) ? 0 : -1;
}
/*----------------------repr--------------------------------------------*/
@@ -1548,8 +1547,7 @@ static void SceneObSeq_dealloc( BPy_SceneObSeq * self )
static int SceneObSeq_compare( BPy_SceneObSeq * a, BPy_SceneObSeq * b )
{
Scene *pa = a->bpyscene->scene, *pb = b->bpyscene->scene;
return ( pa == pb && a->mode == b->mode) ? 0 : -1;
return ( a->bpyscene->scene == b->bpyscene->scene && a->mode == b->mode) ? 0 : -1;
}
/*

View File

@@ -632,8 +632,7 @@ static int Sound_setAttr( BPy_Sound * self, char *name, PyObject * value )
/*****************************************************************************/
static int Sound_compare( BPy_Sound * a, BPy_Sound * b )
{
bSound *pa = a->sound, *pb = b->sound;
return ( pa == pb ) ? 0 : -1;
return ( a->sound == b->sound ) ? 0 : -1;
}
/*****************************************************************************/

View File

@@ -638,8 +638,7 @@ static int Text_setAttr( BPy_Text * self, char *name, PyObject * value )
/*****************************************************************************/
static int Text_compare( BPy_Text * a, BPy_Text * b )
{
Text *pa = a->text, *pb = b->text;
return ( pa == pb ) ? 0 : -1;
return ( a->text == b->text ) ? 0 : -1;
}
/*****************************************************************************/

View File

@@ -1033,8 +1033,7 @@ static int World_SetAttr( BPy_World * self, char *name, PyObject * value )
static int World_Compare( BPy_World * a, BPy_World * b )
{
World *pa = a->world, *pb = b->world;
return ( pa == pb ) ? 0 : -1;
return ( a->world == b->world ) ? 0 : -1;
}
/**

View File

@@ -465,7 +465,7 @@ class Object:
@type drawType: int
@ivar parentType: The object's parent type. Read-only.
See L{ParentTypes} constant dict for values.
@type drawType: int
@type parentType: int
@ivar axis: Enable display of active object's center and axis.
Also see B{AXIS} bit in L{drawMode} attribute.
@type axis: boolean