[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [33196] trunk/blender/source/blender: - report python script errors to blender report system, or through operators reports (when using operator callbacks).

Campbell Barton ideasman42 at gmail.com
Sat Nov 20 17:39:15 CET 2010


Revision: 33196
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=33196
Author:   campbellbarton
Date:     2010-11-20 17:39:15 +0100 (Sat, 20 Nov 2010)

Log Message:
-----------
- report python script errors to blender report system, or through operators reports (when using operator callbacks).
- when python operators fail to execute they were returning RUNNING_MODAL, now return CANCELLED

now when an operator fails it gives an error popup as well as a message in the terminal.

Modified Paths:
--------------
    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/intern/rna_wm_api.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_wm_api.c	2010-11-20 16:00:36 UTC (rev 33195)
+++ trunk/blender/source/blender/makesrna/intern/rna_wm_api.c	2010-11-20 16:39:15 UTC (rev 33196)
@@ -34,6 +34,7 @@
 
 #include "DNA_screen_types.h"
 #include "DNA_space_types.h"
+#include "DNA_windowmanager_types.h"
 
 #ifdef RNA_RUNTIME
 
@@ -92,7 +93,7 @@
 	}
 
 	if(flag & WM_GEN_INVOKE_RETURN) {
-		parm= RNA_def_enum(func, "result", operator_return_items, 0, "result", "");
+		parm= RNA_def_enum(func, "result", operator_return_items, OPERATOR_CANCELLED, "result", "");
 		RNA_def_property_flag(parm, PROP_ENUM_FLAG);
 		RNA_def_function_return(func, parm);
 	}
@@ -161,7 +162,7 @@
 	RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL);
 	RNA_def_pointer(func, "context", "Context", "", "");
 
-	parm= RNA_def_enum(func, "result", operator_return_items, 0, "result", ""); // better name?
+	parm= RNA_def_enum(func, "result", operator_return_items, OPERATOR_CANCELLED, "result", ""); // better name?
 	RNA_def_property_flag(parm, PROP_ENUM_FLAG);
 	RNA_def_function_return(func, parm);
 
@@ -181,7 +182,7 @@
 	RNA_def_pointer(func, "context", "Context", "", "");
 	RNA_def_pointer(func, "event", "Event", "", "");
 
-	parm= RNA_def_enum(func, "result", operator_return_items, 0, "result", ""); // better name?
+	parm= RNA_def_enum(func, "result", operator_return_items, OPERATOR_CANCELLED, "result", ""); // better name?
 	RNA_def_property_flag(parm, PROP_ENUM_FLAG);
 	RNA_def_function_return(func, parm);
 
@@ -191,7 +192,7 @@
 	RNA_def_pointer(func, "context", "Context", "", "");
 	RNA_def_pointer(func, "event", "Event", "", "");
 
-	parm= RNA_def_enum(func, "result", operator_return_items, 0, "result", ""); // better name?
+	parm= RNA_def_enum(func, "result", operator_return_items, OPERATOR_CANCELLED, "result", ""); // better name?
 	RNA_def_property_flag(parm, PROP_ENUM_FLAG);
 	RNA_def_function_return(func, parm);
 

Modified: trunk/blender/source/blender/python/intern/bpy_rna.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_rna.c	2010-11-20 16:00:36 UTC (rev 33195)
+++ trunk/blender/source/blender/python/intern/bpy_rna.c	2010-11-20 16:39:15 UTC (rev 33196)
@@ -5244,6 +5244,20 @@
 	}
 
 	if(err != 0) {
+		ReportList *reports;
+		/* alert the user, else they wont know unless they see the console. */
+		if (!is_static && ptr->data && RNA_struct_is_a(ptr->type, &RNA_Operator)) {
+			wmOperator *op= ptr->data;
+			reports= op->reports;
+		}
+		else {
+			/* wont alert users but they can view in 'info' space */
+			reports= CTX_wm_reports(C);
+		}
+
+		BPy_errors_to_report(reports);
+
+		/* also print in the console for py */
 		PyErr_Print();
 		PyErr_Clear();
 	}





More information about the Bf-blender-cvs mailing list