From 97692a3bf5a91e83e04c9864e3723f2363006111 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 18 Jan 2009 10:46:26 +0000 Subject: Changes to functions from blender/windowmanager/intern/wm_event_system.c Python operator api was using WM_operator_name_call() which was confusing things too much. Added WM_operator_call_py() which ended up being a very small function and split out operator creation into wm_operator_create() Python operator now runs the poll() function and raises an error if it fails. Eventually there should be error messages for poll that python can use to give the exact reason for failing (eg - library linked data, no active object...) --- source/blender/python/intern/bpy_operator.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'source/blender/python') diff --git a/source/blender/python/intern/bpy_operator.c b/source/blender/python/intern/bpy_operator.c index f800b7d0d04..fb1040fac18 100644 --- a/source/blender/python/intern/bpy_operator.c +++ b/source/blender/python/intern/bpy_operator.c @@ -194,6 +194,11 @@ static PyObject * pyop_func_call(BPy_OperatorFunc * self, PyObject *args, PyObje return NULL; } + if(ot->poll && (ot->poll(self->C) == 0)) { + PyErr_SetString( PyExc_SystemError, "Operator poll() function failed, context is incorrect"); + return NULL; + } + WM_operator_properties_create(&ptr, self->name); error_val= PYOP_props_from_dict(&ptr, kw); @@ -203,7 +208,7 @@ static PyObject * pyop_func_call(BPy_OperatorFunc * self, PyObject *args, PyObje BKE_reports_init(&reports, RPT_STORE); - WM_operator_name_call(self->C, self->name, WM_OP_EXEC_DEFAULT, &ptr, &reports); + WM_operator_call_py(self->C, ot, &ptr, &reports); report_str= BKE_reports_string(&reports, RPT_ERROR); -- cgit v1.2.3