[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [32093] trunk/blender: Annoying hack to pretend that an operator and its properties are the same, when passing an operator to an rna function argument which accepts ' AnyType', then pass the properties instead.

Campbell Barton ideasman42 at gmail.com
Fri Sep 24 05:48:27 CEST 2010


Revision: 32093
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=32093
Author:   campbellbarton
Date:     2010-09-24 05:48:26 +0200 (Fri, 24 Sep 2010)

Log Message:
-----------
Annoying hack to pretend that an operator and its properties are the same, when passing an operator to an rna function argument which accepts 'AnyType', then pass the properties instead.

This means we can do operator drawing without passing self.properties as an argument.

while this check if quite specific, if this gives problems later on we should probably change operators not to try to mix an operator and its properties, it looks nice to a scripter but internally is not easy to manage.

Modified Paths:
--------------
    trunk/blender/release/scripts/op/io_mesh_ply/__init__.py
    trunk/blender/release/scripts/op/io_scene_obj/__init__.py
    trunk/blender/release/scripts/op/object.py
    trunk/blender/source/blender/python/intern/bpy_rna.c

Modified: trunk/blender/release/scripts/op/io_mesh_ply/__init__.py
===================================================================
--- trunk/blender/release/scripts/op/io_mesh_ply/__init__.py	2010-09-24 03:42:19 UTC (rev 32092)
+++ trunk/blender/release/scripts/op/io_mesh_ply/__init__.py	2010-09-24 03:48:26 UTC (rev 32093)
@@ -53,11 +53,11 @@
         layout = self.layout
 
         row = layout.row()
-        row.prop(self.properties, "use_modifiers")
-        row.prop(self.properties, "use_normals")
+        row.prop(self, "use_modifiers")
+        row.prop(self, "use_normals")
         row = layout.row()
-        row.prop(self.properties, "use_uv_coords")
-        row.prop(self.properties, "use_colors")
+        row.prop(self, "use_uv_coords")
+        row.prop(self, "use_colors")
 
 
 def menu_func(self, context):

Modified: trunk/blender/release/scripts/op/io_scene_obj/__init__.py
===================================================================
--- trunk/blender/release/scripts/op/io_scene_obj/__init__.py	2010-09-24 03:42:19 UTC (rev 32092)
+++ trunk/blender/release/scripts/op/io_scene_obj/__init__.py	2010-09-24 03:48:26 UTC (rev 32093)
@@ -113,7 +113,6 @@
 
     def execute(self, context):
         import io_scene_obj.export_obj
-        print(self.properties.keys())
         return io_scene_obj.export_obj.save(self, context, **self.properties)
 
 

Modified: trunk/blender/release/scripts/op/object.py
===================================================================
--- trunk/blender/release/scripts/op/object.py	2010-09-24 03:42:19 UTC (rev 32092)
+++ trunk/blender/release/scripts/op/object.py	2010-09-24 03:48:26 UTC (rev 32093)
@@ -67,10 +67,10 @@
     def draw(self, context):
         layout = self.layout
 
-        layout.prop(self.properties, "pattern")
+        layout.prop(self, "pattern")
         row = layout.row()
-        row.prop(self.properties, "case_sensitive")
-        row.prop(self.properties, "extend")
+        row.prop(self, "case_sensitive")
+        row.prop(self, "extend")
 
 
 class SelectCamera(bpy.types.Operator):

Modified: trunk/blender/source/blender/python/intern/bpy_rna.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_rna.c	2010-09-24 03:42:19 UTC (rev 32092)
+++ trunk/blender/source/blender/python/intern/bpy_rna.c	2010-09-24 03:48:26 UTC (rev 32093)
@@ -1065,6 +1065,26 @@
 			StructRNA *ptype= RNA_property_pointer_type(ptr, prop);
 			int flag = RNA_property_flag(prop);
 
+			/* this is really nasty!, so we can fake the operator having direct properties eg:
+			 * layout.prop(self, "filepath")
+			 * ... which infact should be
+			 * layout.prop(self.properties, "filepath")
+			 * 
+			 * we need to do this trick.
+			 * if the prop is not an operator type and the pyobject is an operator, use its properties in place of its self.
+			 * 
+			 * this is so bad that its almost a good reason to do away with fake 'self.properties -> self' class mixing
+			 * if this causes problems in the future it should be removed.
+			 */
+			if(	(ptype == &RNA_AnyType) &&
+				(BPy_StructRNA_Check(value)) &&
+				(RNA_struct_is_a(((BPy_StructRNA *)value)->ptr.type, &RNA_Operator))
+			) {
+				value= PyObject_GetAttrString(value, "properties");
+				value_new= value;
+			}
+
+
 			/* if property is an OperatorProperties pointer and value is a map, forward back to pyrna_pydict_to_props */
 			if (RNA_struct_is_a(ptype, &RNA_OperatorProperties) && PyDict_Check(value)) {
 				PointerRNA opptr = RNA_property_pointer_get(ptr, prop);





More information about the Bf-blender-cvs mailing list