Blender V4.3
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
17#include <Python.h>
18#include <descrobject.h>
19
20#include "RNA_types.hh"
21
22#include "BLI_utildefines.h"
23
24#include "bpy_library.hh"
25#include "bpy_rna.hh"
26#include "bpy_rna_callback.hh"
27#include "bpy_rna_context.hh"
28#include "bpy_rna_data.hh"
30#include "bpy_rna_text.hh"
31#include "bpy_rna_types_capi.hh"
32#include "bpy_rna_ui.hh"
33
34#include "bpy_rna_operator.hh"
35
37
38#include "RNA_prototypes.hh"
39
40#include "MEM_guardedalloc.h"
41
42#include "WM_api.hh"
43
44/* -------------------------------------------------------------------- */
48static PyMethodDef pyrna_blenddata_methods[] = {
49 {nullptr, nullptr, 0, nullptr}, /* #BPY_rna_id_collection_user_map_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
58/* -------------------------------------------------------------------- */
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
70/* -------------------------------------------------------------------- */
74static PyMethodDef pyrna_uilayout_methods[] = {
75 {nullptr, nullptr, 0, nullptr}, /* #BPY_rna_uilayout_introspect_method_def */
76 {nullptr, nullptr, 0, nullptr},
77};
78
81/* -------------------------------------------------------------------- */
85static PyMethodDef pyrna_operator_methods[] = {
86 {nullptr, nullptr, 0, nullptr}, /* #BPY_rna_operator_poll_message_set */
87 {nullptr, nullptr, 0, nullptr},
88};
89
92/* -------------------------------------------------------------------- */
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
104/* -------------------------------------------------------------------- */
112 /* Wrap. */
113 pyrna_WindowManager_clipboard_doc,
114 "Clipboard text storage.\n"
115 "\n"
116 ":type: str");
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
143/* -------------------------------------------------------------------- */
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 (tuple) as last "
160 "argument.\n"
161 " :type callback: Callable[[Any, ..., tuple[int, int]], 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");
172
174 /* Wrap. */
175 pyrna_draw_cursor_remove_doc,
176 ".. classmethod:: draw_cursor_remove(handler)\n"
177 "\n"
178 " Remove a draw cursor handler that was added previously.\n"
179 "\n"
180 " :arg handler: The draw cursor handler that should be removed.\n"
181 " :type handler: object\n");
182
183static PyMethodDef pyrna_windowmanager_methods[] = {
184 {"draw_cursor_add",
186 METH_VARARGS | METH_CLASS,
187 pyrna_draw_cursor_add_doc},
188 {"draw_cursor_remove",
190 METH_VARARGS | METH_CLASS,
191 pyrna_draw_cursor_remove_doc},
192 {nullptr, nullptr, 0, nullptr},
193};
194
195static PyGetSetDef pyrna_windowmanager_getset[] = {
196 {"clipboard",
199 pyrna_WindowManager_clipboard_doc,
200 nullptr},
201 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
202};
203
206/* -------------------------------------------------------------------- */
210static PyMethodDef pyrna_context_methods[] = {
211 {nullptr, nullptr, 0, nullptr}, /* #BPY_rna_context_temp_override_method_def */
212 {nullptr, nullptr, 0, nullptr},
213};
214
217/* -------------------------------------------------------------------- */
222 /* Wrap. */
223 pyrna_draw_handler_add_doc,
224 ".. classmethod:: draw_handler_add(callback, args, region_type, draw_type)\n"
225 "\n"
226 " Add a new draw handler to this space type.\n"
227 " It will be called every time the specified region in the space type will be drawn.\n"
228 " Note: All arguments are positional only for now.\n"
229 "\n"
230 " :arg callback:\n"
231 " A function that will be called when the region is drawn.\n"
232 " It gets the specified arguments as input, it's return value is ignored.\n"
233 " :type callback: Callable[[Any, ...], Any]\n"
234 " :arg args: Arguments that will be passed to the callback.\n"
235 " :type args: tuple[Any, ...]\n"
236 " :arg region_type: The region type the callback draws in; usually ``WINDOW``. "
237 "(:class:`bpy.types.Region.type`)\n"
238 " :type region_type: str\n"
239 " :arg draw_type: Usually ``POST_PIXEL`` for 2D drawing and ``POST_VIEW`` for 3D drawing. "
240 "In some cases ``PRE_VIEW`` can be used. ``BACKDROP`` can be used for backdrops in the node "
241 "editor.\n"
242 " :type draw_type: str\n"
243 " :return: Handler that can be removed later on.\n"
244 " :rtype: object");
245
247 /* Wrap. */
248 pyrna_draw_handler_remove_doc,
249 ".. classmethod:: draw_handler_remove(handler, region_type)\n"
250 "\n"
251 " Remove a draw handler that was added previously.\n"
252 "\n"
253 " :arg handler: The draw handler that should be removed.\n"
254 " :type handler: object\n"
255 " :arg region_type: Region type the callback was added to.\n"
256 " :type region_type: str\n");
257
258static PyMethodDef pyrna_space_methods[] = {
259 {"draw_handler_add",
261 METH_VARARGS | METH_CLASS,
262 pyrna_draw_handler_add_doc},
263 {"draw_handler_remove",
265 METH_VARARGS | METH_CLASS,
266 pyrna_draw_handler_remove_doc},
267 {nullptr, nullptr, 0, nullptr},
268};
269
272/* -------------------------------------------------------------------- */
277{
278 /* BlendData */
286
287 /* BlendDataLibraries */
292 &RNA_BlendDataLibraries, pyrna_blenddatalibraries_methods, nullptr);
293
294 /* uiLayout */
298
299 /* Space */
301
302 /* Text Editor */
308
309 /* wmOperator */
313
314 /* WindowManager */
317
318 /* Context */
320
323}
324
#define BLI_assert(a)
Definition BLI_assert.h:50
#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:9454
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_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:48
void MEM_freeN(void *vmemh)
Definition mallocn.cc:105
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)