diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-04-08 22:45:41 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-04-08 22:45:41 +0400 |
commit | 25d0720dc471926f63a628dc1d24d851c550ceaa (patch) | |
tree | 4d7ba9a2a13d6514f8c8e7a41c8605a3813cab50 | |
parent | d979085614629c05f87715f1cc78bb2640498a21 (diff) |
2.5:
* Fix to make python panels callbacks get the actual
blender Panel as an argument, instead of any instance.
* Fix for callback validation in python 2.5, worked OK
in python 3.0 but gave error in 2.5 because it's a
method instead of a function there.
-rw-r--r-- | source/blender/blenkernel/BKE_screen.h | 4 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_panel_wrap.c | 10 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_util.c | 11 |
3 files changed, 19 insertions, 6 deletions
diff --git a/source/blender/blenkernel/BKE_screen.h b/source/blender/blenkernel/BKE_screen.h index a25a7cff51d..e43b2b3b737 100644 --- a/source/blender/blenkernel/BKE_screen.h +++ b/source/blender/blenkernel/BKE_screen.h @@ -44,6 +44,7 @@ struct wmWindow; struct wmWindowManager; struct uiLayout; struct uiMenuItem; +struct StructRNA; /* spacetype has everything stored to get an editor working, it gets initialized via ED_spacetypes_init() in editors/area/spacetypes.c */ @@ -152,7 +153,8 @@ typedef struct PanelType { void (*draw)(const struct bContext *, struct Panel *); /* python integration */ - void *py_data; + void *py_data; + struct StructRNA *srna; } PanelType; /* header types */ diff --git a/source/blender/python/intern/bpy_panel_wrap.c b/source/blender/python/intern/bpy_panel_wrap.c index 044ac3eefdb..25fcd34fea5 100644 --- a/source/blender/python/intern/bpy_panel_wrap.c +++ b/source/blender/python/intern/bpy_panel_wrap.c @@ -47,15 +47,17 @@ static int PyPanel_generic(int mode, const bContext *C, Panel *pnl) { PyObject *py_class= (PyObject *)(pnl->type->py_data); - //uiLayout *layout= pnl->layout; PyObject *args; PyObject *ret= NULL, *py_class_instance, *item; + PointerRNA panelptr; int ret_flag= 0; PyGILState_STATE gilstate = PyGILState_Ensure(); - args = PyTuple_New(0); + args = PyTuple_New(1); + RNA_pointer_create(&CTX_wm_screen(C)->id, pnl->type->srna, pnl, &panelptr); + PyTuple_SET_ITEM(args, 0, pyrna_struct_CreatePyObject(&panelptr)); py_class_instance = PyObject_Call(py_class, args, NULL); Py_DECREF(args); @@ -211,6 +213,10 @@ PyObject *PyPanel_wrap_add(PyObject *self, PyObject *args) pt->py_data= (void *)py_class; BLI_addtail(&art->paneltypes, pt); + + pt->srna= RNA_def_struct(&BLENDER_RNA, pt->idname, "Panel"); + RNA_struct_py_type_set(pt->srna, py_class); + Py_RETURN_NONE; } diff --git a/source/blender/python/intern/bpy_util.c b/source/blender/python/intern/bpy_util.c index 347b914a030..0623124009c 100644 --- a/source/blender/python/intern/bpy_util.c +++ b/source/blender/python/intern/bpy_util.c @@ -244,7 +244,7 @@ PyObject *PyObject_GetAttrStringArgs(PyObject *o, Py_ssize_t n, ...) int BPY_class_validate(const char *class_type, PyObject *class, PyObject *base_class, BPY_class_attr_check* class_attrs, PyObject **py_class_attrs) { - PyObject *item; + PyObject *item, *fitem; PyObject *py_arg_count; int i, arg_count; @@ -292,12 +292,17 @@ int BPY_class_validate(const char *class_type, PyObject *class, PyObject *base_c } break; case 'f': - if (PyFunction_Check(item)==0) { + if (PyMethod_Check(item)) + fitem= PyMethod_Function(item); /* py 2.x */ + else + fitem= item; /* py 3.x */ + + if (PyFunction_Check(fitem)==0) { PyErr_Format( PyExc_AttributeError, "expected %s class \"%s\" attribute to be a function", class_type, class_attrs->name); return -1; } if (class_attrs->arg_count >= 0) { /* -1 if we dont care*/ - py_arg_count = PyObject_GetAttrString(PyFunction_GET_CODE(item), "co_argcount"); + py_arg_count = PyObject_GetAttrString(PyFunction_GET_CODE(fitem), "co_argcount"); arg_count = PyLong_AsSsize_t(py_arg_count); Py_DECREF(py_arg_count); |