Import images: add file handler
[blender-addons.git] / space_view3d_pie_menus / pie_manipulator_menu.py
blob4dc048a45a677ad7f3c0cf746c3fa05dcdfcec92
1 # SPDX-FileCopyrightText: 2016-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 bl_info = {
6 "name": "Hotkey: 'Alt Spacebar'",
7 "description": "Manipulator Menu",
8 "author": "pitiwazou, meta-androcto",
9 "version": (0, 1, 1),
10 "blender": (2, 80, 0),
11 "location": "3D View",
12 "warning": "",
13 "doc_url": "",
14 "category": "Manipulator Pie"
17 import bpy
18 from bpy.types import (
19 Menu,
20 Operator,
22 from bpy.props import (
23 BoolProperty,
24 EnumProperty,
28 class PIE_OT_WManupulators(Operator):
29 bl_idname = "w.manipulators"
30 bl_label = "W Manupulators"
31 bl_options = {'REGISTER', 'UNDO'}
32 bl_description = " Show/Hide Manipulator"
34 extend: BoolProperty(
35 default=False,
37 type: EnumProperty(
38 items=(
39 ('TRANSLATE', "Move", ""),
40 ('ROTATE', "Rotate", ""),
41 ('SCALE', "Scale", ""),
45 def execute(self, context):
46 space_data = context.space_data
47 space_data.show_gizmo_context = True
49 attrs = (
50 "show_gizmo_object_translate",
51 "show_gizmo_object_rotate",
52 "show_gizmo_object_scale",
54 attr_t, attr_r, attr_s = attrs
55 attr_index = ('TRANSLATE', 'ROTATE', 'SCALE').index(self.type)
56 attr_active = attrs[attr_index]
58 if self.extend:
59 setattr(space_data, attr_active, not getattr(space_data, attr_active))
60 else:
61 for attr in attrs:
62 setattr(space_data, attr, attr == attr_active)
63 return {'FINISHED'}
65 def invoke(self, context, event):
66 self.extend = event.shift
67 return self.execute(context)
70 # Pie Manipulators - Ctrl + Space
71 class PIE_MT_Manipulator(Menu):
72 bl_idname = "PIE_MT_manipulator"
73 bl_label = "Pie Manipulator"
75 def draw(self, context):
76 layout = self.layout
77 pie = layout.menu_pie()
78 # 4 - LEFT
79 pie.operator("w.manipulators", text="Rotate", icon='NONE').type = 'ROTATE'
80 # 6 - RIGHT
81 pie.operator("w.manipulators", text="Scale", icon='NONE').type = 'SCALE'
82 # 2 - BOTTOM
83 props = pie.operator("wm.context_toggle", text="Show/Hide Toggle", icon='NONE')
84 props.data_path = "space_data.show_gizmo_context"
85 # 8 - TOP
86 pie.operator("w.manipulators", text="Translate", icon='NONE').type = 'TRANSLATE'
89 classes = (
90 PIE_OT_WManupulators,
91 PIE_MT_Manipulator,
94 addon_keymaps = []
97 def register():
98 for cls in classes:
99 bpy.utils.register_class(cls)
101 wm = bpy.context.window_manager
102 if wm.keyconfigs.addon:
103 # Manipulators
104 km = wm.keyconfigs.addon.keymaps.new(name='3D View Generic', space_type='VIEW_3D')
105 kmi = km.keymap_items.new('wm.call_menu_pie', 'SPACE', 'PRESS', alt=True)
106 kmi.properties.name = "PIE_MT_manipulator"
107 addon_keymaps.append((km, kmi))
110 def unregister():
111 for cls in classes:
112 bpy.utils.unregister_class(cls)
114 wm = bpy.context.window_manager
115 kc = wm.keyconfigs.addon
116 if kc:
117 for km, kmi in addon_keymaps:
118 km.keymap_items.remove(kmi)
119 addon_keymaps.clear()
122 if __name__ == "__main__":
123 register()