Cleanup: strip trailing space
[blender-addons.git] / space_view3d_pie_menus / pie_editor_switch_menu.py
blob0ba1d1b63a251cfa957afeab26e48ecc063ba46e
1 # SPDX-FileCopyrightText: 2016-2023 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 bl_info = {
6 "name": "Hotkey: 'Ctrl Alt S' ",
7 "description": "Switch Editor Type Menu",
8 "author": "saidenka, meta-androcto",
9 "version": (0, 1, 2),
10 "blender": (3, 40, 1),
11 "location": "All Editors",
12 "warning": "",
13 "doc_url": "",
14 "category": "Editor Switch Pie"
17 import bpy
18 from bpy.types import (
19 Menu,
20 Operator,
22 from bpy.props import (
23 StringProperty,
26 # Pie Menu
29 class PIE_MT_AreaPieEditor(Menu):
30 bl_idname = "PIE_MT_editor"
31 bl_label = "Editor Switch"
33 def draw(self, context):
34 layout = self.layout
35 pie = layout.menu_pie()
36 # 4 - LEFT
37 pie.operator(PIE_OT_SetAreaType.bl_idname,
38 text="Video Sequence Editor", icon="SEQUENCE").types = "SEQUENCE_EDITOR"
39 # 6 - RIGHT
40 pie.menu(PIE_MT_AreaTypePieNode.bl_idname, text="Node Editors", icon="NODETREE")
41 # 2 - BOTTOM
42 pie.menu(PIE_MT_AreaTypePieOther.bl_idname, text="Script/Data Editors", icon="PREFERENCES")
43 # 8 - TOP
44 pie.operator(PIE_OT_SetAreaType.bl_idname, text="3D View", icon="VIEW3D").types = "VIEW_3D"
45 # 7 - TOP - LEFT
46 pie.operator(PIE_OT_SetAreaType.bl_idname, text="Image Editor", icon="IMAGE").types = "IMAGE_EDITOR"
47 # 9 - TOP - RIGHT
48 pie.operator(PIE_OT_SetAreaType.bl_idname, text="UV Editor", icon="UV").types = "UV"
49 # 1 - BOTTOM - LEFT
50 pie.operator(PIE_OT_SetAreaType.bl_idname,
51 text="Movie Clip Editor", icon="TRACKER").types = "CLIP_EDITOR"
52 # 3 - BOTTOM - RIGHT
53 pie.menu(PIE_MT_AreaTypePieAnim.bl_idname, text="Animation Editors", icon="ACTION")
55 # Sub Menu Script/Data Editors
58 class PIE_MT_AreaTypePieOther(Menu):
59 bl_idname = "TOPBAR_MT_window_pie_area_type_other"
60 bl_label = "Editor Type (other)"
61 bl_description = "Is pie menu change editor type (other)"
63 def draw(self, context):
64 self.layout.operator(PIE_OT_SetAreaType.bl_idname, text="Outliner", icon="OUTLINER").types = "OUTLINER"
65 self.layout.operator(PIE_OT_SetAreaType.bl_idname, text="Properties", icon="PROPERTIES").types = "PROPERTIES"
66 self.layout.operator(
67 PIE_OT_SetAreaType.bl_idname,
68 text="File Browser",
69 icon="FILEBROWSER").types = "FILES"
70 self.layout.operator(PIE_OT_SetAreaType.bl_idname, text="Preferences",
71 icon="PREFERENCES").types = "PREFERENCES"
72 self.layout.operator(PIE_OT_SetAreaType.bl_idname, text="Text Editor", icon="TEXT").types = "TEXT_EDITOR"
73 self.layout.operator(PIE_OT_SetAreaType.bl_idname, text="Python Console", icon="CONSOLE").types = "CONSOLE"
74 self.layout.operator(PIE_OT_SetAreaType.bl_idname, text="Info", icon="INFO").types = "INFO"
75 self.layout.operator(PIE_OT_SetAreaType.bl_idname, text="Spreadsheet", icon="SPREADSHEET").types = "SPREADSHEET"
76 self.layout.operator(PIE_OT_SetAreaType.bl_idname, text="Asset Browser", icon="ASSET_MANAGER").types = "ASSETS"
79 # Sub Menu Node editors.
80 class PIE_MT_AreaTypePieNode(Menu):
81 bl_idname = "TOPBAR_MT_window_pie_area_type_node"
82 bl_label = "Editor Type (Node)"
83 bl_description = "Menu to change node editor types"
85 def draw(self, context):
86 self.layout.operator(PIE_OT_SetAreaType.bl_idname, text="Shader", icon="NODE_MATERIAL").types = "ShaderNodeTree"
87 self.layout.operator(PIE_OT_SetAreaType.bl_idname, text="Compositor",
88 icon="NODE_COMPOSITING").types = "CompositorNodeTree"
89 self.layout.operator(PIE_OT_SetAreaType.bl_idname, text="Texture",
90 icon="NODE_TEXTURE").types = "TextureNodeTree"
91 self.layout.operator(PIE_OT_SetAreaType.bl_idname, text="Geometry",
92 icon="NODETREE").types = "GeometryNodeTree"
95 # Sub Menu animation Editors.
96 class PIE_MT_AreaTypePieAnim(Menu):
97 bl_idname = "TOPBAR_MT_window_pie_area_type_anim"
98 bl_label = "Editor Type (Animation)"
99 bl_description = "Menu for changing editor type (animation related)"
101 def draw(self, context):
102 self.layout.operator(PIE_OT_SetAreaType.bl_idname, text="DopeSheet", icon="ACTION").types = "DOPESHEET"
103 self.layout.operator(PIE_OT_Timeline.bl_idname, text="Timeline", icon="TIME")
104 self.layout.operator(PIE_OT_SetAreaType.bl_idname, text="Graph Editor", icon="GRAPH").types = "FCURVES"
105 self.layout.operator(PIE_OT_SetAreaType.bl_idname, text="Drivers", icon="DRIVER").types = "DRIVERS"
106 self.layout.operator(PIE_OT_SetAreaType.bl_idname, text="NLA Editor", icon="NLA").types = "NLA_EDITOR"
109 # Operators.
110 class PIE_OT_SetAreaType(Operator):
111 bl_idname = "wm.set_area_type"
112 bl_label = "Change Editor Type"
113 bl_description = "Change Editor Type"
114 bl_options = {'REGISTER'}
116 types: StringProperty(name="Area Type")
118 def execute(self, context):
119 context.area.ui_type = self.types
120 return {'FINISHED'}
123 class PIE_OT_Timeline(Operator):
124 bl_idname = "wm.set_timeline"
125 bl_label = "Change Editor Type"
126 bl_description = "Change Editor Type"
127 bl_options = {'REGISTER'}
129 def execute(self, context):
130 bpy.context.area.ui_type = 'TIMELINE'
131 return {'FINISHED'}
134 classes = (
135 PIE_MT_AreaPieEditor,
136 PIE_MT_AreaTypePieOther,
137 PIE_OT_SetAreaType,
138 PIE_MT_AreaTypePieAnim,
139 PIE_OT_Timeline,
140 PIE_MT_AreaTypePieNode
143 addon_keymaps = []
146 def register():
147 for cls in classes:
148 bpy.utils.register_class(cls)
150 wm = bpy.context.window_manager
151 if wm.keyconfigs.addon:
152 # Snapping
153 km = wm.keyconfigs.addon.keymaps.new(name='Window')
154 kmi = km.keymap_items.new('wm.call_menu_pie', 'S', 'PRESS', ctrl=True, alt=True)
155 kmi.properties.name = "PIE_MT_editor"
156 addon_keymaps.append((km, kmi))
159 def unregister():
160 for cls in classes:
161 bpy.utils.unregister_class(cls)
163 wm = bpy.context.window_manager
164 kc = wm.keyconfigs.addon
165 if kc:
166 for km, kmi in addon_keymaps:
167 km.keymap_items.remove(kmi)
168 addon_keymaps.clear()
171 if __name__ == "__main__":
172 register()