Blender  V3.3
bpy_rna_types_capi.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
15 #include <Python.h>
16 #include <descrobject.h>
17 
18 #include "RNA_types.h"
19 
20 #include "BLI_utildefines.h"
21 
22 #include "bpy_library.h"
23 #include "bpy_rna.h"
24 #include "bpy_rna_callback.h"
25 #include "bpy_rna_context.h"
26 #include "bpy_rna_data.h"
27 #include "bpy_rna_id_collection.h"
28 #include "bpy_rna_text.h"
29 #include "bpy_rna_types_capi.h"
30 #include "bpy_rna_ui.h"
31 
32 #include "bpy_rna_operator.h"
33 
34 #include "../generic/py_capi_utils.h"
35 
36 #include "RNA_access.h"
37 #include "RNA_prototypes.h"
38 
39 #include "MEM_guardedalloc.h"
40 
41 #include "WM_api.h"
42 
43 /* -------------------------------------------------------------------- */
47 static struct PyMethodDef pyrna_blenddata_methods[] = {
48  {NULL, NULL, 0, NULL}, /* #BPY_rna_id_collection_user_map_method_def */
49  {NULL, NULL, 0, NULL}, /* #BPY_rna_id_collection_batch_remove_method_def */
50  {NULL, NULL, 0, NULL}, /* #BPY_rna_id_collection_orphans_purge_method_def */
51  {NULL, NULL, 0, NULL}, /* #BPY_rna_data_context_method_def */
52  {NULL, NULL, 0, NULL},
53 };
54 
57 /* -------------------------------------------------------------------- */
61 static struct PyMethodDef pyrna_blenddatalibraries_methods[] = {
62  {NULL, NULL, 0, NULL}, /* #BPY_library_load_method_def */
63  {NULL, NULL, 0, NULL}, /* #BPY_library_write_method_def */
64  {NULL, NULL, 0, NULL},
65 };
66 
69 /* -------------------------------------------------------------------- */
73 static struct PyMethodDef pyrna_uilayout_methods[] = {
74  {NULL, NULL, 0, NULL}, /* #BPY_rna_uilayout_introspect_method_def */
75  {NULL, NULL, 0, NULL},
76 };
77 
80 /* -------------------------------------------------------------------- */
84 static struct PyMethodDef pyrna_operator_methods[] = {
85  {NULL, NULL, 0, NULL}, /* #BPY_rna_operator_poll_message_set */
86  {NULL, NULL, 0, NULL},
87 };
88 
91 /* -------------------------------------------------------------------- */
95 static struct PyMethodDef pyrna_text_methods[] = {
96  {NULL, NULL, 0, NULL}, /* #BPY_rna_region_as_string_method_def */
97  {NULL, NULL, 0, NULL}, /* #BPY_rna_region_from_string_method_def */
98  {NULL, NULL, 0, NULL},
99 };
100 
103 /* -------------------------------------------------------------------- */
110 PyDoc_STRVAR(pyrna_WindowManager_clipboard_doc, "Clipboard text storage.\n\n:type: string");
111 static PyObject *pyrna_WindowManager_clipboard_get(PyObject *UNUSED(self), void *UNUSED(flag))
112 {
113  int text_len = 0;
114  char *text = WM_clipboard_text_get(false, &text_len);
115  PyObject *result = PyC_UnicodeFromByteAndSize(text ? text : "", text_len);
116  if (text != NULL) {
117  MEM_freeN(text);
118  }
119  return result;
120 }
121 
122 static int pyrna_WindowManager_clipboard_set(PyObject *UNUSED(self),
123  PyObject *value,
124  void *UNUSED(flag))
125 {
126  PyObject *value_coerce = NULL;
127  const char *text = PyC_UnicodeAsByte(value, &value_coerce);
128  if (text == NULL) {
129  return -1;
130  }
131  WM_clipboard_text_set(text, false);
132  Py_XDECREF(value_coerce);
133  return 0;
134 }
135 
138 /* -------------------------------------------------------------------- */
142 static struct PyMethodDef pyrna_windowmanager_methods[] = {
143  {"draw_cursor_add",
144  (PyCFunction)pyrna_callback_classmethod_add,
145  METH_VARARGS | METH_CLASS,
146  ""},
147  {"draw_cursor_remove",
149  METH_VARARGS | METH_CLASS,
150  ""},
151  {NULL, NULL, 0, NULL},
152 };
153 
154 static struct PyGetSetDef pyrna_windowmanager_getset[] = {
155  {"clipboard",
158  pyrna_WindowManager_clipboard_doc,
159  NULL},
160  {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
161 };
162 
165 /* -------------------------------------------------------------------- */
169 static struct PyMethodDef pyrna_context_methods[] = {
170  {NULL, NULL, 0, NULL}, /* #BPY_rna_context_temp_override_method_def */
171  {NULL, NULL, 0, NULL},
172 };
173 
176 /* -------------------------------------------------------------------- */
181  pyrna_draw_handler_add_doc,
182  ".. method:: draw_handler_add(callback, args, region_type, draw_type)\n"
183  "\n"
184  " Add a new draw handler to this space type.\n"
185  " It will be called every time the specified region in the space type will be drawn.\n"
186  " Note: All arguments are positional only for now.\n"
187  "\n"
188  " :param callback:\n"
189  " A function that will be called when the region is drawn.\n"
190  " It gets the specified arguments as input.\n"
191  " :type callback: function\n"
192  " :param args: Arguments that will be passed to the callback.\n"
193  " :type args: tuple\n"
194  " :param region_type: The region type the callback draws in; usually ``WINDOW``. "
195  "(:class:`bpy.types.Region.type`)\n"
196  " :type region_type: str\n"
197  " :param draw_type: Usually ``POST_PIXEL`` for 2D drawing and ``POST_VIEW`` for 3D drawing. "
198  "In some cases ``PRE_VIEW`` can be used. ``BACKDROP`` can be used for backdrops in the node "
199  "editor.\n"
200  " :type draw_type: str\n"
201  " :return: Handler that can be removed later on.\n"
202  " :rtype: object");
203 
204 PyDoc_STRVAR(pyrna_draw_handler_remove_doc,
205  ".. method:: draw_handler_remove(handler, region_type)\n"
206  "\n"
207  " Remove a draw handler that was added previously.\n"
208  "\n"
209  " :param handler: The draw handler that should be removed.\n"
210  " :type handler: object\n"
211  " :param region_type: Region type the callback was added to.\n"
212  " :type region_type: str\n");
213 
214 static struct PyMethodDef pyrna_space_methods[] = {
215  {"draw_handler_add",
216  (PyCFunction)pyrna_callback_classmethod_add,
217  METH_VARARGS | METH_CLASS,
218  pyrna_draw_handler_add_doc},
219  {"draw_handler_remove",
221  METH_VARARGS | METH_CLASS,
222  pyrna_draw_handler_remove_doc},
223  {NULL, NULL, 0, NULL},
224 };
225 
228 /* -------------------------------------------------------------------- */
233 {
234  /* BlendData */
242 
243  /* BlendDataLibraries */
248 
249  /* uiLayout */
253 
254  /* Space */
256 
257  /* Text Editor */
263 
264  /* wmOperator */
268 
269  /* WindowManager */
272 
273  /* Context */
275 
278 }
279 
#define BLI_assert(a)
Definition: BLI_assert.h:46
#define ARRAY_SIZE(arr)
#define ARRAY_SET_ITEMS(...)
#define UNUSED(x)
Read Guarded memory(de)allocation.
PyMethodDef BPY_library_load_method_def
PyMethodDef BPY_library_write_method_def
void pyrna_struct_type_extend_capi(struct StructRNA *srna, struct PyMethodDef *method, struct PyGetSetDef *getset)
Definition: bpy_rna.c:9228
PyObject * pyrna_callback_classmethod_remove(PyObject *UNUSED(self), PyObject *args)
PyObject * pyrna_callback_classmethod_add(PyObject *UNUSED(self), PyObject *args)
void bpy_rna_context_types_init(void)
PyMethodDef BPY_rna_context_temp_override_method_def
PyMethodDef BPY_rna_data_context_method_def
Definition: bpy_rna_data.c:198
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
Definition: bpy_rna_text.c:155
PyMethodDef BPY_rna_region_as_string_method_def
Definition: bpy_rna_text.c:93
static int pyrna_WindowManager_clipboard_set(PyObject *UNUSED(self), PyObject *value, void *UNUSED(flag))
static PyObject * pyrna_WindowManager_clipboard_get(PyObject *UNUSED(self), void *UNUSED(flag))
static struct PyMethodDef pyrna_uilayout_methods[]
static struct PyMethodDef pyrna_blenddatalibraries_methods[]
static struct PyMethodDef pyrna_context_methods[]
static struct PyGetSetDef pyrna_windowmanager_getset[]
PyDoc_STRVAR(pyrna_WindowManager_clipboard_doc, "Clipboard text storage.\n\n:type: string")
void BPY_rna_types_extend_capi(void)
static struct PyMethodDef pyrna_space_methods[]
static struct PyMethodDef pyrna_text_methods[]
static struct PyMethodDef pyrna_operator_methods[]
static struct PyMethodDef pyrna_blenddata_methods[]
static struct PyMethodDef pyrna_windowmanager_methods[]
PyMethodDef BPY_rna_uilayout_introspect_method_def
Definition: bpy_rna_ui.c:42
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
const char * PyC_UnicodeAsByte(PyObject *py_str, PyObject **coerce)
PyObject * PyC_UnicodeFromByteAndSize(const char *str, Py_ssize_t size)
void WM_clipboard_text_set(const char *buf, bool selection)
Definition: wm_window.c:1780
char * WM_clipboard_text_get(bool selection, int *r_len)
Definition: wm_window.c:1770