Merge from 2.5 r20776 through r20855
[blender.git] / source / blender / python / intern / bpy_rna.c
index 207ca41ed46f4ab373df606f22a3e6f6c30adefb..09e2ab15c5618a0c6af2070e5ad3df0fa84f2d08 100644 (file)
@@ -38,6 +38,7 @@
 #include "BKE_context.h"
 #include "BKE_global.h" /* evil G.* */
 #include "BKE_report.h"
+#include "BKE_utildefines.h" /* FILE_MAX */
 
 static int pyrna_struct_compare( BPy_StructRNA * a, BPy_StructRNA * b )
 {
@@ -1836,6 +1837,33 @@ PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw)
        }
 }
 
+PyObject *BPy_StringProperty(PyObject *self, PyObject *args, PyObject *kw)
+{
+       static char *kwlist[] = {"attr", "name", "description", "maxlen", "default", NULL};
+       char *id, *name="", *description="", *def="";
+       int maxlen=FILE_MAX; // XXX need greater?
+       
+       if (!PyArg_ParseTupleAndKeywords(args, kw, "s|ssis:StringProperty", kwlist, &id, &name, &description, &maxlen, &def))
+               return NULL;
+       
+       if (PyTuple_Size(args) > 0) {
+               PyErr_SetString(PyExc_ValueError, "all args must be keywors"); // TODO - py3 can enforce this.
+               return NULL;
+       }
+       
+       if (self) {
+               StructRNA *srna = PyCObject_AsVoidPtr(self);
+               RNA_def_string(srna, id, def, maxlen, name, description);
+               Py_RETURN_NONE;
+       } else {
+               PyObject *ret = PyTuple_New(2);
+               PyTuple_SET_ITEM(ret, 0, PyCObject_FromVoidPtr((void *)BPy_StringProperty, NULL));
+               PyTuple_SET_ITEM(ret, 1, kw);
+               Py_INCREF(kw);
+               return ret;
+       }
+}
+
 /*-------------------- Type Registration ------------------------*/
 
 static int rna_function_arg_count(FunctionRNA *func)