diff options
author | Campbell Barton <ideasman42@gmail.com> | 2021-02-25 04:00:45 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2021-02-25 04:04:23 +0300 |
commit | c47990f41c7364058a72f5f162e5cdc06bce0adc (patch) | |
tree | cc41a51264a77032aa18212cb8574e7abda36792 /source/blender | |
parent | 17260c9b9a2c591e5269b5025f884630f7aa66c6 (diff) |
PyAPI: expose imbuf.types.ImBuf, include in API docs
Without this, the ImBuf type wasn't part of documentation.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/python/generic/imbuf_py_api.c | 48 |
1 files changed, 45 insertions, 3 deletions
diff --git a/source/blender/python/generic/imbuf_py_api.c b/source/blender/python/generic/imbuf_py_api.c index fe72f267a5d..5b4a4fd237e 100644 --- a/source/blender/python/generic/imbuf_py_api.c +++ b/source/blender/python/generic/imbuf_py_api.c @@ -40,6 +40,8 @@ #include <errno.h> #include <fcntl.h> +static PyObject *BPyInit_imbuf_types(void); + static PyObject *Py_ImBuf_CreatePyObject(ImBuf *ibuf); /* -------------------------------------------------------------------- */ @@ -522,7 +524,7 @@ static PyObject *M_imbuf_write(PyObject *UNUSED(self), PyObject *args, PyObject /** \} */ /* -------------------------------------------------------------------- */ -/** \name Module Definition +/** \name Module Definition (`imbuf`) * \{ */ static PyMethodDef IMB_methods[] = { @@ -547,11 +549,51 @@ static struct PyModuleDef IMB_module_def = { PyObject *BPyInit_imbuf(void) { + PyObject *mod; PyObject *submodule; + PyObject *sys_modules = PyImport_GetModuleDict(); + + mod = PyModule_Create(&IMB_module_def); + + /* `imbuf.types` */ + PyModule_AddObject(mod, "types", (submodule = BPyInit_imbuf_types())); + PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule); + + return mod; +} - submodule = PyModule_Create(&IMB_module_def); +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Module Definition (`imbuf.types`) + * + * `imbuf.types` module, only include this to expose access to `imbuf.types.ImBuf` + * for docs and the ability to use with built-ins such as `isinstance`, `issubclass`. + * \{ */ + +PyDoc_STRVAR(IMB_types_doc, "This module provides access to image buffer types."); + +static struct PyModuleDef IMB_types_module_def = { + PyModuleDef_HEAD_INIT, + "imbuf.types", /* m_name */ + IMB_types_doc, /* m_doc */ + 0, /* m_size */ + NULL, /* m_methods */ + NULL, /* m_reload */ + NULL, /* m_traverse */ + NULL, /* m_clear */ + NULL, /* m_free */ +}; + +PyObject *BPyInit_imbuf_types(void) +{ + PyObject *submodule = PyModule_Create(&IMB_types_module_def); + + if (PyType_Ready(&Py_ImBuf_Type) < 0) { + return NULL; + } - PyType_Ready(&Py_ImBuf_Type); + PyModule_AddType(submodule, &Py_ImBuf_Type); return submodule; } |