21#include "RNA_prototypes.hh"
44 {0,
nullptr, 0,
nullptr,
nullptr},
49 PyObject *cb_func, *cb_args, *
result;
50 PyGILState_STATE gilstate;
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);
85 PyObject *cb_func, *cb_args, *
result;
86 PyGILState_STATE gilstate;
90 cb_func = PyTuple_GET_ITEM((PyObject *)customdata, 1);
91 cb_args = PyTuple_GET_ITEM((PyObject *)customdata, 2);
93 const int cb_args_len = PyTuple_GET_SIZE(cb_args);
95 PyObject *cb_args_xy = PyTuple_New(2);
99 PyTuple_SET_ITEM(cb_args_with_xy, cb_args_len, cb_args_xy);
101 result = PyObject_CallObject(cb_func, cb_args_with_xy);
103 Py_DECREF(cb_args_with_xy);
121 PyObject *cb_func, *cb_args;
122 char *cb_event_str =
nullptr;
125 if (!PyArg_ParseTuple(
126 args,
"OO!|s:bpy_struct.callback_add", &cb_func, &PyTuple_Type, &cb_args, &cb_event_str))
131 if (!PyCallable_Check(cb_func)) {
132 PyErr_SetString(PyExc_TypeError,
"callback_add(): first argument isn't callable");
153 PyErr_SetString(PyExc_TypeError,
"callback_add(): type does not support callbacks");
166 if (!PyArg_ParseTuple(args,
"O!:callback_remove", &PyCapsule_Type, &py_handle)) {
172 if (handle ==
nullptr) {
173 PyErr_SetString(PyExc_ValueError,
174 "callback_remove(handle): nullptr handle given, invalid or already removed");
179 customdata = ED_region_draw_cb_customdata(handle);
180 Py_DECREF((PyObject *)customdata);
185 PyErr_SetString(PyExc_TypeError,
"callback_remove(): type does not support callbacks");
199 if (srna == &RNA_SpaceView3D) {
202 if (srna == &RNA_SpaceGraphEditor) {
205 if (srna == &RNA_SpaceOutliner) {
208 if (srna == &RNA_SpaceProperties) {
211 if (srna == &RNA_SpaceFileBrowser) {
214 if (srna == &RNA_SpaceImageEditor) {
217 if (srna == &RNA_SpaceInfo) {
220 if (srna == &RNA_SpaceSequenceEditor) {
223 if (srna == &RNA_SpaceTextEditor) {
226 if (srna == &RNA_SpaceDopeSheetEditor) {
229 if (srna == &RNA_SpaceNLA) {
232 if (srna == &RNA_SpaceNodeEditor) {
235 if (srna == &RNA_SpaceConsole) {
238 if (srna == &RNA_SpacePreferences) {
241 if (srna == &RNA_SpaceClipEditor) {
244 if (srna == &RNA_SpaceSpreadsheet) {
252 PyObject *args =
static_cast<PyObject *
>(PyCapsule_GetContext(capsule));
260 PyObject *cb_func, *cb_args;
263 if (PyTuple_GET_SIZE(args) < 2) {
264 PyErr_SetString(PyExc_ValueError,
"handler_add(handler): expected at least 2 args");
268 cls = PyTuple_GET_ITEM(args, 0);
272 cb_func = PyTuple_GET_ITEM(args, 1);
273 if (!PyCallable_Check(cb_func)) {
274 PyErr_SetString(PyExc_TypeError,
"first argument isn't callable");
280 if (srna == &RNA_WindowManager) {
290 if (!PyArg_ParseTuple(args,
291 "OOO!|O&O&:WindowManager.draw_cursor_add",
299 &
params.region_type_enum))
305 params.region_type_enum.value,
318 if (!PyArg_ParseTuple(args,
319 "OOO!O&O&:Space.draw_handler_add",
340 if (art ==
nullptr) {
342 PyExc_TypeError,
"region type %R not in space",
params.region_type_enum.value_orig);
349 PyErr_SetString(PyExc_TypeError,
"callback_add(): type does not support callbacks");
361 PyCapsule_SetContext(
ret, args);
373 bool capsule_clear =
false;
374 bool handle_removed =
false;
376 if (PyTuple_GET_SIZE(args) < 2) {
377 PyErr_SetString(PyExc_ValueError,
"callback_remove(handler): expected at least 2 args");
381 cls = PyTuple_GET_ITEM(args, 0);
385 py_handle = PyTuple_GET_ITEM(args, 1);
387 if (handle ==
nullptr) {
388 PyErr_SetString(PyExc_ValueError,
389 "callback_remove(handler): nullptr handler given, invalid or already removed");
393 if (srna == &RNA_WindowManager) {
394 if (!PyArg_ParseTuple(
395 args,
"OO!:WindowManager.draw_cursor_remove", &cls, &PyCapsule_Type, &py_handle))
400 capsule_clear =
true;
403 const char *error_prefix =
"Space.draw_handler_remove";
409 if (!PyArg_ParseTuple(args,
410 "OO!O&:Space.draw_handler_remove",
415 &
params.region_type_enum))
422 PyErr_Format(PyExc_TypeError,
423 "%s: unknown space type '%.200s'",
431 if (art ==
nullptr) {
432 PyErr_Format(PyExc_TypeError,
433 "%s: region type %R not in space",
435 params.region_type_enum.value_orig);
439 capsule_clear =
true;
442 PyErr_SetString(PyExc_TypeError,
"callback_remove(): type does not support callbacks");
449 if (handle_removed ==
true) {
451 PyObject *handle_args =
static_cast<PyObject *
>(PyCapsule_GetContext(py_handle));
452 Py_DECREF(handle_args);
457 PyCapsule_Destructor destructor_fn = PyCapsule_GetDestructor(py_handle);
459 destructor_fn(py_handle);
460 PyCapsule_SetDestructor(py_handle,
nullptr);
474 PyObject *tuple =
static_cast<PyObject *
>(customdata);
477 PyGILState_STATE gilstate;
479 gilstate = PyGILState_Ensure();
485 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 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)
static void cb_wm_cursor_draw(bContext *C, int x, int y, void *customdata)
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)
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)