34#include "RNA_prototypes.hh"
47#define BPY_RELEASE_GIL
51 const char *opname = PyUnicode_AsUTF8(value);
52 if (opname ==
nullptr) {
53 PyErr_Format(PyExc_TypeError,
"%s() expects a string argument", py_fn_id);
59 PyErr_Format(PyExc_KeyError,
"%s(\"%s\") not found", py_fn_id, opname);
65static PyObject *
pyop_poll(PyObject * , PyObject *args)
69 const char *context_str =
nullptr;
79 PyErr_SetString(PyExc_RuntimeError,
"Context is None, cannot poll any operators");
84 static const char *_keywords[] = {
"",
"",
nullptr};
85 static _PyArg_Parser _parser = {
94 if (!_PyArg_ParseTupleAndKeywordsFast(args,
nullptr, &_parser, &opname, &context_str)) {
101 PyErr_Format(PyExc_AttributeError,
102 "Polling operator \"bpy.ops.%s\" error, "
103 "could not be found",
109 int context_int = int(context);
113 PyErr_Format(PyExc_TypeError,
114 "Calling operator \"bpy.ops.%s.poll\" error, "
115 "expected a string enum in (%s)",
128 return Py_NewRef(
ret);
139 const char *context_str =
nullptr;
140 PyObject *kw =
nullptr;
150 PyErr_SetString(PyExc_RuntimeError,
"Context is None, cannot poll any operators");
155 static const char *_keywords[] = {
"",
"",
"",
"",
nullptr};
156 static _PyArg_Parser _parser = {
167 if (!_PyArg_ParseTupleAndKeywordsFast(
168 args,
nullptr, &_parser, &opname, &PyDict_Type, &kw, &context_str, &is_undo))
176 PyErr_Format(PyExc_AttributeError,
177 "Calling operator \"bpy.ops.%s\" error, "
178 "could not be found",
184 PyErr_Format(PyExc_RuntimeError,
185 "Calling operator \"bpy.ops.%s\" error, "
186 "cannot modify blend data in this state (drawing/rendering)",
192 int context_int = int(context);
196 PyErr_Format(PyExc_TypeError,
197 "Calling operator \"bpy.ops.%s\" error, "
198 "expected a string enum in (%s)",
209 bool msg_free =
false;
211 PyErr_Format(PyExc_RuntimeError,
212 "Operator bpy.ops.%.200s.poll() %.200s",
214 msg ? msg :
"failed, context is incorrect");
225 if (kw && PyDict_Size(kw)) {
227 &
ptr, kw,
false,
"Converting py args to operator properties:");
230 if (error_val == 0) {
238#ifdef BPY_RELEASE_GIL
244 PyThreadState *ts = PyEval_SaveThread();
249#ifdef BPY_RELEASE_GIL
251 PyEval_RestoreThread(ts);
285 PyErr_Format(PyExc_AttributeError,
"Operator \"%s\" does not take any args", opname);
294 if (error_val == -1) {
313 PyObject *kw =
nullptr;
314 bool all_args =
true;
315 bool macro_args =
true;
321 PyErr_SetString(PyExc_RuntimeError,
322 "Context is None, cannot get the string representation of this object.");
327 static const char *_keywords[] = {
"",
"",
"",
"",
nullptr};
328 static _PyArg_Parser _parser = {
335 ":_bpy.ops.as_string",
339 if (!_PyArg_ParseTupleAndKeywordsFast(args,
356 PyErr_Format(PyExc_AttributeError,
357 "_bpy.ops.as_string: operator \"%.200s\" "
358 "could not be found",
367 if (kw && PyDict_Size(kw)) {
369 &
ptr, kw,
false,
"Converting py args to operator properties:");
372 std::string op_string;
373 if (error_val == 0) {
379 if (error_val == -1) {
389 PyObject *list = PyList_New(
types.size());
393 PyList_SET_ITEM(list,
i, PyUnicode_FromString(
ot->idname));
409 return (PyObject *)pyrna;
423# pragma clang diagnostic push
424# pragma clang diagnostic ignored "-Wcast-function-type"
426# pragma GCC diagnostic push
427# pragma GCC diagnostic ignored "-Wcast-function-type"
432 {
"poll", (PyCFunction)
pyop_poll, METH_VARARGS,
nullptr},
433 {
"call", (PyCFunction)
pyop_call, METH_VARARGS,
nullptr},
434 {
"as_string", (PyCFunction)
pyop_as_string, METH_VARARGS,
nullptr},
435 {
"dir", (PyCFunction)
pyop_dir, METH_NOARGS,
nullptr},
439 {
nullptr,
nullptr, 0,
nullptr},
444# pragma clang diagnostic pop
446# pragma GCC diagnostic pop
void CTX_wm_operator_poll_msg_clear(bContext *C)
const char * CTX_wm_operator_poll_msg_get(bContext *C, bool *r_free)
@ RPT_PRINT_HANDLED_BY_OWNER
void BKE_reports_free(ReportList *reports)
void BKE_report_print_level_set(ReportList *reports, eReportType level)
void BKE_reports_clear(ReportList *reports)
void BKE_reports_init(ReportList *reports, int flag)
BLI_INLINE bool BLI_listbase_is_empty(const ListBase *lb)
void BPY_modules_update()
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()
static PyObject * pyop_getrna_type(PyObject *, PyObject *value)
static PyObject * pyop_get_bl_options(PyObject *, PyObject *value)
static PyObject * pyop_dir(PyObject *)
static PyMethodDef bpy_ops_methods[]
static PyObject * pyop_call(PyObject *, PyObject *args)
static PyObject * pyop_poll(PyObject *, PyObject *args)
static PyObject * pyop_as_string(PyObject *, PyObject *args)
static PyModuleDef bpy_ops_module
static wmOperatorType * ot_lookup_from_py_string(PyObject *value, const char *py_fn_id)
PyObject * BPY_operator_module()
PyObject * PYOP_wrap_macro_define(PyObject *, PyObject *args)
int pyrna_pydict_to_props(PointerRNA *ptr, PyObject *kw, const bool all_args, const char *error_prefix)
PyObject * pyrna_struct_CreatePyObject(PointerRNA *ptr)
void * MEM_mallocN(size_t len, const char *str)
void MEM_freeN(void *vmemh)
PyObject * pyrna_enum_bitfield_as_set(const EnumPropertyItem *items, int value)
char * pyrna_enum_repr(const EnumPropertyItem *item)
PyObject * PyC_UnicodeFromStdStr(const std::string &str)
int PyC_ParseBool(PyObject *o, void *p)
header-only compatibility defines.
#define PY_ARG_PARSER_HEAD_COMPAT()
bool RNA_enum_value_from_id(const EnumPropertyItem *item, const char *identifier, int *r_value)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
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, blender::wm::OpCallContext context)
wmOperatorStatus WM_operator_call_py(bContext *C, wmOperatorType *ot, blender::wm::OpCallContext context, PointerRNA *properties, ReportList *reports, const bool is_undo)
wmOperatorStatus WM_operator_name_call(bContext *C, const char *opstring, blender::wm::OpCallContext context, PointerRNA *properties, const wmEvent *event)
blender::Span< wmOperatorType * > WM_operatortypes_registered_get()
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)
std::string 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)