Sun Position: fix error in HDRI mode when no env tex is selected
[blender-addons.git] / space_view3d_pie_menus / pie_views_numpad_menu.py
blobdc75d491ce5457b30046cd8559a04848ec7a99a8
1 # SPDX-License-Identifier: GPL-2.0-or-later
3 bl_info = {
4 "name": "Hotkey: 'Alt Q'",
5 "description": "Viewport Numpad Menus",
6 "author": "pitiwazou, meta-androcto",
7 "version": (0, 1, 1),
8 "blender": (2, 80, 0),
9 "location": "Alt Q key",
10 "warning": "",
11 "doc_url": "",
12 "category": "View Numpad Pie"
15 import bpy
16 from bpy.types import (
17 Menu,
18 Operator,
22 # Lock Camera Transforms
23 class PIE_OT_LockTransforms(Operator):
24 bl_idname = "object.locktransforms"
25 bl_label = "Lock Object Transforms"
26 bl_description = (
27 "Enable or disable the editing of objects transforms in the 3D View\n"
28 "Needs an existing Active Object"
30 bl_options = {'REGISTER', 'UNDO'}
32 @classmethod
33 def poll(cls, context):
34 return context.active_object is not None
36 def execute(self, context):
37 obj = context.active_object
38 if obj.lock_rotation[0] is False:
39 obj.lock_rotation[0] = True
40 obj.lock_rotation[1] = True
41 obj.lock_rotation[2] = True
42 obj.lock_scale[0] = True
43 obj.lock_scale[1] = True
44 obj.lock_scale[2] = True
46 elif context.object.lock_rotation[0] is True:
47 obj.lock_rotation[0] = False
48 obj.lock_rotation[1] = False
49 obj.lock_rotation[2] = False
50 obj.lock_scale[0] = False
51 obj.lock_scale[1] = False
52 obj.lock_scale[2] = False
54 return {'FINISHED'}
57 # Pie views numpad - Q
58 class PIE_MT_ViewNumpad(Menu):
59 bl_idname = "PIE_MT_viewnumpad"
60 bl_label = "Pie Views Menu"
62 def draw(self, context):
63 layout = self.layout
64 ob = context.active_object
65 pie = layout.menu_pie()
66 scene = context.scene
67 rd = scene.render
69 # 4 - LEFT
70 pie.operator("view3d.view_axis", text="Left", icon='TRIA_LEFT').type = 'LEFT'
71 # 6 - RIGHT
72 pie.operator("view3d.view_axis", text="Right", icon='TRIA_RIGHT').type = 'RIGHT'
73 # 2 - BOTTOM
74 pie.operator("view3d.view_axis", text="Bottom", icon='TRIA_DOWN').type = 'BOTTOM'
75 # 8 - TOP
76 pie.operator("view3d.view_axis", text="Top", icon='TRIA_UP').type = 'TOP'
77 # 7 - TOP - LEFT
78 pie.operator("view3d.view_axis", text="Back").type = 'BACK'
79 # 9 - TOP - RIGHT
80 pie.operator("view3d.view_axis", text="Front").type = 'FRONT'
81 # 1 - BOTTOM - LEFT
82 box = pie.split().column()
84 row = box.row(align=True)
85 row.operator("view3d.view_camera", text="View Cam", icon='HIDE_OFF')
86 row.operator("view3d.camera_to_view", text="Cam To View", icon='NONE')
88 row = box.row(align=True)
89 if context.space_data.lock_camera is False:
90 row.operator("wm.context_toggle", text="Lock Cam To View",
91 icon='UNLOCKED').data_path = "space_data.lock_camera"
92 elif context.space_data.lock_camera is True:
93 row.operator("wm.context_toggle", text="Lock Cam to View",
94 icon='LOCKED').data_path = "space_data.lock_camera"
96 icon_locked = 'LOCKED' if ob and ob.lock_rotation[0] is False else \
97 'UNLOCKED' if ob and ob.lock_rotation[0] is True else 'LOCKED'
99 row = box.row(align=True)
100 row.operator("object.locktransforms", text="Lock Transforms", icon=icon_locked)
102 row = box.row(align=True)
103 row.prop(rd, "use_border", text="Border")
104 # 3 - BOTTOM - RIGHT
105 box = pie.split().column()
107 row = box.row(align=True)
108 row.operator("view3d.view_all").center = True
109 row.operator("view3d.view_selected", text="Selected")
111 row = box.row(align=True)
112 row.operator("view3d.view_persportho", text="Persp/Ortho")
113 row.operator("view3d.localview", text="Local/Global")
115 row = box.row(align=True)
116 row.operator("screen.region_quadview", text="Toggle Quad")
117 row.operator("screen.screen_full_area", text="Toggle Full")
120 classes = (
121 PIE_MT_ViewNumpad,
122 PIE_OT_LockTransforms,
125 addon_keymaps = []
128 def register():
129 for cls in classes:
130 bpy.utils.register_class(cls)
132 wm = bpy.context.window_manager
133 if wm.keyconfigs.addon:
134 # Views numpad
135 km = wm.keyconfigs.addon.keymaps.new(name='3D View Generic', space_type='VIEW_3D')
136 kmi = km.keymap_items.new('wm.call_menu_pie', 'Q', 'PRESS', alt=True)
137 kmi.properties.name = "PIE_MT_viewnumpad"
138 addon_keymaps.append((km, kmi))
141 def unregister():
142 for cls in classes:
143 bpy.utils.unregister_class(cls)
145 wm = bpy.context.window_manager
146 kc = wm.keyconfigs.addon
147 if kc:
148 for km, kmi in addon_keymaps:
149 km.keymap_items.remove(kmi)
150 addon_keymaps.clear()
153 if __name__ == "__main__":
154 register()