21 #include "../generic/py_capi_rna.h"
22 #include "../generic/py_capi_utils.h"
23 #include "../generic/python_utildefines.h"
32 #include "RNA_prototypes.h"
45 #define BPY_RELEASE_GIL
49 const char *opname = PyUnicode_AsUTF8(value);
51 PyErr_Format(PyExc_TypeError,
"%s() expects a string argument", py_fn_id);
57 PyErr_Format(PyExc_KeyError,
"%s(\"%s\") not found", py_fn_id, opname);
66 PyExc_DeprecationWarning,
70 "Passing in context overrides is deprecated in favor of "
71 "Context.temp_override(..), %s \"%s\"",
76 PyErr_WriteUnraisable(
NULL);
84 PyObject *context_dict =
NULL;
85 const char *context_str =
NULL;
95 PyErr_SetString(PyExc_RuntimeError,
"Context is None, can't poll any operators");
99 if (!PyArg_ParseTuple(args,
"s|Os:_bpy.ops.poll", &opname, &context_dict, &context_str)) {
106 PyErr_Format(PyExc_AttributeError,
107 "Polling operator \"bpy.ops.%s\" error, "
108 "could not be found",
118 PyErr_Format(PyExc_TypeError,
119 "Calling operator \"bpy.ops.%s.poll\" error, "
120 "expected a string enum in (%s)",
130 if (
ELEM(context_dict,
NULL, Py_None)) {
133 else if (PyDict_Check(context_dict)) {
137 PyErr_Format(PyExc_TypeError,
138 "Calling operator \"bpy.ops.%s.poll\" error, "
139 "custom context expected a dict or None, got a %.200s",
141 Py_TYPE(context_dict)->tp_name);
146 if (context_dict !=
NULL) {
148 Py_INCREF(context_dict);
154 if (context_dict !=
NULL) {
156 if (context_dict_test != context_dict) {
157 Py_DECREF(context_dict_test);
161 Py_DECREF(context_dict);
165 return Py_INCREF_RET(
ret);
176 const char *context_str =
NULL;
178 PyObject *context_dict =
NULL;
188 PyErr_SetString(PyExc_RuntimeError,
"Context is None, can't poll any operators");
192 if (!PyArg_ParseTuple(args,
193 "sO|O!si:_bpy.ops.call",
206 PyErr_Format(PyExc_AttributeError,
207 "Calling operator \"bpy.ops.%s\" error, "
208 "could not be found",
214 PyErr_Format(PyExc_RuntimeError,
215 "Calling operator \"bpy.ops.%s\" error, "
216 "can't modify blend data in this state (drawing/rendering)",
226 PyErr_Format(PyExc_TypeError,
227 "Calling operator \"bpy.ops.%s\" error, "
228 "expected a string enum in (%s)",
238 if (
ELEM(context_dict,
NULL, Py_None)) {
241 else if (PyDict_Check(context_dict)) {
245 PyErr_Format(PyExc_TypeError,
246 "Calling operator \"bpy.ops.%s\" error, "
247 "custom context expected a dict or None, got a %.200s",
249 Py_TYPE(context_dict)->tp_name);
259 if (context_dict !=
NULL) {
261 Py_INCREF(context_dict);
265 bool msg_free =
false;
267 PyErr_Format(PyExc_RuntimeError,
268 "Operator bpy.ops.%.200s.poll() %.200s",
270 msg ? msg :
"failed, context is incorrect");
281 if (kw && PyDict_Size(kw)) {
283 &
ptr, kw,
false,
"Converting py args to operator properties: ");
286 if (error_val == 0) {
294 #ifdef BPY_RELEASE_GIL
300 PyThreadState *ts = PyEval_SaveThread();
305 #ifdef BPY_RELEASE_GIL
307 PyEval_RestoreThread(ts);
336 PyErr_Format(PyExc_AttributeError,
"Operator \"%s\" does not take any args", opname);
345 if (context_dict !=
NULL) {
347 if (context_dict_test != context_dict) {
348 Py_DECREF(context_dict_test);
352 Py_DECREF(context_dict);
356 if (error_val == -1) {
377 bool all_args =
true;
378 bool macro_args =
true;
387 PyErr_SetString(PyExc_RuntimeError,
388 "Context is None, can't get the string representation of this object.");
392 if (!PyArg_ParseTuple(args,
393 "s|O!O&O&:_bpy.ops.as_string",
407 PyErr_Format(PyExc_AttributeError,
408 "_bpy.ops.as_string: operator \"%.200s\" "
409 "could not be found",
418 if (kw && PyDict_Size(kw)) {
420 &
ptr, kw,
false,
"Converting py args to operator properties: ");
423 if (error_val == 0) {
429 if (error_val == -1) {
434 pybuf = PyUnicode_FromString(buf);
438 pybuf = PyUnicode_FromString(
"");
455 PyList_SET_ITEM(list, i, PyUnicode_FromString(
ot->
idname));
471 return (PyObject *)pyrna;
495 PyModuleDef_HEAD_INIT,
void CTX_py_state_push(bContext *C, struct bContext_PyState *pystate, void *value)
void * CTX_py_dict_get(const bContext *C)
void CTX_py_state_pop(bContext *C, struct bContext_PyState *pystate)
const char * CTX_wm_operator_poll_msg_get(struct bContext *C, bool *r_free)
void CTX_wm_operator_poll_msg_clear(struct bContext *C)
void BKE_reports_clear(ReportList *reports)
void BKE_reports_init(ReportList *reports, int flag)
void BLI_ghashIterator_step(GHashIterator *ghi)
BLI_INLINE void * BLI_ghashIterator_getValue(GHashIterator *ghi) ATTR_WARN_UNUSED_RESULT
unsigned int BLI_ghash_len(const GHash *gh) ATTR_WARN_UNUSED_RESULT
BLI_INLINE bool BLI_ghashIterator_done(const GHashIterator *ghi) ATTR_WARN_UNUSED_RESULT
BLI_INLINE bool BLI_listbase_is_empty(const struct ListBase *lb)
void BPY_modules_update(void)
Read Guarded memory(de)allocation.
void BPy_reports_write_stdout(const ReportList *reports, const char *header)
short BPy_reports_to_error(ReportList *reports, PyObject *exception, const bool clear)
struct bContext * BPY_context_get(void)
static wmOperatorType * ot_lookup_from_py_string(PyObject *value, const char *py_fn_id)
static PyObject * pyop_getrna_type(PyObject *UNUSED(self), PyObject *value)
static struct PyModuleDef bpy_ops_module
static PyObject * pyop_as_string(PyObject *UNUSED(self), PyObject *args)
static PyObject * pyop_dir(PyObject *UNUSED(self))
static struct PyMethodDef bpy_ops_methods[]
PyObject * BPY_operator_module(void)
static PyObject * pyop_poll(PyObject *UNUSED(self), PyObject *args)
static void op_context_override_deprecated_warning(const char *action, const char *opname)
static PyObject * pyop_call(PyObject *UNUSED(self), PyObject *args)
static PyObject * pyop_get_bl_options(PyObject *UNUSED(self), PyObject *value)
PyObject * PYOP_wrap_macro_define(PyObject *UNUSED(self), PyObject *args)
bool pyrna_write_check(void)
PyObject * pyrna_struct_CreatePyObject(PointerRNA *ptr)
int pyrna_pydict_to_props(PointerRNA *ptr, PyObject *kw, const bool all_args, const char *error_prefix)
void(* MEM_freeN)(void *vmemh)
void *(* MEM_mallocN)(size_t len, const char *str)
PyObject * pyrna_enum_bitfield_as_set(const EnumPropertyItem *items, int value)
char * pyrna_enum_repr(const EnumPropertyItem *item)
int PyC_ParseBool(PyObject *o, void *p)
void RNA_pointer_create(ID *id, StructRNA *type, void *data, PointerRNA *r_ptr)
bool RNA_enum_value_from_id(const EnumPropertyItem *item, const char *identifier, int *r_value)
const EnumPropertyItem rna_enum_operator_context_items[]
const EnumPropertyItem rna_enum_operator_type_flag_items[]
const EnumPropertyItem rna_enum_operator_return_items[]
bool WM_operator_poll_context(bContext *C, wmOperatorType *ot, short context)
int WM_operator_name_call(bContext *C, const char *opstring, wmOperatorCallContext context, PointerRNA *properties, const wmEvent *event)
int WM_operator_call_py(bContext *C, wmOperatorType *ot, wmOperatorCallContext context, PointerRNA *properties, ReportList *reports, const bool is_undo)
void WM_operatortype_iter(GHashIterator *ghi)
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)
char * WM_operator_pystring_ex(bContext *C, wmOperator *op, const bool all_args, const bool macro_args, wmOperatorType *ot, PointerRNA *opptr)
void WM_operator_properties_create_ptr(PointerRNA *ptr, wmOperatorType *ot)
void WM_operator_properties_free(PointerRNA *ptr)
void WM_operator_properties_sanitize(PointerRNA *ptr, const bool no_context)