[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [51834] trunk/blender/source/blender: BPY/ RNA: determine callback functions that are allowed to write data by a flag

Brecht Van Lommel brechtvanlommel at pandora.be
Sat Nov 3 15:31:38 CET 2012


Revision: 51834
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=51834
Author:   blendix
Date:     2012-11-03 14:31:38 +0000 (Sat, 03 Nov 2012)
Log Message:
-----------
BPY/RNA: determine callback functions that are allowed to write data by a flag
on the function instead of checking the name.

Modified Paths:
--------------
    trunk/blender/source/blender/makesrna/RNA_types.h
    trunk/blender/source/blender/makesrna/intern/rna_wm_api.c
    trunk/blender/source/blender/python/intern/bpy_rna.c

Modified: trunk/blender/source/blender/makesrna/RNA_types.h
===================================================================
--- trunk/blender/source/blender/makesrna/RNA_types.h	2012-11-03 14:31:28 UTC (rev 51833)
+++ trunk/blender/source/blender/makesrna/RNA_types.h	2012-11-03 14:31:38 UTC (rev 51834)
@@ -313,6 +313,7 @@
 	FUNC_USE_CONTEXT = 4,
 	FUNC_USE_REPORTS = 8,
 	FUNC_USE_SELF_ID = 2048,
+	FUNC_ALLOW_WRITE = 4096,
 
 	/* registering */
 	FUNC_REGISTER = 16,

Modified: trunk/blender/source/blender/makesrna/intern/rna_wm_api.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_wm_api.c	2012-11-03 14:31:28 UTC (rev 51833)
+++ trunk/blender/source/blender/makesrna/intern/rna_wm_api.c	2012-11-03 14:31:38 UTC (rev 51834)
@@ -316,7 +316,7 @@
 	/* exec */
 	func = RNA_def_function(srna, "execute", NULL);
 	RNA_def_function_ui_description(func, "Execute the operator");
-	RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL);
+	RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL | FUNC_ALLOW_WRITE);
 	parm = RNA_def_pointer(func, "context", "Context", "", "");
 	RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL);
 
@@ -327,7 +327,7 @@
 	/* check */
 	func = RNA_def_function(srna, "check", NULL);
 	RNA_def_function_ui_description(func, "Check the operator settings, return True to signal a change to redraw");
-	RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL);
+	RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL | FUNC_ALLOW_WRITE);
 	parm = RNA_def_pointer(func, "context", "Context", "", "");
 	RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL);
 
@@ -337,7 +337,7 @@
 	/* invoke */
 	func = RNA_def_function(srna, "invoke", NULL);
 	RNA_def_function_ui_description(func, "Invoke the operator");
-	RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL);
+	RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL | FUNC_ALLOW_WRITE);
 	parm = RNA_def_pointer(func, "context", "Context", "", "");
 	RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL);
 	parm = RNA_def_pointer(func, "event", "Event", "", "");
@@ -349,7 +349,7 @@
 
 	func = RNA_def_function(srna, "modal", NULL); /* same as invoke */
 	RNA_def_function_ui_description(func, "Modal operator function");
-	RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL);
+	RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL | FUNC_ALLOW_WRITE);
 	parm = RNA_def_pointer(func, "context", "Context", "", "");
 	RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL);
 	parm = RNA_def_pointer(func, "event", "Event", "", "");
@@ -369,7 +369,7 @@
 	/* cancel */
 	func = RNA_def_function(srna, "cancel", NULL);
 	RNA_def_function_ui_description(func, "Called when the operator is canceled");
-	RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL);
+	RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL | FUNC_ALLOW_WRITE);
 	parm = RNA_def_pointer(func, "context", "Context", "", "");
 	RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL);
 

Modified: trunk/blender/source/blender/python/intern/bpy_rna.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_rna.c	2012-11-03 14:31:28 UTC (rev 51833)
+++ trunk/blender/source/blender/python/intern/bpy_rna.c	2012-11-03 14:31:38 UTC (rev 51834)
@@ -6953,9 +6953,7 @@
 	const int is_operator = RNA_struct_is_a(ptr->type, &RNA_Operator);
 	const char *func_id = RNA_function_identifier(func);
 	/* testing, for correctness, not operator and not draw function */
-	const short is_readonly = ((strncmp("draw", func_id, 4) == 0) || /* draw or draw_header */
-	                           /*strstr("render", func_id) ||*/
-	                           !is_operator);
+	const short is_readonly = !(RNA_function_flag(func) & FUNC_ALLOW_WRITE);
 #endif
 
 	py_class = RNA_struct_py_type_get(ptr->type);




More information about the Bf-blender-cvs mailing list