[Bf-blender-cvs] [b51ee54] wiggly-widgets: Initial Python API for Widgets
Campbell Barton
noreply at git.blender.org
Mon Dec 8 12:25:01 CET 2014
Commit: b51ee540ae1782a4b7fdbdacaf6b56bb9e3e8ca6
Author: Campbell Barton
Date: Sat Dec 6 20:51:12 2014 +0100
Branches: wiggly-widgets
https://developer.blender.org/rBb51ee540ae1782a4b7fdbdacaf6b56bb9e3e8ca6
Initial Python API for Widgets
Note this is only the initial Python API structure & isn't usable in its current state.
Work by Psy-fi & myself.
===================================================================
M source/blender/editors/include/ED_view3d.h
M source/blender/editors/object/object_lamp.c
M source/blender/editors/space_node/space_node.c
M source/blender/editors/space_view3d/space_view3d.c
M source/blender/makesdna/DNA_widget_types.h
M source/blender/makesrna/intern/rna_internal.h
M source/blender/makesrna/intern/rna_wm.c
M source/blender/makesrna/intern/rna_wm_api.c
M source/blender/windowmanager/WM_api.h
M source/blender/windowmanager/WM_types.h
M source/blender/windowmanager/intern/wm_widgets.c
===================================================================
diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h
index 3db0512..47e59cc 100644
--- a/source/blender/editors/include/ED_view3d.h
+++ b/source/blender/editors/include/ED_view3d.h
@@ -64,6 +64,7 @@ struct wmOperatorType;
struct wmWindow;
struct wmWidget;
struct wmWidgetGroup;
+struct wmWidgetGroupType;
/* for derivedmesh drawing callbacks, for view3d_select, .... */
typedef struct ViewContext {
@@ -370,8 +371,8 @@ void ED_view3d_operator_properties_viewmat_set(struct bContext *C, struct wmOper
void ED_view3d_operator_properties_viewmat_get(struct wmOperator *op, int *winx, int *winy, float persmat[4][4]);
#endif
-bool WIDGETGROUP_lamp_poll(struct wmWidgetGroup *wgroup, const struct bContext *C);
-void WIDGETGROUP_lamp_draw(struct wmWidgetGroup *wgroup, const struct bContext *C);
+int WIDGETGROUP_lamp_poll(const struct bContext *C, struct wmWidgetGroupType *wgrouptype);
+void WIDGETGROUP_lamp_draw(const struct bContext *C, struct wmWidgetGroup *wgroup);
/* render */
void ED_view3d_shade_update(struct Main *bmain, struct Scene *scene, struct View3D *v3d, struct ScrArea *sa);
diff --git a/source/blender/editors/object/object_lamp.c b/source/blender/editors/object/object_lamp.c
index 4da2634..3e955d9 100644
--- a/source/blender/editors/object/object_lamp.c
+++ b/source/blender/editors/object/object_lamp.c
@@ -203,7 +203,7 @@ void LAMP_OT_lamp_position(struct wmOperatorType *ot)
RNA_def_float_vector_xyz(ot->srna, "value", 3, NULL, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
}
-bool WIDGETGROUP_lamp_poll(struct wmWidgetGroup *UNUSED(wgroup), const struct bContext *C)
+int WIDGETGROUP_lamp_poll(const struct bContext *C, struct wmWidgetGroupType *UNUSED(wgrouptype))
{
Object *ob = CTX_data_active_object(C);
@@ -214,7 +214,7 @@ bool WIDGETGROUP_lamp_poll(struct wmWidgetGroup *UNUSED(wgroup), const struct bC
return false;
}
-void WIDGETGROUP_lamp_draw(struct wmWidgetGroup *wgroup, const struct bContext *C)
+void WIDGETGROUP_lamp_draw(const struct bContext *C, struct wmWidgetGroup *wgroup)
{
float color_lamp[4] = {0.5f, 0.5f, 1.0f, 1.0f};
Object *ob = CTX_data_active_object(C);
diff --git a/source/blender/editors/space_node/space_node.c b/source/blender/editors/space_node/space_node.c
index 68f54d7..e33ebad 100644
--- a/source/blender/editors/space_node/space_node.c
+++ b/source/blender/editors/space_node/space_node.c
@@ -838,7 +838,7 @@ static int node_context(const bContext *C, const char *member, bContextDataResul
return 0;
}
-static bool WIDGETGROUP_node_transform_poll(struct wmWidgetGroup *UNUSED(wgroup), const struct bContext *C)
+static int WIDGETGROUP_node_transform_poll(const struct bContext *C, struct wmWidgetGroupType *UNUSED(wgrouptype))
{
SpaceNode *snode = CTX_wm_space_node(C);
@@ -852,7 +852,7 @@ static bool WIDGETGROUP_node_transform_poll(struct wmWidgetGroup *UNUSED(wgroup)
return false;
}
-static void WIDGETGROUP_node_transform_update(struct wmWidgetGroup *wgroup, const struct bContext *C)
+static void WIDGETGROUP_node_transform_update(const struct bContext *C, struct wmWidgetGroup *wgroup)
{
Image *ima;
ImBuf *ibuf;
@@ -892,7 +892,7 @@ static void node_widgets(void)
struct wmWidgetGroupType *wgroup_node_transform;
wgroup_node_transform = WM_widgetgrouptype_new(WIDGETGROUP_node_transform_poll, WIDGETGROUP_node_transform_update);
- wmaptype = WM_widgetmaptype_find(SPACE_NODE, RGN_TYPE_WINDOW, false);
+ wmaptype = WM_widgetmaptype_find(SPACE_NODE, RGN_TYPE_WINDOW, false, true);
WM_widgetgrouptype_register(wmaptype, wgroup_node_transform);
}
diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c
index 5b810fe..c331f7c 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -703,7 +703,7 @@ static void view3d_dropboxes(void)
}
-static bool WIDGETGROUP_camera_poll(struct wmWidgetGroup *UNUSED(wgroup), const struct bContext *C)
+static int WIDGETGROUP_camera_poll(const struct bContext *C, struct wmWidgetGroupType *UNUSED(wgrouptype))
{
Object *ob = CTX_data_active_object(C);
@@ -714,7 +714,7 @@ static bool WIDGETGROUP_camera_poll(struct wmWidgetGroup *UNUSED(wgroup), const
return false;
}
-static void WIDGETGROUP_camera_draw(struct wmWidgetGroup *wgroup, const struct bContext *C)
+static void WIDGETGROUP_camera_draw(const struct bContext *C, struct wmWidgetGroup *wgroup)
{
float color_camera[4] = {1.0f, 0.3f, 0.0f, 1.0f};
Object *ob = CTX_data_active_object(C);
@@ -738,7 +738,7 @@ static void WIDGETGROUP_camera_draw(struct wmWidgetGroup *wgroup, const struct b
}
-static bool WIDGETGROUP_shapekey_poll(struct wmWidgetGroup *UNUSED(wgroup), const struct bContext *C)
+static int WIDGETGROUP_shapekey_poll(const struct bContext *C, struct wmWidgetGroupType *UNUSED(wgrouptype))
{
Object *ob = CTX_data_active_object(C);
@@ -757,7 +757,7 @@ static bool WIDGETGROUP_shapekey_poll(struct wmWidgetGroup *UNUSED(wgroup), cons
return false;
}
-static void WIDGETGROUP_shapekey_draw(struct wmWidgetGroup *wgroup, const struct bContext *C)
+static void WIDGETGROUP_shapekey_draw(const struct bContext *C, struct wmWidgetGroup *wgroup)
{
float color_shape[4] = {1.0f, 0.3f, 0.0f, 1.0f};
Object *ob = CTX_data_active_object(C);
@@ -780,7 +780,7 @@ static void WIDGETGROUP_shapekey_draw(struct wmWidgetGroup *wgroup, const struct
static void view3d_widgets(void)
{
- struct wmWidgetMapType *wmaptype = WM_widgetmaptype_find(SPACE_VIEW3D, RGN_TYPE_WINDOW, true);
+ struct wmWidgetMapType *wmaptype = WM_widgetmaptype_find(SPACE_VIEW3D, RGN_TYPE_WINDOW, true, true);
wmWidgetGroupType *wgroup_light,*wgroup_camera, *wgroup_shapekey;
// struct wmWidgetGroupType *wgroup_manipulator;
diff --git a/source/blender/makesdna/DNA_widget_types.h b/source/blender/makesdna/DNA_widget_types.h
index 828c9e6..b133616 100644
--- a/source/blender/makesdna/DNA_widget_types.h
+++ b/source/blender/makesdna/DNA_widget_types.h
@@ -43,4 +43,17 @@ typedef struct wmRectTransformWidget {
float pad;
} wmRectTransformWidget;
-#endif
\ No newline at end of file
+struct wmWidgetGroup {
+ struct wmWidgetGroup *next, *prev;
+
+ struct wmWidgetGroupType *type;
+ ListBase widgets;
+
+ void *py_instance; /* python stores the class instance here */
+ struct ReportList *reports; /* errors and warnings storage */
+
+ int flag;
+ int pad;
+};
+
+#endif
diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h
index 051e727..2b6b60d 100644
--- a/source/blender/makesrna/intern/rna_internal.h
+++ b/source/blender/makesrna/intern/rna_internal.h
@@ -264,6 +264,7 @@ void RNA_api_image(struct StructRNA *srna);
void RNA_api_lattice(struct StructRNA *srna);
void RNA_api_operator(struct StructRNA *srna);
void RNA_api_macro(struct StructRNA *srna);
+void RNA_api_widgetgroup(struct StructRNA *srna);
void RNA_api_keyconfig(struct StructRNA *srna);
void RNA_api_keyconfigs(struct StructRNA *srna);
void RNA_api_keyingset(struct StructRNA *srna);
diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c
index 6a6a2ea..0128630 100644
--- a/source/blender/makesrna/intern/rna_wm.c
+++ b/source/blender/makesrna/intern/rna_wm.c
@@ -518,6 +518,26 @@ static PointerRNA rna_Operator_properties_get(PointerRNA *ptr)
return rna_pointer_inherit_refine(ptr, op->type->srna, op->properties);
}
+static void rna_WidgetGroup_name_get(PointerRNA *ptr, char *value)
+{
+ wmWidgetGroup *wgroup = ptr->data;
+ strcpy(value, "Dummy_XXX" /*wgroup->type->name*/);
+ (void)wgroup;
+}
+
+static int rna_WidgetGroup_name_length(PointerRNA *ptr)
+{
+ wmWidgetGroup *wgroup = ptr->data;
+ return strlen("Dummy_XXX" /*wgroup->type->name*/);
+ (void)wgroup;
+}
+
+static int rna_WidgetGroup_has_reports_get(PointerRNA *ptr)
+{
+ wmWidgetGroup *wgroup = ptr->data;
+ return (wgroup->reports && wgroup->reports->list.first);
+}
+
static PointerRNA rna_OperatorMacro_properties_get(PointerRNA *ptr)
{
wmOperatorTypeMacro *otmacro = (wmOperatorTypeMacro *)ptr->data;
@@ -1360,6 +1380,175 @@ static void rna_Operator_bl_description_set(PointerRNA *ptr, const char *value)
assert(!"setting the bl_description on a non-builtin operator");
}
+#ifdef WITH_PYTHON
+static void rna_WidgetGroup_unregister(struct Main *bmain, StructRNA *type)
+{
+ //const char *idname;
+ wmWidgetGroupType *wgrouptype = RNA_struct_blender_type_get(type);
+ //wmWindowManager *wm;
+ //wmWidgetMapType *wmap = NULL;
+
+ if (!wgrouptype)
+ return;
+
+ WM_main_add_notifier(NC_SCREEN | NA_EDITED, NULL);
+
+ //RNA_struct_free_extension(type, &wgrouptype->ext);
+
+ WM_widgetgrouptype_free(bmain, wgrouptype);
+ //WM_operatortype_remove_ptr(ot);
+ //WM_widgetgrouptype_unregister(wmap, wgrouptype);
+
+ /* 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);
+}
+
+static int widgetgroup_poll(const bContext *C, wmWidgetGroupType *wgrouptype)
+{
+
+ extern FunctionRNA rna_WidgetGroup_poll_func;
+
+ PointerRNA ptr;
+ ParameterList list;
+ FunctionRNA *func;
+ void *ret;
+ int visible;
+
+ RNA_pointer_create(NULL, wgrouptype->ext.srna, NULL, &ptr); /* dummy */
+ func = &rna_WidgetGroup_poll_func; /* RNA_struct_find_function(&ptr, "poll"); */
+
+ RNA_parameter_list_create(&list, &ptr, func);
+ RNA_parameter_set_lookup(&list, "context", &C);
+ wgrouptype->ext.call((bContext *)C, &ptr, func, &list);
+
+ RNA_parameter_get_lookup(&list, "visible", &ret);
+ visible = *(int *)ret;
+
+ RNA_parameter_list_free(&list);
+
+ return visible;
+}
+
+static void widgetgroup_draw(const bContext *C, wmWidgetGroup *wgroup)
+{
+ extern FunctionRNA rna_WidgetGroup_draw_func;
+
+ PointerRNA wgroup_ptr;
+ ParameterList list;
+ FunctionRNA *func;
+
+ RNA_pointer_create(NULL, wgroup->type->ext.srna, wgroup, &wgroup_ptr);
+ func = &rna_WidgetGroup_draw_func; /* RNA_struct_find_function(&wgroupr, "draw"); */
+
+ RNA_parameter_list_create(&list, &wgroup_ptr, func);
+ RNA_parameter_set_lookup(&list, "context", &C);
+ wgroup->type->ext.call((bC
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list