diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-08-19 14:16:30 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-08-19 14:16:30 +0400 |
commit | 4e3390437ea9a632339b47d3a99866b6c98f74af (patch) | |
tree | 21297caa5f67dcb0f52a79420019804a1d2be8dc | |
parent | 98140e234e6d88dc301a3d8663ef54b56520020f (diff) |
- Properties from base classes are now registered too, this allows class mix-in's to define properties.
An example of how this is useful - an importer mixin could define the filepath properties and a generic invoke function which can run the subclasses exec for each selected file.
- Panels and Menus now skip the property check when registering.
- renamed _idproperties_ to _idprops_ in function names, function names were getting very long.
-rw-r--r-- | release/scripts/ui/properties_physics_fluid.py | 2 | ||||
-rw-r--r-- | source/blender/makesrna/RNA_access.h | 5 | ||||
-rw-r--r-- | source/blender/makesrna/RNA_define.h | 2 | ||||
-rw-r--r-- | source/blender/makesrna/RNA_types.h | 3 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_ID.c | 8 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_access.c | 37 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_armature.c | 8 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_define.c | 4 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_internal.h | 4 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_pose.c | 4 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_rna.c | 4 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_ui.c | 2 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_wm.c | 4 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_operator_wrap.c | 19 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna.c | 103 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna.h | 2 |
16 files changed, 122 insertions, 89 deletions
diff --git a/release/scripts/ui/properties_physics_fluid.py b/release/scripts/ui/properties_physics_fluid.py index 00e6aac1bce..dc4fc90e6b6 100644 --- a/release/scripts/ui/properties_physics_fluid.py +++ b/release/scripts/ui/properties_physics_fluid.py @@ -69,7 +69,7 @@ class PHYSICS_PT_fluid(PhysicButtonsPanel, bpy.types.Panel): layout = layout.column() if fluid.type not in ('NONE', 'DOMAIN', 'PARTICLE'): - layout.active = fluid.active + layout.active = fluid.use if fluid.type == 'DOMAIN': layout.operator("fluid.bake", text="Bake Fluid Simulation", icon='MOD_FLUIDSIM') diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index cbd2d7ec5b3..43697ec5d9e 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -607,8 +607,9 @@ void RNA_struct_py_type_set(StructRNA *srna, void *py_type); void *RNA_struct_blender_type_get(StructRNA *srna); void RNA_struct_blender_type_set(StructRNA *srna, void *blender_type); -struct IDProperty *RNA_struct_idproperties(PointerRNA *ptr, int create); -int RNA_struct_idproperties_check(StructRNA *srna); +struct IDProperty *RNA_struct_idprops(PointerRNA *ptr, int create); +int RNA_struct_idprops_check(StructRNA *srna); +int RNA_struct_idprops_register_check(StructRNA *type); PropertyRNA *RNA_struct_find_property(PointerRNA *ptr, const char *identifier); diff --git a/source/blender/makesrna/RNA_define.h b/source/blender/makesrna/RNA_define.h index 9aadd8900e5..f6ae5dcdbbd 100644 --- a/source/blender/makesrna/RNA_define.h +++ b/source/blender/makesrna/RNA_define.h @@ -57,7 +57,7 @@ void RNA_def_struct_nested(BlenderRNA *brna, StructRNA *srna, const char *struct void RNA_def_struct_flag(StructRNA *srna, int flag); void RNA_def_struct_clear_flag(StructRNA *srna, int flag); void RNA_def_struct_refine_func(StructRNA *srna, const char *refine); -void RNA_def_struct_idproperties_func(StructRNA *srna, const char *refine); +void RNA_def_struct_idprops_func(StructRNA *srna, const char *refine); void RNA_def_struct_register_funcs(StructRNA *srna, const char *reg, const char *unreg); void RNA_def_struct_path_func(StructRNA *srna, const char *path); void RNA_def_struct_identifier(StructRNA *srna, const char *identifier); diff --git a/source/blender/makesrna/RNA_types.h b/source/blender/makesrna/RNA_types.h index 88058769f4b..887069d6c00 100644 --- a/source/blender/makesrna/RNA_types.h +++ b/source/blender/makesrna/RNA_types.h @@ -298,7 +298,8 @@ typedef enum StructFlag { /* internal flags */ STRUCT_RUNTIME = 4, STRUCT_GENERATED = 8, - STRUCT_FREE_POINTERS = 16 + STRUCT_FREE_POINTERS = 16, + STRUCT_NO_IDPROPERTIES = 32, /* Menu's and Panels don't need properties */ } StructFlag; typedef int (*StructValidateFunc)(struct PointerRNA *ptr, void *data, int *have_function); diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c index e0bfb9bd03d..a8b7fb1540b 100644 --- a/source/blender/makesrna/intern/rna_ID.c +++ b/source/blender/makesrna/intern/rna_ID.c @@ -176,7 +176,7 @@ StructRNA *rna_ID_refine(PointerRNA *ptr) return ID_code_to_RNA_type(GS(id->name)); } -IDProperty *rna_ID_idproperties(PointerRNA *ptr, int create) +IDProperty *rna_ID_idprops(PointerRNA *ptr, int create) { return IDP_GetProperties(ptr->data, create); } @@ -195,7 +195,7 @@ void rna_ID_fake_user_set(PointerRNA *ptr, int value) } } -IDProperty *rna_IDPropertyGroup_idproperties(PointerRNA *ptr, int create) +IDProperty *rna_IDPropertyGroup_idprops(PointerRNA *ptr, int create) { return ptr->data; } @@ -317,7 +317,7 @@ static void rna_def_ID_properties(BlenderRNA *brna) * care of the properties here */ srna= RNA_def_struct(brna, "IDPropertyGroup", NULL); RNA_def_struct_ui_text(srna, "ID Property Group", "Group of ID properties"); - RNA_def_struct_idproperties_func(srna, "rna_IDPropertyGroup_idproperties"); + RNA_def_struct_idprops_func(srna, "rna_IDPropertyGroup_idprops"); RNA_def_struct_register_funcs(srna, "rna_IDPropertyGroup_register", "rna_IDPropertyGroup_unregister"); RNA_def_struct_refine_func(srna, "rna_IDPropertyGroup_refine"); @@ -341,7 +341,7 @@ static void rna_def_ID(BlenderRNA *brna) RNA_def_struct_ui_text(srna, "ID", "Base type for datablocks, defining a unique name, linking from other libraries and garbage collection"); RNA_def_struct_flag(srna, STRUCT_ID|STRUCT_ID_REFCOUNT); RNA_def_struct_refine_func(srna, "rna_ID_refine"); - RNA_def_struct_idproperties_func(srna, "rna_ID_idproperties"); + RNA_def_struct_idprops_func(srna, "rna_ID_idprops"); prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); RNA_def_property_ui_text(prop, "Name", "Unique datablock ID name"); diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index 050f00b6a38..73af75ca960 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -241,7 +241,7 @@ IDProperty *rna_idproperty_ui(PropertyRNA *prop) return NULL; } -IDProperty *RNA_struct_idproperties(PointerRNA *ptr, int create) +IDProperty *RNA_struct_idprops(PointerRNA *ptr, int create) { StructRNA *type= ptr->type; @@ -251,14 +251,14 @@ IDProperty *RNA_struct_idproperties(PointerRNA *ptr, int create) return NULL; } -int RNA_struct_idproperties_check(StructRNA *srna) +int RNA_struct_idprops_check(StructRNA *srna) { return (srna && srna->idproperties) ? 1 : 0; } static IDProperty *rna_idproperty_find(PointerRNA *ptr, const char *name) { - IDProperty *group= RNA_struct_idproperties(ptr, 0); + IDProperty *group= RNA_struct_idprops(ptr, 0); if(group) return IDP_GetPropertyFromGroup(group, name); @@ -387,7 +387,7 @@ IDProperty *rna_idproperty_check(PropertyRNA **prop, PointerRNA *ptr) IDProperty *idprop= rna_idproperty_find(ptr, (*prop)->identifier); if(idprop && !rna_idproperty_verify_valid(ptr, *prop, idprop)) { - IDProperty *group= RNA_struct_idproperties(ptr, 0); + IDProperty *group= RNA_struct_idprops(ptr, 0); IDP_RemFromGroup(group, idprop); IDP_FreeProperty(idprop); @@ -510,6 +510,11 @@ int RNA_struct_is_ID(StructRNA *type) return (type->flag & STRUCT_ID) != 0; } +int RNA_struct_idprops_register_check(StructRNA *type) +{ + return (type->flag & STRUCT_NO_IDPROPERTIES) == 0; +} + int RNA_struct_is_a(StructRNA *type, StructRNA *srna) { StructRNA *base; @@ -1305,7 +1310,7 @@ void RNA_property_boolean_set(PointerRNA *ptr, PropertyRNA *prop, int value) val.i= value; - group= RNA_struct_idproperties(ptr, 1); + group= RNA_struct_idprops(ptr, 1); if(group) IDP_AddToGroup(group, IDP_New(IDP_INT, val, (char*)prop->identifier)); } @@ -1375,7 +1380,7 @@ void RNA_property_boolean_set_array(PointerRNA *ptr, PropertyRNA *prop, const in val.array.len= prop->totarraylength; val.array.type= IDP_INT; - group= RNA_struct_idproperties(ptr, 1); + group= RNA_struct_idprops(ptr, 1); if(group) { idprop= IDP_New(IDP_ARRAY, val, (char*)prop->identifier); IDP_AddToGroup(group, idprop); @@ -1472,7 +1477,7 @@ void RNA_property_int_set(PointerRNA *ptr, PropertyRNA *prop, int value) val.i= value; - group= RNA_struct_idproperties(ptr, 1); + group= RNA_struct_idprops(ptr, 1); if(group) IDP_AddToGroup(group, IDP_New(IDP_INT, val, (char*)prop->identifier)); } @@ -1542,7 +1547,7 @@ void RNA_property_int_set_array(PointerRNA *ptr, PropertyRNA *prop, const int *v val.array.len= prop->totarraylength; val.array.type= IDP_INT; - group= RNA_struct_idproperties(ptr, 1); + group= RNA_struct_idprops(ptr, 1); if(group) { idprop= IDP_New(IDP_ARRAY, val, (char*)prop->identifier); IDP_AddToGroup(group, idprop); @@ -1648,7 +1653,7 @@ void RNA_property_float_set(PointerRNA *ptr, PropertyRNA *prop, float value) val.f= value; - group= RNA_struct_idproperties(ptr, 1); + group= RNA_struct_idprops(ptr, 1); if(group) IDP_AddToGroup(group, IDP_New(IDP_FLOAT, val, (char*)prop->identifier)); } @@ -1736,7 +1741,7 @@ void RNA_property_float_set_array(PointerRNA *ptr, PropertyRNA *prop, const floa val.array.len= prop->totarraylength; val.array.type= IDP_FLOAT; - group= RNA_struct_idproperties(ptr, 1); + group= RNA_struct_idprops(ptr, 1); if(group) { idprop= IDP_New(IDP_ARRAY, val, (char*)prop->identifier); IDP_AddToGroup(group, idprop); @@ -1861,7 +1866,7 @@ void RNA_property_string_set(PointerRNA *ptr, PropertyRNA *prop, const char *val else if(prop->flag & PROP_EDITABLE) { IDProperty *group; - group= RNA_struct_idproperties(ptr, 1); + group= RNA_struct_idprops(ptr, 1); if(group) IDP_AddToGroup(group, IDP_NewString((char*)value, (char*)prop->identifier, RNA_property_string_maxlength(prop) - 1)); } @@ -1926,7 +1931,7 @@ void RNA_property_enum_set(PointerRNA *ptr, PropertyRNA *prop, int value) val.i= value; - group= RNA_struct_idproperties(ptr, 1); + group= RNA_struct_idprops(ptr, 1); if(group) IDP_AddToGroup(group, IDP_New(IDP_INT, val, (char*)prop->identifier)); } @@ -1999,7 +2004,7 @@ void RNA_property_pointer_add(PointerRNA *ptr, PropertyRNA *prop) val.i= 0; - group= RNA_struct_idproperties(ptr, 1); + group= RNA_struct_idprops(ptr, 1); if(group) IDP_AddToGroup(group, IDP_New(IDP_GROUP, val, (char*)prop->identifier)); } @@ -2012,7 +2017,7 @@ void RNA_property_pointer_remove(PointerRNA *ptr, PropertyRNA *prop) IDProperty *idprop, *group; if((idprop=rna_idproperty_check(&prop, ptr))) { - group= RNA_struct_idproperties(ptr, 0); + group= RNA_struct_idprops(ptr, 0); if(group) { IDP_RemFromGroup(group, idprop); @@ -2125,7 +2130,7 @@ void RNA_property_collection_add(PointerRNA *ptr, PropertyRNA *prop, PointerRNA IDProperty *group, *item; IDPropertyTemplate val = {0}; - group= RNA_struct_idproperties(ptr, 1); + group= RNA_struct_idprops(ptr, 1); if(group) { idprop= IDP_NewIDPArray(prop->identifier); IDP_AddToGroup(group, idprop); @@ -2965,7 +2970,7 @@ int RNA_path_resolve_full(PointerRNA *ptr, const char *path, PointerRNA *r_ptr, return 0; if(use_id_prop) { /* look up property name in current struct */ - IDProperty *group= RNA_struct_idproperties(&curptr, 0); + IDProperty *group= RNA_struct_idprops(&curptr, 0); if(group && rna_token_strip_quotes(token)) prop= (PropertyRNA *)IDP_GetPropertyFromGroup(group, token+1); } diff --git a/source/blender/makesrna/intern/rna_armature.c b/source/blender/makesrna/intern/rna_armature.c index 3217e73e3fb..a2f75a63163 100644 --- a/source/blender/makesrna/intern/rna_armature.c +++ b/source/blender/makesrna/intern/rna_armature.c @@ -123,7 +123,7 @@ static char *rna_Bone_path(PointerRNA *ptr) return BLI_sprintfN("bones[\"%s\"]", ((Bone*)ptr->data)->name); } -static IDProperty *rna_Bone_idproperties(PointerRNA *ptr, int create) +static IDProperty *rna_Bone_idprops(PointerRNA *ptr, int create) { Bone *bone= ptr->data; @@ -135,7 +135,7 @@ static IDProperty *rna_Bone_idproperties(PointerRNA *ptr, int create) return bone->prop; } -static IDProperty *rna_EditBone_idproperties(PointerRNA *ptr, int create) +static IDProperty *rna_EditBone_idprops(PointerRNA *ptr, int create) { EditBone *ebone= ptr->data; @@ -504,7 +504,7 @@ static void rna_def_bone(BlenderRNA *brna) RNA_def_struct_ui_text(srna, "Bone", "Bone in an Armature datablock"); RNA_def_struct_ui_icon(srna, ICON_BONE_DATA); RNA_def_struct_path_func(srna, "rna_Bone_path"); - RNA_def_struct_idproperties_func(srna, "rna_Bone_idproperties"); + RNA_def_struct_idprops_func(srna, "rna_Bone_idprops"); /* pointers/collections */ /* parent (pointer) */ @@ -572,7 +572,7 @@ static void rna_def_edit_bone(BlenderRNA *brna) srna= RNA_def_struct(brna, "EditBone", NULL); RNA_def_struct_sdna(srna, "EditBone"); - RNA_def_struct_idproperties_func(srna, "rna_EditBone_idproperties"); + RNA_def_struct_idprops_func(srna, "rna_EditBone_idprops"); RNA_def_struct_ui_text(srna, "Edit Bone", "Editmode bone in an Armature datablock"); RNA_def_struct_ui_icon(srna, ICON_BONE_DATA); diff --git a/source/blender/makesrna/intern/rna_define.c b/source/blender/makesrna/intern/rna_define.c index 6080d02a1c7..43bf40d3965 100644 --- a/source/blender/makesrna/intern/rna_define.c +++ b/source/blender/makesrna/intern/rna_define.c @@ -781,10 +781,10 @@ void RNA_def_struct_refine_func(StructRNA *srna, const char *refine) if(refine) srna->refine= (StructRefineFunc)refine; } -void RNA_def_struct_idproperties_func(StructRNA *srna, const char *idproperties) +void RNA_def_struct_idprops_func(StructRNA *srna, const char *idproperties) { if(!DefRNA.preprocess) { - fprintf(stderr, "RNA_def_struct_idproperties_func: only during preprocessing.\n"); + fprintf(stderr, "RNA_def_struct_idprops_func: only during preprocessing.\n"); return; } diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h index 1a7036c7a36..669fc5d3871 100644 --- a/source/blender/makesrna/intern/rna_internal.h +++ b/source/blender/makesrna/intern/rna_internal.h @@ -189,9 +189,9 @@ void rna_ID_name_get(struct PointerRNA *ptr, char *value); int rna_ID_name_length(struct PointerRNA *ptr); void rna_ID_name_set(struct PointerRNA *ptr, const char *value); struct StructRNA *rna_ID_refine(struct PointerRNA *ptr); -struct IDProperty *rna_ID_idproperties(struct PointerRNA *ptr, int create); +struct IDProperty *rna_ID_idprops(struct PointerRNA *ptr, int create); void rna_ID_fake_user_set(struct PointerRNA *ptr, int value); -struct IDProperty *rna_IDPropertyGroup_idproperties(struct PointerRNA *ptr, int create); +struct IDProperty *rna_IDPropertyGroup_idprops(struct PointerRNA *ptr, int create); void rna_IDPropertyGroup_unregister(const struct bContext *C, struct StructRNA *type); struct StructRNA *rna_IDPropertyGroup_register(const struct bContext *C, struct ReportList *reports, void *data, const char *identifier, StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free); struct StructRNA* rna_IDPropertyGroup_refine(struct PointerRNA *ptr); diff --git a/source/blender/makesrna/intern/rna_pose.c b/source/blender/makesrna/intern/rna_pose.c index 41adaa7047c..18d0b5658d0 100644 --- a/source/blender/makesrna/intern/rna_pose.c +++ b/source/blender/makesrna/intern/rna_pose.c @@ -120,7 +120,7 @@ static void rna_BoneGroup_color_set_set(PointerRNA *ptr, int value) } } -static IDProperty *rna_PoseBone_idproperties(PointerRNA *ptr, int create) +static IDProperty *rna_PoseBone_idprops(PointerRNA *ptr, int create) { bPoseChannel *pchan= ptr->data; @@ -685,7 +685,7 @@ static void rna_def_pose_channel(BlenderRNA *brna) RNA_def_struct_sdna(srna, "bPoseChannel"); RNA_def_struct_ui_text(srna, "Pose Bone", "Channel defining pose data for a bone in a Pose"); RNA_def_struct_path_func(srna, "rna_PoseBone_path"); - RNA_def_struct_idproperties_func(srna, "rna_PoseBone_idproperties"); + RNA_def_struct_idprops_func(srna, "rna_PoseBone_idprops"); /* Bone Constraints */ prop= RNA_def_property(srna, "constraints", PROP_COLLECTION, PROP_NONE); diff --git a/source/blender/makesrna/intern/rna_rna.c b/source/blender/makesrna/intern/rna_rna.c index 5c8de9c4587..4bfd0e4fd41 100644 --- a/source/blender/makesrna/intern/rna_rna.c +++ b/source/blender/makesrna/intern/rna_rna.c @@ -201,7 +201,7 @@ static void rna_Struct_properties_next(CollectionPropertyIterator *iter) /* try id properties */ if(!iter->valid) { - group= RNA_struct_idproperties(&iter->builtin_parent, 0); + group= RNA_struct_idprops(&iter->builtin_parent, 0); if(group) { rna_iterator_listbase_end(iter); @@ -335,7 +335,7 @@ PointerRNA rna_builtin_properties_lookup_string(PointerRNA *ptr, const char *key if(ptr->data) { IDProperty *group, *idp; - group= RNA_struct_idproperties(ptr, 0); + group= RNA_struct_idprops(ptr, 0); if(group) { for(idp=group->data.group.first; idp; idp=idp->next) { diff --git a/source/blender/makesrna/intern/rna_ui.c b/source/blender/makesrna/intern/rna_ui.c index a9b2672e205..a659ff7c260 100644 --- a/source/blender/makesrna/intern/rna_ui.c +++ b/source/blender/makesrna/intern/rna_ui.c @@ -207,6 +207,7 @@ static StructRNA *rna_Panel_register(const bContext *C, ReportList *reports, voi pt->ext.call= call; pt->ext.free= free; RNA_struct_blender_type_set(pt->ext.srna, pt); + RNA_def_struct_flag(pt->ext.srna, STRUCT_NO_IDPROPERTIES); pt->poll= (have_function[0])? panel_poll: NULL; pt->draw= (have_function[1])? panel_draw: NULL; @@ -418,6 +419,7 @@ static StructRNA *rna_Menu_register(const bContext *C, ReportList *reports, void mt->ext.call= call; mt->ext.free= free; RNA_struct_blender_type_set(mt->ext.srna, mt); + RNA_def_struct_flag(mt->ext.srna, STRUCT_NO_IDPROPERTIES); mt->poll= (have_function[0])? menu_poll: NULL; mt->draw= (have_function[1])? menu_draw: NULL; diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c index 188eda32463..67b8ca057c8 100644 --- a/source/blender/makesrna/intern/rna_wm.c +++ b/source/blender/makesrna/intern/rna_wm.c @@ -324,7 +324,7 @@ static StructRNA *rna_OperatorProperties_refine(PointerRNA *ptr) return ptr->type; } -static IDProperty *rna_OperatorProperties_idproperties(PointerRNA *ptr, int create) +static IDProperty *rna_OperatorProperties_idprops(PointerRNA *ptr, int create) { if(create && !ptr->data) { IDPropertyTemplate val = {0}; @@ -1023,7 +1023,7 @@ static void rna_def_operator(BlenderRNA *brna) srna= RNA_def_struct(brna, "OperatorProperties", NULL); RNA_def_struct_ui_text(srna, "Operator Properties", "Input properties of an Operator"); RNA_def_struct_refine_func(srna, "rna_OperatorProperties_refine"); - RNA_def_struct_idproperties_func(srna, "rna_OperatorProperties_idproperties"); + RNA_def_struct_idprops_func(srna, "rna_OperatorProperties_idprops"); } static void rna_def_macro_operator(BlenderRNA *brna) diff --git a/source/blender/python/intern/bpy_operator_wrap.c b/source/blender/python/intern/bpy_operator_wrap.c index 1e521aea438..6d16896fb16 100644 --- a/source/blender/python/intern/bpy_operator_wrap.c +++ b/source/blender/python/intern/bpy_operator_wrap.c @@ -34,22 +34,15 @@ static void operator_properties_init(wmOperatorType *ot) { PyObject *py_class = ot->ext.data; - PyObject *item= ((PyTypeObject*)py_class)->tp_dict; /* getattr(..., "__dict__") returns a proxy */ - RNA_struct_blender_type_set(ot->ext.srna, ot); - if(item) { - /* only call this so pyrna_deferred_register_props gives a useful error - * WM_operatortype_append_ptr will call RNA_def_struct_identifier - * later */ - RNA_def_struct_identifier(ot->srna, ot->idname); + /* only call this so pyrna_deferred_register_class gives a useful error + * WM_operatortype_append_ptr will call RNA_def_struct_identifier + * later */ + RNA_def_struct_identifier(ot->srna, ot->idname); - if(pyrna_deferred_register_props(ot->srna, item) != 0) { - PyErr_Print(); /* failed to register operator props */ - PyErr_Clear(); - } - } - else { + if(pyrna_deferred_register_class(ot->srna, py_class) != 0) { + PyErr_Print(); /* failed to register operator props */ PyErr_Clear(); } } diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index cb5761c5df4..fd3b59a97f7 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -1663,12 +1663,12 @@ static int pyrna_struct_contains(BPy_StructRNA *self, PyObject *value) return -1; } - if(RNA_struct_idproperties_check(self->ptr.type)==0) { + if(RNA_struct_idprops_check(self->ptr.type)==0) { PyErr_SetString( PyExc_TypeError, "bpy_struct: this type doesnt support IDProperties"); return -1; } - group= RNA_struct_idproperties(&self->ptr, 0); + group= RNA_struct_idprops(&self->ptr, 0); if(!group) return 0; @@ -1721,7 +1721,7 @@ static PyObject *pyrna_struct_subscript( BPy_StructRNA *self, PyObject *key ) IDProperty *group, *idprop; char *name= _PyUnicode_AsString(key); - if(RNA_struct_idproperties_check(self->ptr.type)==0) { + if(RNA_struct_idprops_check(self->ptr.type)==0) { PyErr_SetString( PyExc_TypeError, "this type doesn't support IDProperties"); return NULL; } @@ -1731,7 +1731,7 @@ static PyObject *pyrna_struct_subscript( BPy_StructRNA *self, PyObject *key ) return NULL; } - group= RNA_struct_idproperties(&self->ptr, 0); + group= RNA_struct_idprops(&self->ptr, 0); if(group==NULL) { PyErr_Format( PyExc_KeyError, "bpy_struct[key]: key \"%s\" not found", name); @@ -1750,7 +1750,7 @@ static PyObject *pyrna_struct_subscript( BPy_StructRNA *self, PyObject *key ) static int pyrna_struct_ass_subscript( BPy_StructRNA *self, PyObject *key, PyObject *value ) { - IDProperty *group= RNA_struct_idproperties(&self->ptr, 1); + IDProperty *group= RNA_struct_idprops(&self->ptr, 1); if(group==NULL) { PyErr_SetString(PyExc_TypeError, "bpy_struct[key] = val: id properties not supported for this type"); @@ -1780,12 +1780,12 @@ static PyObject *pyrna_struct_keys(BPy_PropertyRNA *self) { IDProperty *group; - if(RNA_struct_idproperties_check(self->ptr.type)==0) { + if(RNA_struct_idprops_check(self->ptr.type)==0) { PyErr_SetString( PyExc_TypeError, "bpy_struct.keys(): this type doesn't support IDProperties"); return NULL; } - group= RNA_struct_idproperties(&self->ptr, 0); + group= RNA_struct_idprops(&self->ptr, 0); if(group==NULL) return PyList_New(0); @@ -1807,12 +1807,12 @@ static PyObject *pyrna_struct_items(BPy_PropertyRNA *self) { IDProperty *group; - if(RNA_struct_idproperties_check(self->ptr.type)==0) { + if(RNA_struct_idprops_check(self->ptr.type)==0) { PyErr_SetString( PyExc_TypeError, "bpy_struct.items(): this type doesn't support IDProperties"); return NULL; } - group= RNA_struct_idproperties(&self->ptr, 0); + group= RNA_struct_idprops(&self->ptr, 0); if(group==NULL) return PyList_New(0); @@ -1834,12 +1834,12 @@ static PyObject *pyrna_struct_values(BPy_PropertyRNA *self) { IDProperty *group; - if(RNA_struct_idproperties_check(self->ptr.type)==0) { + if(RNA_struct_idprops_check(self->ptr.type)==0) { PyErr_SetString( PyExc_TypeError, "bpy_struct.values(): this type doesn't support IDProperties"); return NULL; } - group= RNA_struct_idproperties(&self->ptr, 0); + group= RNA_struct_idprops(&self->ptr, 0); if(group==NULL) return PyList_New(0); @@ -2101,7 +2101,7 @@ static PyObject *pyrna_struct_is_property_set(BPy_StructRNA *self, PyObject *arg /* double property lookup, could speed up */ /* return PyBool_FromLong(RNA_property_is_set(&self->ptr, name)); */ if(RNA_property_flag(prop) & PROP_IDPROPERTY) { - IDProperty *group= RNA_struct_idproperties(&self->ptr, 0); + IDProperty *group= RNA_struct_idprops(&self->ptr, 0); if(group) { ret= IDP_GetPropertyFromGroup(group, name) ? 1:0; } @@ -2359,7 +2359,7 @@ static PyObject *pyrna_struct_getattro( BPy_StructRNA *self, PyObject *pyname ) if(name[0]=='_') { // rna can't start with a "_", so for __dict__ and similar we can skip using rna lookups /* annoying exception, maybe we need to have different types for this... */ - if((strcmp(name, "__getitem__")==0 || strcmp(name, "__setitem__")==0) && !RNA_struct_idproperties_check(self->ptr.type)) { + if((strcmp(name, "__getitem__")==0 || strcmp(name, "__setitem__")==0) && !RNA_struct_idprops_check(self->ptr.type)) { PyErr_SetString(PyExc_AttributeError, "bpy_struct: no __getitem__ support for this type"); ret = NULL; } @@ -2754,12 +2754,12 @@ static PyObject *pyrna_struct_get(BPy_StructRNA *self, PyObject *args) return NULL; /* mostly copied from BPy_IDGroup_Map_GetItem */ - if(RNA_struct_idproperties_check(self->ptr.type)==0) { + if(RNA_struct_idprops_check(self->ptr.type)==0) { PyErr_SetString( PyExc_TypeError, "this type doesn't support IDProperties"); return NULL; } - group= RNA_struct_idproperties(&self->ptr, 0); + group= RNA_struct_idprops(&self->ptr, 0); if(group) { idprop= IDP_GetPropertyFromGroup(group, key); @@ -4408,7 +4408,7 @@ static int deferred_register_prop(StructRNA *srna, PyObject *item, PyObject *key return 0; } -int pyrna_deferred_register_props(StructRNA *srna, PyObject *class_dict) +static int pyrna_deferred_register_props(StructRNA *srna, PyObject *class_dict) { PyObject *item, *key; PyObject *order; @@ -4418,9 +4418,10 @@ int pyrna_deferred_register_props(StructRNA *srna, PyObject *class_dict) dummy_args = PyTuple_New(0); - order= PyDict_GetItemString(class_dict, "order"); - - if(order && PyList_Check(order)) { + if( !PyDict_CheckExact(class_dict) && + (order= PyDict_GetItemString(class_dict, "order")) && + PyList_CheckExact(order) + ) { for(pos= 0; pos<PyList_GET_SIZE(order); pos++) { key= PyList_GET_ITEM(order, pos); item= PyDict_GetItem(class_dict, key); @@ -4443,6 +4444,49 @@ int pyrna_deferred_register_props(StructRNA *srna, PyObject *class_dict) return 0; } +static int pyrna_deferred_register_class_recursive(StructRNA *srna, PyTypeObject *py_class) +{ + const int len= PyTuple_GET_SIZE(py_class->tp_bases); + int i, ret; + + /* first scan base classes for registerable properties */ + for(i=0; i<len; i++) { + PyTypeObject *py_superclass= (PyTypeObject *)PyTuple_GET_ITEM(py_class->tp_bases, i); + + /* the rules for using these base classes are not clear, + * 'object' is ofcourse not worth looking into and + * existing subclasses of RNA would cause a lot more dictionary + * looping then is needed (SomeOperator would scan Operator.__dict__) + * which is harmless but not at all useful. + * + * So only scan base classes which are not subclasses if blender types. + * This best fits having 'mix-in' classes for operators and render engines. + * */ + if( py_superclass != &PyBaseObject_Type && + !PyObject_IsSubclass((PyObject *)py_superclass, (PyObject *)&pyrna_struct_Type) + ) { + ret= pyrna_deferred_register_class_recursive(srna, py_superclass); + + if(ret != 0) { + return ret; + } + } + } + + /* not register out own properties */ + return pyrna_deferred_register_props(srna, py_class->tp_dict); /* getattr(..., "__dict__") returns a proxy */ +} + +int pyrna_deferred_register_class(StructRNA *srna, PyObject *py_class) +{ + /* Panels and Menus dont need this + * save some time and skip the checks here */ + if(!RNA_struct_idprops_register_check(srna)) + return 0; + + return pyrna_deferred_register_class_recursive(srna, (PyTypeObject *)py_class); +} + /*-------------------- Type Registration ------------------------*/ static int rna_function_arg_count(FunctionRNA *func) @@ -4882,8 +4926,7 @@ static PyObject *pyrna_basetype_register(PyObject *self, PyObject *py_class) StructRegisterFunc reg; StructRNA *srna; StructRNA *srna_new; - PyObject *item; - const char *identifier= ""; + const char *identifier; if(PyDict_GetItemString(((PyTypeObject*)py_class)->tp_dict, "bl_rna")) { PyErr_SetString(PyExc_AttributeError, "bpy.types.register(...): already registered as a subclass."); @@ -4917,12 +4960,7 @@ static PyObject *pyrna_basetype_register(PyObject *self, PyObject *py_class) /* call the register callback with reports & identifier */ BKE_reports_init(&reports, RPT_STORE); - item= PyObject_GetAttrString(py_class, "__name__"); - - if(item) { - identifier= _PyUnicode_AsString(item); - Py_DECREF(item); /* no need to keep a ref, the class owns it */ - } + identifier= ((PyTypeObject*)py_class)->tp_name; srna_new= reg(C, &reports, py_class, identifier, bpy_class_validate, bpy_class_call, bpy_class_free); @@ -4946,15 +4984,8 @@ static PyObject *pyrna_basetype_register(PyObject *self, PyObject *py_class) * * item= PyObject_GetAttrString(py_class, "__dict__"); */ - item= ((PyTypeObject*)py_class)->tp_dict; - if(item) { - if(pyrna_deferred_register_props(srna_new, item)!=0) { - return NULL; - } - } - else { - PyErr_Clear(); - } + if(pyrna_deferred_register_class(srna_new, py_class)!=0) + return NULL; Py_RETURN_NONE; } diff --git a/source/blender/python/intern/bpy_rna.h b/source/blender/python/intern/bpy_rna.h index bd9838a76d4..63f6997d82c 100644 --- a/source/blender/python/intern/bpy_rna.h +++ b/source/blender/python/intern/bpy_rna.h @@ -86,7 +86,7 @@ int pyrna_set_to_enum_bitfield(EnumPropertyItem *items, PyObject *value, int *r_ int pyrna_enum_value_from_id(EnumPropertyItem *item, const char *identifier, int *value, const char *error_prefix); -int pyrna_deferred_register_props(struct StructRNA *srna, PyObject *class_dict); +int pyrna_deferred_register_class(struct StructRNA *srna, PyObject *py_class); /* called before stopping python */ void pyrna_alloc_types(void); |