Blender  V2.93
bpy_rna_types_capi.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
29 #include <Python.h>
30 #include <descrobject.h>
31 
32 #include "RNA_types.h"
33 
34 #include "BLI_utildefines.h"
35 
36 #include "bpy_library.h"
37 #include "bpy_rna.h"
38 #include "bpy_rna_callback.h"
39 #include "bpy_rna_data.h"
40 #include "bpy_rna_id_collection.h"
41 #include "bpy_rna_types_capi.h"
42 #include "bpy_rna_ui.h"
43 
44 #include "../generic/py_capi_utils.h"
45 
46 #include "RNA_access.h"
47 
48 #include "MEM_guardedalloc.h"
49 
50 #include "WM_api.h"
51 
52 /* -------------------------------------------------------------------- */
56 static struct PyMethodDef pyrna_blenddata_methods[] = {
57  {NULL, NULL, 0, NULL}, /* #BPY_rna_id_collection_user_map_method_def */
58  {NULL, NULL, 0, NULL}, /* #BPY_rna_id_collection_batch_remove_method_def */
59  {NULL, NULL, 0, NULL}, /* #BPY_rna_id_collection_orphans_purge_method_def */
60  {NULL, NULL, 0, NULL}, /* #BPY_rna_data_context_method_def */
61  {NULL, NULL, 0, NULL},
62 };
63 
66 /* -------------------------------------------------------------------- */
70 static struct PyMethodDef pyrna_blenddatalibraries_methods[] = {
71  {NULL, NULL, 0, NULL}, /* #BPY_library_load_method_def */
72  {NULL, NULL, 0, NULL}, /* #BPY_library_write_method_def */
73  {NULL, NULL, 0, NULL},
74 };
75 
78 /* -------------------------------------------------------------------- */
82 static struct PyMethodDef pyrna_uilayout_methods[] = {
83  {NULL, NULL, 0, NULL}, /* #BPY_rna_uilayout_introspect_method_def */
84  {NULL, NULL, 0, NULL},
85 };
86 
89 /* -------------------------------------------------------------------- */
96 static PyObject *pyrna_WindowManager_clipboard_get(PyObject *UNUSED(self), void *UNUSED(flag))
97 {
98  int text_len = 0;
99  char *text = WM_clipboard_text_get(false, &text_len);
100  PyObject *result = PyC_UnicodeFromByteAndSize(text ? text : "", text_len);
101  if (text != NULL) {
102  MEM_freeN(text);
103  }
104  return result;
105 }
106 
107 static int pyrna_WindowManager_clipboard_set(PyObject *UNUSED(self),
108  PyObject *value,
109  void *UNUSED(flag))
110 {
111  PyObject *value_coerce = NULL;
112  const char *text = PyC_UnicodeAsByte(value, &value_coerce);
113  if (text == NULL) {
114  return -1;
115  }
116  WM_clipboard_text_set(text, false);
117  Py_XDECREF(value_coerce);
118  return 0;
119 }
120 
123 /* -------------------------------------------------------------------- */
127 static struct PyMethodDef pyrna_windowmanager_methods[] = {
128  {"draw_cursor_add",
129  (PyCFunction)pyrna_callback_classmethod_add,
130  METH_VARARGS | METH_CLASS,
131  ""},
132  {"draw_cursor_remove",
134  METH_VARARGS | METH_CLASS,
135  ""},
136  {NULL, NULL, 0, NULL},
137 };
138 
139 static struct PyGetSetDef pyrna_windowmanager_getset[] = {
140  {"clipboard",
143  NULL,
144  NULL},
145  {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
146 };
147 
150 /* -------------------------------------------------------------------- */
155  pyrna_draw_handler_add_doc,
156  ".. method:: draw_handler_add(callback, args, region_type, draw_type)\n"
157  "\n"
158  " Add a new draw handler to this space type.\n"
159  " It will be called every time the specified region in the space type will be drawn.\n"
160  " Note: All arguments are positional only for now.\n"
161  "\n"
162  " :param callback:\n"
163  " A function that will be called when the region is drawn.\n"
164  " It gets the specified arguments as input.\n"
165  " :type callback: function\n"
166  " :param args: Arguments that will be passed to the callback.\n"
167  " :type args: tuple\n"
168  " :param region_type: The region type the callback draws in; usually ``WINDOW``. "
169  "(:class:`bpy.types.Region.type`)\n"
170  " :type region_type: str\n"
171  " :param draw_type: Usually ``POST_PIXEL`` for 2D drawing and ``POST_VIEW`` for 3D drawing. "
172  "In some cases ``PRE_VIEW`` can be used. ``BACKDROP`` can be used for backdrops in the node "
173  "editor.\n"
174  " :type draw_type: str\n"
175  " :return: Handler that can be removed later on.\n"
176  " :rtype: object");
177 
178 PyDoc_STRVAR(pyrna_draw_handler_remove_doc,
179  ".. method:: draw_handler_remove(handler, region_type)\n"
180  "\n"
181  " Remove a draw handler that was added previously.\n"
182  "\n"
183  " :param handler: The draw handler that should be removed.\n"
184  " :type handler: object\n"
185  " :param region_type: Region type the callback was added to.\n"
186  " :type region_type: str\n");
187 
188 static struct PyMethodDef pyrna_space_methods[] = {
189  {"draw_handler_add",
190  (PyCFunction)pyrna_callback_classmethod_add,
191  METH_VARARGS | METH_CLASS,
192  pyrna_draw_handler_add_doc},
193  {"draw_handler_remove",
195  METH_VARARGS | METH_CLASS,
196  pyrna_draw_handler_remove_doc},
197  {NULL, NULL, 0, NULL},
198 };
199 
202 /* -------------------------------------------------------------------- */
207 {
208  /* BlendData */
216 
217  /* BlendDataLibraries */
222 
223  /* uiLayout */
227 
228  /* Space */
230 
231  /* WindowManager */
234 }
235 
#define BLI_assert(a)
Definition: BLI_assert.h:58
#define ARRAY_SIZE(arr)
#define ARRAY_SET_ITEMS(...)
#define UNUSED(x)
Read Guarded memory(de)allocation.
StructRNA RNA_BlendDataLibraries
StructRNA RNA_Space
StructRNA RNA_WindowManager
StructRNA RNA_UILayout
StructRNA RNA_BlendData
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:9121
PyObject * pyrna_callback_classmethod_remove(PyObject *UNUSED(self), PyObject *args)
PyObject * pyrna_callback_classmethod_add(PyObject *UNUSED(self), PyObject *args)
PyMethodDef BPY_rna_data_context_method_def
Definition: bpy_rna_data.c:205
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
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 PyGetSetDef pyrna_windowmanager_getset[]
void BPY_rna_types_extend_capi(void)
static struct PyMethodDef pyrna_space_methods[]
PyDoc_STRVAR(pyrna_draw_handler_add_doc, ".. method:: draw_handler_add(callback, args, region_type, draw_type)\n" "\n" " Add a new draw handler to this space type.\n" " It will be called every time the specified region in the space type will be drawn.\n" " Note: All arguments are positional only for now.\n" "\n" " :param callback:\n" " A function that will be called when the region is drawn.\n" " It gets the specified arguments as input.\n" " :type callback: function\n" " :param args: Arguments that will be passed to the callback.\n" " :type args: tuple\n" " :param region_type: The region type the callback draws in; usually ``WINDOW``. " "(:class:`bpy.types.Region.type`)\n" " :type region_type: str\n" " :param draw_type: Usually ``POST_PIXEL`` for 2D drawing and ``POST_VIEW`` for 3D drawing. " "In some cases ``PRE_VIEW`` can be used. ``BACKDROP`` can be used for backdrops in the node " "editor.\n" " :type draw_type: str\n" " :return: Handler that can be removed later on.\n" " :rtype: object")
static struct PyMethodDef pyrna_blenddata_methods[]
static struct PyMethodDef pyrna_windowmanager_methods[]
PyMethodDef BPY_rna_uilayout_introspect_method_def
Definition: bpy_rna_ui.c:56
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
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:1778
char * WM_clipboard_text_get(bool selection, int *r_len)
Definition: wm_window.c:1765