Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/python/intern/bpy_rna.c')
-rw-r--r--source/blender/python/intern/bpy_rna.c128
1 files changed, 118 insertions, 10 deletions
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c
index 12c19bd3471..5727bb97483 100644
--- a/source/blender/python/intern/bpy_rna.c
+++ b/source/blender/python/intern/bpy_rna.c
@@ -481,7 +481,9 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *v
BPy_StructRNA *param= (BPy_StructRNA*)value;
int raise_error= 0;
if(data) {
- if(ptype == &RNA_AnyType) {
+ int flag = RNA_property_flag(prop);
+
+ if(flag & PROP_RNAPTR) {
if(value == Py_None)
memset(data, 0, sizeof(PointerRNA));
else
@@ -763,6 +765,39 @@ static PyMappingMethods pyrna_prop_as_mapping = {
( objobjargproc ) pyrna_prop_assign_subscript, /* mp_ass_subscript */
};
+static int pyrna_prop_contains(BPy_PropertyRNA * self, PyObject *value)
+{
+ PointerRNA newptr; /* not used, just so RNA_property_collection_lookup_string runs */
+ char *keyname = _PyUnicode_AsString(value);
+
+ if(keyname==NULL) {
+ PyErr_SetString(PyExc_TypeError, "PropertyRNA - key in prop, key must be a string type");
+ return -1;
+ }
+
+ if (RNA_property_type(self->prop) != PROP_COLLECTION) {
+ PyErr_SetString(PyExc_TypeError, "PropertyRNA - key in prop, is only valid for collection types");
+ return -1;
+ }
+
+
+ if (RNA_property_collection_lookup_string(&self->ptr, self->prop, keyname, &newptr))
+ return 1;
+
+ return 0;
+}
+
+static PySequenceMethods pyrna_prop_as_sequence = {
+ NULL, /* Cant set the len otherwise it can evaluate as false */
+ NULL, /* sq_concat */
+ NULL, /* sq_repeat */
+ NULL, /* sq_item */
+ NULL, /* sq_slice */
+ NULL, /* sq_ass_item */
+ NULL, /* sq_ass_slice */
+ (objobjproc)pyrna_prop_contains, /* sq_contains */
+};
+
static PyObject *pyrna_struct_dir(BPy_StructRNA * self)
{
PyObject *ret, *dict;
@@ -1176,8 +1211,9 @@ PyObject *pyrna_param_to_py(PointerRNA *ptr, PropertyRNA *prop, void *data)
{
PointerRNA newptr;
StructRNA *type= RNA_property_pointer_type(ptr, prop);
+ int flag = RNA_property_flag(prop);
- if(type == &RNA_AnyType) {
+ if(flag & PROP_RNAPTR) {
/* in this case we get the full ptr */
newptr= *(PointerRNA*)data;
}
@@ -1274,11 +1310,19 @@ static PyObject * pyrna_func_call(PyObject * self, PyObject *args, PyObject *kw)
ret= NULL;
if (err==0) {
/* call function */
- RNA_function_call(self_ptr, self_func, parms);
+ ReportList reports;
+ bContext *C= BPy_GetContext();
+
+ BKE_reports_init(&reports, RPT_STORE);
+ RNA_function_call(C, &reports, self_ptr, self_func, parms);
+
+ err= (BPy_reports_to_error(&reports))? -1: 0;
+ BKE_reports_clear(&reports);
/* return value */
- if(pret)
- ret= pyrna_param_to_py(&funcptr, pret, retdata);
+ if(err==0)
+ if(pret)
+ ret= pyrna_param_to_py(&funcptr, pret, retdata);
}
/* cleanup */
@@ -1403,7 +1447,7 @@ PyTypeObject pyrna_prop_Type = {
/* Method suites for standard classes */
NULL, /* PyNumberMethods *tp_as_number; */
- NULL, /* PySequenceMethods *tp_as_sequence; */
+ &pyrna_prop_as_sequence, /* PySequenceMethods *tp_as_sequence; */
&pyrna_prop_as_mapping, /* PyMappingMethods *tp_as_mapping; */
/* More standard operations (here for binary compatibility) */
@@ -1716,7 +1760,44 @@ PyObject *BPY_rna_types(void)
return (PyObject *)self;
}
+static struct PyMethodDef props_methods[] = {
+ {"FloatProperty", (PyCFunction)BPy_FloatProperty, METH_VARARGS|METH_KEYWORDS, ""},
+ {"IntProperty", (PyCFunction)BPy_IntProperty, METH_VARARGS|METH_KEYWORDS, ""},
+ {"BoolProperty", (PyCFunction)BPy_BoolProperty, METH_VARARGS|METH_KEYWORDS, ""},
+ {"StringProperty", (PyCFunction)BPy_StringProperty, METH_VARARGS|METH_KEYWORDS, ""},
+ {NULL, NULL, 0, NULL}
+};
+#if PY_VERSION_HEX >= 0x03000000
+static struct PyModuleDef props_module = {
+ PyModuleDef_HEAD_INIT,
+ "bpyprops",
+ "",
+ -1,/* multiple "initialization" just copies the module dict. */
+ props_methods,
+ NULL, NULL, NULL, NULL
+};
+#endif
+
+PyObject *BPY_rna_props( void )
+{
+ PyObject *submodule, *mod;
+#if PY_VERSION_HEX >= 0x03000000
+ submodule= PyModule_Create(&props_module);
+#else /* Py2.x */
+ submodule= Py_InitModule3( "bpy.props", props_methods, "" );
+#endif
+
+ mod = PyModule_New("props");
+ PyModule_AddObject( submodule, "props", mod );
+
+ /* INCREF since its its assumed that all these functions return the
+ * module with a new ref like PyDict_New, since they are passed to
+ * PyModule_AddObject which steals a ref */
+ Py_INCREF(submodule);
+
+ return submodule;
+}
/* Orphan functions, not sure where they should go */
@@ -1736,7 +1817,7 @@ PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw)
return NULL;
}
- if (self) {
+ if (self && PyCObject_Check(self)) {
StructRNA *srna = PyCObject_AsVoidPtr(self);
RNA_def_float(srna, id, def, min, max, name, description, soft_min, soft_max);
Py_RETURN_NONE;
@@ -1763,7 +1844,7 @@ PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw)
return NULL;
}
- if (self) {
+ if (self && PyCObject_Check(self)) {
StructRNA *srna = PyCObject_AsVoidPtr(self);
RNA_def_int(srna, id, def, min, max, name, description, soft_min, soft_max);
Py_RETURN_NONE;
@@ -1790,7 +1871,7 @@ PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw)
return NULL;
}
- if (self) {
+ if (self && PyCObject_Check(self)) {
StructRNA *srna = PyCObject_AsVoidPtr(self);
RNA_def_boolean(srna, id, def, name, description);
Py_RETURN_NONE;
@@ -1803,6 +1884,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=0;
+
+ 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 && PyCObject_Check(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)
@@ -2085,7 +2193,7 @@ PyObject *pyrna_basetype_register(PyObject *self, PyObject *args)
C= BPy_GetContext();
/* call the register callback */
- BKE_reports_init(&reports, RPT_PRINT);
+ BKE_reports_init(&reports, RPT_STORE);
srna= reg(C, &reports, py_class, bpy_class_validate, bpy_class_call, bpy_class_free);
if(!srna) {