-
Notifications
You must be signed in to change notification settings - Fork 3
/
view_menu.py
68 lines (50 loc) · 2.07 KB
/
view_menu.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from .Utils.core import *
### ------------ Menus ------------ ###
# adds a view manipulation menu
class ViewMenu(bpy.types.Menu):
bl_label = "View"
bl_idname = "VIEW3D_MT_view_menu"
def draw(self, context):
menu = Menu(self)
view_modes = [["Front", 'FRONT'],
["Right", "RIGHT"],
["Top", "TOP"],
["Back", "BACK"],
["Left", "LEFT"],
["Bottom", "BOTTOM"],
["Camera", "CAMERA"]]
# add the menu items
for mode in view_modes:
prop = menu.add_item().operator("view3d.viewnumpad", mode[0])
prop.type = mode[1]
if mode[0] in ["Top", "Bottom", "Camera"]:
menu.add_item().separator()
menu.add_item().menu(OtherViewMenu.bl_idname)
class OtherViewMenu(bpy.types.Menu):
bl_label = "Other"
bl_idname = "VIEW3D_MT_other_view_menu"
def draw(self, context):
menu = Menu(self)
menu.add_item().label(text="Other")
menu.add_item().separator()
menu.add_item().operator("view3d.view_selected")
menu.add_item().operator("view3d.view_persportho")
menu.add_item().operator("view3d.localview", text="View Local/Global")
menu.add_item().operator("screen.region_quadview")
menu.add_item().separator()
menu.add_item().prop(context.space_data, "lock_cursor", toggle=True)
menu.add_item().prop(context.space_data, "lock_camera", toggle=True)
### ------------ New hotkeys and registration ------------ ###
addon_keymaps = []
def register():
# create the global menu hotkey
wm = bpy.context.window_manager
km = wm.keyconfigs.addon.keymaps.new(name='Object Non-modal')
kmi = km.keymap_items.new('wm.call_menu', 'Q', 'PRESS')
kmi.properties.name = 'VIEW3D_MT_view_menu'
addon_keymaps.append((km, kmi))
def unregister():
# remove keymaps when add-on is deactivated
for km, kmi in addon_keymaps:
km.keymap_items.remove(kmi)
addon_keymaps.clear()