Fix layers unittest - we cannot use nestted get_pointer calls
[blender.git] / source / blender / python / intern / bpy_props.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * Contributor(s): Campbell Barton
19  *
20  * ***** END GPL LICENSE BLOCK *****
21  */
22
23 /** \file blender/python/intern/bpy_props.c
24  *  \ingroup pythonintern
25  *
26  * This file defines 'bpy.props' module used so scripts can define their own
27  * rna properties for use with python operators or adding new properties to
28  * existing blender types.
29  */
30
31
32 #include <Python.h>
33
34 #include "RNA_types.h"
35
36 #include "BLI_utildefines.h"
37
38 #include "bpy_props.h"
39 #include "bpy_rna.h"
40 #include "bpy_util.h"
41
42 #include "BKE_idprop.h"
43
44 #include "RNA_access.h"
45 #include "RNA_define.h" /* for defining our own rna */
46 #include "RNA_enum_types.h"
47
48 #include "MEM_guardedalloc.h"
49
50 #include "../generic/py_capi_utils.h"
51
52 /* initial definition of callback slots we'll probably have more than 1 */
53 enum {
54         BPY_DATA_CB_SLOT_UPDATE     = 0,
55         BPY_DATA_CB_SLOT_GET        = 1,
56         BPY_DATA_CB_SLOT_SET        = 2,
57         BPY_DATA_CB_SLOT_POLL       = 3,
58         BPY_DATA_CB_SLOT_SIZE       = 4,
59 };
60
61 extern BPy_StructRNA *bpy_context_module;
62
63 static EnumPropertyItem property_flag_items[] = {
64         {PROP_HIDDEN, "HIDDEN", 0, "Hidden", ""},
65         {PROP_SKIP_SAVE, "SKIP_SAVE", 0, "Skip Save", ""},
66         {PROP_ANIMATABLE, "ANIMATABLE", 0, "Animatable", ""},
67         {PROP_LIB_EXCEPTION, "LIBRARY_EDITABLE", 0, "Library Editable", ""},
68         {PROP_PROPORTIONAL, "PROPORTIONAL", 0, "Adjust values proportionally to eachother", ""},
69         {PROP_TEXTEDIT_UPDATE, "TEXTEDIT_UPDATE", 0, "Update on every keystroke in textedit 'mode'", ""},
70         {0, NULL, 0, NULL, NULL}};
71
72 #define BPY_PROPDEF_OPTIONS_DOC \
73 "   :arg options: Enumerator in ['HIDDEN', 'SKIP_SAVE', 'ANIMATABLE', 'LIBRARY_EDITABLE', 'PROPORTIONAL'," \
74                                 "'TEXTEDIT_UPDATE'].\n" \
75 "   :type options: set\n" \
76 "   :arg poll: function to be called to determine whether an item is valid for this property.\n" \
77 "              The function must take 2 values (self,object) and return Bool.\n" \
78 "   :type poll: function\n" \
79
80 static EnumPropertyItem property_flag_enum_items[] = {
81         {PROP_HIDDEN, "HIDDEN", 0, "Hidden", ""},
82         {PROP_SKIP_SAVE, "SKIP_SAVE", 0, "Skip Save", ""},
83         {PROP_ANIMATABLE, "ANIMATABLE", 0, "Animatable", ""},
84         {PROP_LIB_EXCEPTION, "LIBRARY_EDITABLE", 0, "Library Editable", ""},
85         {PROP_ENUM_FLAG, "ENUM_FLAG", 0, "Enum Flag", ""},
86         {0, NULL, 0, NULL, NULL}};
87
88 #define BPY_PROPDEF_OPTIONS_ENUM_DOC \
89 "   :arg options: Enumerator in ['HIDDEN', 'SKIP_SAVE', 'ANIMATABLE', 'ENUM_FLAG', 'LIBRARY_EDITABLE'].\n" \
90 "   :type options: set\n" \
91
92 /* subtypes */
93 /* XXX Keep in sync with rna_rna.c's rna_enum_property_subtype_items ???
94  *     Currently it is not...
95  */
96 static EnumPropertyItem property_subtype_string_items[] = {
97         {PROP_FILEPATH, "FILE_PATH", 0, "File Path", ""},
98         {PROP_DIRPATH, "DIR_PATH", 0, "Directory Path", ""},
99         {PROP_FILENAME, "FILE_NAME", 0, "Filename", ""},
100         {PROP_BYTESTRING, "BYTE_STRING", 0, "Byte String", ""},
101         {PROP_PASSWORD, "PASSWORD", 0, "Password", "A string that is displayed hidden ('********')"},
102
103         {PROP_NONE, "NONE", 0, "None", ""},
104         {0, NULL, 0, NULL, NULL}};
105
106 #define BPY_PROPDEF_SUBTYPE_STRING_DOC \
107 "   :arg subtype: Enumerator in ['FILE_PATH', 'DIR_PATH', 'FILE_NAME', 'BYTE_STRING', 'PASSWORD', 'NONE'].\n" \
108 "   :type subtype: string\n" \
109
110 static EnumPropertyItem property_subtype_number_items[] = {
111         {PROP_PIXEL, "PIXEL", 0, "Pixel", ""},
112         {PROP_UNSIGNED, "UNSIGNED", 0, "Unsigned", ""},
113         {PROP_PERCENTAGE, "PERCENTAGE", 0, "Percentage", ""},
114         {PROP_FACTOR, "FACTOR", 0, "Factor", ""},
115         {PROP_ANGLE, "ANGLE", 0, "Angle", ""},
116         {PROP_TIME, "TIME", 0, "Time", ""},
117         {PROP_DISTANCE, "DISTANCE", 0, "Distance", ""},
118
119         {PROP_NONE, "NONE", 0, "None", ""},
120         {0, NULL, 0, NULL, NULL}};
121
122 #define BPY_PROPDEF_SUBTYPE_NUMBER_DOC \
123 "   :arg subtype: Enumerator in ['PIXEL', 'UNSIGNED', 'PERCENTAGE', 'FACTOR', 'ANGLE', 'TIME', 'DISTANCE', 'NONE'].\n" \
124 "   :type subtype: string\n" \
125
126 static EnumPropertyItem property_subtype_array_items[] = {
127         {PROP_COLOR, "COLOR", 0, "Color", ""},
128         {PROP_TRANSLATION, "TRANSLATION", 0, "Translation", ""},
129         {PROP_DIRECTION, "DIRECTION", 0, "Direction", ""},
130         {PROP_VELOCITY, "VELOCITY", 0, "Velocity", ""},
131         {PROP_ACCELERATION, "ACCELERATION", 0, "Acceleration", ""},
132         {PROP_MATRIX, "MATRIX", 0, "Matrix", ""},
133         {PROP_EULER, "EULER", 0, "Euler", ""},
134         {PROP_QUATERNION, "QUATERNION", 0, "Quaternion", ""},
135         {PROP_AXISANGLE, "AXISANGLE", 0, "Axis Angle", ""},
136         {PROP_XYZ, "XYZ", 0, "XYZ", ""},
137         {PROP_COLOR_GAMMA, "COLOR_GAMMA", 0, "Color Gamma", ""},
138         {PROP_LAYER, "LAYER", 0, "Layer", ""},
139
140         {PROP_NONE, "NONE", 0, "None", ""},
141         {0, NULL, 0, NULL, NULL}};
142
143 #define BPY_PROPDEF_SUBTYPE_ARRAY_DOC \
144 "   :arg subtype: Enumerator in ['COLOR', 'TRANSLATION', 'DIRECTION', " \
145                                 "'VELOCITY', 'ACCELERATION', 'MATRIX', 'EULER', 'QUATERNION', 'AXISANGLE', " \
146                                 "'XYZ', 'COLOR_GAMMA', 'LAYER', 'NONE'].\n" \
147 "   :type subtype: string\n"
148
149 /* PyObject's */
150 static PyObject *pymeth_BoolProperty = NULL;
151 static PyObject *pymeth_BoolVectorProperty = NULL;
152 static PyObject *pymeth_IntProperty = NULL;
153 static PyObject *pymeth_IntVectorProperty = NULL;
154 static PyObject *pymeth_FloatProperty = NULL;
155 static PyObject *pymeth_FloatVectorProperty = NULL;
156 static PyObject *pymeth_StringProperty = NULL;
157 static PyObject *pymeth_EnumProperty = NULL;
158 static PyObject *pymeth_PointerProperty = NULL;
159 static PyObject *pymeth_CollectionProperty = NULL;
160 static PyObject *pymeth_RemoveProperty = NULL;
161
162 static PyObject *pyrna_struct_as_instance(PointerRNA *ptr)
163 {
164         PyObject *self = NULL;
165         /* first get self */
166         /* operators can store their own instance for later use */
167         if (ptr->data) {
168                 void **instance = RNA_struct_instance(ptr);
169
170                 if (instance) {
171                         if (*instance) {
172                                 self = *instance;
173                                 Py_INCREF(self);
174                         }
175                 }
176         }
177
178         /* in most cases this will run */
179         if (self == NULL) {
180                 self = pyrna_struct_CreatePyObject(ptr);
181         }
182
183         return self;
184 }
185
186 /* could be moved into bpy_utils */
187 static void printf_func_error(PyObject *py_func)
188 {
189         /* since we return to C code we can't leave the error */
190         PyCodeObject *f_code = (PyCodeObject *)PyFunction_GET_CODE(py_func);
191         PyErr_Print();
192         PyErr_Clear();
193
194         /* use py style error */
195         fprintf(stderr, "File \"%s\", line %d, in %s\n",
196                 _PyUnicode_AsString(f_code->co_filename),
197                 f_code->co_firstlineno,
198                 _PyUnicode_AsString(((PyFunctionObject *)py_func)->func_name)
199                 );
200 }
201
202 static void bpy_prop_assign_flag(PropertyRNA *prop, const int flag)
203 {
204         const int flag_mask = ((PROP_ANIMATABLE) & ~flag);
205
206         if (flag) {
207                 RNA_def_property_flag(prop, flag);
208         }
209
210         if (flag_mask) {
211                 RNA_def_property_clear_flag(prop, flag_mask);
212         }
213 }
214
215 /* operators and classes use this so it can store the args given but defer
216  * running it until the operator runs where these values are used to setup
217  * the default args for that operator instance */
218 static PyObject *bpy_prop_deferred_return(PyObject *func, PyObject *kw)
219 {
220         PyObject *ret = PyTuple_New(2);
221         PyTuple_SET_ITEM(ret, 0, func);
222         Py_INCREF(func);
223
224         if (kw == NULL)
225                 kw = PyDict_New();
226         else
227                 Py_INCREF(kw);
228
229         PyTuple_SET_ITEM(ret, 1, kw);
230
231         return ret;
232 }
233
234 /* callbacks */
235 static void bpy_prop_update_cb(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop)
236 {
237         PyGILState_STATE gilstate;
238         PyObject **py_data = RNA_property_py_data_get(prop);
239         PyObject *py_func;
240         PyObject *args;
241         PyObject *self;
242         PyObject *ret;
243         const bool is_write_ok = pyrna_write_check();
244
245         BLI_assert(py_data != NULL);
246
247         if (!is_write_ok) {
248                 pyrna_write_set(true);
249         }
250
251         bpy_context_set(C, &gilstate);
252
253         py_func = py_data[BPY_DATA_CB_SLOT_UPDATE];
254
255         args = PyTuple_New(2);
256         self = pyrna_struct_as_instance(ptr);
257         PyTuple_SET_ITEM(args, 0, self);
258
259         PyTuple_SET_ITEM(args, 1, (PyObject *)bpy_context_module);
260         Py_INCREF(bpy_context_module);
261
262         ret = PyObject_CallObject(py_func, args);
263
264         Py_DECREF(args);
265
266         if (ret == NULL) {
267                 printf_func_error(py_func);
268         }
269         else {
270                 if (ret != Py_None) {
271                         PyErr_SetString(PyExc_ValueError, "the return value must be None");
272                         printf_func_error(py_func);
273                 }
274
275                 Py_DECREF(ret);
276         }
277
278         bpy_context_clear(C, &gilstate);
279
280         if (!is_write_ok) {
281                 pyrna_write_set(false);
282         }
283 }
284
285 static int bpy_prop_boolean_get_cb(struct PointerRNA *ptr, struct PropertyRNA *prop)
286 {
287         PyObject **py_data = RNA_property_py_data_get(prop);
288         PyObject *py_func;
289         PyObject *args;
290         PyObject *self;
291         PyObject *ret;
292         PyGILState_STATE gilstate;
293         bool use_gil;
294         const bool is_write_ok = pyrna_write_check();
295         int value;
296
297         BLI_assert(py_data != NULL);
298
299         if (!is_write_ok) {
300                 pyrna_write_set(true);
301         }
302
303         use_gil = true;  /* !PyC_IsInterpreterActive(); */
304
305         if (use_gil)
306                 gilstate = PyGILState_Ensure();
307
308         py_func = py_data[BPY_DATA_CB_SLOT_GET];
309
310         args = PyTuple_New(1);
311         self = pyrna_struct_as_instance(ptr);
312         PyTuple_SET_ITEM(args, 0, self);
313
314         ret = PyObject_CallObject(py_func, args);
315
316         Py_DECREF(args);
317
318         if (ret == NULL) {
319                 printf_func_error(py_func);
320                 value = false;
321         }
322         else {
323                 value = PyLong_AsLong(ret);
324
325                 if (value == -1 && PyErr_Occurred()) {
326                         printf_func_error(py_func);
327                         value = false;
328                 }
329
330                 Py_DECREF(ret);
331         }
332
333         if (use_gil)
334                 PyGILState_Release(gilstate);
335
336         if (!is_write_ok) {
337                 pyrna_write_set(false);
338         }
339
340         return value;
341 }
342
343 static void bpy_prop_boolean_set_cb(struct PointerRNA *ptr, struct PropertyRNA *prop, int value)
344 {
345         PyObject **py_data = RNA_property_py_data_get(prop);
346         PyObject *py_func;
347         PyObject *args;
348         PyObject *self;
349         PyObject *ret;
350         PyGILState_STATE gilstate;
351         bool use_gil;
352         const bool is_write_ok = pyrna_write_check();
353
354         BLI_assert(py_data != NULL);
355
356         if (!is_write_ok) {
357                 pyrna_write_set(true);
358         }
359
360         use_gil = true;  /* !PyC_IsInterpreterActive(); */
361
362         if (use_gil)
363                 gilstate = PyGILState_Ensure();
364
365         py_func = py_data[BPY_DATA_CB_SLOT_SET];
366
367         args = PyTuple_New(2);
368         self = pyrna_struct_as_instance(ptr);
369         PyTuple_SET_ITEM(args, 0, self);
370
371         PyTuple_SET_ITEM(args, 1, PyBool_FromLong(value));
372
373         ret = PyObject_CallObject(py_func, args);
374
375         Py_DECREF(args);
376
377         if (ret == NULL) {
378                 printf_func_error(py_func);
379         }
380         else {
381                 if (ret != Py_None) {
382                         PyErr_SetString(PyExc_ValueError, "the return value must be None");
383                         printf_func_error(py_func);
384                 }
385
386                 Py_DECREF(ret);
387         }
388         
389         if (use_gil)
390                 PyGILState_Release(gilstate);
391
392         if (!is_write_ok) {
393                 pyrna_write_set(false);
394         }
395 }
396
397 static int bpy_prop_poll_cb(struct PointerRNA *self, PointerRNA candidate, struct PropertyRNA *prop)
398 {
399         PyObject *py_self;
400         PyObject *py_candidate;
401         PyObject *py_func;
402         PyObject **py_data = RNA_property_py_data_get(prop);
403         PyObject *args;
404         PyObject *ret;
405         bool result;
406         const int is_write_ok = pyrna_write_check();
407         PyGILState_STATE gilstate = PyGILState_Ensure();
408
409         BLI_assert(self != NULL);
410
411         py_self = pyrna_struct_as_instance(self);
412         py_candidate = pyrna_struct_as_instance(&candidate);
413         py_func = py_data[BPY_DATA_CB_SLOT_POLL];
414
415         if (!is_write_ok)
416                 pyrna_write_set(true);
417
418         args = PyTuple_New(2);
419         PyTuple_SET_ITEM(args, 0, py_self);
420         PyTuple_SET_ITEM(args, 1, py_candidate);
421
422         ret = PyObject_CallObject(py_func, args);
423
424         Py_DECREF(args);
425
426         if (ret == NULL) {
427                 printf_func_error(py_func);
428                 result = false;
429         }
430         else {
431                 result = PyObject_IsTrue(ret);
432                 Py_DECREF(ret);
433         }
434
435         PyGILState_Release(gilstate);
436         if (!is_write_ok)
437                 pyrna_write_set(false);
438
439         return result;
440 }
441
442 static void bpy_prop_boolean_array_get_cb(struct PointerRNA *ptr, struct PropertyRNA *prop, int *values)
443 {
444         PyObject **py_data = RNA_property_py_data_get(prop);
445         PyObject *py_func;
446         PyObject *args;
447         PyObject *self;
448         PyObject *ret;
449         PyGILState_STATE gilstate;
450         bool use_gil;
451         const bool is_write_ok = pyrna_write_check();
452         int i, len = RNA_property_array_length(ptr, prop);
453
454         BLI_assert(py_data != NULL);
455
456         if (!is_write_ok) {
457                 pyrna_write_set(true);
458         }
459
460         use_gil = true;  /* !PyC_IsInterpreterActive(); */
461
462         if (use_gil)
463                 gilstate = PyGILState_Ensure();
464
465         py_func = py_data[BPY_DATA_CB_SLOT_GET];
466
467         args = PyTuple_New(1);
468         self = pyrna_struct_as_instance(ptr);
469         PyTuple_SET_ITEM(args, 0, self);
470
471         ret = PyObject_CallObject(py_func, args);
472
473         Py_DECREF(args);
474
475         if (ret == NULL) {
476                 printf_func_error(py_func);
477
478                 for (i = 0; i < len; ++i)
479                         values[i] = false;
480         }
481         else {
482                 if (PyC_AsArray(values, ret, len, &PyBool_Type, false, "BoolVectorProperty get") == -1) {
483                         printf_func_error(py_func);
484
485                         for (i = 0; i < len; ++i)
486                                 values[i] = false;
487
488                         /* PyC_AsArray decrements refcount internally on error */
489                 }
490                 else {
491                         Py_DECREF(ret);
492                 }
493         }
494
495         if (use_gil)
496                 PyGILState_Release(gilstate);
497
498         if (!is_write_ok) {
499                 pyrna_write_set(false);
500         }
501 }
502
503 static void bpy_prop_boolean_array_set_cb(struct PointerRNA *ptr, struct PropertyRNA *prop, const int *values)
504 {
505         PyObject **py_data = RNA_property_py_data_get(prop);
506         PyObject *py_func;
507         PyObject *args;
508         PyObject *self;
509         PyObject *ret;
510         PyObject *py_values;
511         PyGILState_STATE gilstate;
512         bool use_gil;
513         const bool is_write_ok = pyrna_write_check();
514         int len = RNA_property_array_length(ptr, prop);
515
516         BLI_assert(py_data != NULL);
517
518         if (!is_write_ok) {
519                 pyrna_write_set(true);
520         }
521
522         use_gil = true;  /* !PyC_IsInterpreterActive(); */
523
524         if (use_gil)
525                 gilstate = PyGILState_Ensure();
526
527         py_func = py_data[BPY_DATA_CB_SLOT_SET];
528
529         args = PyTuple_New(2);
530         self = pyrna_struct_as_instance(ptr);
531         PyTuple_SET_ITEM(args, 0, self);
532
533         py_values = PyC_FromArray(values, len, &PyBool_Type, false, "BoolVectorProperty set");
534         if (!py_values) {
535                 printf_func_error(py_func);
536         }
537         else
538                 PyTuple_SET_ITEM(args, 1, py_values);
539
540         ret = PyObject_CallObject(py_func, args);
541
542         Py_DECREF(args);
543
544         if (ret == NULL) {
545                 printf_func_error(py_func);
546         }
547         else {
548                 if (ret != Py_None) {
549                         PyErr_SetString(PyExc_ValueError, "the return value must be None");
550                         printf_func_error(py_func);
551                 }
552
553                 Py_DECREF(ret);
554         }
555
556         if (use_gil)
557                 PyGILState_Release(gilstate);
558
559         if (!is_write_ok) {
560                 pyrna_write_set(false);
561         }
562 }
563
564 static int bpy_prop_int_get_cb(struct PointerRNA *ptr, struct PropertyRNA *prop)
565 {
566         PyObject **py_data = RNA_property_py_data_get(prop);
567         PyObject *py_func;
568         PyObject *args;
569         PyObject *self;
570         PyObject *ret;
571         PyGILState_STATE gilstate;
572         bool use_gil;
573         const bool is_write_ok = pyrna_write_check();
574         int value;
575
576         BLI_assert(py_data != NULL);
577
578         if (!is_write_ok) {
579                 pyrna_write_set(true);
580         }
581
582         use_gil = true;  /* !PyC_IsInterpreterActive(); */
583
584         if (use_gil)
585                 gilstate = PyGILState_Ensure();
586
587         py_func = py_data[BPY_DATA_CB_SLOT_GET];
588
589         args = PyTuple_New(1);
590         self = pyrna_struct_as_instance(ptr);
591         PyTuple_SET_ITEM(args, 0, self);
592
593         ret = PyObject_CallObject(py_func, args);
594
595         Py_DECREF(args);
596
597         if (ret == NULL) {
598                 printf_func_error(py_func);
599                 value = 0.0f;
600         }
601         else {
602                 value = PyLong_AsLong(ret);
603
604                 if (value == -1 && PyErr_Occurred()) {
605                         printf_func_error(py_func);
606                         value = 0;
607                 }
608
609                 Py_DECREF(ret);
610         }
611
612         if (use_gil)
613                 PyGILState_Release(gilstate);
614
615         if (!is_write_ok) {
616                 pyrna_write_set(false);
617         }
618
619         return value;
620 }
621
622 static void bpy_prop_int_set_cb(struct PointerRNA *ptr, struct PropertyRNA *prop, int value)
623 {
624         PyObject **py_data = RNA_property_py_data_get(prop);
625         PyObject *py_func;
626         PyObject *args;
627         PyObject *self;
628         PyObject *ret;
629         PyGILState_STATE gilstate;
630         bool use_gil;
631         const bool is_write_ok = pyrna_write_check();
632
633         BLI_assert(py_data != NULL);
634
635         if (!is_write_ok) {
636                 pyrna_write_set(true);
637         }
638
639         use_gil = true;  /* !PyC_IsInterpreterActive(); */
640
641         if (use_gil)
642                 gilstate = PyGILState_Ensure();
643
644         py_func = py_data[BPY_DATA_CB_SLOT_SET];
645
646         args = PyTuple_New(2);
647         self = pyrna_struct_as_instance(ptr);
648         PyTuple_SET_ITEM(args, 0, self);
649
650         PyTuple_SET_ITEM(args, 1, PyLong_FromLong(value));
651
652         ret = PyObject_CallObject(py_func, args);
653
654         Py_DECREF(args);
655
656         if (ret == NULL) {
657                 printf_func_error(py_func);
658         }
659         else {
660                 if (ret != Py_None) {
661                         PyErr_SetString(PyExc_ValueError, "the return value must be None");
662                         printf_func_error(py_func);
663                 }
664
665                 Py_DECREF(ret);
666         }
667
668         if (use_gil)
669                 PyGILState_Release(gilstate);
670
671         if (!is_write_ok) {
672                 pyrna_write_set(false);
673         }
674 }
675
676 static void bpy_prop_int_array_get_cb(struct PointerRNA *ptr, struct PropertyRNA *prop, int *values)
677 {
678         PyObject **py_data = RNA_property_py_data_get(prop);
679         PyObject *py_func;
680         PyObject *args;
681         PyObject *self;
682         PyObject *ret;
683         PyGILState_STATE gilstate;
684         bool use_gil;
685         const bool is_write_ok = pyrna_write_check();
686         int i, len = RNA_property_array_length(ptr, prop);
687
688         BLI_assert(py_data != NULL);
689
690         if (!is_write_ok) {
691                 pyrna_write_set(true);
692         }
693
694         use_gil = true;  /* !PyC_IsInterpreterActive(); */
695
696         if (use_gil)
697                 gilstate = PyGILState_Ensure();
698
699         py_func = py_data[BPY_DATA_CB_SLOT_GET];
700
701         args = PyTuple_New(1);
702         self = pyrna_struct_as_instance(ptr);
703         PyTuple_SET_ITEM(args, 0, self);
704
705         ret = PyObject_CallObject(py_func, args);
706
707         Py_DECREF(args);
708
709         if (ret == NULL) {
710                 printf_func_error(py_func);
711
712                 for (i = 0; i < len; ++i)
713                         values[i] = 0;
714         }
715         else {
716                 if (PyC_AsArray(values, ret, len, &PyLong_Type, false, "IntVectorProperty get") == -1) {
717                         printf_func_error(py_func);
718
719                         for (i = 0; i < len; ++i)
720                                 values[i] = 0;
721
722                         /* PyC_AsArray decrements refcount internally on error */
723                 }
724                 else {
725                         Py_DECREF(ret);
726                 }
727         }
728
729         if (use_gil)
730                 PyGILState_Release(gilstate);
731
732         if (!is_write_ok) {
733                 pyrna_write_set(false);
734         }
735 }
736
737 static void bpy_prop_int_array_set_cb(struct PointerRNA *ptr, struct PropertyRNA *prop, const int *values)
738 {
739         PyObject **py_data = RNA_property_py_data_get(prop);
740         PyObject *py_func;
741         PyObject *args;
742         PyObject *self;
743         PyObject *ret;
744         PyObject *py_values;
745         PyGILState_STATE gilstate;
746         bool use_gil;
747         const bool is_write_ok = pyrna_write_check();
748         int len = RNA_property_array_length(ptr, prop);
749
750         BLI_assert(py_data != NULL);
751
752         if (!is_write_ok) {
753                 pyrna_write_set(true);
754         }
755
756         use_gil = true;  /* !PyC_IsInterpreterActive(); */
757
758         if (use_gil)
759                 gilstate = PyGILState_Ensure();
760
761         py_func = py_data[BPY_DATA_CB_SLOT_SET];
762
763         args = PyTuple_New(2);
764         self = pyrna_struct_as_instance(ptr);
765         PyTuple_SET_ITEM(args, 0, self);
766
767         py_values = PyC_FromArray(values, len, &PyLong_Type, false, "IntVectorProperty set");
768         if (!py_values) {
769                 printf_func_error(py_func);
770         }
771         else
772                 PyTuple_SET_ITEM(args, 1, py_values);
773
774         ret = PyObject_CallObject(py_func, args);
775
776         Py_DECREF(args);
777
778         if (ret == NULL) {
779                 printf_func_error(py_func);
780         }
781         else {
782                 if (ret != Py_None) {
783                         PyErr_SetString(PyExc_ValueError, "the return value must be None");
784                         printf_func_error(py_func);
785                 }
786
787                 Py_DECREF(ret);
788         }
789
790         if (use_gil)
791                 PyGILState_Release(gilstate);
792
793         if (!is_write_ok) {
794                 pyrna_write_set(false);
795         }
796 }
797
798 static float bpy_prop_float_get_cb(struct PointerRNA *ptr, struct PropertyRNA *prop)
799 {
800         PyObject **py_data = RNA_property_py_data_get(prop);
801         PyObject *py_func;
802         PyObject *args;
803         PyObject *self;
804         PyObject *ret;
805         PyGILState_STATE gilstate;
806         bool use_gil;
807         const bool is_write_ok = pyrna_write_check();
808         float value;
809
810         BLI_assert(py_data != NULL);
811
812         if (!is_write_ok) {
813                 pyrna_write_set(true);
814         }
815
816         use_gil = true;  /* !PyC_IsInterpreterActive(); */
817
818         if (use_gil)
819                 gilstate = PyGILState_Ensure();
820
821         py_func = py_data[BPY_DATA_CB_SLOT_GET];
822
823         args = PyTuple_New(1);
824         self = pyrna_struct_as_instance(ptr);
825         PyTuple_SET_ITEM(args, 0, self);
826
827         ret = PyObject_CallObject(py_func, args);
828
829         Py_DECREF(args);
830
831         if (ret == NULL) {
832                 printf_func_error(py_func);
833                 value = 0.0f;
834         }
835         else {
836                 value = PyFloat_AsDouble(ret);
837
838                 if (value == -1.0f && PyErr_Occurred()) {
839                         printf_func_error(py_func);
840                         value = 0.0f;
841                 }
842
843                 Py_DECREF(ret);
844         }
845
846         if (use_gil)
847                 PyGILState_Release(gilstate);
848
849         if (!is_write_ok) {
850                 pyrna_write_set(false);
851         }
852
853         return value;
854 }
855
856 static void bpy_prop_float_set_cb(struct PointerRNA *ptr, struct PropertyRNA *prop, float value)
857 {
858         PyObject **py_data = RNA_property_py_data_get(prop);
859         PyObject *py_func;
860         PyObject *args;
861         PyObject *self;
862         PyObject *ret;
863         PyGILState_STATE gilstate;
864         bool use_gil;
865         const bool is_write_ok = pyrna_write_check();
866
867         BLI_assert(py_data != NULL);
868
869         if (!is_write_ok) {
870                 pyrna_write_set(true);
871         }
872
873         use_gil = true;  /* !PyC_IsInterpreterActive(); */
874
875         if (use_gil)
876                 gilstate = PyGILState_Ensure();
877
878         py_func = py_data[BPY_DATA_CB_SLOT_SET];
879
880         args = PyTuple_New(2);
881         self = pyrna_struct_as_instance(ptr);
882         PyTuple_SET_ITEM(args, 0, self);
883
884         PyTuple_SET_ITEM(args, 1, PyFloat_FromDouble(value));
885
886         ret = PyObject_CallObject(py_func, args);
887
888         Py_DECREF(args);
889
890         if (ret == NULL) {
891                 printf_func_error(py_func);
892         }
893         else {
894                 if (ret != Py_None) {
895                         PyErr_SetString(PyExc_ValueError, "the return value must be None");
896                         printf_func_error(py_func);
897                 }
898
899                 Py_DECREF(ret);
900         }
901
902         if (use_gil)
903                 PyGILState_Release(gilstate);
904
905         if (!is_write_ok) {
906                 pyrna_write_set(false);
907         }
908 }
909
910 static void bpy_prop_float_array_get_cb(struct PointerRNA *ptr, struct PropertyRNA *prop, float *values)
911 {
912         PyObject **py_data = RNA_property_py_data_get(prop);
913         PyObject *py_func;
914         PyObject *args;
915         PyObject *self;
916         PyObject *ret;
917         PyGILState_STATE gilstate;
918         bool use_gil;
919         const bool is_write_ok = pyrna_write_check();
920         int i, len = RNA_property_array_length(ptr, prop);
921
922         BLI_assert(py_data != NULL);
923
924         if (!is_write_ok) {
925                 pyrna_write_set(true);
926         }
927
928         use_gil = true;  /* !PyC_IsInterpreterActive(); */
929
930         if (use_gil)
931                 gilstate = PyGILState_Ensure();
932
933         py_func = py_data[BPY_DATA_CB_SLOT_GET];
934
935         args = PyTuple_New(1);
936         self = pyrna_struct_as_instance(ptr);
937         PyTuple_SET_ITEM(args, 0, self);
938
939         ret = PyObject_CallObject(py_func, args);
940
941         Py_DECREF(args);
942
943         if (ret == NULL) {
944                 printf_func_error(py_func);
945
946                 for (i = 0; i < len; ++i)
947                         values[i] = 0.0f;
948         }
949         else {
950                 if (PyC_AsArray(values, ret, len, &PyFloat_Type, false, "FloatVectorProperty get") == -1) {
951                         printf_func_error(py_func);
952
953                         for (i = 0; i < len; ++i)
954                                 values[i] = 0.0f;
955
956                         /* PyC_AsArray decrements refcount internally on error */
957                 }
958                 else {
959                         Py_DECREF(ret);
960                 }
961         }
962
963         if (use_gil)
964                 PyGILState_Release(gilstate);
965
966         if (!is_write_ok) {
967                 pyrna_write_set(false);
968         }
969 }
970
971 static void bpy_prop_float_array_set_cb(struct PointerRNA *ptr, struct PropertyRNA *prop, const float *values)
972 {
973         PyObject **py_data = RNA_property_py_data_get(prop);
974         PyObject *py_func;
975         PyObject *args;
976         PyObject *self;
977         PyObject *ret;
978         PyObject *py_values;
979         PyGILState_STATE gilstate;
980         bool use_gil;
981         const bool is_write_ok = pyrna_write_check();
982         int len = RNA_property_array_length(ptr, prop);
983
984         BLI_assert(py_data != NULL);
985
986         if (!is_write_ok) {
987                 pyrna_write_set(true);
988         }
989
990         use_gil = true;  /* !PyC_IsInterpreterActive(); */
991
992         if (use_gil)
993                 gilstate = PyGILState_Ensure();
994
995         py_func = py_data[BPY_DATA_CB_SLOT_SET];
996
997         args = PyTuple_New(2);
998         self = pyrna_struct_as_instance(ptr);
999         PyTuple_SET_ITEM(args, 0, self);
1000
1001         py_values = PyC_FromArray(values, len, &PyFloat_Type, false, "FloatVectorProperty set");
1002         if (!py_values) {
1003                 printf_func_error(py_func);
1004         }
1005         else
1006                 PyTuple_SET_ITEM(args, 1, py_values);
1007
1008         ret = PyObject_CallObject(py_func, args);
1009
1010         Py_DECREF(args);
1011
1012         if (ret == NULL) {
1013                 printf_func_error(py_func);
1014         }
1015         else {
1016                 if (ret != Py_None) {
1017                         PyErr_SetString(PyExc_ValueError, "the return value must be None");
1018                         printf_func_error(py_func);
1019                 }
1020
1021                 Py_DECREF(ret);
1022         }
1023
1024         if (use_gil)
1025                 PyGILState_Release(gilstate);
1026
1027         if (!is_write_ok) {
1028                 pyrna_write_set(false);
1029         }
1030 }
1031
1032 static void bpy_prop_string_get_cb(struct PointerRNA *ptr, struct PropertyRNA *prop, char *value)
1033 {
1034         PyObject **py_data = RNA_property_py_data_get(prop);
1035         PyObject *py_func;
1036         PyObject *args;
1037         PyObject *self;
1038         PyObject *ret;
1039         PyGILState_STATE gilstate;
1040         bool use_gil;
1041         const bool is_write_ok = pyrna_write_check();
1042
1043         BLI_assert(py_data != NULL);
1044
1045         if (!is_write_ok) {
1046                 pyrna_write_set(true);
1047         }
1048
1049         use_gil = true;  /* !PyC_IsInterpreterActive(); */
1050
1051         if (use_gil)
1052                 gilstate = PyGILState_Ensure();
1053
1054         py_func = py_data[BPY_DATA_CB_SLOT_GET];
1055
1056         args = PyTuple_New(1);
1057         self = pyrna_struct_as_instance(ptr);
1058         PyTuple_SET_ITEM(args, 0, self);
1059
1060         ret = PyObject_CallObject(py_func, args);
1061
1062         Py_DECREF(args);
1063
1064         if (ret == NULL) {
1065                 printf_func_error(py_func);
1066                 value[0] = '\0';
1067         }
1068         else if (!PyUnicode_Check(ret)) {
1069                 PyErr_Format(PyExc_TypeError,
1070                              "return value must be a string, not %.200s",
1071                              Py_TYPE(ret)->tp_name);
1072                 printf_func_error(py_func);
1073                 value[0] = '\0';
1074                 Py_DECREF(ret);
1075         }
1076         else {
1077                 Py_ssize_t length;
1078                 const char *buffer = _PyUnicode_AsStringAndSize(ret, &length);
1079                 memcpy(value, buffer, length + 1);
1080                 Py_DECREF(ret);
1081         }
1082
1083         if (use_gil)
1084                 PyGILState_Release(gilstate);
1085
1086         if (!is_write_ok) {
1087                 pyrna_write_set(false);
1088         }
1089 }
1090
1091 static int bpy_prop_string_length_cb(struct PointerRNA *ptr, struct PropertyRNA *prop)
1092 {
1093         PyObject **py_data = RNA_property_py_data_get(prop);
1094         PyObject *py_func;
1095         PyObject *args;
1096         PyObject *self;
1097         PyObject *ret;
1098         PyGILState_STATE gilstate;
1099         bool use_gil;
1100         const bool is_write_ok = pyrna_write_check();
1101         int length;
1102
1103         BLI_assert(py_data != NULL);
1104
1105         if (!is_write_ok) {
1106                 pyrna_write_set(true);
1107         }
1108
1109         use_gil = true;  /* !PyC_IsInterpreterActive(); */
1110
1111         if (use_gil)
1112                 gilstate = PyGILState_Ensure();
1113
1114         py_func = py_data[BPY_DATA_CB_SLOT_GET];
1115
1116         args = PyTuple_New(1);
1117         self = pyrna_struct_as_instance(ptr);
1118         PyTuple_SET_ITEM(args, 0, self);
1119
1120         ret = PyObject_CallObject(py_func, args);
1121
1122         Py_DECREF(args);
1123
1124         if (ret == NULL) {
1125                 printf_func_error(py_func);
1126                 length = 0;
1127         }
1128         else if (!PyUnicode_Check(ret)) {
1129                 PyErr_Format(PyExc_TypeError,
1130                              "return value must be a string, not %.200s",
1131                              Py_TYPE(ret)->tp_name);
1132                 printf_func_error(py_func);
1133                 length = 0;
1134                 Py_DECREF(ret);
1135         }
1136         else {
1137                 Py_ssize_t length_ssize_t = 0;
1138                 _PyUnicode_AsStringAndSize(ret, &length_ssize_t);
1139                 length = length_ssize_t;
1140                 Py_DECREF(ret);
1141         }
1142
1143         if (use_gil)
1144                 PyGILState_Release(gilstate);
1145
1146         if (!is_write_ok) {
1147                 pyrna_write_set(false);
1148         }
1149
1150         return length;
1151 }
1152
1153 static void bpy_prop_string_set_cb(struct PointerRNA *ptr, struct PropertyRNA *prop, const char *value)
1154 {
1155         PyObject **py_data = RNA_property_py_data_get(prop);
1156         PyObject *py_func;
1157         PyObject *args;
1158         PyObject *self;
1159         PyObject *ret;
1160         PyGILState_STATE gilstate;
1161         bool use_gil;
1162         const bool is_write_ok = pyrna_write_check();
1163         PyObject *py_value;
1164
1165         BLI_assert(py_data != NULL);
1166
1167         if (!is_write_ok) {
1168                 pyrna_write_set(true);
1169         }
1170
1171         use_gil = true;  /* !PyC_IsInterpreterActive(); */
1172
1173         if (use_gil)
1174                 gilstate = PyGILState_Ensure();
1175
1176         py_func = py_data[BPY_DATA_CB_SLOT_SET];
1177
1178         args = PyTuple_New(2);
1179         self = pyrna_struct_as_instance(ptr);
1180         PyTuple_SET_ITEM(args, 0, self);
1181
1182         py_value = PyUnicode_FromString(value);
1183         if (!py_value) {
1184                 PyErr_SetString(PyExc_ValueError, "the return value must be a string");
1185                 printf_func_error(py_func);
1186         }
1187         else
1188                 PyTuple_SET_ITEM(args, 1, py_value);
1189
1190         ret = PyObject_CallObject(py_func, args);
1191
1192         Py_DECREF(args);
1193
1194         if (ret == NULL) {
1195                 printf_func_error(py_func);
1196         }
1197         else {
1198                 if (ret != Py_None) {
1199                         PyErr_SetString(PyExc_ValueError, "the return value must be None");
1200                         printf_func_error(py_func);
1201                 }
1202
1203                 Py_DECREF(ret);
1204         }
1205
1206         if (use_gil)
1207                 PyGILState_Release(gilstate);
1208
1209         if (!is_write_ok) {
1210                 pyrna_write_set(false);
1211         }
1212 }
1213
1214 static int bpy_prop_enum_get_cb(struct PointerRNA *ptr, struct PropertyRNA *prop)
1215 {
1216         PyObject **py_data = RNA_property_py_data_get(prop);
1217         PyObject *py_func;
1218         PyObject *args;
1219         PyObject *self;
1220         PyObject *ret;
1221         PyGILState_STATE gilstate;
1222         bool use_gil;
1223         const bool is_write_ok = pyrna_write_check();
1224         int value;
1225
1226         BLI_assert(py_data != NULL);
1227
1228         if (!is_write_ok) {
1229                 pyrna_write_set(true);
1230         }
1231
1232         use_gil = true;  /* !PyC_IsInterpreterActive(); */
1233
1234         if (use_gil)
1235                 gilstate = PyGILState_Ensure();
1236
1237         py_func = py_data[BPY_DATA_CB_SLOT_GET];
1238
1239         args = PyTuple_New(1);
1240         self = pyrna_struct_as_instance(ptr);
1241         PyTuple_SET_ITEM(args, 0, self);
1242
1243         ret = PyObject_CallObject(py_func, args);
1244
1245         Py_DECREF(args);
1246
1247         if (ret == NULL) {
1248                 printf_func_error(py_func);
1249                 value = RNA_property_enum_get_default(ptr, prop);
1250         }
1251         else {
1252                 value = PyLong_AsLong(ret);
1253
1254                 if (value == -1 && PyErr_Occurred()) {
1255                         printf_func_error(py_func);
1256                         value = RNA_property_enum_get_default(ptr, prop);
1257                 }
1258
1259                 Py_DECREF(ret);
1260         }
1261
1262         if (use_gil)
1263                 PyGILState_Release(gilstate);
1264
1265         if (!is_write_ok) {
1266                 pyrna_write_set(false);
1267         }
1268
1269         return value;
1270 }
1271
1272 static void bpy_prop_enum_set_cb(struct PointerRNA *ptr, struct PropertyRNA *prop, int value)
1273 {
1274         PyObject **py_data = RNA_property_py_data_get(prop);
1275         PyObject *py_func;
1276         PyObject *args;
1277         PyObject *self;
1278         PyObject *ret;
1279         PyGILState_STATE gilstate;
1280         bool use_gil;
1281         const bool is_write_ok = pyrna_write_check();
1282
1283         BLI_assert(py_data != NULL);
1284
1285         if (!is_write_ok) {
1286                 pyrna_write_set(true);
1287         }
1288
1289         use_gil = true;  /* !PyC_IsInterpreterActive(); */
1290
1291         if (use_gil)
1292                 gilstate = PyGILState_Ensure();
1293
1294         py_func = py_data[BPY_DATA_CB_SLOT_SET];
1295
1296         args = PyTuple_New(2);
1297         self = pyrna_struct_as_instance(ptr);
1298         PyTuple_SET_ITEM(args, 0, self);
1299
1300         PyTuple_SET_ITEM(args, 1, PyLong_FromLong(value));
1301
1302         ret = PyObject_CallObject(py_func, args);
1303
1304         Py_DECREF(args);
1305
1306         if (ret == NULL) {
1307                 printf_func_error(py_func);
1308         }
1309         else {
1310                 if (ret != Py_None) {
1311                         PyErr_SetString(PyExc_ValueError, "the return value must be None");
1312                         printf_func_error(py_func);
1313                 }
1314
1315                 Py_DECREF(ret);
1316         }
1317
1318         if (use_gil)
1319                 PyGILState_Release(gilstate);
1320
1321         if (!is_write_ok) {
1322                 pyrna_write_set(false);
1323         }
1324 }
1325
1326 /* utility function we need for parsing int's in an if statement */
1327 static int py_long_as_int(PyObject *py_long, int *r_int)
1328 {
1329         if (PyLong_CheckExact(py_long)) {
1330                 *r_int = (int)PyLong_AS_LONG(py_long);
1331                 return 0;
1332         }
1333         else {
1334                 return -1;
1335         }
1336 }
1337
1338 #if 0
1339 /* copies orig to buf, then sets orig to buf, returns copy length */
1340 static size_t strswapbufcpy(char *buf, const char **orig)
1341 {
1342         const char *src = *orig;
1343         char *dst = buf;
1344         size_t i = 0;
1345         *orig = buf;
1346         while ((*dst = *src)) { dst++; src++; i++; }
1347         return i + 1; /* include '\0' */
1348 }
1349 #endif
1350
1351 static int icon_id_from_name(const char *name)
1352 {
1353         EnumPropertyItem *item;
1354         int id;
1355
1356         if (name[0]) {
1357                 for (item = rna_enum_icon_items, id = 0; item->identifier; item++, id++) {
1358                         if (STREQ(item->name, name)) {
1359                                 return item->value;
1360                         }
1361                 }
1362         }
1363         
1364         return 0;
1365 }
1366
1367 static EnumPropertyItem *enum_items_from_py(PyObject *seq_fast, PyObject *def, int *defvalue, const bool is_enum_flag)
1368 {
1369         EnumPropertyItem *items;
1370         PyObject *item;
1371         const Py_ssize_t seq_len = PySequence_Fast_GET_SIZE(seq_fast);
1372         PyObject **seq_fast_items = PySequence_Fast_ITEMS(seq_fast);
1373         Py_ssize_t totbuf = 0;
1374         int i;
1375         short def_used = 0;
1376         const char *def_cmp = NULL;
1377
1378         if (is_enum_flag) {
1379                 if (seq_len > RNA_ENUM_BITFLAG_SIZE) {
1380                         PyErr_SetString(PyExc_TypeError,
1381                                         "EnumProperty(...): maximum "
1382                                         STRINGIFY(RNA_ENUM_BITFLAG_SIZE)
1383                                         " members for a ENUM_FLAG type property");
1384                         return NULL;
1385                 }
1386                 if (def && !PySet_Check(def)) {
1387                         PyErr_Format(PyExc_TypeError,
1388                                      "EnumProperty(...): default option must be a 'set' "
1389                                      "type when ENUM_FLAG is enabled, not a '%.200s'",
1390                                      Py_TYPE(def)->tp_name);
1391                         return NULL;
1392                 }
1393         }
1394         else {
1395                 if (def) {
1396                         def_cmp = _PyUnicode_AsString(def);
1397                         if (def_cmp == NULL) {
1398                                 PyErr_Format(PyExc_TypeError,
1399                                              "EnumProperty(...): default option must be a 'str' "
1400                                              "type when ENUM_FLAG is disabled, not a '%.200s'",
1401                                              Py_TYPE(def)->tp_name);
1402                                 return NULL;
1403                         }
1404                 }
1405         }
1406
1407         /* blank value */
1408         *defvalue = 0;
1409
1410         items = MEM_callocN(sizeof(EnumPropertyItem) * (seq_len + 1), "enum_items_from_py1");
1411
1412         for (i = 0; i < seq_len; i++) {
1413                 EnumPropertyItem tmp = {0, "", 0, "", ""};
1414                 const char *tmp_icon = NULL;
1415                 Py_ssize_t item_size;
1416                 Py_ssize_t id_str_size;
1417                 Py_ssize_t name_str_size;
1418                 Py_ssize_t desc_str_size;
1419
1420                 item = seq_fast_items[i];
1421
1422                 if ((PyTuple_CheckExact(item)) &&
1423                     (item_size = PyTuple_GET_SIZE(item)) &&
1424                     (item_size >= 3 && item_size <= 5) &&
1425                     (tmp.identifier =  _PyUnicode_AsStringAndSize(PyTuple_GET_ITEM(item, 0), &id_str_size)) &&
1426                     (tmp.name =        _PyUnicode_AsStringAndSize(PyTuple_GET_ITEM(item, 1), &name_str_size)) &&
1427                     (tmp.description = _PyUnicode_AsStringAndSize(PyTuple_GET_ITEM(item, 2), &desc_str_size)) &&
1428                     /* TODO, number isn't ensured to be unique from the script author */
1429                     (item_size != 4 || py_long_as_int(PyTuple_GET_ITEM(item, 3), &tmp.value) != -1) &&
1430                     (item_size != 5 || ((py_long_as_int(PyTuple_GET_ITEM(item, 3), &tmp.icon) != -1 ||
1431                                          (tmp_icon = _PyUnicode_AsString(PyTuple_GET_ITEM(item, 3)))) &&
1432                                         py_long_as_int(PyTuple_GET_ITEM(item, 4), &tmp.value) != -1)))
1433                 {
1434                         if (is_enum_flag) {
1435                                 if (item_size < 4) {
1436                                         tmp.value = 1 << i;
1437                                 }
1438
1439                                 if (def && PySet_Contains(def, PyTuple_GET_ITEM(item, 0))) {
1440                                         *defvalue |= tmp.value;
1441                                         def_used++;
1442                                 }
1443                         }
1444                         else {
1445                                 if (item_size < 4) {
1446                                         tmp.value = i;
1447                                 }
1448
1449                                 if (def && def_used == 0 && STREQ(def_cmp, tmp.identifier)) {
1450                                         *defvalue = tmp.value;
1451                                         def_used++; /* only ever 1 */
1452                                 }
1453                         }
1454
1455                         if (tmp_icon)
1456                                 tmp.icon = icon_id_from_name(tmp_icon);
1457
1458                         items[i] = tmp;
1459
1460                         /* calculate combine string length */
1461                         totbuf += id_str_size + name_str_size + desc_str_size + 3; /* 3 is for '\0's */
1462                 }
1463                 else {
1464                         MEM_freeN(items);
1465                         PyErr_SetString(PyExc_TypeError,
1466                                         "EnumProperty(...): expected a tuple containing "
1467                                         "(identifier, name, description) and optionally an "
1468                                         "icon name and unique number");
1469                         return NULL;
1470                 }
1471
1472         }
1473
1474         if (is_enum_flag) {
1475                 /* strict check that all set members were used */
1476                 if (def && def_used != PySet_GET_SIZE(def)) {
1477                         MEM_freeN(items);
1478
1479                         PyErr_Format(PyExc_TypeError,
1480                                      "EnumProperty(..., default={...}): set has %d unused member(s)",
1481                                      PySet_GET_SIZE(def) - def_used);
1482                         return NULL;
1483                 }
1484         }
1485         else {
1486                 if (def && def_used == 0) {
1487                         MEM_freeN(items);
1488
1489                         PyErr_Format(PyExc_TypeError,
1490                                      "EnumProperty(..., default=\'%s\'): not found in enum members",
1491                                      def_cmp);
1492                         return NULL;
1493                 }
1494         }
1495
1496         /* disabled duplicating strings because the array can still be freed and
1497          * the strings from it referenced, for now we can't support dynamically
1498          * created strings from python. */
1499 #if 0
1500         /* this would all work perfectly _but_ the python strings may be freed
1501          * immediately after use, so we need to duplicate them, ugh.
1502          * annoying because it works most of the time without this. */
1503         {
1504                 EnumPropertyItem *items_dup = MEM_mallocN((sizeof(EnumPropertyItem) * (seq_len + 1)) + (sizeof(char) * totbuf),
1505                                                           "enum_items_from_py2");
1506                 EnumPropertyItem *items_ptr = items_dup;
1507                 char *buf = ((char *)items_dup) + (sizeof(EnumPropertyItem) * (seq_len + 1));
1508                 memcpy(items_dup, items, sizeof(EnumPropertyItem) * (seq_len + 1));
1509                 for (i = 0; i < seq_len; i++, items_ptr++) {
1510                         buf += strswapbufcpy(buf, &items_ptr->identifier);
1511                         buf += strswapbufcpy(buf, &items_ptr->name);
1512                         buf += strswapbufcpy(buf, &items_ptr->description);
1513                 }
1514                 MEM_freeN(items);
1515                 items = items_dup;
1516         }
1517         /* end string duplication */
1518 #endif
1519
1520         return items;
1521 }
1522
1523 static EnumPropertyItem *bpy_prop_enum_itemf_cb(struct bContext *C, PointerRNA *ptr, PropertyRNA *prop, bool *r_free)
1524 {
1525         PyGILState_STATE gilstate;
1526
1527         PyObject *py_func = RNA_property_enum_py_data_get(prop);
1528         PyObject *self = NULL;
1529         PyObject *args;
1530         PyObject *items; /* returned from the function call */
1531
1532         EnumPropertyItem *eitems = NULL;
1533         int err = 0;
1534
1535         if (C) {
1536                 bpy_context_set(C, &gilstate);
1537         }
1538         else {
1539                 gilstate = PyGILState_Ensure();
1540         }
1541
1542         args = PyTuple_New(2);
1543         self = pyrna_struct_as_instance(ptr);
1544         PyTuple_SET_ITEM(args, 0, self);
1545
1546         /* now get the context */
1547         if (C) {
1548                 PyTuple_SET_ITEM(args, 1, (PyObject *)bpy_context_module);
1549                 Py_INCREF(bpy_context_module);
1550         }
1551         else {
1552                 PyTuple_SET_ITEM(args, 1, Py_None);
1553                 Py_INCREF(Py_None);
1554         }
1555
1556         items = PyObject_CallObject(py_func, args);
1557
1558         Py_DECREF(args);
1559
1560         if (items == NULL) {
1561                 err = -1;
1562         }
1563         else {
1564                 PyObject *items_fast;
1565                 int defvalue_dummy = 0;
1566
1567                 if (!(items_fast = PySequence_Fast(items, "EnumProperty(...): "
1568                                                    "return value from the callback was not a sequence")))
1569                 {
1570                         err = -1;
1571                 }
1572                 else {
1573                         eitems = enum_items_from_py(items_fast, NULL, &defvalue_dummy,
1574                                                     (RNA_property_flag(prop) & PROP_ENUM_FLAG) != 0);
1575
1576                         Py_DECREF(items_fast);
1577
1578                         if (!eitems) {
1579                                 err = -1;
1580                         }
1581                 }
1582
1583                 Py_DECREF(items);
1584         }
1585
1586         if (err != -1) { /* worked */
1587                 *r_free = true;
1588         }
1589         else {
1590                 printf_func_error(py_func);
1591
1592                 eitems = DummyRNA_NULL_items;
1593         }
1594
1595         if (C) {
1596                 bpy_context_clear(C, &gilstate);
1597         }
1598         else {
1599                 PyGILState_Release(gilstate);
1600         }
1601
1602         return eitems;
1603 }
1604
1605 static int bpy_prop_callback_check(PyObject *py_func, const char *keyword, int argcount)
1606 {
1607         if (py_func && py_func != Py_None) {
1608                 if (!PyFunction_Check(py_func)) {
1609                         PyErr_Format(PyExc_TypeError,
1610                                      "%s keyword: expected a function type, not a %.200s",
1611                                      keyword, Py_TYPE(py_func)->tp_name);
1612                         return -1;
1613                 }
1614                 else {
1615                         PyCodeObject *f_code = (PyCodeObject *)PyFunction_GET_CODE(py_func);
1616                         if (f_code->co_argcount != argcount) {
1617                                 PyErr_Format(PyExc_TypeError,
1618                                              "%s keyword: expected a function taking %d arguments, not %d",
1619                                              keyword, argcount, f_code->co_argcount);
1620                                 return -1;
1621                         }
1622                 }
1623         }
1624
1625         return 0;
1626 }
1627
1628 static PyObject **bpy_prop_py_data_get(struct PropertyRNA *prop)
1629 {
1630         PyObject **py_data = RNA_property_py_data_get(prop);
1631         if (!py_data) {
1632                 py_data = MEM_callocN(sizeof(PyObject *) * BPY_DATA_CB_SLOT_SIZE, __func__);
1633                 RNA_def_py_data(prop, py_data);
1634         }
1635         return py_data;
1636 }
1637
1638 static void bpy_prop_callback_assign_update(struct PropertyRNA *prop, PyObject *update_cb)
1639 {
1640         /* assume this is already checked for type and arg length */
1641         if (update_cb && update_cb != Py_None) {
1642                 PyObject **py_data = bpy_prop_py_data_get(prop);
1643
1644                 RNA_def_property_update_runtime(prop, (void *)bpy_prop_update_cb);
1645                 py_data[BPY_DATA_CB_SLOT_UPDATE] = update_cb;
1646
1647                 RNA_def_property_flag(prop, PROP_CONTEXT_PROPERTY_UPDATE);
1648         }
1649 }
1650
1651 static void bpy_prop_callback_assign_pointer(struct PropertyRNA *prop, PyObject *poll_cb)
1652 {
1653         if (poll_cb && poll_cb != Py_None) {
1654                 PyObject **py_data = bpy_prop_py_data_get(prop);
1655
1656                 RNA_def_property_poll_runtime(prop, (void *) bpy_prop_poll_cb);
1657                 py_data[BPY_DATA_CB_SLOT_POLL] = poll_cb;
1658         }
1659 }
1660
1661 static void bpy_prop_callback_assign_boolean(struct PropertyRNA *prop, PyObject *get_cb, PyObject *set_cb)
1662 {
1663         BooleanPropertyGetFunc rna_get_cb = NULL;
1664         BooleanPropertySetFunc rna_set_cb = NULL;
1665         
1666         if (get_cb && get_cb != Py_None) {
1667                 PyObject **py_data = bpy_prop_py_data_get(prop);
1668
1669                 rna_get_cb = bpy_prop_boolean_get_cb;
1670                 py_data[BPY_DATA_CB_SLOT_GET] = get_cb;
1671         }
1672
1673         if (set_cb && set_cb != Py_None) {
1674                 PyObject **py_data = bpy_prop_py_data_get(prop);
1675
1676                 rna_set_cb = bpy_prop_boolean_set_cb;
1677                 py_data[BPY_DATA_CB_SLOT_SET] = set_cb;
1678         }
1679
1680         RNA_def_property_boolean_funcs_runtime(prop, rna_get_cb, rna_set_cb);
1681 }
1682
1683 static void bpy_prop_callback_assign_boolean_array(struct PropertyRNA *prop, PyObject *get_cb, PyObject *set_cb)
1684 {
1685         BooleanArrayPropertyGetFunc rna_get_cb = NULL;
1686         BooleanArrayPropertySetFunc rna_set_cb = NULL;
1687         
1688         if (get_cb && get_cb != Py_None) {
1689                 PyObject **py_data = bpy_prop_py_data_get(prop);
1690
1691                 rna_get_cb = bpy_prop_boolean_array_get_cb;
1692                 py_data[BPY_DATA_CB_SLOT_GET] = get_cb;
1693         }
1694
1695         if (set_cb && set_cb != Py_None) {
1696                 PyObject **py_data = bpy_prop_py_data_get(prop);
1697
1698                 rna_set_cb = bpy_prop_boolean_array_set_cb;
1699                 py_data[BPY_DATA_CB_SLOT_SET] = set_cb;
1700         }
1701
1702         RNA_def_property_boolean_array_funcs_runtime(prop, rna_get_cb, rna_set_cb);
1703 }
1704
1705 static void bpy_prop_callback_assign_int(struct PropertyRNA *prop, PyObject *get_cb, PyObject *set_cb)
1706 {
1707         IntPropertyGetFunc rna_get_cb = NULL;
1708         IntPropertySetFunc rna_set_cb = NULL;
1709         
1710         if (get_cb && get_cb != Py_None) {
1711                 PyObject **py_data = bpy_prop_py_data_get(prop);
1712
1713                 rna_get_cb = bpy_prop_int_get_cb;
1714                 py_data[BPY_DATA_CB_SLOT_GET] = get_cb;
1715         }
1716
1717         if (set_cb && set_cb != Py_None) {
1718                 PyObject **py_data = bpy_prop_py_data_get(prop);
1719
1720                 rna_set_cb = bpy_prop_int_set_cb;
1721                 py_data[BPY_DATA_CB_SLOT_SET] = set_cb;
1722         }
1723
1724         RNA_def_property_int_funcs_runtime(prop, rna_get_cb, rna_set_cb, NULL);
1725 }
1726
1727 static void bpy_prop_callback_assign_int_array(struct PropertyRNA *prop, PyObject *get_cb, PyObject *set_cb)
1728 {
1729         IntArrayPropertyGetFunc rna_get_cb = NULL;
1730         IntArrayPropertySetFunc rna_set_cb = NULL;
1731         
1732         if (get_cb && get_cb != Py_None) {
1733                 PyObject **py_data = bpy_prop_py_data_get(prop);
1734
1735                 rna_get_cb = bpy_prop_int_array_get_cb;
1736                 py_data[BPY_DATA_CB_SLOT_GET] = get_cb;
1737         }
1738
1739         if (set_cb && set_cb != Py_None) {
1740                 PyObject **py_data = bpy_prop_py_data_get(prop);
1741
1742                 rna_set_cb = bpy_prop_int_array_set_cb;
1743                 py_data[BPY_DATA_CB_SLOT_SET] = set_cb;
1744         }
1745
1746         RNA_def_property_int_array_funcs_runtime(prop, rna_get_cb, rna_set_cb, NULL);
1747 }
1748
1749 static void bpy_prop_callback_assign_float(struct PropertyRNA *prop, PyObject *get_cb, PyObject *set_cb)
1750 {
1751         FloatPropertyGetFunc rna_get_cb = NULL;
1752         FloatPropertySetFunc rna_set_cb = NULL;
1753         
1754         if (get_cb && get_cb != Py_None) {
1755                 PyObject **py_data = bpy_prop_py_data_get(prop);
1756
1757                 rna_get_cb = bpy_prop_float_get_cb;
1758                 py_data[BPY_DATA_CB_SLOT_GET] = get_cb;
1759         }
1760
1761         if (set_cb && set_cb != Py_None) {
1762                 PyObject **py_data = bpy_prop_py_data_get(prop);
1763
1764                 rna_set_cb = bpy_prop_float_set_cb;
1765                 py_data[BPY_DATA_CB_SLOT_SET] = set_cb;
1766         }
1767
1768         RNA_def_property_float_funcs_runtime(prop, rna_get_cb, rna_set_cb, NULL);
1769 }
1770
1771 static void bpy_prop_callback_assign_float_array(struct PropertyRNA *prop, PyObject *get_cb, PyObject *set_cb)
1772 {
1773         FloatArrayPropertyGetFunc rna_get_cb = NULL;
1774         FloatArrayPropertySetFunc rna_set_cb = NULL;
1775         
1776         if (get_cb && get_cb != Py_None) {
1777                 PyObject **py_data = bpy_prop_py_data_get(prop);
1778
1779                 rna_get_cb = bpy_prop_float_array_get_cb;
1780                 py_data[BPY_DATA_CB_SLOT_GET] = get_cb;
1781         }
1782
1783         if (set_cb && set_cb != Py_None) {
1784                 PyObject **py_data = bpy_prop_py_data_get(prop);
1785
1786                 rna_set_cb = bpy_prop_float_array_set_cb;
1787                 py_data[BPY_DATA_CB_SLOT_SET] = set_cb;
1788         }
1789
1790         RNA_def_property_float_array_funcs_runtime(prop, rna_get_cb, rna_set_cb, NULL);
1791 }
1792
1793 static void bpy_prop_callback_assign_string(struct PropertyRNA *prop, PyObject *get_cb, PyObject *set_cb)
1794 {
1795         StringPropertyGetFunc rna_get_cb = NULL;
1796         StringPropertyLengthFunc rna_length_cb = NULL;
1797         StringPropertySetFunc rna_set_cb = NULL;
1798         
1799         if (get_cb && get_cb != Py_None) {
1800                 PyObject **py_data = bpy_prop_py_data_get(prop);
1801
1802                 rna_get_cb = bpy_prop_string_get_cb;
1803                 rna_length_cb = bpy_prop_string_length_cb;
1804                 py_data[BPY_DATA_CB_SLOT_GET] = get_cb;
1805         }
1806
1807         if (set_cb && set_cb != Py_None) {
1808                 PyObject **py_data = bpy_prop_py_data_get(prop);
1809
1810                 rna_set_cb = bpy_prop_string_set_cb;
1811                 py_data[BPY_DATA_CB_SLOT_SET] = set_cb;
1812         }
1813
1814         RNA_def_property_string_funcs_runtime(prop, rna_get_cb, rna_length_cb, rna_set_cb);
1815 }
1816
1817 static void bpy_prop_callback_assign_enum(struct PropertyRNA *prop, PyObject *get_cb, PyObject *set_cb, PyObject *itemf_cb)
1818 {
1819         EnumPropertyGetFunc rna_get_cb = NULL;
1820         EnumPropertyItemFunc rna_itemf_cb = NULL;
1821         EnumPropertySetFunc rna_set_cb = NULL;
1822         
1823         if (get_cb && get_cb != Py_None) {
1824                 PyObject **py_data = bpy_prop_py_data_get(prop);
1825
1826                 rna_get_cb = bpy_prop_enum_get_cb;
1827                 py_data[BPY_DATA_CB_SLOT_GET] = get_cb;
1828         }
1829
1830         if (set_cb && set_cb != Py_None) {
1831                 PyObject **py_data = bpy_prop_py_data_get(prop);
1832
1833                 rna_set_cb = bpy_prop_enum_set_cb;
1834                 py_data[BPY_DATA_CB_SLOT_SET] = set_cb;
1835         }
1836
1837         if (itemf_cb && itemf_cb != Py_None) {
1838                 rna_itemf_cb = bpy_prop_enum_itemf_cb;
1839                 RNA_def_property_enum_py_data(prop, (void *)itemf_cb);
1840
1841                 /* watch out!, if a user is tricky they can probably crash blender
1842                  * if they manage to free the callback, take care! */
1843                 /* Py_INCREF(itemf_cb); */
1844         }
1845
1846         RNA_def_property_enum_funcs_runtime(prop, rna_get_cb, rna_set_cb, rna_itemf_cb);
1847 }
1848
1849 /* this define runs at the start of each function and deals with 
1850  * returning a deferred property (to be registered later) */
1851 #define BPY_PROPDEF_HEAD(_func)                                               \
1852         if (PyTuple_GET_SIZE(args) == 1) {                                        \
1853                 PyObject *ret;                                                        \
1854                 self = PyTuple_GET_ITEM(args, 0);                                     \
1855                 args = PyTuple_New(0);                                                \
1856                 ret = BPy_##_func(self, args, kw);                                    \
1857                 Py_DECREF(args);                                                      \
1858                 return ret;                                                           \
1859         }                                                                         \
1860         else if (PyTuple_GET_SIZE(args) > 1) {                                    \
1861                 PyErr_SetString(PyExc_ValueError, "all args must be keywords");       \
1862                 return NULL;                                                          \
1863         }                                                                         \
1864         srna = srna_from_self(self, #_func"(...):");                              \
1865         if (srna == NULL) {                                                       \
1866                 if (PyErr_Occurred())                                                 \
1867                         return NULL;                                                      \
1868                 return bpy_prop_deferred_return(pymeth_##_func, kw);                  \
1869         } (void)0
1870
1871 /* terse macros for error checks shared between all funcs cant use function
1872  * calls because of static strings passed to pyrna_set_to_enum_bitfield */
1873 #define BPY_PROPDEF_CHECK(_func, _property_flag_items)                        \
1874         if (UNLIKELY(id_len >= MAX_IDPROP_NAME)) {                                \
1875                 PyErr_Format(PyExc_TypeError,                                         \
1876                              #_func"(): '%.200s' too long, max length is %d",         \
1877                              id, MAX_IDPROP_NAME - 1);                                \
1878                 return NULL;                                                          \
1879         }                                                                         \
1880         if (UNLIKELY(RNA_def_property_free_identifier(srna, id) == -1)) {         \
1881                 PyErr_Format(PyExc_TypeError,                                         \
1882                              #_func"(): '%s' is defined as a non-dynamic type",       \
1883                              id);                                                     \
1884                 return NULL;                                                          \
1885         }                                                                         \
1886         if (UNLIKELY(pyopts && pyrna_set_to_enum_bitfield(_property_flag_items,   \
1887                                                  pyopts,                          \
1888                                                  &opts,                           \
1889                                                  #_func"(options={ ...}):")))     \
1890         {                                                                         \
1891                 return NULL;                                                          \
1892         } (void)0
1893
1894 #define BPY_PROPDEF_SUBTYPE_CHECK(_func, _property_flag_items, _subtype)      \
1895         BPY_PROPDEF_CHECK(_func, _property_flag_items);                           \
1896         if (UNLIKELY(pysubtype && RNA_enum_value_from_id(_subtype,                \
1897                                                 pysubtype,                        \
1898                                                 &subtype) == 0))                  \
1899         {                                                                         \
1900                 const char *enum_str = BPy_enum_as_string(_subtype);                  \
1901                 PyErr_Format(PyExc_TypeError,                                         \
1902                              #_func"(subtype='%s'): "                                 \
1903                              "subtype not found in (%s)",                             \
1904                              pysubtype, enum_str);                                    \
1905                 MEM_freeN((void *)enum_str);                                          \
1906                 return NULL;                                                          \
1907         } (void)0
1908
1909
1910 #define BPY_PROPDEF_NAME_DOC \
1911 "   :arg name: Name used in the user interface.\n" \
1912 "   :type name: string\n" \
1913
1914 #define BPY_PROPDEF_DESC_DOC \
1915 "   :arg description: Text used for the tooltip and api documentation.\n" \
1916 "   :type description: string\n" \
1917
1918 #define BPY_PROPDEF_UNIT_DOC \
1919 "   :arg unit: Enumerator in ['NONE', 'LENGTH', 'AREA', 'VOLUME', 'ROTATION', 'TIME', 'VELOCITY', 'ACCELERATION'].\n" \
1920 "   :type unit: string\n"       \
1921
1922 #define BPY_PROPDEF_NUM_MIN_DOC \
1923 "   :arg min: Hard minimum, trying to assign a value below will silently assign this minimum instead.\n" \
1924
1925 #define BPY_PROPDEF_NUM_MAX_DOC \
1926 "   :arg max: Hard maximum, trying to assign a value above will silently assign this maximum instead.\n" \
1927
1928 #define BPY_PROPDEF_NUM_SOFTMIN_DOC \
1929 "   :arg soft_min: Soft minimum (>= *min*), user won't be able to drag the widget below this value in the UI.\n" \
1930
1931 #define BPY_PROPDEF_NUM_SOFTMAX_DOC \
1932 "   :arg soft_max: Soft maximum (<= *max*), user won't be able to drag the widget above this value in the UI.\n" \
1933
1934 #define BPY_PROPDEF_VECSIZE_DOC \
1935 "   :arg size: Vector dimensions in [1, " STRINGIFY(PYRNA_STACK_ARRAY) "].\n" \
1936 "   :type size: int\n" \
1937
1938 #define BPY_PROPDEF_INT_STEP_DOC \
1939 "   :arg step: Step of increment/decrement in UI, in [1, 100], defaults to 1 (WARNING: unused currently!).\n" \
1940 "   :type step: int\n" \
1941
1942 #define BPY_PROPDEF_FLOAT_STEP_DOC \
1943 "   :arg step: Step of increment/decrement in UI, in [1, 100], defaults to 3 (WARNING: actual value is /100).\n" \
1944 "   :type step: int\n" \
1945
1946 #define BPY_PROPDEF_FLOAT_PREC_DOC \
1947 "   :arg precision: Maximum number of decimal digits to display, in [0, 6].\n" \
1948 "   :type precision: int\n" \
1949
1950 #define BPY_PROPDEF_UPDATE_DOC \
1951 "   :arg update: Function to be called when this value is modified,\n" \
1952 "      This function must take 2 values (self, context) and return None.\n" \
1953 "      *Warning* there are no safety checks to avoid infinite recursion.\n" \
1954 "   :type update: function\n" \
1955
1956 #define BPY_PROPDEF_GET_DOC \
1957 "   :arg get: Function to be called when this value is 'read',\n" \
1958 "      This function must take 1 value (self) and return the value of the property.\n" \
1959 "   :type get: function\n" \
1960
1961 #define BPY_PROPDEF_SET_DOC \
1962 "   :arg set: Function to be called when this value is 'written',\n" \
1963 "      This function must take 2 values (self, value) and return None.\n" \
1964 "   :type set: function\n" \
1965
1966 #define BPY_PROPDEF_TYPE_DOC \
1967 "   :arg type: A subclass of :class:`bpy.types.PropertyGroup` or :class:`bpy.types.ID`.\n" \
1968 "   :type type: class\n" \
1969
1970 #if 0
1971 static int bpy_struct_id_used(StructRNA *srna, char *identifier)
1972 {
1973         PointerRNA ptr;
1974         RNA_pointer_create(NULL, srna, NULL, &ptr);
1975         return (RNA_struct_find_property(&ptr, identifier) != NULL);
1976 }
1977 #endif
1978
1979
1980 /* Function that sets RNA, NOTE - self is NULL when called from python,
1981  * but being abused from C so we can pass the srna along.
1982  * This isn't incorrect since its a python object - but be careful */
1983 PyDoc_STRVAR(BPy_BoolProperty_doc,
1984 ".. function:: BoolProperty(name=\"\", "
1985                            "description=\"\", "
1986                            "default=False, "
1987                            "options={'ANIMATABLE'}, "
1988                            "subtype='NONE', "
1989                            "update=None, "
1990                            "get=None, "
1991                            "set=None)\n"
1992 "\n"
1993 "   Returns a new boolean property definition.\n"
1994 "\n"
1995 BPY_PROPDEF_NAME_DOC
1996 BPY_PROPDEF_DESC_DOC
1997 BPY_PROPDEF_OPTIONS_DOC
1998 BPY_PROPDEF_SUBTYPE_NUMBER_DOC
1999 BPY_PROPDEF_UPDATE_DOC
2000 BPY_PROPDEF_GET_DOC
2001 BPY_PROPDEF_SET_DOC
2002 );
2003 static PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw)
2004 {
2005         StructRNA *srna;
2006
2007         BPY_PROPDEF_HEAD(BoolProperty);
2008
2009         if (srna) {
2010                 static const char *kwlist[] = {"attr", "name", "description", "default",
2011                                                "options", "subtype", "update", "get", "set", NULL};
2012                 const char *id = NULL, *name = NULL, *description = "";
2013                 int id_len;
2014                 bool def = false;
2015                 PropertyRNA *prop;
2016                 PyObject *pyopts = NULL;
2017                 int opts = 0;
2018                 const char *pysubtype = NULL;
2019                 int subtype = PROP_NONE;
2020                 PyObject *update_cb = NULL;
2021                 PyObject *get_cb = NULL;
2022                 PyObject *set_cb = NULL;
2023
2024                 if (!PyArg_ParseTupleAndKeywords(args, kw,
2025                                                  "s#|ssO&O!sOOO:BoolProperty",
2026                                                  (char **)kwlist, &id, &id_len,
2027                                                  &name, &description, PyC_ParseBool, &def,
2028                                                  &PySet_Type, &pyopts, &pysubtype,
2029                                                  &update_cb, &get_cb, &set_cb))
2030                 {
2031                         return NULL;
2032                 }
2033
2034                 BPY_PROPDEF_SUBTYPE_CHECK(BoolProperty, property_flag_items, property_subtype_number_items);
2035
2036                 if (bpy_prop_callback_check(update_cb, "update", 2) == -1) {
2037                         return NULL;
2038                 }
2039                 if (bpy_prop_callback_check(get_cb, "get", 1) == -1) {
2040                         return NULL;
2041                 }
2042                 if (bpy_prop_callback_check(set_cb, "set", 2) == -1) {
2043                         return NULL;
2044                 }
2045
2046                 prop = RNA_def_property(srna, id, PROP_BOOLEAN, subtype);
2047                 RNA_def_property_boolean_default(prop, def);
2048                 RNA_def_property_ui_text(prop, name ? name : id, description);
2049
2050                 if (pyopts) {
2051                         bpy_prop_assign_flag(prop, opts);
2052                 }
2053                 bpy_prop_callback_assign_update(prop, update_cb);
2054                 bpy_prop_callback_assign_boolean(prop, get_cb, set_cb);
2055                 RNA_def_property_duplicate_pointers(srna, prop);
2056         }
2057
2058         Py_RETURN_NONE;
2059 }
2060
2061 PyDoc_STRVAR(BPy_BoolVectorProperty_doc,
2062 ".. function:: BoolVectorProperty(name=\"\", "
2063                                  "description=\"\", "
2064                                  "default=(False, False, False), "
2065                                  "options={'ANIMATABLE'}, "
2066                                  "subtype='NONE', "
2067                                  "size=3, "
2068                                  "update=None, "
2069                                  "get=None, "
2070                                  "set=None)\n"
2071 "\n"
2072 "   Returns a new vector boolean property definition.\n"
2073 "\n"
2074 BPY_PROPDEF_NAME_DOC
2075 BPY_PROPDEF_DESC_DOC
2076 "   :arg default: sequence of booleans the length of *size*.\n"
2077 "   :type default: sequence\n"
2078 BPY_PROPDEF_OPTIONS_DOC
2079 BPY_PROPDEF_SUBTYPE_ARRAY_DOC
2080 BPY_PROPDEF_VECSIZE_DOC
2081 BPY_PROPDEF_UPDATE_DOC
2082 BPY_PROPDEF_GET_DOC
2083 BPY_PROPDEF_SET_DOC
2084 );
2085 static PyObject *BPy_BoolVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
2086 {
2087         StructRNA *srna;
2088
2089         BPY_PROPDEF_HEAD(BoolVectorProperty);
2090
2091         if (srna) {
2092                 static const char *kwlist[] = {"attr", "name", "description", "default",
2093                                                "options", "subtype", "size", "update", "get", "set", NULL};
2094                 const char *id = NULL, *name = NULL, *description = "";
2095                 int id_len;
2096                 int def[PYRNA_STACK_ARRAY] = {0};
2097                 int size = 3;
2098                 PropertyRNA *prop;
2099                 PyObject *pydef = NULL;
2100                 PyObject *pyopts = NULL;
2101                 int opts = 0;
2102                 const char *pysubtype = NULL;
2103                 int subtype = PROP_NONE;
2104                 PyObject *update_cb = NULL;
2105                 PyObject *get_cb = NULL;
2106                 PyObject *set_cb = NULL;
2107
2108                 if (!PyArg_ParseTupleAndKeywords(args, kw,
2109                                                  "s#|ssOO!siOOO:BoolVectorProperty",
2110                                                  (char **)kwlist, &id, &id_len,
2111                                                  &name, &description, &pydef,
2112                                                  &PySet_Type, &pyopts, &pysubtype, &size,
2113                                                  &update_cb, &get_cb, &set_cb))
2114                 {
2115                         return NULL;
2116                 }
2117
2118                 BPY_PROPDEF_SUBTYPE_CHECK(BoolVectorProperty, property_flag_items, property_subtype_array_items);
2119
2120                 if (size < 1 || size > PYRNA_STACK_ARRAY) {
2121                         PyErr_Format(PyExc_TypeError,
2122                                      "BoolVectorProperty(size=%d): size must be between 0 and "
2123                                      STRINGIFY(PYRNA_STACK_ARRAY), size);
2124                         return NULL;
2125                 }
2126
2127                 if (pydef && PyC_AsArray(def, pydef, size, &PyBool_Type, false, "BoolVectorProperty(default=sequence)") == -1)
2128                         return NULL;
2129
2130                 if (bpy_prop_callback_check(update_cb, "update", 2) == -1) {
2131                         return NULL;
2132                 }
2133                 if (bpy_prop_callback_check(get_cb, "get", 1) == -1) {
2134                         return NULL;
2135                 }
2136                 if (bpy_prop_callback_check(set_cb, "set", 2) == -1) {
2137                         return NULL;
2138                 }
2139
2140                 // prop = RNA_def_boolean_array(srna, id, size, pydef ? def:NULL, name ? name : id, description);
2141                 prop = RNA_def_property(srna, id, PROP_BOOLEAN, subtype);
2142                 RNA_def_property_array(prop, size);
2143                 if (pydef) RNA_def_property_boolean_array_default(prop, def);
2144                 RNA_def_property_ui_text(prop, name ? name : id, description);
2145
2146                 if (pyopts) {
2147                         bpy_prop_assign_flag(prop, opts);
2148                 }
2149                 bpy_prop_callback_assign_update(prop, update_cb);
2150                 bpy_prop_callback_assign_boolean_array(prop, get_cb, set_cb);
2151                 RNA_def_property_duplicate_pointers(srna, prop);
2152         }
2153         
2154         Py_RETURN_NONE;
2155 }
2156
2157 PyDoc_STRVAR(BPy_IntProperty_doc,
2158 ".. function:: IntProperty(name=\"\", "
2159                           "description=\"\", "
2160                           "default=0, "
2161                           "min=-2**31, max=2**31-1, "
2162                           "soft_min=-2**31, soft_max=2**31-1, "
2163                           "step=1, "
2164                           "options={'ANIMATABLE'}, "
2165                           "subtype='NONE', "
2166                           "update=None, "
2167                           "get=None, "
2168                           "set=None)\n"
2169 "\n"
2170 "   Returns a new int property definition.\n"
2171 "\n"
2172 BPY_PROPDEF_NAME_DOC
2173 BPY_PROPDEF_DESC_DOC
2174 BPY_PROPDEF_NUM_MIN_DOC
2175 "   :type min: int\n"
2176 BPY_PROPDEF_NUM_MAX_DOC
2177 "   :type max: int\n"
2178 BPY_PROPDEF_NUM_SOFTMAX_DOC
2179 "   :type soft_min: int\n"
2180 BPY_PROPDEF_NUM_SOFTMIN_DOC
2181 "   :type soft_max: int\n"
2182 BPY_PROPDEF_INT_STEP_DOC
2183 BPY_PROPDEF_OPTIONS_DOC
2184 BPY_PROPDEF_SUBTYPE_NUMBER_DOC
2185 BPY_PROPDEF_UPDATE_DOC
2186 BPY_PROPDEF_GET_DOC
2187 BPY_PROPDEF_SET_DOC
2188 );
2189 static PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw)
2190 {
2191         StructRNA *srna;
2192
2193         BPY_PROPDEF_HEAD(IntProperty);
2194
2195         if (srna) {
2196                 static const char *kwlist[] = {"attr", "name", "description", "default",
2197                                                "min", "max", "soft_min", "soft_max",
2198                                                "step", "options", "subtype", "update", "get", "set", NULL};
2199                 const char *id = NULL, *name = NULL, *description = "";
2200                 int id_len;
2201                 int min = INT_MIN, max = INT_MAX, soft_min = INT_MIN, soft_max = INT_MAX, step = 1, def = 0;
2202                 PropertyRNA *prop;
2203                 PyObject *pyopts = NULL;
2204                 int opts = 0;
2205                 const char *pysubtype = NULL;
2206                 int subtype = PROP_NONE;
2207                 PyObject *update_cb = NULL;
2208                 PyObject *get_cb = NULL;
2209                 PyObject *set_cb = NULL;
2210
2211                 if (!PyArg_ParseTupleAndKeywords(args, kw,
2212                                                  "s#|ssiiiiiiO!sOOO:IntProperty",
2213                                                  (char **)kwlist, &id, &id_len,
2214                                                  &name, &description, &def,
2215                                                  &min, &max, &soft_min, &soft_max,
2216                                                  &step, &PySet_Type, &pyopts, &pysubtype,
2217                                                  &update_cb, &get_cb, &set_cb))
2218                 {
2219                         return NULL;
2220                 }
2221
2222                 BPY_PROPDEF_SUBTYPE_CHECK(IntProperty, property_flag_items, property_subtype_number_items);
2223
2224                 if (bpy_prop_callback_check(update_cb, "update", 2) == -1) {
2225                         return NULL;
2226                 }
2227                 if (bpy_prop_callback_check(get_cb, "get", 1) == -1) {
2228                         return NULL;
2229                 }
2230                 if (bpy_prop_callback_check(set_cb, "set", 2) == -1) {
2231                         return NULL;
2232                 }
2233
2234                 prop = RNA_def_property(srna, id, PROP_INT, subtype);
2235                 RNA_def_property_int_default(prop, def);
2236                 RNA_def_property_ui_text(prop, name ? name : id, description);
2237                 RNA_def_property_range(prop, min, max);
2238                 RNA_def_property_ui_range(prop, MAX2(soft_min, min), MIN2(soft_max, max), step, 3);
2239
2240                 if (pyopts) {
2241                         bpy_prop_assign_flag(prop, opts);
2242                 }
2243                 bpy_prop_callback_assign_update(prop, update_cb);
2244                 bpy_prop_callback_assign_int(prop, get_cb, set_cb);
2245                 RNA_def_property_duplicate_pointers(srna, prop);
2246         }
2247         Py_RETURN_NONE;
2248 }
2249
2250 PyDoc_STRVAR(BPy_IntVectorProperty_doc,
2251 ".. function:: IntVectorProperty(name=\"\", "
2252                                 "description=\"\", "
2253                                 "default=(0, 0, 0), min=-2**31, max=2**31-1, "
2254                                 "soft_min=-2**31, "
2255                                 "soft_max=2**31-1, "
2256                                 "step=1, "
2257                                 "options={'ANIMATABLE'}, "
2258                                 "subtype='NONE', "
2259                                 "size=3, "
2260                                 "update=None, "
2261                                 "get=None, "
2262                                 "set=None)\n"
2263 "\n"
2264 "   Returns a new vector int property definition.\n"
2265 "\n"
2266 BPY_PROPDEF_NAME_DOC
2267 BPY_PROPDEF_DESC_DOC
2268 "   :arg default: sequence of ints the length of *size*.\n"
2269 "   :type default: sequence\n"
2270 BPY_PROPDEF_NUM_MIN_DOC
2271 "   :type min: int\n"
2272 BPY_PROPDEF_NUM_MAX_DOC
2273 "   :type max: int\n"
2274 BPY_PROPDEF_NUM_SOFTMIN_DOC
2275 "   :type soft_min: int\n"
2276 BPY_PROPDEF_NUM_SOFTMAX_DOC
2277 "   :type soft_max: int\n"
2278 BPY_PROPDEF_INT_STEP_DOC
2279 BPY_PROPDEF_OPTIONS_DOC
2280 BPY_PROPDEF_SUBTYPE_ARRAY_DOC
2281 BPY_PROPDEF_VECSIZE_DOC
2282 BPY_PROPDEF_UPDATE_DOC
2283 BPY_PROPDEF_GET_DOC
2284 BPY_PROPDEF_SET_DOC
2285 );
2286 static PyObject *BPy_IntVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
2287 {
2288         StructRNA *srna;
2289
2290         BPY_PROPDEF_HEAD(IntVectorProperty);
2291
2292         if (srna) {
2293                 static const char *kwlist[] = {"attr", "name", "description", "default",
2294                                                "min", "max", "soft_min", "soft_max",
2295                                                "step", "options", "subtype", "size", "update", "get", "set", NULL};
2296                 const char *id = NULL, *name = NULL, *description = "";
2297                 int id_len;
2298                 int min = INT_MIN, max = INT_MAX, soft_min = INT_MIN, soft_max = INT_MAX, step = 1;
2299                 int def[PYRNA_STACK_ARRAY] = {0};
2300                 int size = 3;
2301                 PropertyRNA *prop;
2302                 PyObject *pydef = NULL;
2303                 PyObject *pyopts = NULL;
2304                 int opts = 0;
2305                 const char *pysubtype = NULL;
2306                 int subtype = PROP_NONE;
2307                 PyObject *update_cb = NULL;
2308                 PyObject *get_cb = NULL;
2309                 PyObject *set_cb = NULL;
2310
2311                 if (!PyArg_ParseTupleAndKeywords(args, kw,
2312                                                  "s#|ssOiiiiiO!siOOO:IntVectorProperty",
2313                                                  (char **)kwlist, &id, &id_len,
2314                                                  &name, &description, &pydef,
2315                                                  &min, &max, &soft_min, &soft_max,
2316                                                  &step, &PySet_Type, &pyopts,
2317                                                  &pysubtype, &size,
2318                                                  &update_cb, &get_cb, &set_cb))
2319                 {
2320                         return NULL;
2321                 }
2322
2323                 BPY_PROPDEF_SUBTYPE_CHECK(IntVectorProperty, property_flag_items, property_subtype_array_items);
2324
2325                 if (size < 1 || size > PYRNA_STACK_ARRAY) {
2326                         PyErr_Format(PyExc_TypeError,
2327                                      "IntVectorProperty(size=%d): size must be between 0 and "
2328                                      STRINGIFY(PYRNA_STACK_ARRAY), size);
2329                         return NULL;
2330                 }
2331
2332                 if (pydef && PyC_AsArray(def, pydef, size, &PyLong_Type, false, "IntVectorProperty(default=sequence)") == -1)
2333                         return NULL;
2334
2335                 if (bpy_prop_callback_check(update_cb, "update", 2) == -1) {
2336                         return NULL;
2337                 }
2338                 if (bpy_prop_callback_check(get_cb, "get", 1) == -1) {
2339                         return NULL;
2340                 }
2341                 if (bpy_prop_callback_check(set_cb, "set", 2) == -1) {
2342                         return NULL;
2343                 }
2344
2345                 prop = RNA_def_property(srna, id, PROP_INT, subtype);
2346                 RNA_def_property_array(prop, size);
2347                 if (pydef) RNA_def_property_int_array_default(prop, def);
2348                 RNA_def_property_range(prop, min, max);
2349                 RNA_def_property_ui_text(prop, name ? name : id, description);
2350                 RNA_def_property_ui_range(prop, MAX2(soft_min, min), MIN2(soft_max, max), step, 3);
2351
2352                 if (pyopts) {
2353                         bpy_prop_assign_flag(prop, opts);
2354                 }
2355                 bpy_prop_callback_assign_update(prop, update_cb);
2356                 bpy_prop_callback_assign_int_array(prop, get_cb, set_cb);
2357                 RNA_def_property_duplicate_pointers(srna, prop);
2358         }
2359         Py_RETURN_NONE;
2360 }
2361
2362
2363 PyDoc_STRVAR(BPy_FloatProperty_doc,
2364 ".. function:: FloatProperty(name=\"\", "
2365                             "description=\"\", "
2366                             "default=0.0, "
2367                             "min=sys.float_info.min, max=sys.float_info.max, "
2368                             "soft_min=sys.float_info.min, soft_max=sys.float_info.max, "
2369                             "step=3, "
2370                             "precision=2, "
2371                             "options={'ANIMATABLE'}, "
2372                             "subtype='NONE', "
2373                             "unit='NONE', "
2374                             "update=None, "
2375                             "get=None, "
2376                             "set=None)\n"
2377 "\n"
2378 "   Returns a new float property definition.\n"
2379 "\n"
2380 BPY_PROPDEF_NAME_DOC
2381 BPY_PROPDEF_DESC_DOC
2382 BPY_PROPDEF_NUM_MIN_DOC
2383 "   :type min: float\n"
2384 BPY_PROPDEF_NUM_MAX_DOC
2385 "   :type max: float\n"
2386 BPY_PROPDEF_NUM_SOFTMIN_DOC
2387 "   :type soft_min: float\n"
2388 BPY_PROPDEF_NUM_SOFTMAX_DOC
2389 "   :type soft_max: float\n"
2390 BPY_PROPDEF_FLOAT_STEP_DOC
2391 BPY_PROPDEF_FLOAT_PREC_DOC
2392 BPY_PROPDEF_OPTIONS_DOC
2393 BPY_PROPDEF_SUBTYPE_NUMBER_DOC
2394 BPY_PROPDEF_UNIT_DOC
2395 BPY_PROPDEF_UPDATE_DOC
2396 BPY_PROPDEF_GET_DOC
2397 BPY_PROPDEF_SET_DOC
2398 );
2399 static PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw)
2400 {
2401         StructRNA *srna;
2402
2403         BPY_PROPDEF_HEAD(FloatProperty);
2404
2405         if (srna) {
2406                 static const char *kwlist[] = {"attr", "name", "description", "default",
2407                                                "min", "max", "soft_min", "soft_max",
2408                                                "step", "precision", "options", "subtype",
2409                                                "unit", "update", "get", "set", NULL};
2410                 const char *id = NULL, *name = NULL, *description = "";
2411                 int id_len;
2412                 float min = -FLT_MAX, max = FLT_MAX, soft_min = -FLT_MAX, soft_max = FLT_MAX, step = 3, def = 0.0f;
2413                 int precision = 2;
2414                 PropertyRNA *prop;
2415                 PyObject *pyopts = NULL;
2416                 int opts = 0;
2417                 const char *pysubtype = NULL;
2418                 int subtype = PROP_NONE;
2419                 const char *pyunit = NULL;
2420                 int unit = PROP_UNIT_NONE;
2421                 PyObject *update_cb = NULL;
2422                 PyObject *get_cb = NULL;
2423                 PyObject *set_cb = NULL;
2424
2425                 if (!PyArg_ParseTupleAndKeywords(args, kw,
2426                                                  "s#|ssffffffiO!ssOOO:FloatProperty",
2427                                                  (char **)kwlist, &id, &id_len,
2428                                                  &name, &description, &def,
2429                                                  &min, &max, &soft_min, &soft_max,
2430                                                  &step, &precision, &PySet_Type,
2431                                                  &pyopts, &pysubtype, &pyunit,
2432                                                  &update_cb, &get_cb, &set_cb))
2433                 {
2434                         return NULL;
2435                 }
2436
2437                 BPY_PROPDEF_SUBTYPE_CHECK(FloatProperty, property_flag_items, property_subtype_number_items);
2438
2439                 if (pyunit && RNA_enum_value_from_id(rna_enum_property_unit_items, pyunit, &unit) == 0) {
2440                         PyErr_Format(PyExc_TypeError, "FloatProperty(unit='%s'): invalid unit", pyunit);
2441                         return NULL;
2442                 }
2443
2444                 if (bpy_prop_callback_check(update_cb, "update", 2) == -1) {
2445                         return NULL;
2446                 }
2447                 if (bpy_prop_callback_check(get_cb, "get", 1) == -1) {
2448                         return NULL;
2449                 }
2450                 if (bpy_prop_callback_check(set_cb, "set", 2) == -1) {
2451                         return NULL;
2452                 }
2453
2454                 prop = RNA_def_property(srna, id, PROP_FLOAT, subtype | unit);
2455                 RNA_def_property_float_default(prop, def);
2456                 RNA_def_property_range(prop, min, max);
2457                 RNA_def_property_ui_text(prop, name ? name : id, description);
2458                 RNA_def_property_ui_range(prop, MAX2(soft_min, min), MIN2(soft_max, max), step, precision);
2459
2460                 if (pyopts) {
2461                         bpy_prop_assign_flag(prop, opts);
2462                 }
2463                 bpy_prop_callback_assign_update(prop, update_cb);
2464                 bpy_prop_callback_assign_float(prop, get_cb, set_cb);
2465                 RNA_def_property_duplicate_pointers(srna, prop);
2466         }
2467         Py_RETURN_NONE;
2468 }
2469
2470 PyDoc_STRVAR(BPy_FloatVectorProperty_doc,
2471 ".. function:: FloatVectorProperty(name=\"\", "
2472                                   "description=\"\", "
2473                                   "default=(0.0, 0.0, 0.0), "
2474                                   "min=sys.float_info.min, max=sys.float_info.max, "
2475                                   "soft_min=sys.float_info.min, soft_max=sys.float_info.max, "
2476                                   "step=3, "
2477                                   "precision=2, "
2478                                   "options={'ANIMATABLE'}, "
2479                                   "subtype='NONE', "
2480                                   "unit='NONE', "
2481                                   "size=3, "
2482                                   "update=None, "
2483                                   "get=None, "
2484                                   "set=None)\n"
2485 "\n"
2486 "   Returns a new vector float property definition.\n"
2487 "\n"
2488 BPY_PROPDEF_NAME_DOC
2489 BPY_PROPDEF_DESC_DOC
2490 "   :arg default: sequence of floats the length of *size*.\n"
2491 "   :type default: sequence\n"
2492 BPY_PROPDEF_NUM_MIN_DOC
2493 "   :type min: float\n"
2494 BPY_PROPDEF_NUM_MAX_DOC
2495 "   :type max: float\n"
2496 BPY_PROPDEF_NUM_SOFTMIN_DOC
2497 "   :type soft_min: float\n"
2498 BPY_PROPDEF_NUM_SOFTMAX_DOC
2499 "   :type soft_max: float\n"
2500 BPY_PROPDEF_OPTIONS_DOC
2501 BPY_PROPDEF_FLOAT_STEP_DOC
2502 BPY_PROPDEF_FLOAT_PREC_DOC
2503 BPY_PROPDEF_SUBTYPE_ARRAY_DOC
2504 BPY_PROPDEF_UNIT_DOC
2505 BPY_PROPDEF_VECSIZE_DOC
2506 BPY_PROPDEF_UPDATE_DOC
2507 BPY_PROPDEF_GET_DOC
2508 BPY_PROPDEF_SET_DOC
2509 );
2510 static PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
2511 {
2512         StructRNA *srna;
2513
2514         BPY_PROPDEF_HEAD(FloatVectorProperty);
2515
2516         if (srna) {
2517                 static const char *kwlist[] = {"attr", "name", "description", "default",
2518                                                "min", "max", "soft_min", "soft_max",
2519                                                "step", "precision", "options", "subtype",
2520                                                "unit", "size", "update", "get", "set", NULL};
2521                 const char *id = NULL, *name = NULL, *description = "";
2522                 int id_len;
2523                 float min = -FLT_MAX, max = FLT_MAX, soft_min = -FLT_MAX, soft_max = FLT_MAX, step = 3;
2524                 float def[PYRNA_STACK_ARRAY] = {0.0f};
2525                 int precision = 2, size = 3;
2526                 PropertyRNA *prop;
2527                 PyObject *pydef = NULL;
2528                 PyObject *pyopts = NULL;
2529                 int opts = 0;
2530                 const char *pysubtype = NULL;
2531                 int subtype = PROP_NONE;
2532                 const char *pyunit = NULL;
2533                 int unit = PROP_UNIT_NONE;
2534                 PyObject *update_cb = NULL;
2535                 PyObject *get_cb = NULL;
2536                 PyObject *set_cb = NULL;
2537
2538                 if (!PyArg_ParseTupleAndKeywords(args, kw,
2539                                                  "s#|ssOfffffiO!ssiOOO:FloatVectorProperty",
2540                                                  (char **)kwlist, &id, &id_len,
2541                                                  &name, &description, &pydef,
2542                                                  &min, &max, &soft_min, &soft_max,
2543                                                  &step, &precision, &PySet_Type,
2544                                                  &pyopts, &pysubtype, &pyunit, &size,
2545                                                  &update_cb, &get_cb, &set_cb))
2546                 {
2547                         return NULL;
2548                 }
2549
2550                 BPY_PROPDEF_SUBTYPE_CHECK(FloatVectorProperty, property_flag_items, property_subtype_array_items);
2551
2552                 if (pyunit && RNA_enum_value_from_id(rna_enum_property_unit_items, pyunit, &unit) == 0) {
2553                         PyErr_Format(PyExc_TypeError, "FloatVectorProperty(unit='%s'): invalid unit", pyunit);
2554                         return NULL;
2555                 }
2556
2557                 if (size < 1 || size > PYRNA_STACK_ARRAY) {
2558                         PyErr_Format(PyExc_TypeError,
2559                                      "FloatVectorProperty(size=%d): size must be between 0 and "
2560                                      STRINGIFY(PYRNA_STACK_ARRAY), size);
2561                         return NULL;
2562                 }
2563
2564                 if (pydef && PyC_AsArray(def, pydef, size, &PyFloat_Type, false, "FloatVectorProperty(default=sequence)") == -1)
2565                         return NULL;
2566
2567                 if (bpy_prop_callback_check(update_cb, "update", 2) == -1) {
2568                         return NULL;
2569                 }
2570                 if (bpy_prop_callback_check(get_cb, "get", 1) == -1) {
2571                         return NULL;
2572                 }
2573                 if (bpy_prop_callback_check(set_cb, "set", 2) == -1) {
2574                         return NULL;
2575                 }
2576
2577                 prop = RNA_def_property(srna, id, PROP_FLOAT, subtype | unit);
2578                 RNA_def_property_array(prop, size);
2579                 if (pydef) RNA_def_property_float_array_default(prop, def);
2580                 RNA_def_property_range(prop, min, max);
2581                 RNA_def_property_ui_text(prop, name ? name : id, description);
2582                 RNA_def_property_ui_range(prop, MAX2(soft_min, min), MIN2(soft_max, max), step, precision);
2583
2584                 if (pyopts) {
2585                         bpy_prop_assign_flag(prop, opts);
2586                 }
2587                 bpy_prop_callback_assign_update(prop, update_cb);
2588                 bpy_prop_callback_assign_float_array(prop, get_cb, set_cb);
2589                 RNA_def_property_duplicate_pointers(srna, prop);
2590         }
2591         Py_RETURN_NONE;
2592 }
2593
2594 PyDoc_STRVAR(BPy_StringProperty_doc,
2595 ".. function:: StringProperty(name=\"\", "
2596                              "description=\"\", "
2597                              "default=\"\", "
2598                              "maxlen=0, "
2599                              "options={'ANIMATABLE'}, "
2600                              "subtype='NONE', "
2601                              "update=None, "
2602                              "get=None, "
2603                              "set=None)\n"
2604 "\n"
2605 "   Returns a new string property definition.\n"
2606 "\n"
2607 BPY_PROPDEF_NAME_DOC
2608 BPY_PROPDEF_DESC_DOC
2609 "   :arg default: initializer string.\n"
2610 "   :type default: string\n"
2611 "   :arg maxlen: maximum length of the string.\n"
2612 "   :type maxlen: int\n"
2613 BPY_PROPDEF_OPTIONS_DOC
2614 BPY_PROPDEF_SUBTYPE_STRING_DOC
2615 BPY_PROPDEF_UPDATE_DOC
2616 BPY_PROPDEF_GET_DOC
2617 BPY_PROPDEF_SET_DOC
2618 );
2619 static PyObject *BPy_StringProperty(PyObject *self, PyObject *args, PyObject *kw)
2620 {
2621         StructRNA *srna;
2622
2623         BPY_PROPDEF_HEAD(StringProperty);
2624
2625         if (srna) {
2626                 static const char *kwlist[] = {"attr", "name", "description", "default",
2627                                                "maxlen", "options", "subtype", "update", "get", "set", NULL};
2628                 const char *id = NULL, *name = NULL, *description = "", *def = "";
2629                 int id_len;
2630                 int maxlen = 0;
2631                 PropertyRNA *prop;
2632                 PyObject *pyopts = NULL;
2633                 int opts = 0;
2634                 const char *pysubtype = NULL;
2635                 int subtype = PROP_NONE;
2636                 PyObject *update_cb = NULL;
2637                 PyObject *get_cb = NULL;
2638                 PyObject *set_cb = NULL;
2639
2640                 if (!PyArg_ParseTupleAndKeywords(args, kw,
2641                                                  "s#|sssiO!sOOO:StringProperty",
2642                                                  (char **)kwlist, &id, &id_len,
2643                                                  &name, &description, &def,
2644                                                  &maxlen, &PySet_Type, &pyopts, &pysubtype,
2645                                                  &update_cb, &get_cb, &set_cb))
2646                 {
2647                         return NULL;
2648                 }
2649
2650                 BPY_PROPDEF_SUBTYPE_CHECK(StringProperty, property_flag_items, property_subtype_string_items);
2651
2652                 if (bpy_prop_callback_check(update_cb, "update", 2) == -1) {
2653                         return NULL;
2654                 }
2655                 if (bpy_prop_callback_check(get_cb, "get", 1) == -1) {
2656                         return NULL;
2657                 }
2658                 if (bpy_prop_callback_check(set_cb, "set", 2) == -1) {
2659                         return NULL;
2660                 }
2661
2662                 prop = RNA_def_property(srna, id, PROP_STRING, subtype);
2663                 if (maxlen != 0) RNA_def_property_string_maxlength(prop, maxlen + 1);  /* +1 since it includes null terminator */
2664                 if (def && def[0]) RNA_def_property_string_default(prop, def);
2665                 RNA_def_property_ui_text(prop, name ? name : id, description);
2666
2667                 if (pyopts) {
2668                         bpy_prop_assign_flag(prop, opts);
2669                 }
2670                 bpy_prop_callback_assign_update(prop, update_cb);
2671                 bpy_prop_callback_assign_string(prop, get_cb, set_cb);
2672                 RNA_def_property_duplicate_pointers(srna, prop);
2673         }
2674         Py_RETURN_NONE;
2675 }
2676
2677 PyDoc_STRVAR(BPy_EnumProperty_doc,
2678 ".. function:: EnumProperty(items, "
2679                            "name=\"\", "
2680                            "description=\"\", "
2681                            "default=None, "
2682                            "options={'ANIMATABLE'}, "
2683                            "update=None, "
2684                            "get=None, "
2685                            "set=None)\n"
2686 "\n"
2687 "   Returns a new enumerator property definition.\n"
2688 "\n"
2689 "   :arg items: sequence of enum items formatted:\n"
2690 "      ``[(identifier, name, description, icon, number), ...]``.\n"
2691 "\n"
2692 "      The first three elements of the tuples are mandatory.\n"
2693 "\n"
2694 "      :identifier: The identifier is used for Python access.\n"
2695 "      :name: Name for the interace.\n"
2696 "      :description: Used for documentation and tooltips.\n"
2697 "      :icon: An icon string identifier or integer icon value\n"
2698 "         (e.g. returned by :class:`bpy.types.UILayout.icon`)\n"
2699 "      :number: Unique value used as the identifier for this item (stored in file data).\n"
2700 "         Use when the identifier may need to change.\n"
2701 "\n"
2702 "      When an item only contains 4 items they define ``(identifier, name, description, number)``.\n"
2703 "\n"
2704 "      For dynamic values a callback can be passed which returns a list in\n"
2705 "      the same format as the static list.\n"
2706 "      This function must take 2 arguments ``(self, context)``, **context may be None**.\n"
2707 "\n"
2708 "      .. warning::\n"
2709 "\n"
2710 "         There is a known bug with using a callback,\n"
2711 "         Python must keep a reference to the strings returned or Blender will misbehave\n"
2712 "         or even crash."
2713 "\n"
2714 "   :type items: sequence of string tuples or a function\n"
2715 BPY_PROPDEF_NAME_DOC
2716 BPY_PROPDEF_DESC_DOC
2717 "   :arg default: The default value for this enum, a string from the identifiers used in *items*.\n"
2718 "      If the *ENUM_FLAG* option is used this must be a set of such string identifiers instead.\n"
2719 "      WARNING: It shall not be specified (or specified to its default *None* value) for dynamic enums\n"
2720 "      (i.e. if a callback function is given as *items* parameter).\n"
2721 "   :type default: string or set\n"
2722 BPY_PROPDEF_OPTIONS_ENUM_DOC
2723 BPY_PROPDEF_UPDATE_DOC
2724 BPY_PROPDEF_GET_DOC
2725 BPY_PROPDEF_SET_DOC
2726 );
2727 static PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw)
2728 {
2729         StructRNA *srna;
2730
2731         BPY_PROPDEF_HEAD(EnumProperty);
2732         
2733         if (srna) {
2734                 static const char *kwlist[] = {"attr", "items", "name", "description", "default",
2735                                                "options", "update", "get", "set", NULL};
2736                 const char *id = NULL, *name = NULL, *description = "";
2737                 PyObject *def = NULL;
2738                 int id_len;
2739                 int defvalue = 0;
2740                 PyObject *items, *items_fast;
2741                 EnumPropertyItem *eitems;
2742                 PropertyRNA *prop;
2743                 PyObject *pyopts = NULL;
2744                 int opts = 0;
2745                 bool is_itemf = false;
2746                 PyObject *update_cb = NULL;
2747                 PyObject *get_cb = NULL;
2748                 PyObject *set_cb = NULL;
2749
2750                 if (!PyArg_ParseTupleAndKeywords(args, kw,
2751                                                  "s#O|ssOO!OOO:EnumProperty",
2752                                                  (char **)kwlist, &id, &id_len,
2753                                                  &items, &name, &description,
2754                                                  &def, &PySet_Type, &pyopts,
2755                                                  &update_cb, &get_cb, &set_cb))
2756                 {
2757                         return NULL;
2758                 }
2759
2760                 BPY_PROPDEF_CHECK(EnumProperty, property_flag_enum_items);
2761
2762                 if (bpy_prop_callback_check(update_cb, "update", 2) == -1) {
2763                         return NULL;
2764                 }
2765                 if (bpy_prop_callback_check(get_cb, "get", 1) == -1) {
2766                         return NULL;
2767                 }
2768                 if (bpy_prop_callback_check(set_cb, "set", 2) == -1) {
2769                         return NULL;
2770                 }
2771
2772                 if (def == Py_None) {
2773                         /* This allows to get same behavior when explicitly passing None as default value,
2774                          * and not defining a default value at all! */
2775                         def = NULL;
2776                 }
2777
2778                 /* items can be a list or a callable */
2779                 if (PyFunction_Check(items)) { /* don't use PyCallable_Check because we need the function code for errors */
2780                         PyCodeObject *f_code = (PyCodeObject *)PyFunction_GET_CODE(items);
2781                         if (f_code->co_argcount != 2) {
2782                                 PyErr_Format(PyExc_ValueError,
2783                                              "EnumProperty(...): expected 'items' function to take 2 arguments, not %d",
2784                                              f_code->co_argcount);
2785                                 return NULL;
2786                         }
2787
2788                         if (def) {
2789                                 /* note, using type error here is odd but python does this for invalid arguments */
2790                                 PyErr_SetString(PyExc_TypeError,
2791                                                 "EnumProperty(...): 'default' can't be set when 'items' is a function");
2792                                 return NULL;
2793                         }
2794
2795                         is_itemf = true;
2796                         eitems = DummyRNA_NULL_items;
2797                 }
2798                 else {
2799                         if (!(items_fast = PySequence_Fast(items, "EnumProperty(...): "
2800                                                            "expected a sequence of tuples for the enum items or a function")))
2801                         {
2802                                 return NULL;
2803                         }
2804
2805                         eitems = enum_items_from_py(items_fast, def, &defvalue,
2806                                                     (opts & PROP_ENUM_FLAG) != 0);
2807
2808                         if (!eitems) {
2809                                 Py_DECREF(items_fast);
2810                                 return NULL;
2811                         }
2812                 }
2813
2814                 if (opts & PROP_ENUM_FLAG)  prop = RNA_def_enum_flag(srna, id, eitems, defvalue, name ? name : id, description);
2815                 else                        prop = RNA_def_enum(srna, id, eitems, defvalue, name ? name : id, description);
2816
2817                 if (pyopts) {
2818                         bpy_prop_assign_flag(prop, opts);
2819                 }
2820                 bpy_prop_callback_assign_update(prop, update_cb);
2821                 bpy_prop_callback_assign_enum(prop, get_cb, set_cb, (is_itemf ? items : NULL));
2822                 RNA_def_property_duplicate_pointers(srna, prop);
2823
2824                 if (is_itemf == false) {
2825                         /* note: this must be postponed until after #RNA_def_property_duplicate_pointers
2826                          * otherwise if this is a generator it may free the strings before we copy them */
2827                         Py_DECREF(items_fast);
2828
2829                         MEM_freeN(eitems);
2830                 }
2831         }
2832         Py_RETURN_NONE;
2833 }
2834
2835 StructRNA *pointer_type_from_py(PyObject *value, const char *error_prefix)
2836 {
2837         StructRNA *srna;
2838
2839         srna = srna_from_self(value, "");
2840         if (!srna) {
2841                 if (PyErr_Occurred()) {
2842                         PyObject *msg = PyC_ExceptionBuffer();
2843                         const char *msg_char = _PyUnicode_AsString(msg);
2844                         PyErr_Format(PyExc_TypeError,
2845                                      "%.200s expected an RNA type, failed with: %s",
2846                                      error_prefix, msg_char);
2847                         Py_DECREF(msg);
2848                 }
2849                 else {
2850                         PyErr_Format(PyExc_TypeError,
2851                                      "%.200s expected an RNA type, failed with type '%s'",
2852                                      error_prefix, Py_TYPE(value)->tp_name);
2853                 }
2854                 return NULL;
2855         }
2856
2857         return srna;
2858 }
2859
2860 PyDoc_STRVAR(BPy_PointerProperty_doc,
2861 ".. function:: PointerProperty(type=None, "
2862                               "name=\"\", "
2863                               "description=\"\", "
2864                               "options={'ANIMATABLE'}, "
2865                               "poll=None, "
2866                               "update=None)\n"
2867 "\n"
2868 "   Returns a new pointer property definition.\n"
2869 "\n"
2870 BPY_PROPDEF_TYPE_DOC
2871 BPY_PROPDEF_NAME_DOC
2872 BPY_PROPDEF_DESC_DOC
2873 BPY_PROPDEF_OPTIONS_DOC
2874 BPY_PROPDEF_UPDATE_DOC
2875 );
2876 PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *kw)
2877 {
2878         StructRNA *srna;
2879
2880         BPY_PROPDEF_HEAD(PointerProperty);
2881
2882         if (srna) {
2883                 static const char *kwlist[] = {"attr", "type", "name", "description", "options", "poll", "update", NULL};
2884                 const char *id = NULL, *name = NULL, *description = "";
2885                 int id_len;
2886                 PropertyRNA *prop;
2887                 StructRNA *ptype;
2888                 PyObject *type = Py_None;
2889                 PyObject *pyopts = NULL;
2890                 int opts = 0;
2891                 PyObject *update_cb = NULL, *poll_cb = NULL;
2892
2893                 if (!PyArg_ParseTupleAndKeywords(args, kw,
2894                                                  "s#O|ssO!OOO:PointerProperty",
2895                                                  (char **)kwlist, &id, &id_len,
2896                                                  &type, &name, &description,
2897                                                  &PySet_Type, &pyopts,
2898                                                  &poll_cb, &update_cb))
2899                 {
2900                         return NULL;
2901                 }
2902
2903                 BPY_PROPDEF_CHECK(PointerProperty, property_flag_items);
2904
2905                 ptype = pointer_type_from_py(type, "PointerProperty(...)");
2906                 if (!ptype)
2907                         return NULL;
2908                 if (!RNA_struct_is_a(ptype, &RNA_PropertyGroup) && !RNA_struct_is_ID(ptype)) {
2909                         PyErr_Format(PyExc_TypeError,
2910                                      "PointerProperty(...) expected an RNA type derived from %.200s or %.200s",
2911                                      RNA_struct_ui_name(&RNA_ID), RNA_struct_ui_name(&RNA_PropertyGroup));
2912                         return NULL;
2913                 }
2914                 if (bpy_prop_callback_check(update_cb, "update", 2) == -1) {
2915                         return NULL;
2916                 }
2917                 if (bpy_prop_callback_check(poll_cb, "poll", 2) == -1) {
2918                         return NULL;
2919                 }
2920                 prop = RNA_def_pointer_runtime(srna, id, ptype, name ? name : id, description);
2921                 if (pyopts) {
2922                         bpy_prop_assign_flag(prop, opts);
2923                 }
2924
2925                 if (RNA_struct_idprops_contains_datablock(ptype)) {
2926                         if (RNA_struct_is_a(srna, &RNA_PropertyGroup)) {
2927                                 RNA_def_struct_flag(srna, STRUCT_CONTAINS_DATABLOCK_IDPROPERTIES);
2928                         }
2929                 }
2930                 bpy_prop_callback_assign_update(prop, update_cb);
2931                 bpy_prop_callback_assign_pointer(prop, poll_cb);
2932                 RNA_def_property_duplicate_pointers(srna, prop);
2933         }
2934         Py_RETURN_NONE;
2935 }
2936
2937 PyDoc_STRVAR(BPy_CollectionProperty_doc,
2938 ".. function:: CollectionProperty(type=None, "
2939                                  "name=\"\", "
2940                                  "description=\"\", "
2941                                  "options={'ANIMATABLE'})\n"
2942 "\n"
2943 "   Returns a new collection property definition.\n"
2944 "\n"
2945 BPY_PROPDEF_TYPE_DOC
2946 BPY_PROPDEF_NAME_DOC
2947 BPY_PROPDEF_DESC_DOC
2948 BPY_PROPDEF_OPTIONS_DOC
2949 );
2950 PyObject *BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject *kw)
2951 {
2952         StructRNA *srna;
2953
2954         BPY_PROPDEF_HEAD(CollectionProperty);
2955
2956         if (srna) {
2957                 static const char *kwlist[] = {"attr", "type", "name", "description", "options", NULL};
2958                 const char *id = NULL, *name = NULL, *description = "";
2959                 int id_len;
2960                 PropertyRNA *prop;
2961                 StructRNA *ptype;
2962                 PyObject *type = Py_None;
2963                 PyObject *pyopts = NULL;
2964                 int opts = 0;
2965
2966                 if (!PyArg_ParseTupleAndKeywords(args, kw,
2967                                                  "s#O|ssO!:CollectionProperty",
2968                                                  (char **)kwlist, &id, &id_len,
2969                                                  &type, &name, &description,
2970                                                  &PySet_Type, &pyopts))
2971                 {
2972                         return NULL;
2973                 }
2974
2975                 BPY_PROPDEF_CHECK(CollectionProperty, property_flag_items);
2976
2977                 ptype = pointer_type_from_py(type, "CollectionProperty(...):");
2978                 if (!ptype)
2979                         return NULL;
2980
2981                 if (!RNA_struct_is_a(ptype, &RNA_PropertyGroup)) {
2982                         PyErr_Format(PyExc_TypeError,
2983                                 "CollectionProperty(...) expected an RNA type derived from %.200s",
2984                                 RNA_struct_ui_name(&RNA_ID), RNA_struct_ui_name(&RNA_PropertyGroup));
2985                         return NULL;
2986                 }
2987
2988                 prop = RNA_def_collection_runtime(srna, id, ptype, name ? name : id, description);
2989                 if (pyopts) {
2990                         bpy_prop_assign_flag(prop, opts);
2991                 }
2992
2993                 if (RNA_struct_idprops_contains_datablock(ptype)) {
2994                         if (RNA_struct_is_a(srna, &RNA_PropertyGroup)) {
2995                                 RNA_def_struct_flag(srna, STRUCT_CONTAINS_DATABLOCK_IDPROPERTIES);
2996                         }
2997                 }
2998                 RNA_def_property_duplicate_pointers(srna, prop);
2999         }
3000         Py_RETURN_NONE;
3001 }
3002
3003 PyDoc_STRVAR(BPy_RemoveProperty_doc,
3004 ".. function:: RemoveProperty(cls, attr)\n"
3005 "\n"
3006 "   Removes a dynamically defined property.\n"
3007 "\n"
3008 "   :arg cls: The class containing the property (must be a positional argument).\n"
3009 "   :type cls: type\n"
3010 "   :arg attr: Property name (must be passed as a keyword).\n"
3011 "   :type attr: string\n"
3012 "\n"
3013 ".. note:: Typically this function doesn't need to be accessed directly.\n"
3014 "   Instead use ``del cls.attr``\n"
3015 );
3016 static PyObject *BPy_RemoveProperty(PyObject *self, PyObject *args, PyObject *kw)
3017 {
3018         StructRNA *srna;
3019
3020         if (PyTuple_GET_SIZE(args) == 1) {
3021                 PyObject *ret;
3022                 self = PyTuple_GET_ITEM(args, 0);
3023                 args = PyTuple_New(0);
3024                 ret = BPy_RemoveProperty(self, args, kw);
3025                 Py_DECREF(args);
3026                 return ret;
3027         }
3028         else if (PyTuple_GET_SIZE(args) > 1) {
3029                 PyErr_SetString(PyExc_ValueError, "expected one positional arg, one keyword arg");
3030                 return NULL;
3031         }
3032
3033         srna = srna_from_self(self, "RemoveProperty(...):");
3034         if (srna == NULL && PyErr_Occurred()) {
3035                 return NULL; /* self's type was compatible but error getting the srna */
3036         }
3037         else if (srna == NULL) {
3038                 PyErr_SetString(PyExc_TypeError, "RemoveProperty(): struct rna not available for this type");
3039                 return NULL;
3040         }
3041         else {
3042                 static const char *kwlist[] = {"attr", NULL};
3043                 
3044                 const char *id = NULL;
3045
3046                 if (!PyArg_ParseTupleAndKeywords(args, kw,
3047                                                  "s:RemoveProperty",
3048                                                  (char **)kwlist, &id))
3049                 {
3050                         return NULL;
3051                 }
3052
3053                 if (RNA_def_property_free_identifier(srna, id) != 1) {
3054                         PyErr_Format(PyExc_TypeError, "RemoveProperty(): '%s' not a defined dynamic property", id);
3055                         return NULL;
3056                 }
3057         }
3058         Py_RETURN_NONE;
3059 }
3060
3061 static struct PyMethodDef props_methods[] = {
3062         {"BoolProperty", (PyCFunction)BPy_BoolProperty, METH_VARARGS | METH_KEYWORDS, BPy_BoolProperty_doc},
3063         {"BoolVectorProperty", (PyCFunction)BPy_BoolVectorProperty, METH_VARARGS | METH_KEYWORDS, BPy_BoolVectorProperty_doc},
3064         {"IntProperty", (PyCFunction)BPy_IntProperty, METH_VARARGS | METH_KEYWORDS, BPy_IntProperty_doc},
3065         {"IntVectorProperty", (PyCFunction)BPy_IntVectorProperty, METH_VARARGS | METH_KEYWORDS, BPy_IntVectorProperty_doc},
3066         {"FloatProperty", (PyCFunction)BPy_FloatProperty, METH_VARARGS | METH_KEYWORDS, BPy_FloatProperty_doc},
3067         {"FloatVectorProperty", (PyCFunction)BPy_FloatVectorProperty, METH_VARARGS | METH_KEYWORDS, BPy_FloatVectorProperty_doc},
3068         {"StringProperty", (PyCFunction)BPy_StringProperty, METH_VARARGS | METH_KEYWORDS, BPy_StringProperty_doc},
3069         {"EnumProperty", (PyCFunction)BPy_EnumProperty, METH_VARARGS | METH_KEYWORDS, BPy_EnumProperty_doc},
3070         {"PointerProperty", (PyCFunction)BPy_PointerProperty, METH_VARARGS | METH_KEYWORDS, BPy_PointerProperty_doc},
3071         {"CollectionProperty", (PyCFunction)BPy_CollectionProperty, METH_VARARGS | METH_KEYWORDS, BPy_CollectionProperty_doc},
3072
3073         {"RemoveProperty", (PyCFunction)BPy_RemoveProperty, METH_VARARGS | METH_KEYWORDS, BPy_RemoveProperty_doc},
3074         {NULL, NULL, 0, NULL}
3075 };
3076
3077 static struct PyModuleDef props_module = {
3078         PyModuleDef_HEAD_INIT,
3079         "bpy.props",
3080         "This module defines properties to extend Blender's internal data. The result of these functions"
3081         " is used to assign properties to classes registered with Blender and can't be used directly.\n"
3082         "\n"
3083         ".. note:: All parameters to these functions must be passed as keywords.\n",
3084         -1, /* multiple "initialization" just copies the module dict. */
3085         props_methods,
3086         NULL, NULL, NULL, NULL
3087 };
3088
3089 PyObject *BPY_rna_props(void)
3090 {
3091         PyObject *submodule;
3092         PyObject *submodule_dict;
3093         
3094         submodule = PyModule_Create(&props_module);
3095         PyDict_SetItemString(PyImport_GetModuleDict(), props_module.m_name, submodule);
3096
3097         /* INCREF since its its assumed that all these functions return the
3098          * module with a new ref like PyDict_New, since they are passed to
3099          * PyModule_AddObject which steals a ref */
3100         Py_INCREF(submodule);
3101         
3102         /* api needs the PyObjects internally */
3103         submodule_dict = PyModule_GetDict(submodule);
3104
3105 #define ASSIGN_STATIC(_name) pymeth_##_name = PyDict_GetItemString(submodule_dict, #_name)
3106
3107         ASSIGN_STATIC(BoolProperty);
3108         ASSIGN_STATIC(BoolVectorProperty);
3109         ASSIGN_STATIC(IntProperty);
3110         ASSIGN_STATIC(IntVectorProperty);
3111         ASSIGN_STATIC(FloatProperty);
3112         ASSIGN_STATIC(FloatVectorProperty);
3113         ASSIGN_STATIC(StringProperty);
3114         ASSIGN_STATIC(EnumProperty);
3115         ASSIGN_STATIC(PointerProperty);
3116         ASSIGN_STATIC(CollectionProperty);
3117         ASSIGN_STATIC(RemoveProperty);
3118         
3119         return submodule;
3120 }