PyAPI: support PyGetSetDef when extending RNA types
Support extending properties as well as methods.
This commit is contained in:
@@ -9034,9 +9034,11 @@ static PyObject *pyrna_unregister_class(PyObject *UNUSED(self), PyObject *py_cla
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extend RNA types with C/API methods.
|
* Extend RNA types with C/API methods, properties.
|
||||||
*/
|
*/
|
||||||
void pyrna_struct_type_extend_capi(struct StructRNA *srna, struct PyMethodDef *method)
|
void pyrna_struct_type_extend_capi(struct StructRNA *srna,
|
||||||
|
struct PyMethodDef *method,
|
||||||
|
struct PyGetSetDef *getset)
|
||||||
{
|
{
|
||||||
PyObject *cls = pyrna_srna_Subtype(srna);
|
PyObject *cls = pyrna_srna_Subtype(srna);
|
||||||
if (method != NULL) {
|
if (method != NULL) {
|
||||||
@@ -9052,6 +9054,16 @@ void pyrna_struct_type_extend_capi(struct StructRNA *srna, struct PyMethodDef *m
|
|||||||
Py_DECREF(args); /* Clears 'func' too. */
|
Py_DECREF(args); /* Clears 'func' too. */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (getset != NULL) {
|
||||||
|
for (; getset->name != NULL; getset++) {
|
||||||
|
PyObject *dict = ((PyTypeObject *)cls)->tp_dict;
|
||||||
|
PyObject *descr = PyDescr_NewGetSet((PyTypeObject *)cls, getset);
|
||||||
|
BLI_assert(PyDict_GetItem(dict, PyDescr_NAME(descr)) == NULL);
|
||||||
|
PyDict_SetItem(dict, PyDescr_NAME(descr), descr);
|
||||||
|
Py_DECREF(descr);
|
||||||
|
}
|
||||||
|
}
|
||||||
Py_DECREF(cls);
|
Py_DECREF(cls);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -220,7 +220,9 @@ int pyrna_enum_value_from_id(const EnumPropertyItem *item,
|
|||||||
|
|
||||||
int pyrna_deferred_register_class(struct StructRNA *srna, PyTypeObject *py_class);
|
int pyrna_deferred_register_class(struct StructRNA *srna, PyTypeObject *py_class);
|
||||||
|
|
||||||
void pyrna_struct_type_extend_capi(struct StructRNA *srna, struct PyMethodDef *py_method);
|
void pyrna_struct_type_extend_capi(struct StructRNA *srna,
|
||||||
|
struct PyMethodDef *py_method,
|
||||||
|
struct PyGetSetDef *py_getset);
|
||||||
|
|
||||||
/* called before stopping python */
|
/* called before stopping python */
|
||||||
void pyrna_alloc_types(void);
|
void pyrna_alloc_types(void);
|
||||||
|
|||||||
@@ -121,9 +121,8 @@ static struct PyMethodDef pyrna_space_methods[] = {
|
|||||||
|
|
||||||
void BPY_rna_types_extend_capi(void)
|
void BPY_rna_types_extend_capi(void)
|
||||||
{
|
{
|
||||||
pyrna_struct_type_extend_capi(&RNA_Space, pyrna_space_methods);
|
pyrna_struct_type_extend_capi(&RNA_Space, pyrna_space_methods, NULL);
|
||||||
pyrna_struct_type_extend_capi(
|
pyrna_struct_type_extend_capi(&RNA_WindowManager, pyrna_windowmanager_methods, NULL);
|
||||||
&RNA_WindowManager, pyrna_windowmanager_methods);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** \} */
|
/** \} */
|
||||||
|
|||||||
Reference in New Issue
Block a user