Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2011-02-15 21:12:41 +0300
committerCampbell Barton <ideasman42@gmail.com>2011-02-15 21:12:41 +0300
commit884516357453e2530dc0a804cc14c6373e44e39c (patch)
tree067ed9aee9d6f10f6cb9c3c93cbe8a83b068993b /release
parent35c03e85efda280f6ed153c0557b928745b55c85 (diff)
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.
Diffstat (limited to 'release')
-rw-r--r--release/scripts/op/wm.py32
1 files changed, 32 insertions, 0 deletions
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"