[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19789] branches/blender2.5/blender: RNA: Generic Type Registration

Brecht Van Lommel brecht at blender.org
Sun Apr 19 15:37:59 CEST 2009


Revision: 19789
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19789
Author:   blendix
Date:     2009-04-19 15:37:59 +0200 (Sun, 19 Apr 2009)

Log Message:
-----------
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).

Modified Paths:
--------------
    branches/blender2.5/blender/release/ui/buttons_objects.py
    branches/blender2.5/blender/release/ui/buttons_scene.py
    branches/blender2.5/blender/source/blender/blenkernel/BKE_screen.h
    branches/blender2.5/blender/source/blender/blenkernel/intern/anim_sys.c
    branches/blender2.5/blender/source/blender/blenkernel/intern/fcurve.c
    branches/blender2.5/blender/source/blender/blenkernel/intern/screen.c
    branches/blender2.5/blender/source/blender/blenlib/intern/util.c
    branches/blender2.5/blender/source/blender/editors/animation/anim_ipo_utils.c
    branches/blender2.5/blender/source/blender/editors/animation/drivers.c
    branches/blender2.5/blender/source/blender/editors/animation/keyframing.c
    branches/blender2.5/blender/source/blender/editors/animation/keyingsets.c
    branches/blender2.5/blender/source/blender/editors/interface/interface.c
    branches/blender2.5/blender/source/blender/editors/interface/interface_anim.c
    branches/blender2.5/blender/source/blender/editors/interface/interface_layout.c
    branches/blender2.5/blender/source/blender/editors/interface/interface_panel.c
    branches/blender2.5/blender/source/blender/editors/interface/interface_regions.c
    branches/blender2.5/blender/source/blender/editors/interface/interface_utils.c
    branches/blender2.5/blender/source/blender/editors/space_outliner/outliner.c
    branches/blender2.5/blender/source/blender/editors/space_text/text_header.c
    branches/blender2.5/blender/source/blender/makesrna/RNA_access.h
    branches/blender2.5/blender/source/blender/makesrna/RNA_define.h
    branches/blender2.5/blender/source/blender/makesrna/RNA_types.h
    branches/blender2.5/blender/source/blender/makesrna/intern/makesrna.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_access.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_define.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_internal_types.h
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_rna.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_screen.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_ui.c
    branches/blender2.5/blender/source/blender/python/intern/bpy_operator.c
    branches/blender2.5/blender/source/blender/python/intern/bpy_operator_wrap.c
    branches/blender2.5/blender/source/blender/python/intern/bpy_rna.c
    branches/blender2.5/blender/source/blender/python/intern/bpy_rna.h
    branches/blender2.5/blender/source/blender/python/intern/bpy_ui.c
    branches/blender2.5/blender/source/blender/python/intern/bpy_util.c
    branches/blender2.5/blender/source/blender/python/intern/bpy_util.h
    branches/blender2.5/blender/source/blender/windowmanager/intern/wm_operators.c

Removed Paths:
-------------
    branches/blender2.5/blender/source/blender/python/intern/bpy_panel_wrap.c
    branches/blender2.5/blender/source/blender/python/intern/bpy_panel_wrap.h

Modified: branches/blender2.5/blender/release/ui/buttons_objects.py
===================================================================
--- branches/blender2.5/blender/release/ui/buttons_objects.py	2009-04-19 12:46:39 UTC (rev 19788)
+++ branches/blender2.5/blender/release/ui/buttons_objects.py	2009-04-19 13:37:59 UTC (rev 19789)
@@ -1,9 +1,15 @@
+
 import bpy
 
-class OBJECT_PT_transform(bpy.types.Panel):
-	__label__ = "Transform"
+class ObjectButtonsPanel(bpy.types.Panel):
+	__space_type__ = "BUTTONS_WINDOW"
+	__region_type__ = "WINDOW"
 	__context__ = "object"
 
+class OBJECT_PT_transform(ObjectButtonsPanel):
+	__idname__ = "OBJECT_PT_transform"
+	__label__ = "Transform"
+
 	def draw(self, context):
 		ob = context.active_object
 		layout = self.layout
@@ -16,9 +22,9 @@
 		layout.itemR(ob, "rotation")
 		layout.itemR(ob, "scale")
 
-class OBJECT_PT_groups(bpy.types.Panel):
+class OBJECT_PT_groups(ObjectButtonsPanel):
+	__idname__ = "OBJECT_PT_groups"
 	__label__ = "Groups"
-	__context__ = "object"
 
 	def draw(self, context):
 		ob = context.active_object
@@ -46,9 +52,9 @@
 				sub.itemR(group, "layer")
 				sub.itemR(group, "dupli_offset")
 
-class OBJECT_PT_display(bpy.types.Panel):
+class OBJECT_PT_display(ObjectButtonsPanel):
+	__idname__ = "OBJECT_PT_display"
 	__label__ = "Display"
-	__context__ = "object"
 
 	def draw(self, context):
 		ob = context.active_object
@@ -69,9 +75,9 @@
 		layout.itemR(ob, "x_ray", text="X-Ray")
 		layout.itemR(ob, "draw_transparent", text="Transparency")
 
-class OBJECT_PT_duplication(bpy.types.Panel):
+class OBJECT_PT_duplication(ObjectButtonsPanel):
+	__idname__ = "OBJECT_PT_duplication"
 	__label__ = "Duplication"
-	__context__ = "object"
 
 	def draw(self, context):
 		ob = context.active_object
@@ -90,9 +96,9 @@
 			layout.itemR(ob, "dupli_frames_on", text="On:")
 			layout.itemR(ob, "dupli_frames_off", text="Off:")
 
-class OBJECT_PT_animation(bpy.types.Panel):
+class OBJECT_PT_animation(ObjectButtonsPanel):
+	__idname__ = "OBJECT_PT_animation"
 	__label__ = "Animation"
-	__context__ = "object"
 
 	def draw(self, context):
 		ob = context.active_object
@@ -119,9 +125,9 @@
 		sub.itemR(ob, "up_axis", text="Up Axis")
 		sub.itemR(ob, "track_rotation", text="Rotation")
 
-bpy.ui.addPanel(OBJECT_PT_transform, "BUTTONS_WINDOW", "WINDOW")
-bpy.ui.addPanel(OBJECT_PT_groups, "BUTTONS_WINDOW", "WINDOW")
-bpy.ui.addPanel(OBJECT_PT_display, "BUTTONS_WINDOW", "WINDOW")
-bpy.ui.addPanel(OBJECT_PT_duplication, "BUTTONS_WINDOW", "WINDOW")
-bpy.ui.addPanel(OBJECT_PT_animation, "BUTTONS_WINDOW", "WINDOW")
+bpy.types.register(OBJECT_PT_transform)
+bpy.types.register(OBJECT_PT_groups)
+bpy.types.register(OBJECT_PT_display)
+bpy.types.register(OBJECT_PT_duplication)
+bpy.types.register(OBJECT_PT_animation)
 

Modified: branches/blender2.5/blender/release/ui/buttons_scene.py
===================================================================
--- branches/blender2.5/blender/release/ui/buttons_scene.py	2009-04-19 12:46:39 UTC (rev 19788)
+++ branches/blender2.5/blender/release/ui/buttons_scene.py	2009-04-19 13:37:59 UTC (rev 19789)
@@ -1,10 +1,14 @@
 
 import bpy
 
-class RENDER_PT_shading(bpy.types.Panel):
-	__label__ = "Shading"
+class RenderButtonsPanel(bpy.types.Panel):
+	__space_type__ = "BUTTONS_WINDOW"
+	__region_type__ = "WINDOW"
 	__context__ = "render"
 
+class RENDER_PT_shading(RenderButtonsPanel):
+	__label__ = "Shading"
+
 	def draw(self, context):
 		scene = context.scene
 		layout = self.layout
@@ -25,7 +29,7 @@
 		layout.row()
 		layout.itemR(rd, "alpha_mode")
 
-class RENDER_PT_image(bpy.types.Panel):
+class RENDER_PT_image(RenderButtonsPanel):
 	__label__ = "Image"
 	__context__ = "render"
 
@@ -47,7 +51,7 @@
 		layout.row()
 		layout.itemR(rd, "crop_to_border")
 
-class RENDER_PT_antialiasing(bpy.types.Panel):
+class RENDER_PT_antialiasing(RenderButtonsPanel):
 	__label__ = "Anti-Aliasing"
 	__context__ = "render"
 
@@ -66,7 +70,7 @@
 		layout.itemR(rd, "pixel_filter")
 		layout.itemR(rd, "filter_size")
 
-class RENDER_PT_render(bpy.types.Panel):
+class RENDER_PT_render(RenderButtonsPanel):
 	__label__ = "Render"
 	__context__ = "render"
 
@@ -118,8 +122,8 @@
 		layout.itemR(rd, "border", text="Border Render")
 		layout.itemR(rd, "panorama")
 
-bpy.ui.addPanel(RENDER_PT_shading, "BUTTONS_WINDOW", "WINDOW")
-bpy.ui.addPanel(RENDER_PT_image, "BUTTONS_WINDOW", "WINDOW")
-bpy.ui.addPanel(RENDER_PT_antialiasing, "BUTTONS_WINDOW", "WINDOW")
-bpy.ui.addPanel(RENDER_PT_render, "BUTTONS_WINDOW", "WINDOW")
+bpy.types.register(RENDER_PT_shading)
+bpy.types.register(RENDER_PT_image)
+bpy.types.register(RENDER_PT_antialiasing)
+bpy.types.register(RENDER_PT_render)
 

Modified: branches/blender2.5/blender/source/blender/blenkernel/BKE_screen.h
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/BKE_screen.h	2009-04-19 12:46:39 UTC (rev 19788)
+++ branches/blender2.5/blender/source/blender/blenkernel/BKE_screen.h	2009-04-19 13:37:59 UTC (rev 19789)
@@ -45,6 +45,9 @@
 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 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 */

Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/anim_sys.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/anim_sys.c	2009-04-19 12:46:39 UTC (rev 19788)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/anim_sys.c	2009-04-19 13:37:59 UTC (rev 19789)
@@ -377,22 +377,22 @@
 		/* 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);

Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/fcurve.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/fcurve.c	2009-04-19 12:46:39 UTC (rev 19788)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/fcurve.c	2009-04-19 13:37:59 UTC (rev 19789)
@@ -679,21 +679,21 @@
 	
 	/* 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);

Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/screen.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/screen.c	2009-04-19 12:46:39 UTC (rev 19788)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/screen.c	2009-04-19 13:37:59 UTC (rev 19789)
@@ -53,25 +53,16 @@
 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
-		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
+		for(pt= art->paneltypes.first; pt; pt= pt->next)
+			if(pt->py_free)
+				pt->py_free(pt->py_data);
+
+		BLI_freelistN(&art->paneltypes);
 		BLI_freelistN(&art->headertypes);
 	}
 	

Modified: branches/blender2.5/blender/source/blender/blenlib/intern/util.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenlib/intern/util.c	2009-04-19 12:46:39 UTC (rev 19788)
+++ branches/blender2.5/blender/source/blender/blenlib/intern/util.c	2009-04-19 13:37:59 UTC (rev 19789)
@@ -848,6 +848,12 @@

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list