UI: add back Layout.introspect

Add back this function, removed 2e14b7fb97.

Useful for checking operators used in menus.
This commit is contained in:
2020-09-01 15:23:55 +10:00
parent 89ed6b1293
commit 428a1aaf73
7 changed files with 239 additions and 3 deletions

View File

@@ -79,6 +79,7 @@ set(SRC
bpy_rna_gizmo.c
bpy_rna_id_collection.c
bpy_rna_types_capi.c
bpy_rna_ui.c
bpy_traceback.c
bpy_utils_previews.c
bpy_utils_units.c
@@ -116,6 +117,7 @@ set(SRC
bpy_rna_gizmo.h
bpy_rna_id_collection.h
bpy_rna_types_capi.h
bpy_rna_ui.h
bpy_traceback.h
bpy_utils_previews.h
bpy_utils_units.h

View File

@@ -9010,11 +9010,12 @@ void pyrna_struct_type_extend_capi(struct StructRNA *srna,
py_method = PyClassMethod_New(cfunc);
Py_DECREF(cfunc);
}
else {
/* Currently only static and class methods are used. */
BLI_assert(method->ml_flags & METH_STATIC);
else if (method->ml_flags & METH_STATIC) {
py_method = PyCFunction_New(method, NULL);
}
else {
py_method = PyDescr_NewMethod(type, method);
}
const int err = PyDict_SetItemString(dict, method->ml_name, py_method);
Py_DECREF(py_method);

View File

@@ -38,6 +38,7 @@
#include "bpy_rna_callback.h"
#include "bpy_rna_id_collection.h"
#include "bpy_rna_types_capi.h"
#include "bpy_rna_ui.h"
#include "../generic/py_capi_utils.h"
@@ -72,6 +73,17 @@ static struct PyMethodDef pyrna_blenddatalibraries_methods[] = {
/** \} */
/* -------------------------------------------------------------------- */
/** \name UI Layout
* \{ */
static struct PyMethodDef pyrna_uilayout_methods[] = {
{NULL, NULL, 0, NULL}, /* #BPY_rna_uilayout_introspect_method_def */
{NULL, NULL, 0, NULL},
};
/** \} */
/* -------------------------------------------------------------------- */
/** \name Window Manager Clipboard Property
*
@@ -205,6 +217,11 @@ void BPY_rna_types_extend_capi(void)
BLI_assert(ARRAY_SIZE(pyrna_blenddatalibraries_methods) == 3);
pyrna_struct_type_extend_capi(&RNA_BlendDataLibraries, pyrna_blenddatalibraries_methods, NULL);
/* uiLayout */
ARRAY_SET_ITEMS(pyrna_uilayout_methods, BPY_rna_uilayout_introspect_method_def);
BLI_assert(ARRAY_SIZE(pyrna_uilayout_methods) == 2);
pyrna_struct_type_extend_capi(&RNA_UILayout, pyrna_uilayout_methods, NULL);
/* Space */
pyrna_struct_type_extend_capi(&RNA_Space, pyrna_space_methods, NULL);

View File

@@ -0,0 +1,58 @@
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/** \file
* \ingroup pythonintern
*
* This adds helpers to #uiLayout which can't be added easily to RNA it's self.
*/
#include <Python.h>
#include "MEM_guardedalloc.h"
#include "../generic/py_capi_utils.h"
#include "UI_interface.h"
#include "bpy_rna.h"
PyDoc_STRVAR(bpy_rna_uilayout_introspect_doc,
".. method:: introspect()\n"
"\n"
" Return a dictionary containing a textual representation of the UI layout.\n");
static PyObject *bpy_rna_uilayout_introspect(PyObject *self)
{
BPy_StructRNA *pyrna = (BPy_StructRNA *)self;
uiLayout *layout = pyrna->ptr.data;
const char *expr = UI_layout_introspect(layout);
PyObject *main_mod = NULL;
PyC_MainModule_Backup(&main_mod);
PyObject *py_dict = PyC_DefaultNameSpace("<introspect>");
PyObject *result = PyRun_String(expr, Py_eval_input, py_dict, py_dict);
MEM_freeN((void *)expr);
Py_DECREF(py_dict);
PyC_MainModule_Restore(main_mod);
return result;
}
PyMethodDef BPY_rna_uilayout_introspect_method_def = {
"introspect",
(PyCFunction)bpy_rna_uilayout_introspect,
METH_NOARGS,
bpy_rna_uilayout_introspect_doc,
};

View File

@@ -0,0 +1,31 @@
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/** \file
* \ingroup pythonintern
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
extern PyMethodDef BPY_rna_uilayout_introspect_method_def;
#ifdef __cplusplus
}
#endif