[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [35588] trunk/blender/source/blender/ makesrna/intern: add cancel() method for python defined operators.

Campbell Barton ideasman42 at gmail.com
Thu Mar 17 08:02:02 CET 2011


Revision: 35588
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=35588
Author:   campbellbarton
Date:     2011-03-17 07:02:02 +0000 (Thu, 17 Mar 2011)
Log Message:
-----------
add cancel() method for python defined operators.

Modified Paths:
--------------
    trunk/blender/source/blender/makesrna/intern/rna_wm.c
    trunk/blender/source/blender/makesrna/intern/rna_wm_api.c

Modified: trunk/blender/source/blender/makesrna/intern/rna_wm.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_wm.c	2011-03-17 06:57:12 UTC (rev 35587)
+++ trunk/blender/source/blender/makesrna/intern/rna_wm.c	2011-03-17 07:02:02 UTC (rev 35588)
@@ -828,6 +828,30 @@
 	RNA_parameter_list_free(&list);
 }
 
+/* same as exec(), but call cancel */
+static int operator_cancel(bContext *C, wmOperator *op)
+{
+	PointerRNA opr;
+	ParameterList list;
+	FunctionRNA *func;
+	void *ret;
+	int result;
+
+	RNA_pointer_create(&CTX_wm_screen(C)->id, op->type->ext.srna, op, &opr);
+	func= RNA_struct_find_function(&opr, "cancel");
+
+	RNA_parameter_list_create(&list, &opr, func);
+	RNA_parameter_set_lookup(&list, "context", &C);
+	op->type->ext.call(C, &opr, func, &list);
+
+	RNA_parameter_get_lookup(&list, "result", &ret);
+	result= *(int*)ret;
+
+	RNA_parameter_list_free(&list);
+
+	return result;
+}
+
 void operator_wrapper(wmOperatorType *ot, void *userdata);
 void macro_wrapper(wmOperatorType *ot, void *userdata);
 
@@ -839,7 +863,7 @@
 	wmOperatorType dummyot = {NULL};
 	wmOperator dummyop= {NULL};
 	PointerRNA dummyotr;
-	int have_function[6];
+	int have_function[7];
 
 	/* setup dummy operator & operator type to store static properties in */
 	dummyop.type= &dummyot;
@@ -927,6 +951,7 @@
 	dummyot.invoke=		(have_function[3])? operator_invoke: NULL;
 	dummyot.modal=		(have_function[4])? operator_modal: NULL;
 	dummyot.ui=			(have_function[5])? operator_draw: NULL;
+	dummyot.cancel=		(have_function[6])? operator_cancel: NULL;
 	WM_operatortype_append_ptr(operator_wrapper, (void *)&dummyot);
 
 	/* update while blender is running */

Modified: trunk/blender/source/blender/makesrna/intern/rna_wm_api.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_wm_api.c	2011-03-17 06:57:12 UTC (rev 35587)
+++ trunk/blender/source/blender/makesrna/intern/rna_wm_api.c	2011-03-17 07:02:02 UTC (rev 35588)
@@ -215,6 +215,13 @@
 	RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL);
 	parm= RNA_def_pointer(func, "context", "Context", "", "");
 	RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL);
+
+	/* cancel */
+	func= RNA_def_function(srna, "cancel", NULL);
+	RNA_def_function_ui_description(func, "Called when the operator is cancelled.");
+	RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL);
+	parm= RNA_def_pointer(func, "context", "Context", "", "");
+	RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL);
 }
 
 void RNA_api_macro(StructRNA *srna)




More information about the Bf-blender-cvs mailing list