diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-04-19 17:37:59 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-04-19 17:37:59 +0400 |
commit | adff6aeb1c749183921c0facd373972bbeb874b4 (patch) | |
tree | 07987d408713eee8a3dd8bb5cb4ecf3c112de654 /source/blender/blenkernel | |
parent | d880257d165888638b7c924fb6ef7071343b783e (diff) |
RNA: Generic Type Registration
The Python API to define Panels and Operators is based on subclassing,
this makes that system more generic, and based on RNA. Hopefully that
will make it easy to make various parts of Blender more extensible.
* The system simply uses RNA properties and functions and marks them
with REGISTER to make them part of the type registration process.
Additionally, the struct must provide a register/unregister callback
to create/free the PanelType or similar.
* From the python side there were some small changes, mainly that
registration now goes trough bpy.types.register instead of
bpy.ui.addPanel.
* Only Panels have been wrapped this way now. Check rna_ui.c to see
how this code works. There's still some rough edges and possibilities
to make it cleaner, though it works without any manual python code.
* Started some docs here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/RNATypeRegistration
* Also changed some RNA_property and RNA_struct functions to not
require a PointerRNA anymore, where they were not required (which
is actually the cause of most changed files).
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_screen.h | 17 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/anim_sys.c | 8 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/fcurve.c | 8 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/screen.c | 21 |
4 files changed, 26 insertions, 28 deletions
diff --git a/source/blender/blenkernel/BKE_screen.h b/source/blender/blenkernel/BKE_screen.h index e43b2b3b737..fb0c65b3cf9 100644 --- a/source/blender/blenkernel/BKE_screen.h +++ b/source/blender/blenkernel/BKE_screen.h @@ -45,6 +45,9 @@ struct wmWindowManager; struct uiLayout; struct uiMenuItem; struct StructRNA; +struct PointerRNA; +struct FunctionRNA; +struct ParameterList; /* spacetype has everything stored to get an editor working, it gets initialized via ED_spacetypes_init() in editors/area/spacetypes.c */ @@ -143,18 +146,22 @@ typedef struct ARegionType { typedef struct PanelType { struct PanelType *next, *prev; - char *idname; /* unique name */ - char *name; /* for panel header */ - char *context; /* for buttons window */ + char idname[BKE_ST_MAXNAME]; /* unique name */ + char label[BKE_ST_MAXNAME]; /* for panel header */ + char context[BKE_ST_MAXNAME]; /* for buttons window */ + char space_type[BKE_ST_MAXNAME]; + char region_type[BKE_ST_MAXNAME]; /* verify if the panel should draw or not */ - int (*poll)(const struct bContext *); + int (*poll)(const struct bContext *, struct PanelType *); /* draw entirely, view changes should be handled here */ void (*draw)(const struct bContext *, struct Panel *); /* python integration */ void *py_data; - struct StructRNA *srna; + struct StructRNA *py_srna; + int (*py_call)(struct PointerRNA *, struct FunctionRNA *, struct ParameterList *); + void (*py_free)(void *py_data); } PanelType; /* header types */ diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c index 1d819b7de8b..5b10f921d7d 100644 --- a/source/blender/blenkernel/intern/anim_sys.c +++ b/source/blender/blenkernel/intern/anim_sys.c @@ -377,22 +377,22 @@ static short animsys_write_rna_setting (PointerRNA *ptr, char *path, int array_i /* set value - only for animatable numerical values */ if (RNA_property_animateable(&new_ptr, prop)) { - switch (RNA_property_type(&new_ptr, prop)) + switch (RNA_property_type(prop)) { case PROP_BOOLEAN: - if (RNA_property_array_length(&new_ptr, prop)) + if (RNA_property_array_length(prop)) RNA_property_boolean_set_index(&new_ptr, prop, array_index, (int)value); else RNA_property_boolean_set(&new_ptr, prop, (int)value); break; case PROP_INT: - if (RNA_property_array_length(&new_ptr, prop)) + if (RNA_property_array_length(prop)) RNA_property_int_set_index(&new_ptr, prop, array_index, (int)value); else RNA_property_int_set(&new_ptr, prop, (int)value); break; case PROP_FLOAT: - if (RNA_property_array_length(&new_ptr, prop)) + if (RNA_property_array_length(prop)) RNA_property_float_set_index(&new_ptr, prop, array_index, value); else RNA_property_float_set(&new_ptr, prop, value); diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c index d7b1bdaeff3..cce4f3a1217 100644 --- a/source/blender/blenkernel/intern/fcurve.c +++ b/source/blender/blenkernel/intern/fcurve.c @@ -679,21 +679,21 @@ static float driver_get_target_value (ChannelDriver *driver, DriverTarget *dtar) /* get property to read from, and get value as appropriate */ if (RNA_path_resolve(&id_ptr, path, &ptr, &prop)) { - switch (RNA_property_type(&ptr, prop)) { + switch (RNA_property_type(prop)) { case PROP_BOOLEAN: - if (RNA_property_array_length(&ptr, prop)) + if (RNA_property_array_length(prop)) value= (float)RNA_property_boolean_get_index(&ptr, prop, index); else value= (float)RNA_property_boolean_get(&ptr, prop); break; case PROP_INT: - if (RNA_property_array_length(&ptr, prop)) + if (RNA_property_array_length(prop)) value= (float)RNA_property_int_get_index(&ptr, prop, index); else value= (float)RNA_property_int_get(&ptr, prop); break; case PROP_FLOAT: - if (RNA_property_array_length(&ptr, prop)) + if (RNA_property_array_length(prop)) value= RNA_property_float_get_index(&ptr, prop, index); else value= RNA_property_float_get(&ptr, prop); diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c index 2f3ca52a09e..f43dc287062 100644 --- a/source/blender/blenkernel/intern/screen.c +++ b/source/blender/blenkernel/intern/screen.c @@ -53,25 +53,16 @@ static ListBase spacetypes= {NULL, NULL}; static void spacetype_free(SpaceType *st) { ARegionType *art; + PanelType *pt; for(art= st->regiontypes.first; art; art= art->next) { BLI_freelistN(&art->drawcalls); -#ifdef DISABLE_PYTHON + + for(pt= art->paneltypes.first; pt; pt= pt->next) + if(pt->py_free) + pt->py_free(pt->py_data); + BLI_freelistN(&art->paneltypes); -#else - { - PanelType *pnl, *pnl_next; - for(pnl= art->paneltypes.first; pnl; pnl= pnl_next) { - pnl_next= pnl->next; - - if(pnl->py_data) - BPY_DECREF(pnl->py_data); - - MEM_freeN(pnl); - } - art->paneltypes.first= art->paneltypes.last= NULL; - } -#endif BLI_freelistN(&art->headertypes); } |