Merge branch 'blender-v2.92-release'
[blender-addons.git] / space_view3d_pie_menus / pie_manipulator_menu.py
blob428254d48ab7061daf7a5896825f5bddb90c1c2b
1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
19 # <pep8 compliant>
21 bl_info = {
22 "name": "Hotkey: 'Alt Spacebar'",
23 "description": "Manipulator Menu",
24 "author": "pitiwazou, meta-androcto",
25 "version": (0, 1, 1),
26 "blender": (2, 80, 0),
27 "location": "3D View",
28 "warning": "",
29 "doc_url": "",
30 "category": "Manipulator Pie"
33 import bpy
34 from bpy.types import (
35 Menu,
36 Operator,
38 from bpy.props import (
39 BoolProperty,
40 EnumProperty,
44 class PIE_OT_WManupulators(Operator):
45 bl_idname = "w.manipulators"
46 bl_label = "W Manupulators"
47 bl_options = {'REGISTER', 'UNDO'}
48 bl_description = " Show/Hide Manipulator"
50 extend: BoolProperty(
51 default=False,
53 type: EnumProperty(
54 items=(
55 ('TRANSLATE', "Move", ""),
56 ('ROTATE', "Rotate", ""),
57 ('SCALE', "Scale", ""),
61 def execute(self, context):
62 space_data = context.space_data
63 space_data.show_gizmo_context = True
65 attrs = (
66 "show_gizmo_object_translate",
67 "show_gizmo_object_rotate",
68 "show_gizmo_object_scale",
70 attr_t, attr_r, attr_s = attrs
71 attr_index = ('TRANSLATE', 'ROTATE', 'SCALE').index(self.type)
72 attr_active = attrs[attr_index]
74 if self.extend:
75 setattr(space_data, attr_active, not getattr(space_data, attr_active))
76 else:
77 for attr in attrs:
78 setattr(space_data, attr, attr == attr_active)
79 return {'FINISHED'}
81 def invoke(self, context, event):
82 self.extend = event.shift
83 return self.execute(context)
86 # Pie Manipulators - Ctrl + Space
87 class PIE_MT_Manipulator(Menu):
88 bl_idname = "PIE_MT_manipulator"
89 bl_label = "Pie Manipulator"
91 def draw(self, context):
92 layout = self.layout
93 pie = layout.menu_pie()
94 # 4 - LEFT
95 pie.operator("w.manipulators", text="Rotate", icon='NONE').type = 'ROTATE'
96 # 6 - RIGHT
97 pie.operator("w.manipulators", text="Scale", icon='NONE').type = 'SCALE'
98 # 2 - BOTTOM
99 props = pie.operator("wm.context_toggle", text="Show/Hide Toggle", icon='NONE')
100 props.data_path = "space_data.show_gizmo_context"
101 # 8 - TOP
102 pie.operator("w.manipulators", text="Translate", icon='NONE').type = 'TRANSLATE'
106 classes = (
107 PIE_OT_WManupulators,
108 PIE_MT_Manipulator,
111 addon_keymaps = []
114 def register():
115 for cls in classes:
116 bpy.utils.register_class(cls)
118 wm = bpy.context.window_manager
119 if wm.keyconfigs.addon:
120 # Manipulators
121 km = wm.keyconfigs.addon.keymaps.new(name='3D View Generic', space_type='VIEW_3D')
122 kmi = km.keymap_items.new('wm.call_menu_pie', 'SPACE', 'PRESS', alt=True)
123 kmi.properties.name = "PIE_MT_manipulator"
124 addon_keymaps.append((km, kmi))
127 def unregister():
128 for cls in classes:
129 bpy.utils.unregister_class(cls)
131 wm = bpy.context.window_manager
132 kc = wm.keyconfigs.addon
133 if kc:
134 for km, kmi in addon_keymaps:
135 km.keymap_items.remove(kmi)
136 addon_keymaps.clear()
139 if __name__ == "__main__":
140 register()