~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to release/scripts/templates_py/ui_menu.py

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
if __name__ == "__main__":
 
46
    register()
 
47
 
 
48
    # The menu can also be called from scripts
 
49
    bpy.ops.wm.call_menu(name=CustomMenu.bl_idname)