From 884516357453e2530dc0a804cc14c6373e44e39c Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 15 Feb 2011 18:12:41 +0000 Subject: menu to select an enum from an RNA path: eg, bpy.ops.wm.context_menu_enum(data_path="scene.tool_settings.vertex_paint.brush.stroke_method") This saves us defining operators only for menus. --- release/scripts/op/wm.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'release') diff --git a/release/scripts/op/wm.py b/release/scripts/op/wm.py index cbc9e3cd55f..0210dc912df 100644 --- a/release/scripts/op/wm.py +++ b/release/scripts/op/wm.py @@ -384,6 +384,38 @@ class WM_OT_context_cycle_array(bpy.types.Operator): return {'FINISHED'} +class WM_MT_context_menu_enum(bpy.types.Menu): + bl_label = "" + data_path = "" # BAD DESIGN, set from operator below. + def draw(self, context): + data_path = self.data_path + value = context_path_validate(bpy.context, data_path) + if value is Ellipsis: + return {'PASS_THROUGH'} + base_path, prop_string = data_path.rsplit(".", 1) + value_base = context_path_validate(context, base_path) + + values = [(i.name, i.identifier) for i in value_base.bl_rna.properties[prop_string].items] + + for name, identifier in values: + prop = self.layout.operator("wm.context_set_enum", text=name) + prop.data_path = data_path + prop.value = identifier + + +class WM_OT_context_menu_enum(bpy.types.Operator): + bl_idname = "wm.context_menu_enum" + bl_label = "Context Enum Menu" + bl_options = {'UNDO'} + data_path = rna_path_prop + + def execute(self, context): + data_path = self.data_path + WM_MT_context_menu_enum.data_path = data_path + bpy.ops.wm.call_menu(name="WM_MT_context_menu_enum") + return {'PASS_THROUGH'} + + class WM_OT_context_set_id(bpy.types.Operator): '''Toggle a context value.''' bl_idname = "wm.context_set_id" -- cgit v1.2.3