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).
This commit is contained in:
@@ -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) );
|
||||
|
||||
|
@@ -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", ¯o, &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);
|
||||
|
||||
|
@@ -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 */
|
||||
|
@@ -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 );
|
||||
|
Reference in New Issue
Block a user