=IDProperties Python update=

Updated id properties interface as per
discussed in python meeting.  Basically,
id properties are now entirely accessed
through the dict-like interface if IDGroupType.
Also, tp_getsetters are used throughout the code
now.

Using the dict interface allowed for a major cleanup
of the wrapping code.  The biggest change is that ID
properties are no longer wrapped in a structure with 
.type .name and .data members; instead when you get
properties from the group it returns the direct value.
Ints, strings and floats return simple python types,
while arrays and groups return special wrappers though.

This means to detect the type of an ID property, you
have to use type().  For string and int types this is
easy; for group and array types (which of course have
their own wrappers) you use type() with Blender.IDGroupType
or Blender.IDArrayType.

Update of epydocs plus a temporary gui script will be
forthcoming; the gui script will be removed before release
as of course by then we'll have a built-in gui for id
properties.
This commit is contained in:
Joseph Eagar 2006-12-16 23:54:45 +00:00
parent 47ee194922
commit 3a84791b53
5 changed files with 417 additions and 559 deletions

View File

@ -95,6 +95,10 @@ be reorganized to work properly.
*/
int IDP_AddToGroup(struct IDProperty *group, struct IDProperty *prop);
/*this is the same as IDP_AddToGroup, only you pass an item
in the group list to be inserted after.*/
int IDP_InsertToGroup(struct IDProperty *group, struct IDProperty *previous,
struct IDProperty *pnew);
/*NOTE: this does not free the property!!

View File

@ -182,6 +182,19 @@ int IDP_AddToGroup(IDProperty *group, IDProperty *prop)
return 1;
}
int IDP_InsertToGroup(IDProperty *group, IDProperty *previous, IDProperty *pnew)
{
IDProperty *loop;
for (loop=group->data.group.first; loop; loop=loop->next) {
if (BSTR_EQ(loop->name, pnew->name)) return 0;
}
group->len++;
BLI_insertlink(&group->data.group, previous, pnew);
return 1;
}
void IDP_RemFromGroup(IDProperty *group, IDProperty *prop)
{
group->len--;

View File

@ -907,6 +907,10 @@ static PyObject *Blender_UnpackModesDict( void )
/*****************************************************************************/
/* Function: initBlender */
/*****************************************************************************/
extern PyTypeObject IDArray_Type;
extern PyTypeObject IDGroup_Type;
extern PyTypeObject IDGroup_Iter_Type;
void M_Blender_Init(void)
{
PyObject *module;
@ -971,6 +975,9 @@ void M_Blender_Init(void)
EXPP_dict_set_item_str(dict, "event", PyString_FromString(""));
EXPP_dict_set_item_str(dict, "mode", smode);
PyDict_SetItemString(dict, "IDGroupType", &IDGroup_Type);
PyDict_SetItemString(dict, "IDArrayType", &IDArray_Type);
PyDict_SetItemString(dict, "Armature", Armature_Init());
PyDict_SetItemString(dict, "BezTriple", BezTriple_Init());
PyDict_SetItemString(dict, "BGL", BGL_Init());

File diff suppressed because it is too large Load Diff

View File

@ -51,7 +51,11 @@ typedef struct BPy_IDGroup_Iter {
PyObject_VAR_HEAD
BPy_IDProperty *group;
struct IDProperty *cur;
int mode;
} BPy_IDGroup_Iter;
PyObject *BPy_Wrap_IDProperty(struct ID *id, struct IDProperty *prop, struct IDProperty *parent);
void IDProp_Init_Types(void);
#define IDPROP_ITER_KEYS 0
#define IDPROP_ITER_ITEMS 1