Cleanup: autopep8 format pie menus
[blender-addons.git] / space_view3d_pie_menus / pie_manipulator_menu.py
blob98e28b85d9028a126947d4b268aa5562ab5c240a
1 # SPDX-License-Identifier: GPL-2.0-or-later
3 bl_info = {
4 "name": "Hotkey: 'Alt Spacebar'",
5 "description": "Manipulator Menu",
6 "author": "pitiwazou, meta-androcto",
7 "version": (0, 1, 1),
8 "blender": (2, 80, 0),
9 "location": "3D View",
10 "warning": "",
11 "doc_url": "",
12 "category": "Manipulator Pie"
15 import bpy
16 from bpy.types import (
17 Menu,
18 Operator,
20 from bpy.props import (
21 BoolProperty,
22 EnumProperty,
26 class PIE_OT_WManupulators(Operator):
27 bl_idname = "w.manipulators"
28 bl_label = "W Manupulators"
29 bl_options = {'REGISTER', 'UNDO'}
30 bl_description = " Show/Hide Manipulator"
32 extend: BoolProperty(
33 default=False,
35 type: EnumProperty(
36 items=(
37 ('TRANSLATE', "Move", ""),
38 ('ROTATE', "Rotate", ""),
39 ('SCALE', "Scale", ""),
43 def execute(self, context):
44 space_data = context.space_data
45 space_data.show_gizmo_context = True
47 attrs = (
48 "show_gizmo_object_translate",
49 "show_gizmo_object_rotate",
50 "show_gizmo_object_scale",
52 attr_t, attr_r, attr_s = attrs
53 attr_index = ('TRANSLATE', 'ROTATE', 'SCALE').index(self.type)
54 attr_active = attrs[attr_index]
56 if self.extend:
57 setattr(space_data, attr_active, not getattr(space_data, attr_active))
58 else:
59 for attr in attrs:
60 setattr(space_data, attr, attr == attr_active)
61 return {'FINISHED'}
63 def invoke(self, context, event):
64 self.extend = event.shift
65 return self.execute(context)
68 # Pie Manipulators - Ctrl + Space
69 class PIE_MT_Manipulator(Menu):
70 bl_idname = "PIE_MT_manipulator"
71 bl_label = "Pie Manipulator"
73 def draw(self, context):
74 layout = self.layout
75 pie = layout.menu_pie()
76 # 4 - LEFT
77 pie.operator("w.manipulators", text="Rotate", icon='NONE').type = 'ROTATE'
78 # 6 - RIGHT
79 pie.operator("w.manipulators", text="Scale", icon='NONE').type = 'SCALE'
80 # 2 - BOTTOM
81 props = pie.operator("wm.context_toggle", text="Show/Hide Toggle", icon='NONE')
82 props.data_path = "space_data.show_gizmo_context"
83 # 8 - TOP
84 pie.operator("w.manipulators", text="Translate", icon='NONE').type = 'TRANSLATE'
87 classes = (
88 PIE_OT_WManupulators,
89 PIE_MT_Manipulator,
92 addon_keymaps = []
95 def register():
96 for cls in classes:
97 bpy.utils.register_class(cls)
99 wm = bpy.context.window_manager
100 if wm.keyconfigs.addon:
101 # Manipulators
102 km = wm.keyconfigs.addon.keymaps.new(name='3D View Generic', space_type='VIEW_3D')
103 kmi = km.keymap_items.new('wm.call_menu_pie', 'SPACE', 'PRESS', alt=True)
104 kmi.properties.name = "PIE_MT_manipulator"
105 addon_keymaps.append((km, kmi))
108 def unregister():
109 for cls in classes:
110 bpy.utils.unregister_class(cls)
112 wm = bpy.context.window_manager
113 kc = wm.keyconfigs.addon
114 if kc:
115 for km, kmi in addon_keymaps:
116 km.keymap_items.remove(kmi)
117 addon_keymaps.clear()
120 if __name__ == "__main__":
121 register()