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.
This commit is contained in:
2010-09-24 03:48:26 +00:00
parent f866de1c9f
commit e90ad1d9ba
4 changed files with 27 additions and 8 deletions

View File

@@ -53,11 +53,11 @@ class ExportPLY(bpy.types.Operator, ExportHelper):
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):

View File

@@ -113,7 +113,6 @@ class ExportOBJ(bpy.types.Operator, ExportHelper):
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)

View File

@@ -67,10 +67,10 @@ class SelectPattern(bpy.types.Operator):
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):

View File

@@ -1065,6 +1065,26 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, ParameterList *p
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);