[Bf-blender-cvs] [3513cba] wiggly-widgets: Work in progress changes to py initialization
Campbell Barton
noreply at git.blender.org
Wed Jan 6 11:21:56 CET 2016
Commit: 3513cba71bbc673ab3a61e3219319495bcf2827c
Author: Campbell Barton
Date: Wed Jan 6 21:12:06 2016 +1100
Branches: wiggly-widgets
https://developer.blender.org/rB3513cba71bbc673ab3a61e3219319495bcf2827c
Work in progress changes to py initialization
Various minor fixes to initializing the Python rna subclass.
With remaining issue that we can't immediately call the keymap_init callback (which is expected).
===================================================================
M source/blender/makesrna/intern/rna_wm.c
M source/blender/windowmanager/WM_api.h
M source/blender/windowmanager/intern/wm_widgets.c
===================================================================
diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c
index 8881530..11f5366 100644
--- a/source/blender/makesrna/intern/rna_wm.c
+++ b/source/blender/makesrna/intern/rna_wm.c
@@ -1560,12 +1560,8 @@ static void operator_cancel(bContext *C, wmWidgetGroup *op)
void widgetgroup_wrapper(wmWidgetGroupType *ot, void *userdata);
-static char _widgetgroup_idname[OP_MAX_TYPENAME];
-//static char _widgetgroup_name[OP_MAX_TYPENAME];
-//static char _widgetgroup_descr[RNA_DYN_DESCR_MAX];
-//static char _widgetgroup_ctxt[RNA_DYN_DESCR_MAX];
static StructRNA *rna_WidgetGroup_register(
- Main *UNUSED(bmain), ReportList *reports, void *data, const char *identifier,
+ Main *bmain, ReportList *reports, void *data, const char *identifier,
StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
{
@@ -1578,9 +1574,6 @@ static StructRNA *rna_WidgetGroup_register(
dummywg.type = &dummywgt;
RNA_pointer_create(NULL, &RNA_WidgetGroup, &dummywg, &wgptr);
- /* clear in case they are left unset */
- _widgetgroup_idname[0] = '\0';
-
/* validate the python class */
if (validate(&wgptr, data, have_function) != 0)
return NULL;
@@ -1614,33 +1607,33 @@ static StructRNA *rna_WidgetGroup_register(
/* 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;
-
- dummywgt.poll = (have_function[0]) ? widgetgroup_poll : NULL;
- dummywgt.keymap_init = (have_function[1]) ? widgetgroup_keymap_init : NULL;
- dummywgt.create = (have_function[2]) ? widgetgroup_draw : NULL;
-
wgrouptype = WM_widgetgrouptype_register_ptr(
NULL, wmaptype,
- dummywgt.poll, dummywgt.create, dummywgt.keymap_init,
+ (have_function[0]) ? widgetgroup_poll : NULL,
+ (have_function[2]) ? widgetgroup_draw : NULL,
+ (have_function[1]) ? widgetgroup_keymap_init : NULL,
dummywgt.name);
- memcpy(wgrouptype, &dummywgt, sizeof(dummywgt));
-
+
+ /* 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);
+
+ /* by passing NULL as main to WM_widgetgrouptype_register_ptr, we delay initialization */
+
+ /* XXX, currently not working since we cant call own callbacks until this function finishes, catch22! */
+ WM_widgetgrouptype_init_runtime(bmain, wmaptype, wgrouptype);
+
/* update while blender is running */
WM_main_add_notifier(NC_SCREEN | NA_EDITED, NULL);
- dummywgt.ext.srna = RNA_def_struct_ptr(&BLENDER_RNA, dummywgt.idname, &RNA_WidgetGroup);
-
- return dummywgt.ext.srna;
+ return wgrouptype->ext.srna;
}
-//RNA_struct_blender_type_set(pt->ext.srna, pt);
-
static void **rna_WidgetGroup_instance(PointerRNA *ptr)
{
wmWidgetGroup *wgroup = ptr->data;
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index a4f379d..ae1a095 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -585,6 +585,10 @@ struct wmWidgetGroupType *WM_widgetgrouptype_register(
wmKeyMap *(*keymap_init)(const struct wmWidgetGroupType *wgrouptype, struct wmKeyConfig *config),
const char *name);
+void WM_widgetgrouptype_init_runtime(
+ const struct Main *bmain, struct wmWidgetMapType *wmaptype,
+ struct wmWidgetGroupType *wgrouptype);
+
void WM_widgetgrouptype_unregister(struct bContext *C, struct Main *bmain, struct wmWidgetGroupType *wgroup);
void WM_widgetmap_delete(struct wmWidgetMap *wmap);
diff --git a/source/blender/windowmanager/intern/wm_widgets.c b/source/blender/windowmanager/intern/wm_widgets.c
index 0d17b16..7edb2ca 100644
--- a/source/blender/windowmanager/intern/wm_widgets.c
+++ b/source/blender/windowmanager/intern/wm_widgets.c
@@ -128,9 +128,37 @@ wmWidgetGroupType *WM_widgetgrouptype_register_ptr(
/* Main is missing on startup when we create new areas.
* So this is only called for widgets initialized on runtime */
- if (!bmain)
- return wgrouptype;
+ if (bmain) {
+ WM_widgetgrouptype_init_runtime(bmain, wmaptype, wgrouptype);
+ }
+
+ return wgrouptype;
+}
+
+wmWidgetGroupType *WM_widgetgrouptype_register(
+ const Main *bmain, const struct wmWidgetMapType_Params *wmap_params,
+ int (*poll)(const bContext *C, wmWidgetGroupType *),
+ void (*create)(const bContext *, wmWidgetGroup *),
+ wmKeyMap *(*keymap_init)(const wmWidgetGroupType *wgrouptype, wmKeyConfig *config),
+ const char *name)
+{
+ wmWidgetMapType *wmaptype = WM_widgetmaptype_find(wmap_params);
+
+ if (!wmaptype) {
+ fprintf(stderr, "widgetgrouptype creation: widgetmap type does not exist");
+ return NULL;
+ }
+
+ return WM_widgetgrouptype_register_ptr(
+ bmain, wmaptype,
+ poll, create, keymap_init,
+ name);
+}
+void WM_widgetgrouptype_init_runtime(
+ const Main *bmain, wmWidgetMapType *wmaptype,
+ wmWidgetGroupType *wgrouptype)
+{
/* init keymap - on startup there's an extra call to init keymaps for 'permanent' widget-groups */
wm_widgetgrouptype_keymap_init(wgrouptype, ((wmWindowManager *)bmain->wm.first)->defaultconf);
@@ -157,28 +185,6 @@ wmWidgetGroupType *WM_widgetgrouptype_register_ptr(
}
}
}
-
- return wgrouptype;
-}
-
-wmWidgetGroupType *WM_widgetgrouptype_register(
- const Main *bmain, const struct wmWidgetMapType_Params *wmap_params,
- int (*poll)(const bContext *C, wmWidgetGroupType *),
- void (*create)(const bContext *, wmWidgetGroup *),
- wmKeyMap *(*keymap_init)(const wmWidgetGroupType *wgrouptype, wmKeyConfig *config),
- const char *name)
-{
- wmWidgetMapType *wmaptype = WM_widgetmaptype_find(wmap_params);
-
- if (!wmaptype) {
- fprintf(stderr, "widgetgrouptype creation: widgetmap type does not exist");
- return NULL;
- }
-
- return WM_widgetgrouptype_register_ptr(
- bmain, wmaptype,
- poll, create, keymap_init,
- name);
}
/**
More information about the Bf-blender-cvs
mailing list