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:
authorMartin Poirier <theeth@yahoo.com>2009-12-31 01:14:32 +0300
committerMartin Poirier <theeth@yahoo.com>2009-12-31 01:14:32 +0300
commitb00cddeb66f2b9f51cad15ed597a6ca975bd31dd (patch)
treebd686691ecde5cd24abd2330dea086e275d07635 /source/blender/python
parent3702998fec6d237eb567bb8353ac93c8d4a68d4c (diff)
Macro registration using the normal rna registration methods (like operators).
bpy.types.register(MacroClass) instead of bpy.ops.add_macro(MacroClass) The rest is unchanged. Also remove some now unused code for the old registration methods (there's still some remaining).
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.c61
-rw-r--r--source/blender/python/intern/bpy_rna.c6
-rw-r--r--source/blender/python/intern/bpy_rna.h3
4 files changed, 51 insertions, 23 deletions
diff --git a/source/blender/python/intern/bpy_operator.c b/source/blender/python/intern/bpy_operator.c
index 101f3619da4..e7cce8e7812 100644
--- a/source/blender/python/intern/bpy_operator.c
+++ b/source/blender/python/intern/bpy_operator.c
@@ -245,7 +245,7 @@ PyObject *BPY_operator_module( void )
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_macro_meth ={"add_macro", (PyCFunction) PYOP_wrap_add_macro, 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};
@@ -257,7 +257,7 @@ PyObject *BPY_operator_module( void )
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_macro", PyCFunction_New(&pyop_add_macro_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 b3f281b4b3f..0a468f2de73 100644
--- a/source/blender/python/intern/bpy_operator_wrap.c
+++ b/source/blender/python/intern/bpy_operator_wrap.c
@@ -299,7 +299,47 @@ void operator_wrapper(wmOperatorType *ot, void *userdata)
}
}
+void macro_wrapper(wmOperatorType *ot, void *userdata)
+{
+ wmOperatorType *data = (wmOperatorType *)userdata;
+ /* only copy a couple of things, the rest is set by the macro registration */
+ ot->name = data->name;
+ ot->idname = data->idname;
+ ot->description = data->description;
+ ot->flag |= data->flag; /* append flags to the one set by registration */
+ ot->pyop_poll = data->pyop_poll;
+ ot->ui = data->ui;
+ ot->ext = data->ext;
+
+ 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();
+ }
+ }
+}
@@ -588,11 +628,11 @@ PyObject *PYOP_wrap_macro_define(PyObject *self, PyObject *args)
wmOperatorType *ot;
wmOperatorTypeMacro *otmacro;
PyObject *macro;
- PyObject *item;
PointerRNA ptr_otmacro;
+ StructRNA *srna;
char *opname;
- char *macroname;
+ const char *macroname;
if (!PyArg_ParseTuple(args, "Os:_bpy.ops.macro_define", &macro, &opname))
return NULL;
@@ -603,21 +643,8 @@ PyObject *PYOP_wrap_macro_define(PyObject *self, PyObject *args)
}
/* identifiers */
- item= PyObject_GetAttrString(macro, PYOP_ATTR_IDNAME_BL);
-
- if (!item) {
- item= PyObject_GetAttrString(macro, PYOP_ATTR_IDNAME);
-
- if (!item) {
- PyErr_Format(PyExc_ValueError, "Macro Define: not a valid Macro class");
- } else {
- macroname= _PyUnicode_AsString(item);
- PyErr_Format(PyExc_ValueError, "Macro Define: '%s' hasn't been registered yet", macroname);
- }
- return NULL;
- }
-
- macroname= _PyUnicode_AsString(item);
+ srna= srna_from_self(macro);
+ macroname = RNA_struct_identifier(srna);
ot = WM_operatortype_exists(macroname);
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c
index 7c4e49e93e3..c8f0a29ca64 100644
--- a/source/blender/python/intern/bpy_rna.c
+++ b/source/blender/python/intern/bpy_rna.c
@@ -244,8 +244,6 @@ PyObject *pyrna_math_object_from_array(PointerRNA *ptr, PropertyRNA *prop)
#endif
-static StructRNA *pyrna_struct_as_srna(PyObject *self);
-
static int pyrna_struct_compare( BPy_StructRNA * a, BPy_StructRNA * b )
{
return (a->ptr.data==b->ptr.data) ? 0 : -1;
@@ -3354,7 +3352,7 @@ PyObject *BPY_rna_props( void )
return submodule;
}
-static StructRNA *pyrna_struct_as_srna(PyObject *self)
+StructRNA *pyrna_struct_as_srna(PyObject *self)
{
BPy_StructRNA *py_srna = NULL;
StructRNA *srna;
@@ -3395,7 +3393,7 @@ static StructRNA *pyrna_struct_as_srna(PyObject *self)
/* Orphan functions, not sure where they should go */
/* get the srna for methods attached to types */
/* */
-static StructRNA *srna_from_self(PyObject *self)
+StructRNA *srna_from_self(PyObject *self)
{
/* a bit sloppy but would cause a very confusing bug if
* an error happened to be set here */
diff --git a/source/blender/python/intern/bpy_rna.h b/source/blender/python/intern/bpy_rna.h
index 37f6af36726..74a16b43dc1 100644
--- a/source/blender/python/intern/bpy_rna.h
+++ b/source/blender/python/intern/bpy_rna.h
@@ -62,6 +62,9 @@ typedef struct {
/* cheap trick */
#define BPy_BaseTypeRNA BPy_PropertyRNA
+StructRNA *srna_from_self(PyObject *self);
+StructRNA *pyrna_struct_as_srna(PyObject *self);
+
void BPY_rna_init( void );
PyObject *BPY_rna_module( void );
void BPY_update_rna_module( void );