Import images: add file handler
[blender-addons.git] / space_view3d_pie_menus / pie_views_numpad_menu.py
blob387e62a509d3f8de10500df7362ebca4391f1c63
1 # SPDX-FileCopyrightText: 2016-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 bl_info = {
6 "name": "Hotkey: 'Alt Q'",
7 "description": "Viewport Numpad Menus",
8 "author": "pitiwazou, meta-androcto",
9 "version": (0, 1, 1),
10 "blender": (2, 80, 0),
11 "location": "Alt Q key",
12 "warning": "",
13 "doc_url": "",
14 "category": "View Numpad Pie"
17 import bpy
18 from bpy.types import (
19 Menu,
20 Operator,
24 # Lock Camera Transforms
25 class PIE_OT_LockTransforms(Operator):
26 bl_idname = "object.locktransforms"
27 bl_label = "Lock Object Transforms"
28 bl_description = (
29 "Enable or disable the editing of objects transforms in the 3D View\n"
30 "Needs an existing Active Object"
32 bl_options = {'REGISTER', 'UNDO'}
34 @classmethod
35 def poll(cls, context):
36 return context.active_object is not None
38 def execute(self, context):
39 obj = context.active_object
40 if obj.lock_rotation[0] is False:
41 obj.lock_rotation[0] = True
42 obj.lock_rotation[1] = True
43 obj.lock_rotation[2] = True
44 obj.lock_scale[0] = True
45 obj.lock_scale[1] = True
46 obj.lock_scale[2] = True
48 elif context.object.lock_rotation[0] is True:
49 obj.lock_rotation[0] = False
50 obj.lock_rotation[1] = False
51 obj.lock_rotation[2] = False
52 obj.lock_scale[0] = False
53 obj.lock_scale[1] = False
54 obj.lock_scale[2] = False
56 return {'FINISHED'}
59 # Pie views numpad - Q
60 class PIE_MT_ViewNumpad(Menu):
61 bl_idname = "PIE_MT_viewnumpad"
62 bl_label = "Pie Views Menu"
64 def draw(self, context):
65 layout = self.layout
66 ob = context.active_object
67 pie = layout.menu_pie()
68 scene = context.scene
69 rd = scene.render
71 # 4 - LEFT
72 pie.operator("view3d.view_axis", text="Left", icon='TRIA_LEFT').type = 'LEFT'
73 # 6 - RIGHT
74 pie.operator("view3d.view_axis", text="Right", icon='TRIA_RIGHT').type = 'RIGHT'
75 # 2 - BOTTOM
76 pie.operator("view3d.view_axis", text="Bottom", icon='TRIA_DOWN').type = 'BOTTOM'
77 # 8 - TOP
78 pie.operator("view3d.view_axis", text="Top", icon='TRIA_UP').type = 'TOP'
79 # 7 - TOP - LEFT
80 pie.operator("view3d.view_axis", text="Back").type = 'BACK'
81 # 9 - TOP - RIGHT
82 pie.operator("view3d.view_axis", text="Front").type = 'FRONT'
83 # 1 - BOTTOM - LEFT
84 box = pie.split().column()
86 row = box.row(align=True)
87 row.operator("view3d.view_camera", text="View Cam", icon='HIDE_OFF')
88 row.operator("view3d.camera_to_view", text="Cam To View", icon='NONE')
90 row = box.row(align=True)
91 if context.space_data.lock_camera is False:
92 row.operator("wm.context_toggle", text="Lock Cam To View",
93 icon='UNLOCKED').data_path = "space_data.lock_camera"
94 elif context.space_data.lock_camera is True:
95 row.operator("wm.context_toggle", text="Lock Cam to View",
96 icon='LOCKED').data_path = "space_data.lock_camera"
98 icon_locked = 'LOCKED' if ob and ob.lock_rotation[0] is False else \
99 'UNLOCKED' if ob and ob.lock_rotation[0] is True else 'LOCKED'
101 row = box.row(align=True)
102 row.operator("object.locktransforms", text="Lock Transforms", icon=icon_locked)
104 row = box.row(align=True)
105 row.prop(rd, "use_border", text="Border")
106 # 3 - BOTTOM - RIGHT
107 box = pie.split().column()
109 row = box.row(align=True)
110 row.operator("view3d.view_all").center = True
111 row.operator("view3d.view_selected", text="Selected")
113 row = box.row(align=True)
114 row.operator("view3d.view_persportho", text="Persp/Ortho")
115 row.operator("view3d.localview", text="Local/Global")
117 row = box.row(align=True)
118 row.operator("screen.region_quadview", text="Toggle Quad")
119 row.operator("screen.screen_full_area", text="Toggle Full")
122 classes = (
123 PIE_MT_ViewNumpad,
124 PIE_OT_LockTransforms,
127 addon_keymaps = []
130 def register():
131 for cls in classes:
132 bpy.utils.register_class(cls)
134 wm = bpy.context.window_manager
135 if wm.keyconfigs.addon:
136 # Views numpad
137 km = wm.keyconfigs.addon.keymaps.new(name='3D View Generic', space_type='VIEW_3D')
138 kmi = km.keymap_items.new('wm.call_menu_pie', 'Q', 'PRESS', alt=True)
139 kmi.properties.name = "PIE_MT_viewnumpad"
140 addon_keymaps.append((km, kmi))
143 def unregister():
144 for cls in classes:
145 bpy.utils.unregister_class(cls)
147 wm = bpy.context.window_manager
148 kc = wm.keyconfigs.addon
149 if kc:
150 for km, kmi in addon_keymaps:
151 km.keymap_items.remove(kmi)
152 addon_keymaps.clear()
155 if __name__ == "__main__":
156 register()