diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-06-01 08:06:38 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-06-01 08:06:38 +0400 |
commit | 2d4a682a8e48e41af2867bc71a621eb0fac27b1e (patch) | |
tree | 040f6811f870d72f8268250b61f719b3eef2f0a7 /source/blender/makesrna/intern/rna_wm_api.c | |
parent | 0ad88d1001449f71b9448e237e6f05fb244f1a85 (diff) |
add popup menu to allow python scripts to show popups without having to define a menu class first.
Diffstat (limited to 'source/blender/makesrna/intern/rna_wm_api.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_wm_api.c | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/source/blender/makesrna/intern/rna_wm_api.c b/source/blender/makesrna/intern/rna_wm_api.c index b747c8053df..5805bcefdb4 100644 --- a/source/blender/makesrna/intern/rna_wm_api.c +++ b/source/blender/makesrna/intern/rna_wm_api.c @@ -45,6 +45,7 @@ #ifdef RNA_RUNTIME +#include "UI_interface.h" #include "BKE_context.h" static wmKeyMap *rna_keymap_active(wmKeyMap *km, bContext *C) @@ -250,6 +251,24 @@ static void rna_KeyConfig_remove(wmWindowManager *wm, ReportList *reports, Point RNA_POINTER_INVALIDATE(keyconf_ptr); } +/* popup menu wrapper */ +static PointerRNA rna_PupMenuBegin(bContext *C, const char *title, int icon) +{ + PointerRNA r_ptr; + void *data; + + data = (void *)uiPupMenuBegin(C, title, icon); + + RNA_pointer_create(NULL, &RNA_UIPopupMenu, data, &r_ptr); + + return r_ptr; +} + +static void rna_PupMenuEnd(bContext *C, PointerRNA *handle) +{ + uiPupMenuEnd(C, handle->data); +} + #else #define WM_GEN_INVOKE_EVENT (1 << 0) @@ -348,7 +367,25 @@ void RNA_api_wm(StructRNA *srna) func = RNA_def_function(srna, "invoke_confirm", "rna_Operator_confirm"); RNA_def_function_ui_description(func, "Operator confirmation"); rna_generic_op_invoke(func, WM_GEN_INVOKE_EVENT | WM_GEN_INVOKE_RETURN); - + + + /* wrap uiPupMenuBegin */ + func = RNA_def_function(srna, "pupmenu_begin__internal", "rna_PupMenuBegin"); + RNA_def_function_flag(func, FUNC_NO_SELF | FUNC_USE_CONTEXT); + parm = RNA_def_string(func, "title", "", 0, "", ""); + RNA_def_property_flag(parm, PROP_REQUIRED); + parm = RNA_def_property(func, "icon", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_items(parm, icon_items); + /* return */ + parm = RNA_def_pointer(func, "menu", "UIPopupMenu", "", ""); + RNA_def_property_flag(parm, PROP_RNAPTR | PROP_NEVER_NULL); + RNA_def_function_return(func, parm); + + /* wrap uiPupMenuEnd */ + func = RNA_def_function(srna, "pupmenu_end__internal", "rna_PupMenuEnd"); + RNA_def_function_flag(func, FUNC_NO_SELF | FUNC_USE_CONTEXT); + parm = RNA_def_pointer(func, "menu", "UIPopupMenu", "", ""); + RNA_def_property_flag(parm, PROP_RNAPTR | PROP_NEVER_NULL); } void RNA_api_operator(StructRNA *srna) |