PyDoc: add bpy_prop_collection_idprop class document

Ref: !132587
This commit is contained in:
nutti
2025-01-03 17:53:10 +09:00
committed by Campbell Barton
parent aa81aed109
commit 10e3e3b4a0
2 changed files with 59 additions and 4 deletions

View File

@@ -598,6 +598,7 @@ from types import (
_BPY_STRUCT_FAKE = "bpy_struct"
_BPY_PROP_COLLECTION_FAKE = "bpy_prop_collection"
_BPY_PROP_COLLECTION_IDPROP_FAKE = "bpy_prop_collection_idprop"
if _BPY_PROP_COLLECTION_FAKE:
_BPY_PROP_COLLECTION_ID = ":class:`{:s}`".format(_BPY_PROP_COLLECTION_FAKE)
@@ -1871,6 +1872,13 @@ def pyrna2sphinx(basepath):
"built-in class used for all collections.", use_subclasses=False,
)
if _BPY_PROP_COLLECTION_IDPROP_FAKE:
class_value = bpy.data.objects.__class__
fake_bpy_type(
"bpy.types", class_value, _BPY_PROP_COLLECTION_IDPROP_FAKE,
"built-in class used for user defined collections.", use_subclasses=False,
)
# Operators.
def write_ops():
API_BASEURL = "https://projects.blender.org/blender/blender/src/branch/main/scripts"

View File

@@ -4897,6 +4897,15 @@ static int pyrna_prop_collection_setattro(BPy_PropertyRNA *self, PyObject *pynam
/**
* Odd case, we need to be able return a Python method from a #PyTypeObject.tp_getset.
*/
PyDoc_STRVAR(
/* Wrap. */
pyrna_prop_collection_idprop_add_doc,
".. method:: add()\n"
"\n"
" This is a function to add a new item to a collection.\n"
"\n"
" :return: A newly created item.\n"
" :rtype: Any\n");
static PyObject *pyrna_prop_collection_idprop_add(BPy_PropertyRNA *self)
{
PointerRNA r_ptr;
@@ -4917,6 +4926,15 @@ static PyObject *pyrna_prop_collection_idprop_add(BPy_PropertyRNA *self)
return pyrna_struct_CreatePyObject(&r_ptr);
}
PyDoc_STRVAR(
/* Wrap. */
pyrna_prop_collection_idprop_remove_doc,
".. method:: remove(index)\n"
"\n"
" This is a function to remove an item from a collection.\n"
"\n"
" :arg index: Index of the item to be removed.\n"
" :type index: int\n");
static PyObject *pyrna_prop_collection_idprop_remove(BPy_PropertyRNA *self, PyObject *value)
{
const int key = PyLong_AsLong(value);
@@ -4941,6 +4959,12 @@ static PyObject *pyrna_prop_collection_idprop_remove(BPy_PropertyRNA *self, PyOb
Py_RETURN_NONE;
}
PyDoc_STRVAR(
/* Wrap. */
pyrna_prop_collection_idprop_clear_doc,
".. method:: clear()\n"
"\n"
" This is a function to remove all items from a collection.\n");
static PyObject *pyrna_prop_collection_idprop_clear(BPy_PropertyRNA *self)
{
#ifdef USE_PEDANTIC_WRITE
@@ -4954,6 +4978,17 @@ static PyObject *pyrna_prop_collection_idprop_clear(BPy_PropertyRNA *self)
Py_RETURN_NONE;
}
PyDoc_STRVAR(
/* Wrap. */
pyrna_prop_collection_idprop_move_doc,
".. method:: move(src_index, dst_index)\n"
"\n"
" This is a function to move an item in a collection.\n"
"\n"
" :arg src_index: Source item index.\n"
" :type src_index: int\n"
" :arg dst_index: Destination item index.\n"
" :type dst_index: int\n");
static PyObject *pyrna_prop_collection_idprop_move(BPy_PropertyRNA *self, PyObject *args)
{
int key = 0, pos = 0;
@@ -6184,10 +6219,22 @@ static PyMethodDef pyrna_prop_collection_methods[] = {
};
static PyMethodDef pyrna_prop_collection_idprop_methods[] = {
{"add", (PyCFunction)pyrna_prop_collection_idprop_add, METH_NOARGS, nullptr},
{"remove", (PyCFunction)pyrna_prop_collection_idprop_remove, METH_O, nullptr},
{"clear", (PyCFunction)pyrna_prop_collection_idprop_clear, METH_NOARGS, nullptr},
{"move", (PyCFunction)pyrna_prop_collection_idprop_move, METH_VARARGS, nullptr},
{"add",
(PyCFunction)pyrna_prop_collection_idprop_add,
METH_NOARGS,
pyrna_prop_collection_idprop_add_doc},
{"remove",
(PyCFunction)pyrna_prop_collection_idprop_remove,
METH_O,
pyrna_prop_collection_idprop_remove_doc},
{"clear",
(PyCFunction)pyrna_prop_collection_idprop_clear,
METH_NOARGS,
pyrna_prop_collection_idprop_clear_doc},
{"move",
(PyCFunction)pyrna_prop_collection_idprop_move,
METH_VARARGS,
pyrna_prop_collection_idprop_move_doc},
{nullptr, nullptr, 0, nullptr},
};