Blender V5.0
bpy_rna_types_capi.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
16
17#include <Python.h>
18#include <descrobject.h>
19
20#include "BLI_utildefines.h"
21
22#include "bpy_library.hh"
23#include "bpy_rna.hh"
24#include "bpy_rna_callback.hh"
25#include "bpy_rna_context.hh"
26#include "bpy_rna_data.hh"
28#include "bpy_rna_text.hh"
29#include "bpy_rna_types_capi.hh"
30#include "bpy_rna_ui.hh"
31
32#include "bpy_rna_operator.hh"
33
35
36#include "RNA_prototypes.hh"
37
38#include "MEM_guardedalloc.h"
39
40#include "WM_api.hh"
41
42/* -------------------------------------------------------------------- */
45
46static PyMethodDef pyrna_blenddata_methods[] = {
47 {nullptr, nullptr, 0, nullptr}, /* #BPY_rna_id_collection_user_map_method_def */
48 {nullptr, nullptr, 0, nullptr}, /* #BPY_rna_id_collection_file_path_map_method_def */
49 {nullptr, nullptr, 0, nullptr}, /* #BPY_rna_id_collection_file_path_foreach_method_def */
50 {nullptr, nullptr, 0, nullptr}, /* #BPY_rna_id_collection_batch_remove_method_def */
51 {nullptr, nullptr, 0, nullptr}, /* #BPY_rna_id_collection_orphans_purge_method_def */
52 {nullptr, nullptr, 0, nullptr}, /* #BPY_rna_data_context_method_def */
53 {nullptr, nullptr, 0, nullptr},
54};
55
57
58/* -------------------------------------------------------------------- */
61
62static PyMethodDef pyrna_blenddatalibraries_methods[] = {
63 {nullptr, nullptr, 0, nullptr}, /* #BPY_library_load_method_def */
64 {nullptr, nullptr, 0, nullptr}, /* #BPY_library_write_method_def */
65 {nullptr, nullptr, 0, nullptr},
66};
67
69
70/* -------------------------------------------------------------------- */
73
74static PyMethodDef pyrna_uilayout_methods[] = {
75 {nullptr, nullptr, 0, nullptr}, /* #BPY_rna_uilayout_introspect_method_def */
76 {nullptr, nullptr, 0, nullptr},
77};
78
80
81/* -------------------------------------------------------------------- */
84
85static PyMethodDef pyrna_operator_methods[] = {
86 {nullptr, nullptr, 0, nullptr}, /* #BPY_rna_operator_poll_message_set */
87 {nullptr, nullptr, 0, nullptr},
88};
89
91
92/* -------------------------------------------------------------------- */
95
96static PyMethodDef pyrna_text_methods[] = {
97 {nullptr, nullptr, 0, nullptr}, /* #BPY_rna_region_as_string_method_def */
98 {nullptr, nullptr, 0, nullptr}, /* #BPY_rna_region_from_string_method_def */
99 {nullptr, nullptr, 0, nullptr},
100};
101
103
104/* -------------------------------------------------------------------- */
110
112 /* Wrap. */
113 pyrna_WindowManager_clipboard_doc,
114 "Clipboard text storage.\n"
115 "\n"
116 ":type: str\n");
117static PyObject *pyrna_WindowManager_clipboard_get(PyObject * /*self*/, void * /*flag*/)
118{
119 int text_len = 0;
120 /* No need for UTF8 validation as #PyC_UnicodeFromBytesAndSize handles invalid byte sequences. */
121 char *text = WM_clipboard_text_get(false, false, &text_len);
122 PyObject *result = PyC_UnicodeFromBytesAndSize(text ? text : "", text_len);
123 if (text != nullptr) {
124 MEM_freeN(text);
125 }
126 return result;
127}
128
129static int pyrna_WindowManager_clipboard_set(PyObject * /*self*/, PyObject *value, void * /*flag*/)
130{
131 PyObject *value_coerce = nullptr;
132 const char *text = PyC_UnicodeAsBytes(value, &value_coerce);
133 if (text == nullptr) {
134 return -1;
135 }
136 WM_clipboard_text_set(text, false);
137 Py_XDECREF(value_coerce);
138 return 0;
139}
140
142
143/* -------------------------------------------------------------------- */
146
148 /* Wrap. */
149 pyrna_draw_cursor_add_doc,
150 ".. classmethod:: draw_cursor_add(callback, args, space_type, region_type)\n"
151 "\n"
152 " Add a new draw cursor handler to this space type.\n"
153 " It will be called every time the cursor for the specified region in the space "
154 "type will be drawn.\n"
155 " Note: All arguments are positional only for now.\n"
156 "\n"
157 " :arg callback:\n"
158 " A function that will be called when the cursor is drawn.\n"
159 " It gets the specified arguments as input with the mouse position "
160 "(``tuple[int, int]``) as last argument.\n"
161 " :type callback: Callable[..., Any]\n"
162 " :arg args: Arguments that will be passed to the callback.\n"
163 " :type args: tuple[Any, ...]\n"
164 " :arg space_type: The space type the callback draws in; for example ``VIEW_3D``. "
165 "(:class:`bpy.types.Space.type`)\n"
166 " :type space_type: str\n"
167 " :arg region_type: The region type the callback draws in; usually ``WINDOW``. "
168 "(:class:`bpy.types.Region.type`)\n"
169 " :type region_type: str\n"
170 " :return: Handler that can be removed later on.\n"
171 " :rtype: object\n");
173 /* Wrap. */
174 pyrna_draw_cursor_remove_doc,
175 ".. classmethod:: draw_cursor_remove(handler)\n"
176 "\n"
177 " Remove a draw cursor handler that was added previously.\n"
178 "\n"
179 " :arg handler: The draw cursor handler that should be removed.\n"
180 " :type handler: object\n");
181
182static PyMethodDef pyrna_windowmanager_methods[] = {
183 {"draw_cursor_add",
185 METH_VARARGS | METH_CLASS,
186 pyrna_draw_cursor_add_doc},
187 {"draw_cursor_remove",
189 METH_VARARGS | METH_CLASS,
190 pyrna_draw_cursor_remove_doc},
191 {nullptr, nullptr, 0, nullptr},
192};
193
194static PyGetSetDef pyrna_windowmanager_getset[] = {
195 {"clipboard",
198 pyrna_WindowManager_clipboard_doc,
199 nullptr},
200 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
201};
202
204
205/* -------------------------------------------------------------------- */
208
209static PyMethodDef pyrna_context_methods[] = {
210 {nullptr, nullptr, 0, nullptr}, /* #BPY_rna_context_temp_override_method_def */
211 {nullptr, nullptr, 0, nullptr},
212};
213
215
216/* -------------------------------------------------------------------- */
219
221 /* Wrap. */
222 pyrna_draw_handler_add_doc,
223 ".. classmethod:: draw_handler_add(callback, args, region_type, draw_type)\n"
224 "\n"
225 " Add a new draw handler to this space type.\n"
226 " It will be called every time the specified region in the space type will be drawn.\n"
227 " Note: All arguments are positional only for now.\n"
228 "\n"
229 " :arg callback:\n"
230 " A function that will be called when the region is drawn.\n"
231 " It gets the specified arguments as input, it's return value is ignored.\n"
232 " :type callback: Callable[..., Any]\n"
233 " :arg args: Arguments that will be passed to the callback.\n"
234 " :type args: tuple[Any, ...]\n"
235 " :arg region_type: The region type the callback draws in; usually ``WINDOW``. "
236 "(:class:`bpy.types.Region.type`)\n"
237 " :type region_type: str\n"
238 " :arg draw_type: Usually ``POST_PIXEL`` for 2D drawing and ``POST_VIEW`` for 3D drawing. "
239 "In some cases ``PRE_VIEW`` can be used. ``BACKDROP`` can be used for backdrops in the node "
240 "editor.\n"
241 " :type draw_type: str\n"
242 " :return: Handler that can be removed later on.\n"
243 " :rtype: object\n");
245 /* Wrap. */
246 pyrna_draw_handler_remove_doc,
247 ".. classmethod:: draw_handler_remove(handler, region_type)\n"
248 "\n"
249 " Remove a draw handler that was added previously.\n"
250 "\n"
251 " :arg handler: The draw handler that should be removed.\n"
252 " :type handler: object\n"
253 " :arg region_type: Region type the callback was added to.\n"
254 " :type region_type: str\n");
255
256static PyMethodDef pyrna_space_methods[] = {
257 {"draw_handler_add",
259 METH_VARARGS | METH_CLASS,
260 pyrna_draw_handler_add_doc},
261 {"draw_handler_remove",
263 METH_VARARGS | METH_CLASS,
264 pyrna_draw_handler_remove_doc},
265 {nullptr, nullptr, 0, nullptr},
266};
267
269
270/* -------------------------------------------------------------------- */
273
275{
276 /* BlendData */
284 BLI_STATIC_ASSERT(ARRAY_SIZE(pyrna_blenddata_methods) == 7, "Unexpected number of methods")
286
287 /* BlendDataLibraries */
291 "Unexpected number of methods")
293 &RNA_BlendDataLibraries, pyrna_blenddatalibraries_methods, nullptr);
294
295 /* uiLayout */
297 BLI_STATIC_ASSERT(ARRAY_SIZE(pyrna_uilayout_methods) == 2, "Unexpected number of methods")
299
300 /* Space */
302
303 /* Text Editor */
307 BLI_STATIC_ASSERT(ARRAY_SIZE(pyrna_text_methods) == 3, "Unexpected number of methods")
309
310 /* wmOperator */
312 BLI_STATIC_ASSERT(ARRAY_SIZE(pyrna_operator_methods) == 2, "Unexpected number of methods")
314
315 /* WindowManager */
318
319 /* Context */
321
324}
325
#define BLI_STATIC_ASSERT(a, msg)
Definition BLI_assert.h:83
#define ARRAY_SIZE(arr)
#define ARRAY_SET_ITEMS(...)
Read Guarded memory(de)allocation.
PyMethodDef BPY_library_load_method_def
PyMethodDef BPY_library_write_method_def
void pyrna_struct_type_extend_capi(StructRNA *srna, PyMethodDef *method, PyGetSetDef *getset)
Definition bpy_rna.cc:10511
PyObject * pyrna_callback_classmethod_remove(PyObject *, PyObject *args)
PyObject * pyrna_callback_classmethod_add(PyObject *, PyObject *args)
void bpy_rna_context_types_init()
PyMethodDef BPY_rna_context_temp_override_method_def
PyMethodDef BPY_rna_data_context_method_def
PyMethodDef BPY_rna_id_collection_file_path_foreach_method_def
PyMethodDef BPY_rna_id_collection_batch_remove_method_def
PyMethodDef BPY_rna_id_collection_orphans_purge_method_def
PyMethodDef BPY_rna_id_collection_file_path_map_method_def
PyMethodDef BPY_rna_id_collection_user_map_method_def
PyMethodDef BPY_rna_operator_poll_message_set_method_def
PyMethodDef BPY_rna_region_from_string_method_def
PyMethodDef BPY_rna_region_as_string_method_def
static PyMethodDef pyrna_uilayout_methods[]
static PyMethodDef pyrna_blenddata_methods[]
static PyMethodDef pyrna_blenddatalibraries_methods[]
static PyMethodDef pyrna_context_methods[]
static PyMethodDef pyrna_windowmanager_methods[]
static PyMethodDef pyrna_text_methods[]
static int pyrna_WindowManager_clipboard_set(PyObject *, PyObject *value, void *)
static PyMethodDef pyrna_operator_methods[]
static PyGetSetDef pyrna_windowmanager_getset[]
static PyMethodDef pyrna_space_methods[]
static PyObject * pyrna_WindowManager_clipboard_get(PyObject *, void *)
void BPY_rna_types_extend_capi()
PyDoc_STRVAR(pyrna_WindowManager_clipboard_doc, "Clipboard text storage.\n" "\n" ":type: str\n")
PyMethodDef BPY_rna_uilayout_introspect_method_def
Definition bpy_rna_ui.cc:55
void MEM_freeN(void *vmemh)
Definition mallocn.cc:113
PyObject * PyC_UnicodeFromBytesAndSize(const char *str, Py_ssize_t size)
const char * PyC_UnicodeAsBytes(PyObject *py_str, PyObject **r_coerce)
void WM_clipboard_text_set(const char *buf, bool selection)
char * WM_clipboard_text_get(bool selection, bool ensure_utf8, int *r_len)