Commit: a8b50c168927b87bb4cef679854476cb77d3fb55 Author: Campbell Barton Date: Mon Jun 5 22:09:49 2017 +1000 Branches: custom-manipulators https://developer.blender.org/rBa8b50c168927b87bb4cef679854476cb77d3fb55
PyAPI: widget group (un)register working again WIP, not yet usable. =================================================================== M build_files/cmake/macros.cmake M source/blender/makesrna/intern/rna_wm.c M source/blender/python/intern/CMakeLists.txt A source/blender/python/intern/bpy_widgetgroup_wrap.c A source/blender/python/intern/bpy_widgetgroup_wrap.h M source/blender/windowmanager/manipulators/WM_manipulator_api.h M source/blender/windowmanager/manipulators/WM_manipulator_types.h M source/blender/windowmanager/manipulators/intern/wm_manipulatorgroup.c M source/blenderplayer/bad_level_call_stubs/stubs.c =================================================================== diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake index 92342d580c3..e327425949c 100644 --- a/build_files/cmake/macros.cmake +++ b/build_files/cmake/macros.cmake @@ -611,6 +611,7 @@ function(SETUP_BLENDER_SORTED_LIBS) bf_physics bf_nodes bf_rna + bf_python bf_imbuf bf_blenlib bf_depsgraph diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c index 7e411d4ad05..c59dd72b27d 100644 --- a/source/blender/makesrna/intern/rna_wm.c +++ b/source/blender/makesrna/intern/rna_wm.c @@ -1568,12 +1568,11 @@ static void rna_WidgetGroup_unregister(struct Main *bmain, StructRNA *type) WM_main_add_notifier(NC_SCREEN | NA_EDITED, NULL); - //RNA_struct_free_extension(type, &wgrouptype->ext); + RNA_struct_free_extension(type, &wgrouptype->ext); WM_manipulatorgrouptype_unregister(NULL, bmain, wgrouptype); //WM_operatortype_remove_ptr(ot); - /* not to be confused with the RNA_struct_free that WM_operatortype_remove calls, they are 2 different srna's */ RNA_struct_free(&BLENDER_RNA, type); } @@ -1669,14 +1668,14 @@ static void operator_cancel(bContext *C, wmManipulatorGroup *op) } #endif -void widgetgroup_wrapper(wmManipulatorGroupType *ot, void *userdata); +void widgetgroup_wrapper(wmManipulatorGroupType *mgrouptype, void *userdata); static StructRNA *rna_WidgetGroup_register( Main *bmain, ReportList *reports, void *data, const char *identifier, StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free) { - wmManipulatorGroupType *wgrouptype, dummywgt = {NULL}; + wmManipulatorGroupType dummywgt = {NULL}; wmManipulatorGroup dummywg = {NULL}; PointerRNA wgptr; int have_function[3]; @@ -1697,7 +1696,9 @@ static StructRNA *rna_WidgetGroup_register( /* check if the area supports widgets */ const struct wmManipulatorMapType_Params wmap_params = { - dummywgt.mapidname, dummywgt.spaceid, dummywgt.regionid + .idname = dummywgt.idname, + .spaceid = dummywgt.spaceid, + .regionid = dummywgt.regionid, }; wmManipulatorMapType *wmaptype = WM_manipulatormaptype_ensure(&wmap_params); @@ -1706,54 +1707,37 @@ static StructRNA *rna_WidgetGroup_register( return NULL; } -#if 0 /* check if we have registered this widgetgroup type before, and remove it */ { - //wmManipulatorGroupType *ot = WM_manipulatorrouptype_find(dummywgt.idname, true); - if (ot && ot->ext.srna) - rna_WidgetGroup_unregister(bmain, ot->ext.srna); + wmManipulatorGroupType *wgrouptype = WM_manipulatorgrouptype_find(wmaptype, dummywgt.idname); + if (wgrouptype && wgrouptype->ext.srna) { + printf("Unregister!\n"); + WM_main_add_notifier(NC_SCREEN | NA_EDITED, NULL); + WM_manipulatorgrouptype_unregister(NULL, bmain, wgrouptype); + } } -#endif - /* XXX, this doubles up with the widgetgroup name [#29666] - * for now just remove from dir(bpy.types) */ + /* create a new widgetgroup type */ + dummywgt.ext.srna = RNA_def_struct_ptr(&BLENDER_RNA, dummywgt.idname, &RNA_WidgetGroup); + RNA_def_struct_flag(dummywgt.ext.srna, STRUCT_NO_IDPROPERTIES); /* widgetgroup properties are registered separately */ + dummywgt.ext.data = data; + dummywgt.ext.call = call; + dummywgt.ext.free = free; /* We used to register widget group types like this, now we do it similar to * operator types. Thus we should be able to do the same as operator types now. */ -#if 0 - wgrouptype = WM_manipulatorrouptype_register_ptr( - NULL, wmaptype, - (have_function[0]) ? widgetgroup_poll : NULL, - (have_function[2]) ? widgetgroup_draw : NULL, - NULL, NULL, /* TODO */ - (have_function[1]) ? widgetgroup_keymap_init : NULL, - dummywgt.name); -#else - /* XXX needs updating */ dummywgt.poll = (have_function[0]) ? widgetgroup_poll : NULL; - dummywgt.init = (have_function[2]) ? widgetgroup_draw : NULL; dummywgt.keymap_init = (have_function[1]) ? widgetgroup_keymap_init : NULL; - wgrouptype = &dummywgt; /* XXX incorrect, just to avoid uninitialized value warning */ -#endif - - /* create a new widgetgroup type */ - wgrouptype->ext.srna = RNA_def_struct_ptr(&BLENDER_RNA, wgrouptype->idname, &RNA_WidgetGroup); - RNA_def_struct_flag(wgrouptype->ext.srna, STRUCT_NO_IDPROPERTIES); /* widgetgroup properties are registered separately */ - wgrouptype->ext.data = data; - wgrouptype->ext.call = call; - wgrouptype->ext.free = free; - - RNA_struct_blender_type_set(wgrouptype->ext.srna, wgrouptype); + dummywgt.init = (have_function[2]) ? widgetgroup_draw : NULL; - /* by passing NULL as main to WM_manipulatorrouptype_register_ptr, we delay initialization */ + WM_manipulatorgrouptype_append_ptr_runtime(bmain, wmaptype, widgetgroup_wrapper, (void *)&dummywgt); - /* XXX, currently not working since we cant call own callbacks until this function finishes, catch22! */ - WM_manipulatorgrouptype_init_runtime(bmain, wmaptype, wgrouptype); + RNA_def_struct_duplicate_pointers(dummywgt.ext.srna); /* update while blender is running */ WM_main_add_notifier(NC_SCREEN | NA_EDITED, NULL); - return wgrouptype->ext.srna; + return dummywgt.ext.srna; } static void **rna_WidgetGroup_instance(PointerRNA *ptr) diff --git a/source/blender/python/intern/CMakeLists.txt b/source/blender/python/intern/CMakeLists.txt index 038c1e7eb10..296a0fc1e6f 100644 --- a/source/blender/python/intern/CMakeLists.txt +++ b/source/blender/python/intern/CMakeLists.txt @@ -78,6 +78,7 @@ set(SRC bpy_util.c bpy_utils_previews.c bpy_utils_units.c + bpy_widgetgroup_wrap.c stubs.c gpu.h @@ -108,6 +109,7 @@ set(SRC bpy_util.h bpy_utils_previews.h bpy_utils_units.h + bpy_widgetgroup_wrap.h ../BPY_extern.h ) diff --git a/source/blender/python/intern/bpy_widgetgroup_wrap.c b/source/blender/python/intern/bpy_widgetgroup_wrap.c new file mode 100644 index 00000000000..de0eb40eb47 --- /dev/null +++ b/source/blender/python/intern/bpy_widgetgroup_wrap.c @@ -0,0 +1,90 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * 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. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/python/intern/bpy_widgetgroup_wrap.c + * \ingroup pythonintern + * + * This file is so Python can define widget-group's that C can call into. + * The generic callback functions for Python widget-group are defines in + * 'rna_wm.c', some calling into functions here to do python specific + * functionality. + * + * \note This follows 'bpy_operator_wrap.c' very closely. + * Keep in sync unless there is good reason not to! + */ + +#include <Python.h> + +#include "BLI_utildefines.h" + +#include "WM_api.h" +#include "WM_types.h" + +#include "RNA_access.h" +#include "RNA_define.h" + +#include "bpy_rna.h" +#include "bpy_intern_string.h" +#include "bpy_widgetgroup_wrap.h" /* own include */ + +/* we may want to add, but not now */ +// #define USE_SRNA + +static void widgetgroup_properties_init(wmManipulatorGroupType *mgrouptype) +{ +#ifdef USE_SRNA + PyTypeObject *py_class = mgrouptype->ext.data; +#endif + RNA_struct_blender_type_set(mgrouptype->ext.srna, mgrouptype); + +#ifdef USE_SRNA + /* only call this so pyrna_deferred_register_class gives a useful error + * WM_operatortype_append_ptr will call RNA_def_struct_identifier + * later */ + RNA_def_struct_identifier(mgrouptype->srna, mgrouptype->idname); + + if (pyrna_deferred_register_class(mgrouptype->srna, py_class) != 0) { + PyErr_Print(); /* failed to register operator props */ + PyErr_Clear(); + } +#endif +} + +void widgetgroup_wrapper(wmManipulatorGroupType *mgrouptype, void *userdata) +{ + /* take care not to overwrite anything set in + * WM_manipulatorgrouptype_append_ptr before opfunc() is called */ +#ifdef USE_SRNA + StructRNA *srna = mgrouptype->srna; +#endif + *mgrouptype = *((wmManipulatorGroupType *)userdata); +#ifdef USE_SRNA + mgrouptype->srna = srna; /* restore */ +#endif + +#ifdef USE_SRNA + /* Use i18n context from ext.srna if possible (py widgetgroups). */ + if (mgrouptype->ext.srna) { + RNA_def_struct_translation_context(mgrouptype->srna, RNA_struct_translation_context(mgrouptype->ext.srna)); + } +#endif + + widgetgroup_properties_init(mgrouptype); +} diff --git a/source/blender/python/intern/bpy_widgetgroup_wrap.h b/source/blender/python/intern/bpy_widgetgroup_wrap.h new file mode 100644 index 00000000000..9d6bcfabe81 --- /dev/null +++ b/source/blender/python/intern/bpy_widgetgroup_wrap.h @@ -0,0 +1,34 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * 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. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/python/intern/bpy_widgetgroup_wrap.h + * \ingroup pythonintern + */ + +#ifndef __BPY_WIDGETGROUP_WRAP_H__ +#define __BPY_WIDGETGROUP_WRAP_H__ + +struct wmManipulatorGroupType; + +/* exposed to rna/wm api */ +void widgetgroup_wrapper(struct wmManipulatorGroupT @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs