[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [27544] trunk/blender: fix for nasty bug where registering properties would register them in the parent classes SRNA , made for confusing rigify args turning up in add sequencer adding collection .

Brecht Van Lommel brecht at blender.org
Tue Mar 16 18:20:15 CET 2010


Revision: 27544
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=27544
Author:   blendix
Date:     2010-03-16 18:20:15 +0100 (Tue, 16 Mar 2010)

Log Message:
-----------
fix for nasty bug where registering properties would register them in the parent classes SRNA, made for confusing rigify args turning up in add sequencer adding collection.
(commit 27433 by Campbell from render25 branch)

Modified Paths:
--------------
    trunk/blender/release/scripts/ui/properties_data_armature_rigify.py
    trunk/blender/source/blender/python/intern/bpy_operator_wrap.c
    trunk/blender/source/blender/python/intern/bpy_props.c
    trunk/blender/source/blender/python/intern/bpy_rna.c
    trunk/blender/source/blender/python/intern/bpy_rna.h

Modified: trunk/blender/release/scripts/ui/properties_data_armature_rigify.py
===================================================================
--- trunk/blender/release/scripts/ui/properties_data_armature_rigify.py	2010-03-16 17:19:42 UTC (rev 27543)
+++ trunk/blender/release/scripts/ui/properties_data_armature_rigify.py	2010-03-16 17:20:15 UTC (rev 27544)
@@ -29,29 +29,7 @@
 class PoseTemplate(bpy.types.IDPropertyGroup):
     pass
 
-PoseTemplate.StringProperty(attr="name",
-                name="Name of the slave",
-                description="",
-                maxlen=64,
-                default="")
 
-
-PoseTemplateSettings.CollectionProperty(attr="templates", type=PoseTemplate, name="Templates", description="")
-PoseTemplateSettings.IntProperty(attr="active_template_index",
-                name="Index of the active slave",
-                description="",
-                default=-1,
-                min=-1,
-                max=65535)
-
-PoseTemplateSettings.BoolProperty(attr="generate_def_rig",
-                name="Create Deform Rig",
-                description="Create a copy of the metarig, constrainted by the generated rig",
-                default=False)
-
-bpy.types.Scene.PointerProperty(attr="pose_templates", type=PoseTemplateSettings, name="Pose Templates", description="Pose Template Settings")
-
-
 def metarig_templates():
     import rigify
     return rigify.get_submodule_types()
@@ -356,6 +334,28 @@
     for cls in classes:
         register(cls)
 
+    PoseTemplate.StringProperty(attr="name",
+                    name="Name of the slave",
+                    description="",
+                    maxlen=64,
+                    default="")
+
+
+    PoseTemplateSettings.CollectionProperty(attr="templates", type=PoseTemplate, name="Templates", description="")
+    PoseTemplateSettings.IntProperty(attr="active_template_index",
+                    name="Index of the active slave",
+                    description="",
+                    default=-1,
+                    min=-1,
+                    max=65535)
+
+    PoseTemplateSettings.BoolProperty(attr="generate_def_rig",
+                    name="Create Deform Rig",
+                    description="Create a copy of the metarig, constrainted by the generated rig",
+                    default=False)
+
+    bpy.types.Scene.PointerProperty(attr="pose_templates", type=PoseTemplateSettings, name="Pose Templates", description="Pose Template Settings")
+
     space_info.INFO_MT_armature_add.append(menu_func)
 
 

Modified: trunk/blender/source/blender/python/intern/bpy_operator_wrap.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_operator_wrap.c	2010-03-16 17:19:42 UTC (rev 27543)
+++ trunk/blender/source/blender/python/intern/bpy_operator_wrap.c	2010-03-16 17:20:15 UTC (rev 27544)
@@ -111,7 +111,7 @@
 	}
 
 	/* identifiers */
-	srna= srna_from_self(macro);
+	srna= srna_from_self(macro, "Macro Define:");
 	macroname = RNA_struct_identifier(srna);
 
 	ot = WM_operatortype_exists(macroname);

Modified: trunk/blender/source/blender/python/intern/bpy_props.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_props.c	2010-03-16 17:19:42 UTC (rev 27543)
+++ trunk/blender/source/blender/python/intern/bpy_props.c	2010-03-16 17:20:15 UTC (rev 27544)
@@ -115,7 +115,7 @@
 		return NULL;
 	}
 
-	srna= srna_from_self(self);
+	srna= srna_from_self(self, "BoolProperty(...):");
 	if(srna==NULL && PyErr_Occurred()) {
 		return NULL; /* self's type was compatible but error getting the srna */
 	}
@@ -181,7 +181,7 @@
 		return NULL;
 	}
 
-	srna= srna_from_self(self);
+	srna= srna_from_self(self, "BoolVectorProperty(...):");
 	if(srna==NULL && PyErr_Occurred()) {
 		return NULL; /* self's type was compatible but error getting the srna */
 	}
@@ -258,7 +258,7 @@
 		return NULL;
 	}
 
-	srna= srna_from_self(self);
+	srna= srna_from_self(self, "IntProperty(...):");
 	if(srna==NULL && PyErr_Occurred()) {
 		return NULL; /* self's type was compatible but error getting the srna */
 	}
@@ -325,7 +325,7 @@
 		return NULL;
 	}
 
-	srna= srna_from_self(self);
+	srna= srna_from_self(self, "IntVectorProperty(...):");
 	if(srna==NULL && PyErr_Occurred()) {
 		return NULL; /* self's type was compatible but error getting the srna */
 	}
@@ -406,7 +406,7 @@
 		return NULL;
 	}
 
-	srna= srna_from_self(self);
+	srna= srna_from_self(self, "FloatProperty(...):");
 	if(srna==NULL && PyErr_Occurred()) {
 		return NULL; /* self's type was compatible but error getting the srna */
 	}
@@ -481,7 +481,7 @@
 		return NULL;
 	}
 
-	srna= srna_from_self(self);
+	srna= srna_from_self(self, "FloatVectorProperty(...):");
 	if(srna==NULL && PyErr_Occurred()) {
 		return NULL; /* self's type was compatible but error getting the srna */
 	}
@@ -559,7 +559,7 @@
 		return NULL;
 	}
 
-	srna= srna_from_self(self);
+	srna= srna_from_self(self, "StringProperty(...):");
 	if(srna==NULL && PyErr_Occurred()) {
 		return NULL; /* self's type was compatible but error getting the srna */
 	}
@@ -671,7 +671,7 @@
 		return NULL;
 	}
 
-	srna= srna_from_self(self);
+	srna= srna_from_self(self, "EnumProperty(...):");
 	if(srna==NULL && PyErr_Occurred()) {
 		return NULL; /* self's type was compatible but error getting the srna */
 	}
@@ -716,18 +716,22 @@
 	}
 }
 
-static StructRNA *pointer_type_from_py(PyObject *value)
+static StructRNA *pointer_type_from_py(PyObject *value, const char *error_prefix)
 {
 	StructRNA *srna;
 
-	srna= srna_from_self(value);
+	srna= srna_from_self(value, "BoolProperty(...):");
 	if(!srna) {
-	 	PyErr_SetString(PyExc_SystemError, "expected an RNA type derived from IDPropertyGroup");
+
+		PyObject *msg= BPY_exception_buffer();
+		char *msg_char= _PyUnicode_AsString(msg);
+		PyErr_Format(PyExc_TypeError, "%.200s expected an RNA type derived from IDPropertyGroup, failed with: %s", error_prefix, msg_char);
+		Py_DECREF(msg);
 		return NULL;
 	}
 
 	if(!RNA_struct_is_a(srna, &RNA_IDPropertyGroup)) {
-	 	PyErr_SetString(PyExc_SystemError, "expected an RNA type derived from IDPropertyGroup");
+	 	PyErr_Format(PyExc_SystemError, "%.200s expected an RNA type derived from IDPropertyGroup", error_prefix);
 		return NULL;
 	}
 
@@ -752,7 +756,7 @@
 		return NULL;
 	}
 
-	srna= srna_from_self(self);
+	srna= srna_from_self(self, "PointerProperty(...):");
 	if(srna==NULL && PyErr_Occurred()) {
 		return NULL; /* self's type was compatible but error getting the srna */
 	}
@@ -777,7 +781,7 @@
 		if(pyopts && pyrna_set_to_enum_bitfield(property_flag_items, pyopts, &opts, "PointerProperty(options={...}):"))
 			return NULL;
 
-		ptype= pointer_type_from_py(type);
+		ptype= pointer_type_from_py(type, "PointerProperty(...):");
 		if(!ptype)
 			return NULL;
 
@@ -813,7 +817,7 @@
 		return NULL;
 	}
 
-	srna= srna_from_self(self);
+	srna= srna_from_self(self, "CollectionProperty(...):");
 	if(srna==NULL && PyErr_Occurred()) {
 		return NULL; /* self's type was compatible but error getting the srna */
 	}
@@ -838,7 +842,7 @@
 		if(pyopts && pyrna_set_to_enum_bitfield(property_flag_items, pyopts, &opts, "CollectionProperty(options={...}):"))
 			return NULL;
 
-		ptype= pointer_type_from_py(type);
+		ptype= pointer_type_from_py(type, "CollectionProperty(...):");
 		if(!ptype)
 			return NULL;
 

Modified: trunk/blender/source/blender/python/intern/bpy_rna.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_rna.c	2010-03-16 17:19:42 UTC (rev 27543)
+++ trunk/blender/source/blender/python/intern/bpy_rna.c	2010-03-16 17:20:15 UTC (rev 27544)
@@ -3537,26 +3537,6 @@
 	}
 }
 
-/*
-static StructRNA *srna_from_self(PyObject *self);
-PyObject *BPy_GetStructRNA(PyObject *self)
-{
-	StructRNA *srna= pyrna_struct_as_srna(self);
-	PointerRNA ptr;
-	PyObject *ret;
-
-	RNA_pointer_create(NULL, &RNA_Struct, srna, &ptr);
-	ret= pyrna_struct_CreatePyObject(&ptr);
-
-	if(ret) {
-		return ret;
-	}
-	else {
-		Py_RETURN_NONE;
-	}
-}
-*/
-
 static PyObject* pyrna_srna_Subtype(StructRNA *srna);
 
 /* return a borrowed reference */
@@ -3897,7 +3877,7 @@
 	return (PyObject *)self;
 }
 
-StructRNA *pyrna_struct_as_srna(PyObject *self)
+StructRNA *pyrna_struct_as_srna(PyObject *self, int parent, const char *error_prefix)
 {
 	BPy_StructRNA *py_srna = NULL;
 	StructRNA *srna;
@@ -3907,23 +3887,27 @@
 		py_srna = (BPy_StructRNA *)PyDict_GetItemString(((PyTypeObject *)self)->tp_dict, "bl_rna");
 		Py_XINCREF(py_srna);
 	}
-	
-	if(py_srna==NULL)
-		py_srna = (BPy_StructRNA*)PyObject_GetAttrString(self, "bl_rna");
 
+	if(parent) {
+		/* be very careful with this since it will return a parent classes srna.
+		 * modifying this will do confusing stuff! */
+		if(py_srna==NULL)
+			py_srna = (BPy_StructRNA*)PyObject_GetAttrString(self, "bl_rna");
+	}
+
 	if(py_srna==NULL) {
-	 	PyErr_SetString(PyExc_SystemError, "internal error, self had no bl_rna attribute, should never happen.");
+	 	PyErr_Format(PyExc_SystemError, "%.200s internal error, self of type '%.200s' had no bl_rna attribute, should never happen", error_prefix, Py_TYPE(self)->tp_name);
 		return NULL;
 	}
 
 	if(!BPy_StructRNA_Check(py_srna)) {
-	 	PyErr_Format(PyExc_SystemError, "internal error, bl_rna was of type %.200s, instead of %.200s instance.", Py_TYPE(py_srna)->tp_name, pyrna_struct_Type.tp_name);
+	 	PyErr_Format(PyExc_SystemError, "%.200s internal error, bl_rna was of type '%.200s', instead of %.200s instance", error_prefix, Py_TYPE(py_srna)->tp_name, pyrna_struct_Type.tp_name);
 	 	Py_DECREF(py_srna);
 		return NULL;
 	}
 
 	if(py_srna->ptr.type != &RNA_Struct) {
-	 	PyErr_SetString(PyExc_SystemError, "internal error, bl_rna was not a RNA_Struct type of rna struct.");
+		PyErr_Format(PyExc_SystemError, "%.200s internal error, bl_rna was not a RNA_Struct type of rna struct", error_prefix);
 	 	Py_DECREF(py_srna);
 		return NULL;
 	}
@@ -3937,7 +3921,7 @@
 /* Orphan functions, not sure where they should go */
 /* get the srna for methods attached to types */
 /* */
-StructRNA *srna_from_self(PyObject *self)
+StructRNA *srna_from_self(PyObject *self, const char *error_prefix)
 {
 	/* a bit sloppy but would cause a very confusing bug if
 	 * an error happened to be set here */
@@ -3955,7 +3939,7 @@
 	/* These cases above not errors, they just mean the type was not compatible
 	 * After this any errors will be raised in the script */
 
-	return pyrna_struct_as_srna(self);

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list