Cleanup: use staticmethod where appropriate
[blender.git] / release / scripts / templates_py / ui_menu.py
1 import bpy
2
3
4 class CustomMenu(bpy.types.Menu):
5     bl_label = "Custom Menu"
6     bl_idname = "OBJECT_MT_custom_menu"
7
8     def draw(self, context):
9         layout = self.layout
10
11         layout.operator("wm.open_mainfile")
12         layout.operator("wm.save_as_mainfile").copy = True
13
14         layout.operator("object.shade_smooth")
15
16         layout.label(text="Hello world!", icon='WORLD_DATA')
17
18         # use an operator enum property to populate a sub-menu
19         layout.operator_menu_enum("object.select_by_type",
20                                   property="type",
21                                   text="Select All by Type...",
22                                   )
23
24         # call another menu
25         layout.operator("wm.call_menu", text="Unwrap").name = "VIEW3D_MT_uv_map"
26
27
28 def draw_item(self, context):
29     layout = self.layout
30     layout.menu(CustomMenu.bl_idname)
31
32
33 def register():
34     bpy.utils.register_class(CustomMenu)
35
36     # lets add ourselves to the main header
37     bpy.types.INFO_HT_header.append(draw_item)
38
39
40 def unregister():
41     bpy.utils.unregister_class(CustomMenu)
42
43     bpy.types.INFO_HT_header.remove(draw_item)
44
45
46 if __name__ == "__main__":
47     register()
48
49     # The menu can also be called from scripts
50     bpy.ops.wm.call_menu(name=CustomMenu.bl_idname)