diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-01-02 10:54:38 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-01-02 10:54:38 +0300 |
commit | 5d23eaa8f462cdace80b8afc2b766068b4630243 (patch) | |
tree | a24348957a690523f007be7c36035de628f2b743 /source/blender/python/intern/bpy_operator.c | |
parent | cf43c6b0a1a125cf49207d382b6ae6157e0905b4 (diff) |
python support for reporting with operators.
* errors in python called operators are raised as errors
* Python defined operators errors are reported as errors (not full traceback yet)
* added BKE_reports_string, same as BKE_reports_print but it returns a string rather then printing it.
* WM_operator_name_call optionally takes an initialized report struct
Diffstat (limited to 'source/blender/python/intern/bpy_operator.c')
-rw-r--r-- | source/blender/python/intern/bpy_operator.c | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/source/blender/python/intern/bpy_operator.c b/source/blender/python/intern/bpy_operator.c index cc87fd0704e..061c43c4773 100644 --- a/source/blender/python/intern/bpy_operator.c +++ b/source/blender/python/intern/bpy_operator.c @@ -35,7 +35,8 @@ #include "WM_types.h" #include "MEM_guardedalloc.h" -#include "BKE_idprop.h" +//#include "BKE_idprop.h" +#include "BKE_report.h" extern ListBase global_ops; /* evil, temp use */ @@ -168,7 +169,7 @@ PyObject *pyop_func_get_rna(BPy_OperatorFunc *self) } static PyGetSetDef pyop_func_getseters[] = { - {"rna", (getter)pyop_func_get_rna, (setter)NULL, "vertex's coordinate", NULL}, + {"rna", (getter)pyop_func_get_rna, (setter)NULL, "Operator RNA properties", NULL}, {NULL,NULL,NULL,NULL,NULL} /* Sentinel */ }; @@ -178,7 +179,8 @@ static PyObject * pyop_func_call(BPy_OperatorFunc * self, PyObject *args, PyObje int error_val = 0; PointerRNA ptr; - + char *report_str= NULL; + if (PyTuple_Size(args)) { PyErr_SetString( PyExc_AttributeError, "All operator args must be keywords"); return NULL; @@ -195,7 +197,22 @@ static PyObject * pyop_func_call(BPy_OperatorFunc * self, PyObject *args, PyObje error_val= PYOP_props_from_dict(&ptr, kw); if (error_val==0) { - WM_operator_name_call(self->C, self->name, WM_OP_EXEC_DEFAULT, &ptr); + ReportList reports; + + BKE_reports_init(&reports, RPT_STORE); + + WM_operator_name_call(self->C, self->name, WM_OP_EXEC_DEFAULT, &ptr, &reports); + + report_str= BKE_reports_string(&reports, RPT_ERROR); + + if (report_str) { + PyErr_SetString(PyExc_SystemError, report_str); + MEM_freeN(report_str); + error_val = -1; + } + + if (reports.list.first) + BKE_reports_clear(&reports); } WM_operator_properties_free(&ptr); |