diff options
author | Campbell Barton <ideasman42@gmail.com> | 2020-09-01 08:23:55 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2020-09-02 08:58:44 +0300 |
commit | 428a1aaf7372aaad793fe7cc03128db18e3ae602 (patch) | |
tree | 8ff7b138f3d666d9533e63b448519611c673d009 /source/blender/python | |
parent | 89ed6b12936bc2a89b18cf6dbd7b86e0fbc760d3 (diff) |
UI: add back Layout.introspect
Add back this function, removed 2e14b7fb9770b.
Useful for checking operators used in menus.
Diffstat (limited to 'source/blender/python')
-rw-r--r-- | source/blender/python/intern/CMakeLists.txt | 2 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna.c | 7 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna_types_capi.c | 17 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna_ui.c | 58 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna_ui.h | 31 |
5 files changed, 112 insertions, 3 deletions
diff --git a/source/blender/python/intern/CMakeLists.txt b/source/blender/python/intern/CMakeLists.txt index 44949c478cc..b50aee73a13 100644 --- a/source/blender/python/intern/CMakeLists.txt +++ b/source/blender/python/intern/CMakeLists.txt @@ -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 diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index a3ded8813ac..cc981c7c2e1 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -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); diff --git a/source/blender/python/intern/bpy_rna_types_capi.c b/source/blender/python/intern/bpy_rna_types_capi.c index 5a2ba4a5cdb..30623724593 100644 --- a/source/blender/python/intern/bpy_rna_types_capi.c +++ b/source/blender/python/intern/bpy_rna_types_capi.c @@ -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" @@ -73,6 +74,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 * * Avoid using the RNA API because this value may change between checking it's length @@ -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); diff --git a/source/blender/python/intern/bpy_rna_ui.c b/source/blender/python/intern/bpy_rna_ui.c new file mode 100644 index 00000000000..9f37b8300db --- /dev/null +++ b/source/blender/python/intern/bpy_rna_ui.c @@ -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, +}; diff --git a/source/blender/python/intern/bpy_rna_ui.h b/source/blender/python/intern/bpy_rna_ui.h new file mode 100644 index 00000000000..bd2e87aae40 --- /dev/null +++ b/source/blender/python/intern/bpy_rna_ui.h @@ -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 |