* was using __members__ to get a list of attributes, has been deprecated in python for a while now. use a "__dir__" method instead. now dir() works for rna and operator types.
* added array support for bpyoperator doc generation
This commit is contained in:
@@ -106,8 +106,8 @@ int PYOP_props_from_dict(PointerRNA *ptr, PyObject *kw)
|
||||
return error_val;
|
||||
}
|
||||
|
||||
/* floats bigger then this are displayed as inf in the docstrings */
|
||||
#define MAXFLOAT_DOC 10000000
|
||||
|
||||
|
||||
|
||||
static int pyop_func_compare( BPy_OperatorFunc * a, BPy_OperatorFunc * b )
|
||||
{
|
||||
@@ -133,76 +133,45 @@ static PyObject *pyop_base_getattro( BPy_OperatorBase * self, PyObject *pyname )
|
||||
PyObject *ret;
|
||||
wmOperatorType *ot;
|
||||
|
||||
if( strcmp( name, "__members__" ) == 0 ) {
|
||||
PyObject *item;
|
||||
ret = PyList_New(2);
|
||||
|
||||
PyList_SET_ITEM(ret, 0, PyUnicode_FromString("add"));
|
||||
PyList_SET_ITEM(ret, 1, PyUnicode_FromString("remove"));
|
||||
|
||||
for(ot= WM_operatortype_first(); ot; ot= ot->next) {
|
||||
item = PyUnicode_FromString( ot->idname );
|
||||
PyList_Append(ret, item);
|
||||
Py_DECREF(item);
|
||||
}
|
||||
if ((ot = WM_operatortype_find(name))) {
|
||||
ret= pyop_func_CreatePyObject(self->C, name);
|
||||
}
|
||||
else if ( strcmp( name, "add" ) == 0 ) {
|
||||
ret= PYOP_wrap_add_func();
|
||||
}
|
||||
else if ( strcmp( name, "remove" ) == 0 ) {
|
||||
ret= PYOP_wrap_remove_func();
|
||||
}
|
||||
else {
|
||||
ot = WM_operatortype_find(name);
|
||||
|
||||
if (ot) {
|
||||
ret= pyop_func_CreatePyObject(self->C, name);
|
||||
}
|
||||
else {
|
||||
PyErr_Format( PyExc_AttributeError, "Operator \"%s\" not found", name);
|
||||
ret= NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
//---------------getattr--------------------------------------------
|
||||
static PyObject * pyop_func_getattro(BPy_OperatorFunc * self, PyObject *pyname)
|
||||
{
|
||||
char *name = _PyUnicode_AsString(pyname);
|
||||
PyObject *ret;
|
||||
|
||||
if( strcmp( name, "__members__" ) == 0 ) {
|
||||
ret = PyList_New(1);
|
||||
PyList_SET_ITEM(ret, 0, PyUnicode_FromString("rna"));
|
||||
}
|
||||
else if ( strcmp( name, "rna" ) == 0 ) {
|
||||
BPy_StructRNA *pyrna;
|
||||
PointerRNA ptr;
|
||||
//IDProperty *properties = NULL;
|
||||
wmOperatorType *ot;
|
||||
|
||||
ot= WM_operatortype_find(self->name);
|
||||
if (ot == NULL) {
|
||||
PyErr_SetString( PyExc_SystemError, "Operator could not be found");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pyrna= (BPy_StructRNA *)pyrna_struct_CreatePyObject(&ptr); /* were not really using &ptr, overwite next */
|
||||
|
||||
/* XXX POINTER - if this 'ot' is python generated, it could be free'd */
|
||||
RNA_pointer_create(NULL, NULL, ot->srna, &pyrna->properties, &pyrna->ptr);
|
||||
ret= (PyObject *)pyrna;
|
||||
else if ((ret = PyObject_GenericGetAttr((PyObject *)self, pyname))) {
|
||||
/* do nothing, this accounts for methoddef's add and remove */
|
||||
}
|
||||
else {
|
||||
PyErr_Format( PyExc_AttributeError, "Operator \"%s\" not found", name);
|
||||
ret= NULL;
|
||||
}
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* getseter's */
|
||||
PyObject *pyop_func_get_rna(BPy_OperatorFunc *self)
|
||||
{
|
||||
BPy_StructRNA *pyrna;
|
||||
PointerRNA ptr;
|
||||
wmOperatorType *ot;
|
||||
|
||||
ot= WM_operatortype_find(self->name);
|
||||
if (ot == NULL) {
|
||||
PyErr_SetString( PyExc_SystemError, "Operator could not be found");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pyrna= (BPy_StructRNA *)pyrna_struct_CreatePyObject(&ptr); /* were not really using &ptr, overwite next */
|
||||
|
||||
/* XXX POINTER - if this 'ot' is python generated, it could be free'd */
|
||||
RNA_pointer_create(NULL, NULL, ot->srna, &pyrna->properties, &pyrna->ptr);
|
||||
return (PyObject *)pyrna;
|
||||
}
|
||||
|
||||
static PyGetSetDef pyop_func_getseters[] = {
|
||||
{"rna", (getter)pyop_func_get_rna, (setter)NULL, "vertex's coordinate", NULL},
|
||||
{NULL,NULL,NULL,NULL,NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
static PyObject * pyop_func_call(BPy_OperatorFunc * self, PyObject *args, PyObject *kw)
|
||||
{
|
||||
IDProperty *properties = NULL;
|
||||
@@ -234,8 +203,6 @@ static PyObject * pyop_func_call(BPy_OperatorFunc * self, PyObject *args, PyObje
|
||||
IDP_FreeProperty(properties);
|
||||
MEM_freeN(properties);
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
/* if there is some way to know an operator takes args we should use this */
|
||||
{
|
||||
@@ -256,6 +223,37 @@ static PyObject * pyop_func_call(BPy_OperatorFunc * self, PyObject *args, PyObje
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static struct PyMethodDef pyop_base_methods[];
|
||||
|
||||
PyObject *pyop_base_dir(PyObject *self)
|
||||
{
|
||||
PyObject *ret = PyList_New(0);
|
||||
PyObject *item;
|
||||
wmOperatorType *ot;
|
||||
PyMethodDef *meth;
|
||||
|
||||
for(ot= WM_operatortype_first(); ot; ot= ot->next) {
|
||||
item = PyUnicode_FromString( ot->idname );
|
||||
PyList_Append(ret, item);
|
||||
Py_DECREF(item);
|
||||
}
|
||||
|
||||
for(meth=pyop_base_methods; meth->ml_name; meth++) {
|
||||
item = PyUnicode_FromString( meth->ml_name );
|
||||
PyList_Append(ret, item);
|
||||
Py_DECREF(item);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static struct PyMethodDef pyop_base_methods[] = {
|
||||
{"add", (PyCFunction)PYOP_wrap_add, METH_VARARGS, ""},
|
||||
{"remove", (PyCFunction)PYOP_wrap_remove, METH_VARARGS, ""},
|
||||
{"__dir__", (PyCFunction)pyop_base_dir, METH_NOARGS, ""},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
/*-----------------------BPy_OperatorBase method def------------------------------*/
|
||||
PyTypeObject pyop_base_Type = {
|
||||
#if (PY_VERSION_HEX >= 0x02060000)
|
||||
@@ -318,9 +316,9 @@ PyTypeObject pyop_base_Type = {
|
||||
NULL, /* iternextfunc tp_iternext; */
|
||||
|
||||
/*** Attribute descriptor and subclassing stuff ***/
|
||||
NULL, /* struct PyMethodDef *tp_methods; */
|
||||
pyop_base_methods, /* struct PyMethodDef *tp_methods; */
|
||||
NULL, /* struct PyMemberDef *tp_members; */
|
||||
NULL, /* struct PyGetSetDef *tp_getset; */
|
||||
NULL, /* struct PyGetSetDef *tp_getset; */
|
||||
NULL, /* struct _typeobject *tp_base; */
|
||||
NULL, /* PyObject *tp_dict; */
|
||||
NULL, /* descrgetfunc tp_descr_get; */
|
||||
@@ -374,7 +372,7 @@ PyTypeObject pyop_func_Type = {
|
||||
NULL, /* hashfunc tp_hash; */
|
||||
(ternaryfunc)pyop_func_call, /* ternaryfunc tp_call; */
|
||||
NULL, /* reprfunc tp_str; */
|
||||
( getattrofunc ) pyop_func_getattro, /* getattrofunc tp_getattro; */
|
||||
NULL, /* getattrofunc tp_getattro; */
|
||||
NULL, /*PyObject_GenericSetAttr - MINGW Complains, assign later */ /* setattrofunc tp_setattro; */
|
||||
|
||||
/* Functions to access object as input/output buffer */
|
||||
@@ -406,7 +404,7 @@ PyTypeObject pyop_func_Type = {
|
||||
/*** Attribute descriptor and subclassing stuff ***/
|
||||
NULL, /* struct PyMethodDef *tp_methods; */
|
||||
NULL, /* struct PyMemberDef *tp_members; */
|
||||
NULL, /* struct PyGetSetDef *tp_getset; */
|
||||
pyop_func_getseters, /* struct PyGetSetDef *tp_getset; */
|
||||
NULL, /* struct _typeobject *tp_base; */
|
||||
NULL, /* PyObject *tp_dict; */
|
||||
NULL, /* descrgetfunc tp_descr_get; */
|
||||
|
||||
@@ -322,7 +322,7 @@ void PYTHON_OT_wrapper(wmOperatorType *ot, void *userdata)
|
||||
}
|
||||
|
||||
/* pyOperators - Operators defined IN Python */
|
||||
static PyObject *pyop_add(PyObject *self, PyObject *args)
|
||||
PyObject *PYOP_wrap_add(PyObject *self, PyObject *args)
|
||||
{
|
||||
PyOperatorType *pyot;
|
||||
|
||||
@@ -360,7 +360,7 @@ static PyObject *pyop_add(PyObject *self, PyObject *args)
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *pyop_remove(PyObject *self, PyObject *args)
|
||||
PyObject *PYOP_wrap_remove(PyObject *self, PyObject *args)
|
||||
{
|
||||
char *idname= NULL;
|
||||
wmOperatorType *ot;
|
||||
@@ -388,20 +388,3 @@ static PyObject *pyop_remove(PyObject *self, PyObject *args)
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyMethodDef pyop_add_methdef[] = {
|
||||
{"add", pyop_add, METH_VARARGS, ""}
|
||||
};
|
||||
|
||||
static PyMethodDef pyop_remove_methdef[] = {
|
||||
{"remove", pyop_remove, METH_VARARGS, ""}
|
||||
};
|
||||
|
||||
PyObject *PYOP_wrap_add_func( void )
|
||||
{
|
||||
return PyCFunction_New( pyop_add_methdef, NULL );
|
||||
}
|
||||
PyObject *PYOP_wrap_remove_func( void )
|
||||
{
|
||||
return PyCFunction_New( pyop_remove_methdef, NULL );
|
||||
}
|
||||
|
||||
|
||||
@@ -27,9 +27,9 @@
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
/* returns the python functions */
|
||||
PyObject *PYOP_wrap_add_func( void );
|
||||
PyObject *PYOP_wrap_remove_func( void );
|
||||
/* these are used for operator methods, used by bpy_operator.c */
|
||||
PyObject *PYOP_wrap_add(PyObject *self, PyObject *args);
|
||||
PyObject *PYOP_wrap_remove(PyObject *self, PyObject *args);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -702,27 +702,7 @@ static PyObject *pyrna_struct_getattro( BPy_StructRNA * self, PyObject *pyname )
|
||||
else PyErr_Clear();
|
||||
/* done with subtypes */
|
||||
|
||||
if( strcmp( name, "__members__" ) == 0 ) {
|
||||
PyObject *item;
|
||||
|
||||
PropertyRNA *iterprop;
|
||||
CollectionPropertyIterator iter;
|
||||
|
||||
ret = PyList_New(0);
|
||||
|
||||
iterprop= RNA_struct_iterator_property(&self->ptr);
|
||||
RNA_property_collection_begin(&self->ptr, iterprop, &iter);
|
||||
|
||||
|
||||
for(; iter.valid; RNA_property_collection_next(&iter)) {
|
||||
prop = iter.ptr.data;
|
||||
item = PyUnicode_FromString( RNA_property_identifier(&iter.ptr, prop) );
|
||||
PyList_Append(ret, item);
|
||||
Py_DECREF(item);
|
||||
}
|
||||
|
||||
RNA_property_collection_end(&iter);
|
||||
} else if ( strcmp( name, "__doc__" ) == 0 ) {
|
||||
if ( strcmp( name, "__doc__" ) == 0 ) {
|
||||
ret = pyrna_struct_to_docstring(self);
|
||||
} else {
|
||||
prop = RNA_struct_find_property(&self->ptr, name);
|
||||
@@ -758,6 +738,32 @@ static int pyrna_struct_setattro( BPy_StructRNA * self, PyObject *pyname, PyObje
|
||||
return pyrna_py_to_prop(&self->ptr, prop, value);
|
||||
}
|
||||
|
||||
static PyObject *pyrna_struct_dir( BPy_StructRNA * self )
|
||||
{
|
||||
PyObject *ret = PyList_New(0);
|
||||
PyObject *item;
|
||||
PropertyRNA *prop;
|
||||
PropertyRNA *iterprop;
|
||||
CollectionPropertyIterator iter;
|
||||
|
||||
iterprop= RNA_struct_iterator_property(&self->ptr);
|
||||
RNA_property_collection_begin(&self->ptr, iterprop, &iter);
|
||||
|
||||
|
||||
for(; iter.valid; RNA_property_collection_next(&iter)) {
|
||||
prop = iter.ptr.data;
|
||||
item = PyUnicode_FromString( RNA_property_identifier(&iter.ptr, prop) );
|
||||
PyList_Append(ret, item);
|
||||
Py_DECREF(item);
|
||||
}
|
||||
|
||||
RNA_property_collection_end(&iter);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
PyObject *pyrna_prop_keys(BPy_PropertyRNA *self)
|
||||
{
|
||||
PyObject *ret;
|
||||
@@ -896,6 +902,10 @@ PyObject *pyrna_prop_iter(BPy_PropertyRNA *self)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct PyMethodDef pyrna_struct_methods[] = {
|
||||
{"__dir__", (PyCFunction)pyrna_struct_dir, METH_NOARGS, ""},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
static struct PyMethodDef pyrna_prop_methods[] = {
|
||||
{"keys", (PyCFunction)pyrna_prop_keys, METH_NOARGS, ""},
|
||||
@@ -1002,7 +1012,7 @@ PyTypeObject pyrna_struct_Type = {
|
||||
NULL, /* iternextfunc tp_iternext; */
|
||||
|
||||
/*** Attribute descriptor and subclassing stuff ***/
|
||||
NULL, /* struct PyMethodDef *tp_methods; */
|
||||
pyrna_struct_methods, /* struct PyMethodDef *tp_methods; */
|
||||
NULL, /* struct PyMemberDef *tp_members; */
|
||||
NULL, /* struct PyGetSetDef *tp_getset; */
|
||||
NULL, /* struct _typeobject *tp_base; */
|
||||
|
||||
Reference in New Issue
Block a user