21#include "RNA_prototypes.hh"
44 {0,
nullptr, 0,
nullptr,
nullptr},
49 PyGILState_STATE gilstate;
52 PyObject *cb_func, *cb_args, *
result;
54 cb_func = PyTuple_GET_ITEM((PyObject *)customdata, 1);
55 cb_args = PyTuple_GET_ITEM((PyObject *)customdata, 2);
56 result = PyObject_CallObject(cb_func, cb_args);
72 PyObject *dst = PyTuple_New(len_dst);
73 const int len_src = PyTuple_GET_SIZE(src);
75 for (
int i = 0;
i < len_src;
i++) {
76 PyObject *item = PyTuple_GET_ITEM(src,
i);
77 PyTuple_SET_ITEM(dst,
i, item);
88 PyGILState_STATE gilstate;
91 PyObject *cb_func, *cb_args, *
result;
92 cb_func = PyTuple_GET_ITEM((PyObject *)customdata, 1);
93 cb_args = PyTuple_GET_ITEM((PyObject *)customdata, 2);
95 const int cb_args_len = PyTuple_GET_SIZE(cb_args);
97 PyObject *cb_args_xy = PyTuple_New(2);
101 PyTuple_SET_ITEM(cb_args_with_xy, cb_args_len, cb_args_xy);
103 result = PyObject_CallObject(cb_func, cb_args_with_xy);
105 Py_DECREF(cb_args_with_xy);
123 PyObject *cb_func, *cb_args;
124 char *cb_event_str =
nullptr;
127 if (!PyArg_ParseTuple(
128 args,
"OO!|s:bpy_struct.callback_add", &cb_func, &PyTuple_Type, &cb_args, &cb_event_str))
133 if (!PyCallable_Check(cb_func)) {
134 PyErr_SetString(PyExc_TypeError,
"callback_add(): first argument isn't callable");
155 PyErr_SetString(PyExc_TypeError,
"callback_add(): type does not support callbacks");
168 if (!PyArg_ParseTuple(args,
"O!:callback_remove", &PyCapsule_Type, &py_handle)) {
174 if (handle ==
nullptr) {
175 PyErr_SetString(PyExc_ValueError,
176 "callback_remove(handle): nullptr handle given, invalid or already removed");
181 customdata = ED_region_draw_cb_customdata(handle);
182 Py_DECREF((PyObject *)customdata);
187 PyErr_SetString(PyExc_TypeError,
"callback_remove(): type does not support callbacks");
201 if (srna == &RNA_SpaceView3D) {
204 if (srna == &RNA_SpaceGraphEditor) {
207 if (srna == &RNA_SpaceOutliner) {
210 if (srna == &RNA_SpaceProperties) {
213 if (srna == &RNA_SpaceFileBrowser) {
216 if (srna == &RNA_SpaceImageEditor) {
219 if (srna == &RNA_SpaceInfo) {
222 if (srna == &RNA_SpaceSequenceEditor) {
225 if (srna == &RNA_SpaceTextEditor) {
228 if (srna == &RNA_SpaceDopeSheetEditor) {
231 if (srna == &RNA_SpaceNLA) {
234 if (srna == &RNA_SpaceNodeEditor) {
237 if (srna == &RNA_SpaceConsole) {
240 if (srna == &RNA_SpacePreferences) {
243 if (srna == &RNA_SpaceClipEditor) {
246 if (srna == &RNA_SpaceSpreadsheet) {
254 PyObject *args =
static_cast<PyObject *
>(PyCapsule_GetContext(capsule));
262 PyObject *cb_func, *cb_args;
265 if (PyTuple_GET_SIZE(args) < 2) {
266 PyErr_SetString(PyExc_ValueError,
"handler_add(handler): expected at least 2 args");
270 cls = PyTuple_GET_ITEM(args, 0);
274 cb_func = PyTuple_GET_ITEM(args, 1);
275 if (!PyCallable_Check(cb_func)) {
276 PyErr_SetString(PyExc_TypeError,
"first argument isn't callable");
282 if (srna == &RNA_WindowManager) {
292 if (!PyArg_ParseTuple(args,
293 "OOO!|O&O&:WindowManager.draw_cursor_add",
301 &
params.region_type_enum))
307 params.region_type_enum.value,
320 if (!PyArg_ParseTuple(args,
321 "OOO!O&O&:Space.draw_handler_add",
342 if (art ==
nullptr) {
344 PyExc_TypeError,
"region type %R not in space",
params.region_type_enum.value_orig);
351 PyErr_SetString(PyExc_TypeError,
"callback_add(): type does not support callbacks");
363 PyCapsule_SetContext(
ret, args);
375 bool capsule_clear =
false;
376 bool handle_removed =
false;
378 if (PyTuple_GET_SIZE(args) < 2) {
379 PyErr_SetString(PyExc_ValueError,
"callback_remove(handler): expected at least 2 args");
383 cls = PyTuple_GET_ITEM(args, 0);
387 py_handle = PyTuple_GET_ITEM(args, 1);
389 if (handle ==
nullptr) {
390 PyErr_SetString(PyExc_ValueError,
391 "callback_remove(handler): nullptr handler given, invalid or already removed");
395 if (srna == &RNA_WindowManager) {
396 if (!PyArg_ParseTuple(
397 args,
"OO!:WindowManager.draw_cursor_remove", &cls, &PyCapsule_Type, &py_handle))
402 capsule_clear =
true;
405 const char *error_prefix =
"Space.draw_handler_remove";
411 if (!PyArg_ParseTuple(args,
412 "OO!O&:Space.draw_handler_remove",
417 &
params.region_type_enum))
424 PyErr_Format(PyExc_TypeError,
425 "%s: unknown space type '%.200s'",
433 if (art ==
nullptr) {
434 PyErr_Format(PyExc_TypeError,
435 "%s: region type %R not in space",
437 params.region_type_enum.value_orig);
441 capsule_clear =
true;
444 PyErr_SetString(PyExc_TypeError,
"callback_remove(): type does not support callbacks");
451 if (handle_removed ==
true) {
453 PyObject *handle_args =
static_cast<PyObject *
>(PyCapsule_GetContext(py_handle));
454 Py_DECREF(handle_args);
459 PyCapsule_Destructor destructor_fn = PyCapsule_GetDestructor(py_handle);
461 destructor_fn(py_handle);
462 PyCapsule_SetDestructor(py_handle,
nullptr);
476 PyGILState_STATE gilstate = PyGILState_Ensure();
478 PyObject *tuple =
static_cast<PyObject *
>(customdata);
481 PyGILState_Release(gilstate);
SpaceType * BKE_spacetype_from_id(int spaceid)
ARegionType * BKE_regiontype_from_id(const SpaceType *st, int regionid)
void * ED_region_draw_cb_activate(ARegionType *art, void(*draw)(const bContext *, ARegion *, void *), void *customdata, int type)
void ED_region_draw_cb_remove_by_type(ARegionType *art, void *draw_fn, void(*free)(void *))
#define REGION_DRAW_POST_VIEW
#define REGION_DRAW_BACKDROP
bool ED_region_draw_cb_exit(ARegionType *art, void *handle)
#define REGION_DRAW_POST_PIXEL
#define REGION_DRAW_PRE_VIEW
void bpy_context_clear(struct bContext *C, const PyGILState_STATE *gilstate)
void bpy_context_set(struct bContext *C, PyGILState_STATE *gilstate)
StructRNA * pyrna_struct_as_srna(PyObject *self, const bool parent, const char *error_prefix)
static eSpace_Type rna_Space_refine_reverse(StructRNA *srna)
static PyObject * PyC_Tuple_CopySized(PyObject *src, int len_dst)
static void cb_wm_cursor_draw(bContext *C, const blender::int2 &xy, const blender::float2 &, void *customdata)
static const char * rna_capsual_id_invalid
static void cb_customdata_free(void *customdata)
void BPY_callback_screen_free(ARegionType *art)
static void cb_region_draw(const bContext *C, ARegion *, void *customdata)
static void cb_rna_capsule_destructor(PyObject *capsule)
PyObject * pyrna_callback_classmethod_remove(PyObject *, PyObject *args)
PyObject * pyrna_callback_classmethod_add(PyObject *, PyObject *args)
static const EnumPropertyItem region_draw_mode_items[]
static const char * rna_capsual_id
void BPY_callback_wm_free(wmWindowManager *wm)
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
int pyrna_enum_value_from_id(const EnumPropertyItem *item, const char *identifier, int *r_value, const char *error_prefix)
int pyrna_enum_value_parse_string(PyObject *o, void *p)
#define PyTuple_SET_ITEMS(op_arg,...)
bool RNA_struct_is_a(const StructRNA *type, const StructRNA *srna)
const char * RNA_struct_identifier(const StructRNA *type)
const EnumPropertyItem rna_enum_region_type_items[]
const EnumPropertyItem rna_enum_space_type_items[]
bool WM_paint_cursor_end(wmPaintCursor *handle)
void WM_paint_cursor_remove_by_type(wmWindowManager *wm, void *draw_fn, void(*free)(void *))
wmPaintCursor * WM_paint_cursor_activate(short space_type, short region_type, bool(*poll)(bContext *C), wmPaintCursorDraw draw, void *customdata)