21#include "RNA_prototypes.hh"
46 {0,
nullptr, 0,
nullptr,
nullptr},
51 PyGILState_STATE gilstate;
54 PyObject *cb_func, *cb_args, *
result;
56 cb_func = PyTuple_GET_ITEM((PyObject *)customdata, 1);
57 cb_args = PyTuple_GET_ITEM((PyObject *)customdata, 2);
58 result = PyObject_CallObject(cb_func, cb_args);
73 PyObject *dst = PyTuple_New(len_dst);
74 const int len_src = PyTuple_GET_SIZE(src);
76 for (
int i = 0; i < len_src; i++) {
77 PyObject *item = PyTuple_GET_ITEM(src, i);
78 PyTuple_SET_ITEM(dst, i, item);
89 PyGILState_STATE gilstate;
92 PyObject *cb_func, *cb_args, *
result;
93 cb_func = PyTuple_GET_ITEM((PyObject *)customdata, 1);
94 cb_args = PyTuple_GET_ITEM((PyObject *)customdata, 2);
96 const int cb_args_len = PyTuple_GET_SIZE(cb_args);
98 PyObject *cb_args_xy = PyTuple_New(2);
102 PyTuple_SET_ITEM(cb_args_with_xy, cb_args_len, cb_args_xy);
104 result = PyObject_CallObject(cb_func, cb_args_with_xy);
106 Py_DECREF(cb_args_with_xy);
119PyObject *pyrna_callback_add(BPy_StructRNA *self, PyObject *args)
123 PyObject *cb_func, *cb_args;
124 char *cb_event_str =
nullptr;
127 if (!PyArg_ParseTuple(args,
132 ":bpy_struct.callback_add",
141 if (!PyCallable_Check(cb_func)) {
142 PyErr_SetString(PyExc_TypeError,
"callback_add(): first argument isn't callable");
163 PyErr_SetString(PyExc_TypeError,
"callback_add(): type does not support callbacks");
170PyObject *pyrna_callback_remove(
BPy_StructRNA *self, PyObject *args)
176 if (!PyArg_ParseTuple(args,
187 if (handle ==
nullptr) {
188 PyErr_SetString(PyExc_ValueError,
189 "callback_remove(handle): null handle given, invalid or already removed");
194 customdata = ED_region_draw_cb_customdata(handle);
195 Py_DECREF((PyObject *)customdata);
200 PyErr_SetString(PyExc_TypeError,
"callback_remove(): type does not support callbacks");
214 if (srna == RNA_SpaceView3D) {
217 if (srna == RNA_SpaceGraphEditor) {
220 if (srna == RNA_SpaceOutliner) {
223 if (srna == RNA_SpaceProperties) {
226 if (srna == RNA_SpaceFileBrowser) {
229 if (srna == RNA_SpaceImageEditor) {
232 if (srna == RNA_SpaceInfo) {
235 if (srna == RNA_SpaceSequenceEditor) {
238 if (srna == RNA_SpaceTextEditor) {
241 if (srna == RNA_SpaceDopeSheetEditor) {
244 if (srna == RNA_SpaceNLA) {
247 if (srna == RNA_SpaceNodeEditor) {
250 if (srna == RNA_SpaceConsole) {
253 if (srna == RNA_SpacePreferences) {
256 if (srna == RNA_SpaceClipEditor) {
259 if (srna == RNA_SpaceSpreadsheet) {
262 if (srna == RNA_SpaceProject) {
270 PyObject *args =
static_cast<PyObject *
>(PyCapsule_GetContext(capsule));
278 PyObject *cb_func, *cb_args;
281 if (PyTuple_GET_SIZE(args) < 2) {
282 PyErr_SetString(PyExc_ValueError,
"handler_add(handler): expected at least 2 args");
286 cls = PyTuple_GET_ITEM(args, 0);
290 cb_func = PyTuple_GET_ITEM(args, 1);
291 if (!PyCallable_Check(cb_func)) {
292 PyErr_SetString(PyExc_TypeError,
"first argument isn't callable");
298 if (srna == RNA_WindowManager) {
308 if (!PyArg_ParseTuple(args,
315 ":WindowManager.draw_cursor_add",
321 ¶ms.space_type_enum,
323 ¶ms.region_type_enum))
329 params.region_type_enum.value,
332 static_cast<void *
>(args));
342 if (!PyArg_ParseTuple(args,
348 ":Space.draw_handler_add",
354 ¶ms.region_type_enum,
369 if (art ==
nullptr) {
371 PyExc_TypeError,
"region type %R not in space", params.region_type_enum.value_orig);
375 art,
cb_region_draw,
static_cast<void *
>(args), params.event_enum.value);
378 PyErr_SetString(PyExc_TypeError,
"callback_add(): type does not support callbacks");
392 PyCapsule_SetContext(
ret, args);
404 bool capsule_clear =
false;
405 bool handle_removed =
false;
407 if (PyTuple_GET_SIZE(args) < 2) {
408 PyErr_SetString(PyExc_ValueError,
"callback_remove(handler): expected at least 2 args");
412 cls = PyTuple_GET_ITEM(args, 0);
416 py_handle = PyTuple_GET_ITEM(args, 1);
418 if (handle ==
nullptr) {
419 PyErr_SetString(PyExc_ValueError,
420 "callback_remove(handler): null handler given, invalid or already removed");
424 if (srna == RNA_WindowManager) {
425 if (!PyArg_ParseTuple(args,
428 ":WindowManager.draw_cursor_remove",
436 capsule_clear =
true;
439 const char *error_prefix =
"Space.draw_handler_remove";
445 if (!PyArg_ParseTuple(args,
449 ":Space.draw_handler_remove",
454 ¶ms.region_type_enum))
461 PyErr_Format(PyExc_TypeError,
462 "%s: unknown space type '%.200s'",
470 if (art ==
nullptr) {
471 PyErr_Format(PyExc_TypeError,
472 "%s: region type %R not in space",
474 params.region_type_enum.value_orig);
478 capsule_clear =
true;
481 PyErr_SetString(PyExc_TypeError,
"callback_remove(): type does not support callbacks");
488 if (handle_removed ==
true) {
490 PyObject *handle_args =
static_cast<PyObject *
>(PyCapsule_GetContext(py_handle));
491 Py_DECREF(handle_args);
496 PyCapsule_Destructor destructor_fn = PyCapsule_GetDestructor(py_handle);
498 destructor_fn(py_handle);
499 PyCapsule_SetDestructor(py_handle,
nullptr);
513 PyGILState_STATE gilstate = PyGILState_Ensure();
515 PyObject *tuple =
static_cast<PyObject *
>(customdata);
518 PyGILState_Release(gilstate);
#define REGION_DRAW_POST_VIEW
#define REGION_DRAW_BACKDROP
#define REGION_DRAW_POST_PIXEL
#define REGION_DRAW_PRE_VIEW
void BPY_callback_screen_free(ARegionType *art)
static void cb_rna_capsule_destructor(PyObject *capsule)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
const EnumPropertyItem rna_enum_space_type_items[]
bool RNA_struct_is_a(const StructRNA *type, const StructRNA *srna)
static const char * rna_capsule_id
static PyObject * PyC_Tuple_CopySized(PyObject *src, int len_dst)
void * ED_region_draw_cb_activate(ARegionType *art, void(*draw)(const bContext *, ARegion *, void *), void *customdata, int type)
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
bool ED_region_draw_cb_exit(ARegionType *art, void *handle)
PyObject * pyrna_callback_classmethod_add(PyObject *, PyObject *args)
static void cb_region_draw(const bContext *C, ARegion *, void *customdata)
static const EnumPropertyItem region_draw_mode_items[]
static eSpace_Type rna_Space_refine_reverse(StructRNA *srna)
ARegionType * BKE_regiontype_from_id(const SpaceType *st, int regionid)
SpaceType * BKE_spacetype_from_id(int spaceid)
static void cb_wm_cursor_draw(bContext *C, const int2 &xy, const float2 &, void *customdata)
wmPaintCursor * WM_paint_cursor_activate(short space_type, short region_type, wmPaintCursorPoll poll, wmPaintCursorDraw draw, void *customdata)
PyObject * pyrna_callback_classmethod_remove(PyObject *, PyObject *args)
const char * RNA_struct_identifier(const StructRNA *type)
const EnumPropertyItem rna_enum_region_type_items[]
StructRNA * pyrna_struct_as_srna(PyObject *self, const bool parent, const char *error_prefix)
void BPY_callback_wm_free(wmWindowManager *wm)
bool bpy_context_set(struct bContext *C, PyGILState_STATE *gilstate) ATTR_NONNULL(1)
void ED_region_draw_cb_remove_by_type(ARegionType *art, void *draw_fn, void(*free)(void *))
void WM_paint_cursor_remove_by_type(wmWindowManager *wm, wmPaintCursorDraw draw_fn, void(*free)(void *))
static void cb_customdata_free(void *customdata)
static const char * rna_capsule_id_invalid
int pyrna_enum_value_from_id(const EnumPropertyItem *item, const char *identifier, int *r_value, const char *error_prefix)
void bpy_context_clear(struct bContext *C, const PyGILState_STATE *gilstate)
int pyrna_enum_value_parse_string(PyObject *o, void *p)
bool WM_paint_cursor_end(wmPaintCursor *handle)
#define PyTuple_SET_ITEMS(op_arg,...)