diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-06-07 18:53:08 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-06-07 18:53:08 +0400 |
commit | bb06e311a18518740edec42dce26d377ab16f0d7 (patch) | |
tree | 9d163f631f461c5a53e46a44384eefed125bea76 /source/blender/editors/interface/interface_layout.c | |
parent | eecf7722b635545f0f5c51b74a15418e3cc9f47e (diff) |
added item_enumO() so python menu items can call enum types with string args.
Example sequencer menu
self.layout.column()
self.layout.item_enumO("SEQUENCER_OT_effect_strip_add", property='type', value='ADD', text="Effect Strip (Add)")
Diffstat (limited to 'source/blender/editors/interface/interface_layout.c')
-rw-r--r-- | source/blender/editors/interface/interface_layout.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index ea576ad7263..df7d81b8806 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -597,6 +597,39 @@ void uiItemsEnumO(uiLayout *layout, char *opname, char *propname) } } +/* for use in cases where we have */ +void uiItemEnumO_string(uiLayout *layout, char *name, int icon, char *opname, char *propname, char *value_str) +{ + PointerRNA ptr; + + /* for getting the enum */ + PropertyRNA *prop; + const EnumPropertyItem *item; + int totitem; + int value; + + WM_operator_properties_create(&ptr, opname); + + /*RNA_enum_set(&ptr, propname, value);*/ + if(prop= RNA_struct_find_property(&ptr, propname)) { + RNA_property_enum_items(&ptr, prop, &item, &totitem); + if(RNA_enum_value_from_id(item, value_str, &value)==0) { + printf("uiItemEnumO_string: %s.%s, enum %s not found.\n", RNA_struct_identifier(ptr.type), propname, value); + return; + } + } + else { + printf("uiItemEnumO_string: %s.%s not found.\n", RNA_struct_identifier(ptr.type), propname); + return; + } + + /* same as uiItemEnumO */ + if(!name) + name= ui_menu_enumpropname(opname, propname, value); + + uiItemFullO(layout, name, icon, opname, ptr.data, layout->root->opcontext); +} + void uiItemBooleanO(uiLayout *layout, char *name, int icon, char *opname, char *propname, int value) { PointerRNA ptr; |