Blender V4.5
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_batch_remove_method_def */
50 {nullptr, nullptr, 0, nullptr}, /* #BPY_rna_id_collection_orphans_purge_method_def */
51 {nullptr, nullptr, 0, nullptr}, /* #BPY_rna_data_context_method_def */
52 {nullptr, nullptr, 0, nullptr},
53};
54
56
57/* -------------------------------------------------------------------- */
60
61static PyMethodDef pyrna_blenddatalibraries_methods[] = {
62 {nullptr, nullptr, 0, nullptr}, /* #BPY_library_load_method_def */
63 {nullptr, nullptr, 0, nullptr}, /* #BPY_library_write_method_def */
64 {nullptr, nullptr, 0, nullptr},
65};
66
68
69/* -------------------------------------------------------------------- */
72
73static PyMethodDef pyrna_uilayout_methods[] = {
74 {nullptr, nullptr, 0, nullptr}, /* #BPY_rna_uilayout_introspect_method_def */
75 {nullptr, nullptr, 0, nullptr},
76};
77
79
80/* -------------------------------------------------------------------- */
83
84static PyMethodDef pyrna_operator_methods[] = {
85 {nullptr, nullptr, 0, nullptr}, /* #BPY_rna_operator_poll_message_set */
86 {nullptr, nullptr, 0, nullptr},
87};
88
90
91/* -------------------------------------------------------------------- */
94
95static PyMethodDef pyrna_text_methods[] = {
96 {nullptr, nullptr, 0, nullptr}, /* #BPY_rna_region_as_string_method_def */
97 {nullptr, nullptr, 0, nullptr}, /* #BPY_rna_region_from_string_method_def */
98 {nullptr, nullptr, 0, nullptr},
99};
100
102
103/* -------------------------------------------------------------------- */
109
111 /* Wrap. */
112 pyrna_WindowManager_clipboard_doc,
113 "Clipboard text storage.\n"
114 "\n"
115 ":type: str");
116static PyObject *pyrna_WindowManager_clipboard_get(PyObject * /*self*/, void * /*flag*/)
117{
118 int text_len = 0;
119 /* No need for UTF8 validation as #PyC_UnicodeFromBytesAndSize handles invalid byte sequences. */
120 char *text = WM_clipboard_text_get(false, false, &text_len);
121 PyObject *result = PyC_UnicodeFromBytesAndSize(text ? text : "", text_len);
122 if (text != nullptr) {
123 MEM_freeN(text);
124 }
125 return result;
126}
127
128static int pyrna_WindowManager_clipboard_set(PyObject * /*self*/, PyObject *value, void * /*flag*/)
129{
130 PyObject *value_coerce = nullptr;
131 const char *text = PyC_UnicodeAsBytes(value, &value_coerce);
132 if (text == nullptr) {
133 return -1;
134 }
135 WM_clipboard_text_set(text, false);
136 Py_XDECREF(value_coerce);
137 return 0;
138}
139
141
142/* -------------------------------------------------------------------- */
145
147 /* Wrap. */
148 pyrna_draw_cursor_add_doc,
149 ".. classmethod:: draw_cursor_add(callback, args, space_type, region_type)\n"
150 "\n"
151 " Add a new draw cursor handler to this space type.\n"
152 " It will be called every time the cursor for the specified region in the space "
153 "type will be drawn.\n"
154 " Note: All arguments are positional only for now.\n"
155 "\n"
156 " :arg callback:\n"
157 " A function that will be called when the cursor is drawn.\n"
158 " It gets the specified arguments as input with the mouse position "
159 "(``tuple[int, int]``) as last argument.\n"
160 " :type callback: Callable[..., Any]\n"
161 " :arg args: Arguments that will be passed to the callback.\n"
162 " :type args: tuple[Any, ...]\n"
163 " :arg space_type: The space type the callback draws in; for example ``VIEW_3D``. "
164 "(:class:`bpy.types.Space.type`)\n"
165 " :type space_type: str\n"
166 " :arg region_type: The region type the callback draws in; usually ``WINDOW``. "
167 "(:class:`bpy.types.Region.type`)\n"
168 " :type region_type: str\n"
169 " :return: Handler that can be removed later on.\n"
170 " :rtype: object\n");
171
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");
244
246 /* Wrap. */
247 pyrna_draw_handler_remove_doc,
248 ".. classmethod:: draw_handler_remove(handler, region_type)\n"
249 "\n"
250 " Remove a draw handler that was added previously.\n"
251 "\n"
252 " :arg handler: The draw handler that should be removed.\n"
253 " :type handler: object\n"
254 " :arg region_type: Region type the callback was added to.\n"
255 " :type region_type: str\n");
256
257static PyMethodDef pyrna_space_methods[] = {
258 {"draw_handler_add",
260 METH_VARARGS | METH_CLASS,
261 pyrna_draw_handler_add_doc},
262 {"draw_handler_remove",
264 METH_VARARGS | METH_CLASS,
265 pyrna_draw_handler_remove_doc},
266 {nullptr, nullptr, 0, nullptr},
267};
268
270
271/* -------------------------------------------------------------------- */
274
276{
277 /* BlendData */
284 BLI_STATIC_ASSERT(ARRAY_SIZE(pyrna_blenddata_methods) == 6, "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:10352
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_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[]
PyDoc_STRVAR(pyrna_WindowManager_clipboard_doc, "Clipboard text storage.\n" "\n" ":type: str")
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()
PyMethodDef BPY_rna_uilayout_introspect_method_def
Definition bpy_rna_ui.cc:53
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)