[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [25103] trunk/blender: - property decorators for setting attributes didnt work, hack to prevent every instance of an BPyStructRNA to have its own dictionary , set the tp_dictoffset to 0.

Campbell Barton ideasman42 at gmail.com
Thu Dec 3 22:53:01 CET 2009


Revision: 25103
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=25103
Author:   campbellbarton
Date:     2009-12-03 22:53:01 +0100 (Thu, 03 Dec 2009)

Log Message:
-----------
- property decorators for setting attributes didnt work, hack to prevent every instance of an BPyStructRNA to have its own dictionary, set the tp_dictoffset to 0. attempted to use __slots__ but this doesnt work for some reason.
- made bone.length writable

Modified Paths:
--------------
    trunk/blender/release/scripts/modules/bpy_types.py
    trunk/blender/source/blender/makesdna/DNA_action_types.h
    trunk/blender/source/blender/python/intern/bpy_rna.c

Modified: trunk/blender/release/scripts/modules/bpy_types.py
===================================================================
--- trunk/blender/release/scripts/modules/bpy_types.py	2009-12-03 21:49:29 UTC (rev 25102)
+++ trunk/blender/release/scripts/modules/bpy_types.py	2009-12-03 21:53:01 UTC (rev 25103)
@@ -88,6 +88,11 @@
     @property
     def length(self):
         return (self.head - self.tail).length
+    
+    @length.setter
+    def length(self, value):
+        """The distance from head to tail"""
+        self.tail = self.head + ((self.tail - self.head).normalize() * value)
 
     @property
     def children(self):

Modified: trunk/blender/source/blender/makesdna/DNA_action_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_action_types.h	2009-12-03 21:49:29 UTC (rev 25102)
+++ trunk/blender/source/blender/makesdna/DNA_action_types.h	2009-12-03 21:53:01 UTC (rev 25103)
@@ -244,7 +244,7 @@
  * though there is a define for it (hack for the outliner).
  */
 typedef struct bPose {
-	ListBase chanbase; 			/* list of pose channels */
+	ListBase chanbase; 			/* list of pose channels, PoseBones in RNA */
 	
 	short flag, proxy_layer;	/* proxy layer: copy from armature, gets synced */
 	

Modified: trunk/blender/source/blender/python/intern/bpy_rna.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_rna.c	2009-12-03 21:49:29 UTC (rev 25102)
+++ trunk/blender/source/blender/python/intern/bpy_rna.c	2009-12-03 21:53:01 UTC (rev 25103)
@@ -1738,19 +1738,22 @@
 	PropertyRNA *prop = RNA_struct_find_property(&self->ptr, name);
 	
 	if (prop==NULL) {
+		return PyObject_GenericSetAttr((PyObject *)self, pyname, value);
+#if 0
 		// XXX - This currently allows anything to be assigned to an rna prop, need to see how this should be used
 		// but for now it makes porting scripts confusing since it fails silently.
 		// edit: allowing this for setting classes internal attributes.
 		// edit: allow this for any attribute that alredy exists as a python attr
 		if (	(name[0]=='_' /* || pyrna_struct_pydict_contains(self, pyname) */ ) &&
 				!BPy_StructRNA_CheckExact(self) &&
-				PyObject_GenericSetAttr((PyObject *)self, pyname, value) >= 0) {
+
 			return 0;
 		} else
 		{
 			PyErr_Format( PyExc_AttributeError, "StructRNA - Attribute \"%.200s\" not found", name);
 			return -1;
 		}
+#endif
 	}		
 	
 	if (!RNA_property_editable(&self->ptr, prop)) {
@@ -2984,6 +2987,9 @@
 		PyObject *base_compare= pyrna_srna_PyBase(srna);
 		PyObject *bases= PyObject_GetAttrString(newclass, "__bases__");
 
+		// XXX - highly dodgy!, this stops blender from creating __dict__ in instances
+		((PyTypeObject *)newclass)->tp_dictoffset = 0;
+
 		if(PyTuple_GET_SIZE(bases)) {
 			PyObject *base= PyTuple_GET_ITEM(bases, 0);
 
@@ -3039,6 +3045,9 @@
 
 		if (newclass) {
 
+			// XXX - highly dodgy!, this stops blender from creating __dict__ in instances
+			((PyTypeObject *)newclass)->tp_dictoffset = 0;
+
 			/* srna owns one, and the other is owned by the caller */
 			pyrna_subtype_set_rna(newclass, srna);
 





More information about the Bf-blender-cvs mailing list