forked from bartvdbraak/blender
my chnges broke 'del idprop["key"]'
made it possible to remove properties from rna types. eg. del group["someprop"]
This commit is contained in:
parent
98d4a56d55
commit
3087da0b25
@ -65,7 +65,7 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult
|
|||||||
"selected_editable_objects", "selected_editable_bases",
|
"selected_editable_objects", "selected_editable_bases",
|
||||||
"visible_bones", "editable_bones", "selected_bones", "selected_editable_bones",
|
"visible_bones", "editable_bones", "selected_bones", "selected_editable_bones",
|
||||||
"visible_pchans", "selected_pchans", "active_bone", "active_pchan",
|
"visible_pchans", "selected_pchans", "active_bone", "active_pchan",
|
||||||
"active_base", "active_object", "edit_object",
|
"active_base", "active_object", "object", "edit_object",
|
||||||
"sculpt_object", "vertex_paint_object", "weight_paint_object",
|
"sculpt_object", "vertex_paint_object", "weight_paint_object",
|
||||||
"texture_paint_object", "particle_edit_object", NULL};
|
"texture_paint_object", "particle_edit_object", NULL};
|
||||||
|
|
||||||
|
@ -307,24 +307,17 @@ char *BPy_IDProperty_Map_ValidateAndCreate(char *name, IDProperty *group, PyObje
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int BPy_IDGroup_Map_SetItem(BPy_IDProperty *self, PyObject *key, PyObject *val)
|
int BPy_Wrap_SetMapItem(IDProperty *prop, PyObject *key, PyObject *val)
|
||||||
{
|
{
|
||||||
char *err;
|
if (prop->type != IDP_GROUP) {
|
||||||
|
|
||||||
if (self->prop->type != IDP_GROUP) {
|
|
||||||
PyErr_SetString( PyExc_TypeError, "unsubscriptable object");
|
PyErr_SetString( PyExc_TypeError, "unsubscriptable object");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!PyUnicode_Check(key)) {
|
if (val == NULL) { /* del idprop[key] */
|
||||||
PyErr_SetString( PyExc_TypeError, "only strings are allowed as subgroup keys" );
|
IDProperty *pkey = IDP_GetPropertyFromGroup(prop, _PyUnicode_AsString(key));
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (val == NULL) {
|
|
||||||
IDProperty *pkey = IDP_GetPropertyFromGroup(self->prop, _PyUnicode_AsString(key));
|
|
||||||
if (pkey) {
|
if (pkey) {
|
||||||
IDP_RemFromGroup(self->prop, pkey);
|
IDP_RemFromGroup(prop, pkey);
|
||||||
IDP_FreeProperty(pkey);
|
IDP_FreeProperty(pkey);
|
||||||
MEM_freeN(pkey);
|
MEM_freeN(pkey);
|
||||||
return 0;
|
return 0;
|
||||||
@ -333,14 +326,27 @@ static int BPy_IDGroup_Map_SetItem(BPy_IDProperty *self, PyObject *key, PyObject
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
char *err;
|
||||||
|
|
||||||
err = BPy_IDProperty_Map_ValidateAndCreate(_PyUnicode_AsString(key), self->prop, val);
|
if (!PyUnicode_Check(key)) {
|
||||||
|
PyErr_SetString( PyExc_TypeError, "only strings are allowed as subgroup keys" );
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = BPy_IDProperty_Map_ValidateAndCreate(_PyUnicode_AsString(key), prop, val);
|
||||||
if (err) {
|
if (err) {
|
||||||
PyErr_SetString( PyExc_RuntimeError, err );
|
PyErr_SetString( PyExc_RuntimeError, err );
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int BPy_IDGroup_Map_SetItem(BPy_IDProperty *self, PyObject *key, PyObject *val)
|
||||||
|
{
|
||||||
|
BPy_Wrap_SetMapItem(self->prop, key, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *BPy_IDGroup_SpawnIterator(BPy_IDProperty *self)
|
static PyObject *BPy_IDGroup_SpawnIterator(BPy_IDProperty *self)
|
||||||
|
@ -52,6 +52,7 @@ PyObject *BPy_Wrap_IDProperty(struct ID *id, struct IDProperty *prop, struct IDP
|
|||||||
PyObject *BPy_Wrap_GetKeys(IDProperty *prop);
|
PyObject *BPy_Wrap_GetKeys(IDProperty *prop);
|
||||||
PyObject *BPy_Wrap_GetValues(ID *id, IDProperty *prop);
|
PyObject *BPy_Wrap_GetValues(ID *id, IDProperty *prop);
|
||||||
PyObject *BPy_Wrap_GetItems(ID *id, IDProperty *prop);
|
PyObject *BPy_Wrap_GetItems(ID *id, IDProperty *prop);
|
||||||
|
int BPy_Wrap_SetMapItem(IDProperty *prop, PyObject *key, PyObject *val);
|
||||||
|
|
||||||
|
|
||||||
PyObject *BPy_IDGroup_WrapData( ID *id, IDProperty *prop );
|
PyObject *BPy_IDGroup_WrapData( ID *id, IDProperty *prop );
|
||||||
|
@ -1225,35 +1225,18 @@ static PyObject *pyrna_struct_subscript( BPy_StructRNA *self, PyObject *key )
|
|||||||
}
|
}
|
||||||
|
|
||||||
return BPy_IDGroup_WrapData(self->ptr.id.data, idprop);
|
return BPy_IDGroup_WrapData(self->ptr.id.data, idprop);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int pyrna_struct_ass_subscript( BPy_StructRNA *self, PyObject *key, PyObject *value )
|
static int pyrna_struct_ass_subscript( BPy_StructRNA *self, PyObject *key, PyObject *value )
|
||||||
{
|
{
|
||||||
IDProperty *group;
|
IDProperty *group= RNA_struct_idproperties(&self->ptr, 1);
|
||||||
char *name= _PyUnicode_AsString(key);
|
|
||||||
char *err;
|
|
||||||
|
|
||||||
if(name==NULL) {
|
|
||||||
PyErr_SetString( PyExc_TypeError, "only strings are allowed as keys of ID properties");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
group= RNA_struct_idproperties(&self->ptr, 1);
|
|
||||||
|
|
||||||
if(group==NULL) {
|
if(group==NULL) {
|
||||||
PyErr_SetString(PyExc_TypeError, "id properties not supported for this type");
|
PyErr_SetString(PyExc_TypeError, "id properties not supported for this type");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = BPy_IDProperty_Map_ValidateAndCreate(_PyUnicode_AsString(key), group, value);
|
return BPy_Wrap_SetMapItem(group, key, value);
|
||||||
if (err) {
|
|
||||||
PyErr_SetString( PyExc_RuntimeError, err );
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyMappingMethods pyrna_struct_as_mapping = {
|
static PyMappingMethods pyrna_struct_as_mapping = {
|
||||||
|
Loading…
Reference in New Issue
Block a user