6ea52abc5f4f22296ebc6a0659c18c1207e24126
[blender-staging.git] / source / blender / python / intern / bpy_props.c
1 /*
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * Contributor(s): Campbell Barton
21  *
22  * ***** END GPL LICENSE BLOCK *****
23  */
24
25 /** \file blender/python/intern/bpy_props.c
26  *  \ingroup pythonintern
27  */
28
29
30 #include <Python.h>
31
32 #include "RNA_types.h"
33
34 #include "bpy_props.h"
35 #include "bpy_rna.h"
36 #include "bpy_util.h"
37
38 #include "BLI_utildefines.h"
39
40 #include "BKE_idprop.h"
41
42 #include "RNA_access.h"
43 #include "RNA_define.h" /* for defining our own rna */
44 #include "RNA_enum_types.h"
45
46 #include "MEM_guardedalloc.h"
47
48 #include "../generic/py_capi_utils.h"
49
50 static EnumPropertyItem property_flag_items[]= {
51         {PROP_HIDDEN, "HIDDEN", 0, "Hidden", ""},
52         {PROP_ANIMATABLE, "ANIMATABLE", 0, "Animateable", ""},
53         {0, NULL, 0, NULL, NULL}};
54
55 static EnumPropertyItem property_flag_enum_items[]= {
56         {PROP_HIDDEN, "HIDDEN", 0, "Hidden", ""},
57         {PROP_ANIMATABLE, "ANIMATABLE", 0, "Animateable", ""},
58         {PROP_ENUM_FLAG, "ENUM_FLAG", 0, "Enum Flag", ""},
59         {0, NULL, 0, NULL, NULL}};
60
61 /* subtypes */
62 static EnumPropertyItem property_subtype_string_items[]= {
63         {PROP_FILEPATH, "FILE_PATH", 0, "File Path", ""},
64         {PROP_DIRPATH, "DIR_PATH", 0, "Directory Path", ""},
65         {PROP_FILENAME, "FILENAME", 0, "Filename", ""},
66
67         {PROP_NONE, "NONE", 0, "None", ""},
68         {0, NULL, 0, NULL, NULL}};
69
70 static EnumPropertyItem property_subtype_number_items[]= {
71         {PROP_UNSIGNED, "UNSIGNED", 0, "Unsigned", ""},
72         {PROP_PERCENTAGE, "PERCENTAGE", 0, "Percentage", ""},
73         {PROP_FACTOR, "FACTOR", 0, "Factor", ""},
74         {PROP_ANGLE, "ANGLE", 0, "Angle", ""},
75         {PROP_TIME, "TIME", 0, "Time", ""},
76         {PROP_DISTANCE, "DISTANCE", 0, "Distance", ""},
77
78         {PROP_NONE, "NONE", 0, "None", ""},
79         {0, NULL, 0, NULL, NULL}};
80
81 static EnumPropertyItem property_subtype_array_items[]= {
82         {PROP_COLOR, "COLOR", 0, "Color", ""},
83         {PROP_TRANSLATION, "TRANSLATION", 0, "Translation", ""},
84         {PROP_DIRECTION, "DIRECTION", 0, "Direction", ""},
85         {PROP_VELOCITY, "VELOCITY", 0, "Velocity", ""},
86         {PROP_ACCELERATION, "ACCELERATION", 0, "Acceleration", ""},
87         {PROP_MATRIX, "MATRIX", 0, "Matrix", ""},
88         {PROP_EULER, "EULER", 0, "Euler", ""},
89         {PROP_QUATERNION, "QUATERNION", 0, "Quaternion", ""},
90         {PROP_AXISANGLE, "AXISANGLE", 0, "Axis Angle", ""},
91         {PROP_XYZ, "XYZ", 0, "XYZ", ""},
92         {PROP_COLOR_GAMMA, "COLOR_GAMMA", 0, "Color Gamma", ""},
93         {PROP_LAYER, "LAYER", 0, "Layer", ""},
94
95         {PROP_NONE, "NONE", 0, "None", ""},
96         {0, NULL, 0, NULL, NULL}};
97
98 /* PyObject's */
99 static PyObject *pymeth_BoolProperty= NULL;
100 static PyObject *pymeth_BoolVectorProperty= NULL;
101 static PyObject *pymeth_IntProperty= NULL;
102 static PyObject *pymeth_IntVectorProperty= NULL;
103 static PyObject *pymeth_FloatProperty= NULL;
104 static PyObject *pymeth_FloatVectorProperty= NULL;
105 static PyObject *pymeth_StringProperty= NULL;
106 static PyObject *pymeth_EnumProperty= NULL;
107 static PyObject *pymeth_PointerProperty= NULL;
108 static PyObject *pymeth_CollectionProperty= NULL;
109 static PyObject *pymeth_RemoveProperty= NULL;
110
111
112 /* operators and classes use this so it can store the args given but defer
113  * running it until the operator runs where these values are used to setup
114  * the default args for that operator instance */
115 static PyObject *bpy_prop_deferred_return(PyObject *func, PyObject *kw)
116 {
117         PyObject *ret= PyTuple_New(2);
118         PyTuple_SET_ITEM(ret, 0, func);
119         Py_INCREF(func);
120
121         if(kw==NULL)
122                 kw= PyDict_New();
123         else
124                 Py_INCREF(kw);
125
126         PyTuple_SET_ITEM(ret, 1, kw);
127
128         return ret;
129 }
130
131 /* this define runs at the start of each function and deals with 
132  * returning a deferred property (to be registered later) */
133 #define BPY_PROPDEF_HEAD(_func) \
134         if (PyTuple_GET_SIZE(args) == 1) { \
135                 PyObject *ret; \
136                 self= PyTuple_GET_ITEM(args, 0); \
137                 args= PyTuple_New(0); \
138                 ret= BPy_##_func(self, args, kw); \
139                 Py_DECREF(args); \
140                 return ret; \
141         } \
142         else if (PyTuple_GET_SIZE(args) > 1) { \
143                 PyErr_SetString(PyExc_ValueError, "all args must be keywords"); \
144                 return NULL; \
145         } \
146         srna= srna_from_self(self, #_func"(...):"); \
147         if(srna==NULL) { \
148                 if(PyErr_Occurred()) \
149                         return NULL; \
150                 return bpy_prop_deferred_return((void *)pymeth_##_func, kw); \
151         } \
152
153 /* terse macros for error checks shared between all funcs cant use function
154  * calls because of static strins passed to pyrna_set_to_enum_bitfield */
155 #define BPY_PROPDEF_CHECK(_func, _property_flag_items) \
156         if(id_len >= MAX_IDPROP_NAME) { \
157                 PyErr_Format(PyExc_TypeError, #_func"(): '%.200s' too long, max length is %d", id, MAX_IDPROP_NAME-1); \
158                 return NULL; \
159         } \
160         if(RNA_def_property_free_identifier(srna, id) == -1) { \
161                 PyErr_Format(PyExc_TypeError, #_func"(): '%s' is defined as a non-dynamic type", id); \
162                 return NULL; \
163         } \
164         if(pyopts && pyrna_set_to_enum_bitfield(_property_flag_items, pyopts, &opts, #_func"(options={...}):")) \
165                 return NULL; \
166
167 #define BPY_PROPDEF_SUBTYPE_CHECK(_func, _property_flag_items, _subtype) \
168         BPY_PROPDEF_CHECK(_func, _property_flag_items) \
169         if(pysubtype && RNA_enum_value_from_id(_subtype, pysubtype, &subtype)==0) { \
170                 PyErr_Format(PyExc_TypeError, #_func"(subtype='%s'): invalid subtype", pysubtype); \
171                 return NULL; \
172         } \
173
174
175 #define BPY_PROPDEF_NAME_DOC \
176 "   :arg name: Name used in the user interface.\n" \
177 "   :type name: string\n" \
178
179
180 #define BPY_PROPDEF_DESC_DOC \
181 "   :arg description: Text used for the tooltip and api documentation.\n" \
182 "   :type description: string\n" \
183
184
185 #if 0
186 static int bpy_struct_id_used(StructRNA *srna, char *identifier)
187 {
188         PointerRNA ptr;
189         RNA_pointer_create(NULL, srna, NULL, &ptr);
190         return (RNA_struct_find_property(&ptr, identifier) != NULL);
191 }
192 #endif
193
194
195 /* Function that sets RNA, NOTE - self is NULL when called from python, but being abused from C so we can pass the srna allong
196  * This isnt incorrect since its a python object - but be careful */
197 static char BPy_BoolProperty_doc[] =
198 ".. function:: BoolProperty(name=\"\", description=\"\", default=False, options={'ANIMATABLE'}, subtype='NONE')\n"
199 "\n"
200 "   Returns a new boolean property definition.\n"
201 "\n"
202 BPY_PROPDEF_NAME_DOC
203 BPY_PROPDEF_DESC_DOC
204 "   :arg options: Enumerator in ['HIDDEN', 'ANIMATABLE'].\n"
205 "   :type options: set\n"
206 "   :arg subtype: Enumerator in ['UNSIGNED', 'PERCENTAGE', 'FACTOR', 'ANGLE', 'TIME', 'DISTANCE', 'NONE'].\n"
207 "   :type subtype: string\n"
208 ;
209 static PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw)
210 {
211         StructRNA *srna;
212
213         BPY_PROPDEF_HEAD(BoolProperty)
214
215         if(srna) {
216                 static const char *kwlist[]= {"attr", "name", "description", "default", "options", "subtype", NULL};
217                 const char *id=NULL, *name="", *description="";
218                 int id_len;
219                 int def=0;
220                 PropertyRNA *prop;
221                 PyObject *pyopts= NULL;
222                 int opts=0;
223                 char *pysubtype= NULL;
224                 int subtype= PROP_NONE;
225
226                 if (!PyArg_ParseTupleAndKeywords(args, kw,
227                                                  "s#|ssiO!s:BoolProperty",
228                                                  (char **)kwlist, &id, &id_len,
229                                                  &name, &description, &def,
230                                                  &PySet_Type, &pyopts, &pysubtype))
231                 {
232                         return NULL;
233                 }
234
235                 BPY_PROPDEF_SUBTYPE_CHECK(BoolProperty, property_flag_items, property_subtype_number_items)
236
237                 prop= RNA_def_property(srna, id, PROP_BOOLEAN, subtype);
238                 RNA_def_property_boolean_default(prop, def);
239                 RNA_def_property_ui_text(prop, name, description);
240
241                 if(pyopts) {
242                         if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
243                         if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
244                 }
245                 RNA_def_property_duplicate_pointers(srna, prop);
246         }
247
248         Py_RETURN_NONE;
249 }
250
251 static char BPy_BoolVectorProperty_doc[] =
252 ".. function:: BoolVectorProperty(name=\"\", description=\"\", default=(False, False, False), options={'ANIMATABLE'}, subtype='NONE', size=3)\n"
253 "\n"
254 "   Returns a new vector boolean property definition.\n"
255 "\n"
256 BPY_PROPDEF_NAME_DOC
257 BPY_PROPDEF_DESC_DOC
258 "   :arg default: sequence of booleans the length of *size*.\n"
259 "   :type default: sequence\n"
260 "   :arg options: Enumerator in ['HIDDEN', 'ANIMATABLE'].\n"
261 "   :type options: set\n"
262 "   :arg subtype: Enumerator in ['COLOR', 'TRANSLATION', 'DIRECTION', 'VELOCITY', 'ACCELERATION', 'MATRIX', 'EULER', 'QUATERNION', 'AXISANGLE', 'XYZ', 'COLOR_GAMMA', 'LAYER', 'NONE'].\n"
263 "   :type subtype: string\n"
264 "   :arg size: Vector dimensions in [1, and " STRINGIFY(PYRNA_STACK_ARRAY) "].\n"
265 "   :type size: int\n"
266 ;
267 static PyObject *BPy_BoolVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
268 {
269         StructRNA *srna;
270
271         BPY_PROPDEF_HEAD(BoolVectorProperty)
272
273         if(srna) {
274                 static const char *kwlist[]= {"attr", "name", "description", "default", "options", "subtype", "size", NULL};
275                 const char *id=NULL, *name="", *description="";
276                 int id_len;
277                 int def[PYRNA_STACK_ARRAY]={0};
278                 int size=3;
279                 PropertyRNA *prop;
280                 PyObject *pydef= NULL;
281                 PyObject *pyopts= NULL;
282                 int opts=0;
283                 char *pysubtype= NULL;
284                 int subtype= PROP_NONE;
285
286                 if (!PyArg_ParseTupleAndKeywords(args, kw,
287                                                  "s#|ssOO!si:BoolVectorProperty",
288                                                  (char **)kwlist, &id, &id_len,
289                                                  &name, &description, &pydef,
290                                                  &PySet_Type, &pyopts, &pysubtype,&size))
291                 {
292                         return NULL;
293                 }
294
295                 BPY_PROPDEF_SUBTYPE_CHECK(BoolVectorProperty, property_flag_items, property_subtype_array_items)
296
297                 if(size < 1 || size > PYRNA_STACK_ARRAY) {
298                         PyErr_Format(PyExc_TypeError, "BoolVectorProperty(size=%d): size must be between 0 and " STRINGIFY(PYRNA_STACK_ARRAY), size);
299                         return NULL;
300                 }
301
302                 if(pydef && PyC_AsArray(def, pydef, size, &PyBool_Type, "BoolVectorProperty(default=sequence)") < 0)
303                         return NULL;
304
305                 // prop= RNA_def_boolean_array(srna, id, size, pydef ? def:NULL, name, description);
306                 prop= RNA_def_property(srna, id, PROP_BOOLEAN, subtype);
307                 RNA_def_property_array(prop, size);
308                 if(pydef) RNA_def_property_boolean_array_default(prop, def);
309                 RNA_def_property_ui_text(prop, name, description);
310
311                 if(pyopts) {
312                         if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
313                         if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
314                 }
315                 RNA_def_property_duplicate_pointers(srna, prop);
316         }
317         
318         Py_RETURN_NONE;
319 }
320
321 static char BPy_IntProperty_doc[] =
322 ".. function:: IntProperty(name=\"\", description=\"\", default=0, min=-sys.maxint, max=sys.maxint, soft_min=-sys.maxint, soft_max=sys.maxint, step=1, options={'ANIMATABLE'}, subtype='NONE')\n"
323 "\n"
324 "   Returns a new int property definition.\n"
325 "\n"
326 BPY_PROPDEF_NAME_DOC
327 BPY_PROPDEF_DESC_DOC
328 "   :arg options: Enumerator in ['HIDDEN', 'ANIMATABLE'].\n"
329 "   :type options: set\n"
330 "   :arg subtype: Enumerator in ['UNSIGNED', 'PERCENTAGE', 'FACTOR', 'ANGLE', 'TIME', 'DISTANCE', 'NONE'].\n"
331 "   :type subtype: string\n"
332 ;
333 static PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw)
334 {
335         StructRNA *srna;
336
337         BPY_PROPDEF_HEAD(IntProperty)
338
339         if(srna) {
340                 static const char *kwlist[]= {"attr", "name", "description", "default", "min", "max", "soft_min", "soft_max", "step", "options", "subtype", NULL};
341                 const char *id=NULL, *name="", *description="";
342                 int id_len;
343                 int min=INT_MIN, max=INT_MAX, soft_min=INT_MIN, soft_max=INT_MAX, step=1, def=0;
344                 PropertyRNA *prop;
345                 PyObject *pyopts= NULL;
346                 int opts=0;
347                 char *pysubtype= NULL;
348                 int subtype= PROP_NONE;
349
350                 if (!PyArg_ParseTupleAndKeywords(args, kw,
351                                                  "s#|ssiiiiiiO!s:IntProperty",
352                                                  (char **)kwlist, &id, &id_len,
353                                                  &name, &description, &def,
354                                                  &min, &max, &soft_min, &soft_max,
355                                                  &step, &PySet_Type, &pyopts, &pysubtype))
356                 {
357                         return NULL;
358                 }
359
360                 BPY_PROPDEF_SUBTYPE_CHECK(IntProperty, property_flag_items, property_subtype_number_items)
361
362                 prop= RNA_def_property(srna, id, PROP_INT, subtype);
363                 RNA_def_property_int_default(prop, def);
364                 RNA_def_property_range(prop, min, max);
365                 RNA_def_property_ui_text(prop, name, description);
366                 RNA_def_property_ui_range(prop, MAX2(soft_min, min), MIN2(soft_max, max), step, 3);
367
368                 if(pyopts) {
369                         if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
370                         if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
371                 }
372                 RNA_def_property_duplicate_pointers(srna, prop);
373         }
374         Py_RETURN_NONE;
375 }
376
377 static char BPy_IntVectorProperty_doc[] =
378 ".. function:: IntVectorProperty(name=\"\", description=\"\", default=(0, 0, 0), min=-sys.maxint, max=sys.maxint, soft_min=-sys.maxint, soft_max=sys.maxint, options={'ANIMATABLE'}, subtype='NONE', size=3)\n"
379 "\n"
380 "   Returns a new vector int property definition.\n"
381 "\n"
382 BPY_PROPDEF_NAME_DOC
383 BPY_PROPDEF_DESC_DOC
384 "   :arg default: sequence of ints the length of *size*.\n"
385 "   :type default: sequence\n"
386 "   :arg options: Enumerator in ['HIDDEN', 'ANIMATABLE'].\n"
387 "   :type options: set\n"
388 "   :arg subtype: Enumerator in ['COLOR', 'TRANSLATION', 'DIRECTION', 'VELOCITY', 'ACCELERATION', 'MATRIX', 'EULER', 'QUATERNION', 'AXISANGLE', 'XYZ', 'COLOR_GAMMA', 'LAYER', 'NONE'].\n"
389 "   :type subtype: string\n"
390 "   :arg size: Vector dimensions in [1, and " STRINGIFY(PYRNA_STACK_ARRAY) "].\n"
391 "   :type size: int\n"
392 ;
393 static PyObject *BPy_IntVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
394 {
395         StructRNA *srna;
396
397         BPY_PROPDEF_HEAD(IntVectorProperty)
398
399         if(srna) {
400                 static const char *kwlist[]= {"attr", "name", "description", "default", "min", "max", "soft_min", "soft_max", "step", "options", "subtype", "size", NULL};
401                 const char *id=NULL, *name="", *description="";
402                 int id_len;
403                 int min=INT_MIN, max=INT_MAX, soft_min=INT_MIN, soft_max=INT_MAX, step=1, def[PYRNA_STACK_ARRAY]={0};
404                 int size=3;
405                 PropertyRNA *prop;
406                 PyObject *pydef= NULL;
407                 PyObject *pyopts= NULL;
408                 int opts=0;
409                 char *pysubtype= NULL;
410                 int subtype= PROP_NONE;
411
412                 if (!PyArg_ParseTupleAndKeywords(args, kw,
413                                                  "s#|ssOiiiiiO!si:IntVectorProperty",
414                                                  (char **)kwlist, &id, &id_len,
415                                                  &name, &description, &pydef,
416                                                  &min, &max, &soft_min, &soft_max,
417                                                  &step, &PySet_Type, &pyopts,
418                                                  &pysubtype, &size))
419                 {
420                         return NULL;
421                 }
422
423                 BPY_PROPDEF_SUBTYPE_CHECK(IntVectorProperty, property_flag_items, property_subtype_array_items)
424
425                 if(size < 1 || size > PYRNA_STACK_ARRAY) {
426                         PyErr_Format(PyExc_TypeError, "IntVectorProperty(size=%d): size must be between 0 and " STRINGIFY(PYRNA_STACK_ARRAY), size);
427                         return NULL;
428                 }
429
430                 if(pydef && PyC_AsArray(def, pydef, size, &PyLong_Type, "IntVectorProperty(default=sequence)") < 0)
431                         return NULL;
432
433                 prop= RNA_def_property(srna, id, PROP_INT, subtype);
434                 RNA_def_property_array(prop, size);
435                 if(pydef) RNA_def_property_int_array_default(prop, def);
436                 RNA_def_property_range(prop, min, max);
437                 RNA_def_property_ui_text(prop, name, description);
438                 RNA_def_property_ui_range(prop, MAX2(soft_min, min), MIN2(soft_max, max), step, 3);
439
440                 if(pyopts) {
441                         if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
442                         if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
443                 }
444                 RNA_def_property_duplicate_pointers(srna, prop);
445         }
446         Py_RETURN_NONE;
447 }
448
449
450 static char BPy_FloatProperty_doc[] =
451 ".. function:: FloatProperty(name=\"\", description=\"\", default=0.0, min=sys.float_info.min, max=sys.float_info.max, soft_min=sys.float_info.min, soft_max=sys.float_info.max, step=3, precision=2, options={'ANIMATABLE'}, subtype='NONE', unit='NONE')\n"
452 "\n"
453 "   Returns a new float property definition.\n"
454 "\n"
455 BPY_PROPDEF_NAME_DOC
456 BPY_PROPDEF_DESC_DOC
457 "   :arg options: Enumerator in ['HIDDEN', 'ANIMATABLE'].\n"
458 "   :type options: set\n"
459 "   :arg subtype: Enumerator in ['UNSIGNED', 'PERCENTAGE', 'FACTOR', 'ANGLE', 'TIME', 'DISTANCE', 'NONE'].\n"
460 "   :type subtype: string\n"
461 "   :arg unit: Enumerator in ['NONE', 'LENGTH', 'AREA', 'VOLUME', 'ROTATION', 'TIME', 'VELOCITY', 'ACCELERATION'].\n"
462 "   :type unit: string\n"
463 ;
464 static PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw)
465 {
466         StructRNA *srna;
467
468         BPY_PROPDEF_HEAD(FloatProperty)
469
470         if(srna) {
471                 static const char *kwlist[]= {"attr", "name", "description", "default", "min", "max", "soft_min", "soft_max", "step", "precision", "options", "subtype", "unit", NULL};
472                 const char *id=NULL, *name="", *description="";
473                 int id_len;
474                 float min=-FLT_MAX, max=FLT_MAX, soft_min=-FLT_MAX, soft_max=FLT_MAX, step=3, def=0.0f;
475                 int precision= 2;
476                 PropertyRNA *prop;
477                 PyObject *pyopts= NULL;
478                 int opts=0;
479                 char *pysubtype= NULL;
480                 int subtype= PROP_NONE;
481                 char *pyunit= NULL;
482                 int unit= PROP_UNIT_NONE;
483
484                 if (!PyArg_ParseTupleAndKeywords(args, kw,
485                                                  "s#|ssffffffiO!ss:FloatProperty",
486                                                  (char **)kwlist, &id, &id_len,
487                                                  &name, &description, &def,
488                                                  &min, &max, &soft_min, &soft_max,
489                                                  &step, &precision, &PySet_Type,
490                                                  &pyopts, &pysubtype, &pyunit))
491                 {
492                         return NULL;
493                 }
494
495                 BPY_PROPDEF_SUBTYPE_CHECK(FloatProperty, property_flag_items, property_subtype_number_items)
496
497                 if(pyunit && RNA_enum_value_from_id(property_unit_items, pyunit, &unit)==0) {
498                         PyErr_Format(PyExc_TypeError, "FloatProperty(unit='%s'): invalid unit");
499                         return NULL;
500                 }
501
502                 prop= RNA_def_property(srna, id, PROP_FLOAT, subtype | unit);
503                 RNA_def_property_float_default(prop, def);
504                 RNA_def_property_range(prop, min, max);
505                 RNA_def_property_ui_text(prop, name, description);
506                 RNA_def_property_ui_range(prop, MAX2(soft_min, min), MIN2(soft_max, max), step, precision);
507
508                 if(pyopts) {
509                         if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
510                         if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
511                 }
512                 RNA_def_property_duplicate_pointers(srna, prop);
513         }
514         Py_RETURN_NONE;
515 }
516
517 static char BPy_FloatVectorProperty_doc[] =
518 ".. function:: FloatVectorProperty(name=\"\", description=\"\", default=(0.0, 0.0, 0.0), min=sys.float_info.min, max=sys.float_info.max, soft_min=sys.float_info.min, soft_max=sys.float_info.max, step=3, precision=2, options={'ANIMATABLE'}, subtype='NONE', size=3)\n"
519 "\n"
520 "   Returns a new vector float property definition.\n"
521 "\n"
522 BPY_PROPDEF_NAME_DOC
523 BPY_PROPDEF_DESC_DOC
524 "   :arg default: sequence of floats the length of *size*.\n"
525 "   :type default: sequence\n"
526 "   :arg options: Enumerator in ['HIDDEN', 'ANIMATABLE'].\n"
527 "   :type options: set\n"
528 "   :arg subtype: Enumerator in ['COLOR', 'TRANSLATION', 'DIRECTION', 'VELOCITY', 'ACCELERATION', 'MATRIX', 'EULER', 'QUATERNION', 'AXISANGLE', 'XYZ', 'COLOR_GAMMA', 'LAYER', 'NONE'].\n"
529 "   :type subtype: string\n"
530 "   :arg size: Vector dimensions in [1, and " STRINGIFY(PYRNA_STACK_ARRAY) "].\n"
531 "   :type size: int\n"
532 ;
533 static PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
534 {
535         StructRNA *srna;
536
537         BPY_PROPDEF_HEAD(FloatVectorProperty)
538
539         if(srna) {
540                 static const char *kwlist[]= {"attr", "name", "description", "default", "min", "max", "soft_min", "soft_max", "step", "precision", "options", "subtype", "size", NULL};
541                 const char *id=NULL, *name="", *description="";
542                 int id_len;
543                 float min=-FLT_MAX, max=FLT_MAX, soft_min=-FLT_MAX, soft_max=FLT_MAX, step=3, def[PYRNA_STACK_ARRAY]={0.0f};
544                 int precision= 2, size=3;
545                 PropertyRNA *prop;
546                 PyObject *pydef= NULL;
547                 PyObject *pyopts= NULL;
548                 int opts=0;
549                 char *pysubtype= NULL;
550                 int subtype= PROP_NONE;
551
552                 if (!PyArg_ParseTupleAndKeywords(args, kw,
553                                                  "s#|ssOfffffiO!si:FloatVectorProperty",
554                                                  (char **)kwlist, &id, &id_len,
555                                                  &name, &description, &pydef,
556                                                  &min, &max, &soft_min, &soft_max,
557                                                  &step, &precision, &PySet_Type,
558                                                  &pyopts, &pysubtype, &size))
559                 {
560                         return NULL;
561                 }
562
563                 BPY_PROPDEF_SUBTYPE_CHECK(FloatVectorProperty, property_flag_items, property_subtype_array_items)
564
565                 if(size < 1 || size > PYRNA_STACK_ARRAY) {
566                         PyErr_Format(PyExc_TypeError, "FloatVectorProperty(size=%d): size must be between 0 and " STRINGIFY(PYRNA_STACK_ARRAY), size);
567                         return NULL;
568                 }
569
570                 if(pydef && PyC_AsArray(def, pydef, size, &PyFloat_Type, "FloatVectorProperty(default=sequence)") < 0)
571                         return NULL;
572
573                 prop= RNA_def_property(srna, id, PROP_FLOAT, subtype);
574                 RNA_def_property_array(prop, size);
575                 if(pydef) RNA_def_property_float_array_default(prop, def);
576                 RNA_def_property_range(prop, min, max);
577                 RNA_def_property_ui_text(prop, name, description);
578                 RNA_def_property_ui_range(prop, MAX2(soft_min, min), MIN2(soft_max, max), step, precision);
579
580                 if(pyopts) {
581                         if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
582                         if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
583                 }
584                 RNA_def_property_duplicate_pointers(srna, prop);
585         }
586         Py_RETURN_NONE;
587 }
588
589 static char BPy_StringProperty_doc[] =
590 ".. function:: StringProperty(name=\"\", description=\"\", default=\"\", maxlen=0, options={'ANIMATABLE'}, subtype='NONE')\n"
591 "\n"
592 "   Returns a new string property definition.\n"
593 "\n"
594 BPY_PROPDEF_NAME_DOC
595 BPY_PROPDEF_DESC_DOC
596 "   :arg options: Enumerator in ['HIDDEN', 'ANIMATABLE'].\n"
597 "   :type options: set\n"
598 "   :arg subtype: Enumerator in ['FILE_PATH', 'DIR_PATH', 'FILENAME', 'NONE'].\n"
599 "   :type subtype: string\n"
600 ;
601 static PyObject *BPy_StringProperty(PyObject *self, PyObject *args, PyObject *kw)
602 {
603         StructRNA *srna;
604
605         BPY_PROPDEF_HEAD(StringProperty)
606
607         if(srna) {
608                 static const char *kwlist[]= {"attr", "name", "description", "default", "maxlen", "options", "subtype", NULL};
609                 const char *id=NULL, *name="", *description="", *def="";
610                 int id_len;
611                 int maxlen=0;
612                 PropertyRNA *prop;
613                 PyObject *pyopts= NULL;
614                 int opts=0;
615                 char *pysubtype= NULL;
616                 int subtype= PROP_NONE;
617
618                 if (!PyArg_ParseTupleAndKeywords(args, kw,
619                                                  "s#|sssiO!s:StringProperty",
620                                                  (char **)kwlist, &id, &id_len,
621                                                  &name, &description, &def,
622                                                  &maxlen, &PySet_Type, &pyopts, &pysubtype))
623                 {
624                         return NULL;
625                 }
626
627                 BPY_PROPDEF_SUBTYPE_CHECK(StringProperty, property_flag_items, property_subtype_string_items)
628
629                 prop= RNA_def_property(srna, id, PROP_STRING, subtype);
630                 if(maxlen != 0) RNA_def_property_string_maxlength(prop, maxlen + 1); /* +1 since it includes null terminator */
631                 if(def) RNA_def_property_string_default(prop, def);
632                 RNA_def_property_ui_text(prop, name, description);
633
634                 if(pyopts) {
635                         if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
636                         if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
637                 }
638                 RNA_def_property_duplicate_pointers(srna, prop);
639         }
640         Py_RETURN_NONE;
641 }
642
643 static EnumPropertyItem *enum_items_from_py(PyObject *seq_fast, PyObject *def, int *defvalue, const short is_enum_flag)
644 {
645         EnumPropertyItem *items= NULL;
646         PyObject *item;
647         int seq_len, i, totitem= 0;
648         short def_used= 0;
649         const char *def_cmp= NULL;
650
651         seq_len= PySequence_Fast_GET_SIZE(seq_fast);
652
653         if(is_enum_flag) {
654                 if(seq_len > RNA_ENUM_BITFLAG_SIZE) {
655                         PyErr_SetString(PyExc_TypeError, "EnumProperty(...): maximum " STRINGIFY(RNA_ENUM_BITFLAG_SIZE) " members for a ENUM_FLAG type property");
656                         return NULL;
657                 }
658                 if(def && !PySet_Check(def)) {
659                         PyErr_Format(PyExc_TypeError,
660                                      "EnumProperty(...): default option must be a 'set' "
661                                      "type when ENUM_FLAG is enabled, not a '%.200s'",
662                                      Py_TYPE(def)->tp_name);
663                         return NULL;
664                 }
665         }
666         else {
667                 if(def) {
668                         def_cmp= _PyUnicode_AsString(def);
669                         if(def_cmp==NULL) {
670                                 PyErr_Format(PyExc_TypeError,
671                                              "EnumProperty(...): default option must be a 'str' "
672                                              "type when ENUM_FLAG is disabled, not a '%.200s'",
673                                              Py_TYPE(def)->tp_name);
674                                 return NULL;
675                         }
676                 }
677         }
678
679         /* blank value */
680         *defvalue= 0;
681
682         for(i=0; i<seq_len; i++) {
683                 EnumPropertyItem tmp= {0, "", 0, "", ""};
684
685                 item= PySequence_Fast_GET_ITEM(seq_fast, i);
686                 if(PyTuple_Check(item)==0) {
687                         PyErr_SetString(PyExc_TypeError, "EnumProperty(...): expected a sequence of tuples for the enum items");
688                         if(items) MEM_freeN(items);
689                         return NULL;
690                 }
691
692                 if(!PyArg_ParseTuple(item, "sss", &tmp.identifier, &tmp.name, &tmp.description)) {
693                         PyErr_SetString(PyExc_TypeError, "EnumProperty(...): expected an identifier, name and description in the tuple");
694                         return NULL;
695                 }
696
697                 if(is_enum_flag) {
698                         tmp.value= 1<<i;
699
700                         if(def && PySet_Contains(def, PyTuple_GET_ITEM(item, 0))) {
701                                 *defvalue |= tmp.value;
702                                 def_used++;
703                         }
704                 }
705                 else {
706                         tmp.value= i;
707
708                         if(def && def_used == 0 && strcmp(def_cmp, tmp.identifier)==0) {
709                                 *defvalue= tmp.value;
710                                 def_used++; /* only ever 1 */
711                         }
712                 }
713
714                 RNA_enum_item_add(&items, &totitem, &tmp);
715         }
716
717         RNA_enum_item_end(&items, &totitem);
718
719         if(is_enum_flag) {
720                 /* strict check that all set members were used */
721                 if(def && def_used != PySet_GET_SIZE(def)) {
722                         MEM_freeN(items);
723
724                         PyErr_Format(PyExc_TypeError,
725                                      "EnumProperty(..., default={...}): set has %d unused member(s)",
726                                      PySet_GET_SIZE(def) - def_used);
727                         return NULL;
728                 }
729         }
730         else {
731                 if(def && def_used == 0) {
732                         MEM_freeN(items);
733
734                         PyErr_Format(PyExc_TypeError,
735                                      "EnumProperty(..., default=\'%s\'): not found in enum members",
736                                      def);
737                         return NULL;
738                 }
739         }
740
741         return items;
742 }
743
744 static char BPy_EnumProperty_doc[] =
745 ".. function:: EnumProperty(items, name=\"\", description=\"\", default=\"\", options={'ANIMATABLE'})\n"
746 "\n"
747 "   Returns a new enumerator property definition.\n"
748 "\n"
749 BPY_PROPDEF_NAME_DOC
750 BPY_PROPDEF_DESC_DOC
751 "   :arg default: The default value for this enum, A string when *ENUM_FLAG* is disabled otherwise a set which may only contain string identifiers used in *items*.\n"
752 "   :type default: string or set\n"
753 "   :arg options: Enumerator in ['HIDDEN', 'ANIMATABLE', 'ENUM_FLAG'].\n"
754 "   :type options: set\n"
755 "   :arg items: sequence of enum items formatted: [(identifier, name, description), ...] where the identifier is used for python access and other values are used for the interface.\n"
756 "   :type items: sequence of string triplets\n"
757 ;
758 static PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw)
759 {
760         StructRNA *srna;
761
762         BPY_PROPDEF_HEAD(EnumProperty)
763         
764         if(srna) {
765                 static const char *kwlist[]= {"attr", "items", "name", "description", "default", "options", NULL};
766                 const char *id=NULL, *name="", *description="";
767                 PyObject *def= NULL;
768                 int id_len;
769                 int defvalue=0;
770                 PyObject *items, *items_fast;
771                 EnumPropertyItem *eitems;
772                 PropertyRNA *prop;
773                 PyObject *pyopts= NULL;
774                 int opts=0;
775
776                 if (!PyArg_ParseTupleAndKeywords(args, kw,
777                                                  "s#O|ssOO!:EnumProperty",
778                                                  (char **)kwlist, &id, &id_len,
779                                                  &items, &name, &description,
780                                                  &def, &PySet_Type, &pyopts))
781                 {
782                         return NULL;
783                 }
784
785                 BPY_PROPDEF_CHECK(EnumProperty, property_flag_enum_items)
786
787                 if(!(items_fast= PySequence_Fast(items, "EnumProperty(...): expected a sequence of tuples for the enum items"))) {
788                         return NULL;
789                 }
790
791                 eitems= enum_items_from_py(items_fast, def, &defvalue, (opts & PROP_ENUM_FLAG)!=0);
792
793                 Py_DECREF(items_fast);
794
795                 if(!eitems)
796                         return NULL;
797
798                 if(opts & PROP_ENUM_FLAG)       prop= RNA_def_enum_flag(srna, id, eitems, defvalue, name, description);
799                 else                                            prop= RNA_def_enum(srna, id, eitems, defvalue, name, description);
800
801                 if(pyopts) {
802                         if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
803                         if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
804                 }
805                 RNA_def_property_duplicate_pointers(srna, prop);
806                 MEM_freeN(eitems);
807         }
808         Py_RETURN_NONE;
809 }
810
811 static StructRNA *pointer_type_from_py(PyObject *value, const char *error_prefix)
812 {
813         StructRNA *srna;
814
815         srna= srna_from_self(value, "");
816         if(!srna) {
817                 if(PyErr_Occurred()) {
818                         PyObject *msg= PyC_ExceptionBuffer();
819                         char *msg_char= _PyUnicode_AsString(msg);
820                         PyErr_Format(PyExc_TypeError,
821                                      "%.200s expected an RNA type derived from PropertyGroup, failed with: %s",
822                                      error_prefix, msg_char);
823                         Py_DECREF(msg);
824                 }
825                 else {
826                         PyErr_Format(PyExc_TypeError,
827                                      "%.200s expected an RNA type derived from PropertyGroup, failed with type '%s'",
828                                      error_prefix, Py_TYPE(value)->tp_name);
829                 }
830                 return NULL;
831         }
832
833         if(!RNA_struct_is_a(srna, &RNA_PropertyGroup)) {
834                 PyErr_Format(PyExc_TypeError,
835                              "%.200s expected an RNA type derived from PropertyGroup",
836                              error_prefix);
837                 return NULL;
838         }
839
840         return srna;
841 }
842
843 static char BPy_PointerProperty_doc[] =
844 ".. function:: PointerProperty(type=\"\", description=\"\", options={'ANIMATABLE'})\n"
845 "\n"
846 "   Returns a new pointer property definition.\n"
847 "\n"
848 "   :arg type: A subclass of :class:`bpy.types.PropertyGroup`.\n"
849 "   :type type: class\n"
850 BPY_PROPDEF_NAME_DOC
851 BPY_PROPDEF_DESC_DOC
852 "   :arg options: Enumerator in ['HIDDEN', 'ANIMATABLE'].\n"
853 "   :type options: set\n"
854 ;
855 static PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *kw)
856 {
857         StructRNA *srna;
858
859         BPY_PROPDEF_HEAD(PointerProperty)
860
861         if(srna) {
862                 static const char *kwlist[]= {"attr", "type", "name", "description", "options", NULL};
863                 const char *id=NULL, *name="", *description="";
864                 int id_len;
865                 PropertyRNA *prop;
866                 StructRNA *ptype;
867                 PyObject *type= Py_None;
868                 PyObject *pyopts= NULL;
869                 int opts=0;
870
871                 if (!PyArg_ParseTupleAndKeywords(args, kw,
872                                                  "s#O|ssO!:PointerProperty",
873                                                  (char **)kwlist, &id, &id_len,
874                                                  &type, &name, &description,
875                                                  &PySet_Type, &pyopts))
876                 {
877                         return NULL;
878                 }
879
880                 BPY_PROPDEF_CHECK(PointerProperty, property_flag_items)
881
882                 ptype= pointer_type_from_py(type, "PointerProperty(...):");
883                 if(!ptype)
884                         return NULL;
885
886                 prop= RNA_def_pointer_runtime(srna, id, ptype, name, description);
887                 if(pyopts) {
888                         if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
889                         if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
890                 }
891                 RNA_def_property_duplicate_pointers(srna, prop);
892         }
893         Py_RETURN_NONE;
894 }
895
896 static char BPy_CollectionProperty_doc[] =
897 ".. function:: CollectionProperty(items, type=\"\", description=\"\", default=\"\", options={'ANIMATABLE'})\n"
898 "\n"
899 "   Returns a new collection property definition.\n"
900 "\n"
901 "   :arg type: A subclass of :class:`bpy.types.PropertyGroup`.\n"
902 "   :type type: class\n"
903 BPY_PROPDEF_NAME_DOC
904 BPY_PROPDEF_DESC_DOC
905 "   :arg options: Enumerator in ['HIDDEN', 'ANIMATABLE'].\n"
906 "   :type options: set\n"
907 ;
908 static PyObject *BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject *kw)
909 {
910         StructRNA *srna;
911
912         BPY_PROPDEF_HEAD(CollectionProperty)
913
914         if(srna) {
915                 static const char *kwlist[]= {"attr", "type", "name", "description", "options", NULL};
916                 const char *id=NULL, *name="", *description="";
917                 int id_len;
918                 PropertyRNA *prop;
919                 StructRNA *ptype;
920                 PyObject *type= Py_None;
921                 PyObject *pyopts= NULL;
922                 int opts=0;
923
924                 if (!PyArg_ParseTupleAndKeywords(args, kw,
925                                                  "s#O|ssO!:CollectionProperty",
926                                                  (char **)kwlist, &id, &id_len,
927                                                  &type, &name, &description,
928                                                  &PySet_Type, &pyopts))
929                 {
930                         return NULL;
931                 }
932
933                 BPY_PROPDEF_CHECK(CollectionProperty, property_flag_items)
934
935                 ptype= pointer_type_from_py(type, "CollectionProperty(...):");
936                 if(!ptype)
937                         return NULL;
938
939                 prop= RNA_def_collection_runtime(srna, id, ptype, name, description);
940                 if(pyopts) {
941                         if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
942                         if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
943                 }
944                 RNA_def_property_duplicate_pointers(srna, prop);
945         }
946         Py_RETURN_NONE;
947 }
948
949 static char BPy_RemoveProperty_doc[] =
950 ".. function:: RemoveProperty(attr)\n"
951 "\n"
952 "   Removes a dynamically defined property.\n"
953 "\n"
954 "   :arg attr: Property name.\n"
955 "   :type attr: string\n"
956 ;
957 static PyObject *BPy_RemoveProperty(PyObject *self, PyObject *args, PyObject *kw)
958 {
959         StructRNA *srna;
960
961         if(PyTuple_GET_SIZE(args) == 1) {
962                 PyObject *ret;
963                 self= PyTuple_GET_ITEM(args, 0);
964                 args= PyTuple_New(0);
965                 ret= BPy_RemoveProperty(self, args, kw);
966                 Py_DECREF(args);
967                 return ret;     
968         }
969         else if (PyTuple_GET_SIZE(args) > 1) {
970                 PyErr_SetString(PyExc_ValueError, "all args must be keywords"); \
971                 return NULL;
972         }
973
974         srna= srna_from_self(self, "RemoveProperty(...):");
975         if(srna==NULL && PyErr_Occurred()) {
976                 return NULL; /* self's type was compatible but error getting the srna */
977         }
978         else if(srna==NULL) {
979                 PyErr_SetString(PyExc_TypeError, "RemoveProperty(): struct rna not available for this type");
980                 return NULL;
981         }
982         else {
983                 static const char *kwlist[]= {"attr", NULL};
984                 
985                 char *id=NULL;
986
987                 if (!PyArg_ParseTupleAndKeywords(args, kw,
988                                                  "s:RemoveProperty",
989                                                  (char **)kwlist, &id))
990                 {
991                         return NULL;
992                 }
993
994                 if(RNA_def_property_free_identifier(srna, id) != 1) {
995                         PyErr_Format(PyExc_TypeError, "RemoveProperty(): '%s' not a defined dynamic property", id);
996                         return NULL;
997                 }
998         }
999         Py_RETURN_NONE;
1000 }
1001
1002 static struct PyMethodDef props_methods[]= {
1003         {"BoolProperty", (PyCFunction)BPy_BoolProperty, METH_VARARGS|METH_KEYWORDS, BPy_BoolProperty_doc},
1004         {"BoolVectorProperty", (PyCFunction)BPy_BoolVectorProperty, METH_VARARGS|METH_KEYWORDS, BPy_BoolVectorProperty_doc},
1005         {"IntProperty", (PyCFunction)BPy_IntProperty, METH_VARARGS|METH_KEYWORDS, BPy_IntProperty_doc},
1006         {"IntVectorProperty", (PyCFunction)BPy_IntVectorProperty, METH_VARARGS|METH_KEYWORDS, BPy_IntVectorProperty_doc},
1007         {"FloatProperty", (PyCFunction)BPy_FloatProperty, METH_VARARGS|METH_KEYWORDS, BPy_FloatProperty_doc},
1008         {"FloatVectorProperty", (PyCFunction)BPy_FloatVectorProperty, METH_VARARGS|METH_KEYWORDS, BPy_FloatVectorProperty_doc},
1009         {"StringProperty", (PyCFunction)BPy_StringProperty, METH_VARARGS|METH_KEYWORDS, BPy_StringProperty_doc},
1010         {"EnumProperty", (PyCFunction)BPy_EnumProperty, METH_VARARGS|METH_KEYWORDS, BPy_EnumProperty_doc},
1011         {"PointerProperty", (PyCFunction)BPy_PointerProperty, METH_VARARGS|METH_KEYWORDS, BPy_PointerProperty_doc},
1012         {"CollectionProperty", (PyCFunction)BPy_CollectionProperty, METH_VARARGS|METH_KEYWORDS, BPy_CollectionProperty_doc},
1013
1014         {"RemoveProperty", (PyCFunction)BPy_RemoveProperty, METH_VARARGS|METH_KEYWORDS, BPy_RemoveProperty_doc},
1015         {NULL, NULL, 0, NULL}
1016 };
1017
1018 static struct PyModuleDef props_module= {
1019         PyModuleDef_HEAD_INIT,
1020         "bpy.props",
1021         "This module defines properties to extend blenders internal data, the result of these functions"
1022         " is used to assign properties to classes registered with blender and can't be used directly.",
1023         -1,/* multiple "initialization" just copies the module dict. */
1024         props_methods,
1025         NULL, NULL, NULL, NULL
1026 };
1027
1028 PyObject *BPY_rna_props( void )
1029 {
1030         PyObject *submodule;
1031         PyObject *submodule_dict;
1032         
1033         submodule= PyModule_Create(&props_module);
1034         PyDict_SetItemString(PyImport_GetModuleDict(), props_module.m_name, submodule);
1035
1036         /* INCREF since its its assumed that all these functions return the
1037          * module with a new ref like PyDict_New, since they are passed to
1038          * PyModule_AddObject which steals a ref */
1039         Py_INCREF(submodule);
1040         
1041         /* api needs the PyObjects internally */
1042         submodule_dict= PyModule_GetDict(submodule);
1043
1044 #define ASSIGN_STATIC(_name) pymeth_##_name= PyDict_GetItemString(submodule_dict, #_name)
1045
1046         ASSIGN_STATIC(BoolProperty);
1047         ASSIGN_STATIC(BoolVectorProperty);
1048         ASSIGN_STATIC(IntProperty);
1049         ASSIGN_STATIC(IntVectorProperty);
1050         ASSIGN_STATIC(FloatProperty);
1051         ASSIGN_STATIC(FloatVectorProperty);
1052         ASSIGN_STATIC(StringProperty);
1053         ASSIGN_STATIC(EnumProperty);
1054         ASSIGN_STATIC(PointerProperty);
1055         ASSIGN_STATIC(CollectionProperty);
1056         ASSIGN_STATIC(RemoveProperty);
1057         
1058         return submodule;
1059 }