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:
authorCampbell Barton <ideasman42@gmail.com>2009-12-24 22:50:43 +0300
committerCampbell Barton <ideasman42@gmail.com>2009-12-24 22:50:43 +0300
commitbbe13e7823d916523ed9434023dee34f34d6cb8e (patch)
tree5e2fe2c848337d59f028b12a5afc3ea989dfa43f /source/blender/python
parent4dd3e6c36070e64d8b1d784a34d9881ae2c3eed8 (diff)
* register operators like other classes
* operators now return sets (converted into flags) * can't remove bpy_operator_wrap.c since macro's still use the custom register funcs
Diffstat (limited to 'source/blender/python')
-rw-r--r--source/blender/python/intern/bpy_operator.c4
-rw-r--r--source/blender/python/intern/bpy_operator_wrap.c71
-rw-r--r--source/blender/python/intern/bpy_rna.c12
3 files changed, 71 insertions, 16 deletions
diff --git a/source/blender/python/intern/bpy_operator.c b/source/blender/python/intern/bpy_operator.c
index 7ccbe1c16a4..101f3619da4 100644
--- a/source/blender/python/intern/bpy_operator.c
+++ b/source/blender/python/intern/bpy_operator.c
@@ -244,7 +244,7 @@ PyObject *BPY_operator_module( void )
static PyMethodDef pyop_as_string_meth ={"as_string", (PyCFunction) pyop_as_string, METH_VARARGS, NULL};
static PyMethodDef pyop_dir_meth = {"dir", (PyCFunction) pyop_dir, METH_NOARGS, NULL};
static PyMethodDef pyop_getrna_meth = {"get_rna", (PyCFunction) pyop_getrna, METH_O, NULL};
- static PyMethodDef pyop_add_meth = {"add", (PyCFunction) PYOP_wrap_add, METH_O, NULL};
+// static PyMethodDef pyop_add_meth = {"add", (PyCFunction) PYOP_wrap_add, METH_O, NULL};
static PyMethodDef pyop_add_macro_meth ={"add_macro", (PyCFunction) PYOP_wrap_add_macro, METH_O, NULL};
static PyMethodDef pyop_macro_def_meth ={"macro_define", (PyCFunction) PYOP_wrap_macro_define, METH_VARARGS, NULL};
static PyMethodDef pyop_remove_meth = {"remove", (PyCFunction) PYOP_wrap_remove, METH_O, NULL};
@@ -256,7 +256,7 @@ PyObject *BPY_operator_module( void )
PyModule_AddObject( submodule, "as_string",PyCFunction_New(&pyop_as_string_meth,NULL) );
PyModule_AddObject( submodule, "dir", PyCFunction_New(&pyop_dir_meth, NULL) );
PyModule_AddObject( submodule, "get_rna", PyCFunction_New(&pyop_getrna_meth, NULL) );
- PyModule_AddObject( submodule, "add", PyCFunction_New(&pyop_add_meth, NULL) );
+// PyModule_AddObject( submodule, "add", PyCFunction_New(&pyop_add_meth, NULL) );
PyModule_AddObject( submodule, "add_macro", PyCFunction_New(&pyop_add_macro_meth, NULL) );
PyModule_AddObject( submodule, "macro_define",PyCFunction_New(&pyop_macro_def_meth, NULL) );
PyModule_AddObject( submodule, "remove", PyCFunction_New(&pyop_remove_meth, NULL) );
diff --git a/source/blender/python/intern/bpy_operator_wrap.c b/source/blender/python/intern/bpy_operator_wrap.c
index cd5b0756531..3bd18d98563 100644
--- a/source/blender/python/intern/bpy_operator_wrap.c
+++ b/source/blender/python/intern/bpy_operator_wrap.c
@@ -105,7 +105,7 @@ static int PYTHON_OT_generic(int mode, bContext *C, wmOperatorType *ot, wmOperat
py_class_instance = PyObject_Call(py_class, args, NULL);
Py_DECREF(args);
-
+
if (py_class_instance==NULL) { /* Initializing the class worked, now run its invoke function */
PyErr_Print();
PyErr_Clear();
@@ -128,7 +128,7 @@ static int PYTHON_OT_generic(int mode, bContext *C, wmOperatorType *ot, wmOperat
else if (mode==PYOP_EXEC) {
item= PyObject_GetAttrString(py_class, "execute");
args = PyTuple_New(2);
-
+
PyTuple_SET_ITEM(args, 1, pyrna_struct_CreatePyObject(&ptr_context));
}
else if (mode==PYOP_POLL) {
@@ -173,7 +173,7 @@ static int PYTHON_OT_generic(int mode, bContext *C, wmOperatorType *ot, wmOperat
Py_DECREF(args);
Py_DECREF(item);
}
-
+
if (ret == NULL) { /* covers py_class_instance failing too */
if(op)
BPy_errors_to_report(op->reports);
@@ -202,7 +202,7 @@ static int PYTHON_OT_generic(int mode, bContext *C, wmOperatorType *ot, wmOperat
* If we ever want to do this and use the props again,
* it can be done with - pyrna_pydict_to_props(op->ptr, kw, "")
*/
-
+
Py_DECREF(ret);
}
@@ -215,7 +215,7 @@ static int PYTHON_OT_generic(int mode, bContext *C, wmOperatorType *ot, wmOperat
BPY_flag_def *flag_def = pyop_ret_flags;
strcpy(flag_str, "");
-
+
while(flag_def->name) {
if (ret_flag & flag_def->flag) {
if(flag_str[1])
@@ -260,6 +260,49 @@ static void PYTHON_OT_draw(bContext *C, wmOperator *op, uiLayout *layout)
PYTHON_OT_generic(PYOP_DRAW, C, op->type, op, NULL, layout);
}
+
+
+void operator_wrapper(wmOperatorType *ot, void *userdata)
+{
+ /* take care not to overwrite anything set in
+ * WM_operatortype_append_ptr before opfunc() is called */
+ StructRNA *srna = ot->srna;
+ *ot= *((wmOperatorType *)userdata);
+ ot->srna= srna; /* restore */
+
+ RNA_struct_blender_type_set(ot->ext.srna, ot);
+
+
+ /* Can't use this because it returns a dict proxy
+ *
+ * item= PyObject_GetAttrString(py_class, "__dict__");
+ */
+ {
+ PyObject *py_class = ot->ext.data;
+ PyObject *item= ((PyTypeObject*)py_class)->tp_dict;
+ if(item) {
+ /* only call this so pyrna_deferred_register_props gives a useful error
+ * WM_operatortype_append_ptr will call RNA_def_struct_identifier
+ * later */
+ RNA_def_struct_identifier(ot->srna, ot->idname);
+
+ if(pyrna_deferred_register_props(ot->srna, item)!=0) {
+ /* failed to register operator props */
+ PyErr_Print();
+ PyErr_Clear();
+
+ }
+ }
+ else {
+ PyErr_Clear();
+ }
+ }
+}
+
+
+
+
+
void PYTHON_OT_wrapper(wmOperatorType *ot, void *userdata)
{
PyObject *py_class = (PyObject *)userdata;
@@ -283,8 +326,8 @@ void PYTHON_OT_wrapper(wmOperatorType *ot, void *userdata)
item= PyObject_GetAttrString(py_class, PYOP_ATTR_DESCRIPTION);
ot->description= (item && PyUnicode_Check(item)) ? _PyUnicode_AsString(item):"undocumented python operator";
Py_XDECREF(item);
-
- /* api callbacks, detailed checks dont on adding */
+
+ /* api callbacks, detailed checks dont on adding */
if (PyObject_HasAttrString(py_class, "invoke"))
ot->invoke= PYTHON_OT_invoke;
//else
@@ -296,9 +339,9 @@ void PYTHON_OT_wrapper(wmOperatorType *ot, void *userdata)
ot->pyop_poll= PYTHON_OT_poll;
if (PyObject_HasAttrString(py_class, "draw"))
ot->ui= PYTHON_OT_draw;
-
+
ot->pyop_data= userdata;
-
+
/* flags */
ot->flag= 0;
@@ -419,11 +462,11 @@ void PYTHON_OT_MACRO_wrapper(wmOperatorType *ot, void *userdata)
/* pyOperators - Operators defined IN Python */
PyObject *PYOP_wrap_add(PyObject *self, PyObject *py_class)
-{
+{
PyObject *base_class, *item;
wmOperatorType *ot;
-
-
+
+
char *idname= NULL;
char idname_bl[OP_MAX_TYPENAME]; /* converted to blender syntax */
@@ -466,7 +509,7 @@ PyObject *PYOP_wrap_add(PyObject *self, PyObject *py_class)
Py_DECREF(item);
/* end annoying conversion! */
-
+
/* remove if it already exists */
if ((ot=WM_operatortype_exists(idname))) {
if(ot->pyop_data) {
@@ -474,7 +517,7 @@ PyObject *PYOP_wrap_add(PyObject *self, PyObject *py_class)
}
WM_operatortype_remove(idname);
}
-
+
Py_INCREF(py_class);
WM_operatortype_append_ptr(PYTHON_OT_wrapper, py_class);
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c
index d0cc3e95097..8eda19d8198 100644
--- a/source/blender/python/intern/bpy_rna.c
+++ b/source/blender/python/intern/bpy_rna.c
@@ -3912,7 +3912,18 @@ static int bpy_class_validate(PointerRNA *dummyptr, void *py_data, int *have_fun
}
}
+#if 0
+ if(strcmp(identifier, "bl_label") == 0) {
+ item= PyObject_GetAttrString(py_class, "__doc__");
+ if(item) {
+ Py_DECREF(item); /* no need to keep a ref, the class owns it */
+
+ if(pyrna_py_to_prop(dummyptr, prop, NULL, item, "validating class error:") != 0)
+ return -1;
+ }
+ }
+#endif
if (item == NULL && (((flag & PROP_REGISTER_OPTIONAL) != PROP_REGISTER_OPTIONAL))) {
PyErr_Format( PyExc_AttributeError, "expected %.200s, %.200s class to have an \"%.200s\" attribute", class_type, py_class_name, identifier);
return -1;
@@ -4092,6 +4103,7 @@ void pyrna_free_types(void)
}
}
RNA_PROP_END;
+
}
/* Note! MemLeak XXX