Cleanup: pep8
[blender.git] / release / scripts / startup / bl_ui / space_nla.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2 #
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.
7 #
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.
12 #
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.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20
21 from bpy.types import Header, Menu, Panel
22 from bpy.app.translations import contexts as i18n_contexts
23 from .space_dopesheet import (
24     DopesheetFilterPopoverBase,
25     dopesheet_filter,
26 )
27
28
29 class NLA_HT_header(Header):
30     bl_space_type = 'NLA_EDITOR'
31
32     def draw(self, context):
33         layout = self.layout
34
35         st = context.space_data
36
37         layout.template_header()
38
39         NLA_MT_editor_menus.draw_collapsible(context, layout)
40
41         layout.separator_spacer()
42
43         dopesheet_filter(layout, context)
44
45         layout.popover(
46             panel="NLA_PT_filters",
47             text="",
48             icon='FILTER',
49         )
50
51         layout.prop(st, "auto_snap", text="")
52
53
54 class NLA_PT_filters(DopesheetFilterPopoverBase, Panel):
55     bl_space_type = 'NLA_EDITOR'
56     bl_region_type = 'HEADER'
57     bl_label = "Filters"
58
59     def draw(self, context):
60         layout = self.layout
61
62         DopesheetFilterPopoverBase.draw_generic_filters(context, layout)
63         layout.separator()
64         DopesheetFilterPopoverBase.draw_search_filters(context, layout)
65         layout.separator()
66         DopesheetFilterPopoverBase.draw_standard_filters(context, layout)
67
68
69 class NLA_MT_editor_menus(Menu):
70     bl_idname = "NLA_MT_editor_menus"
71     bl_label = ""
72
73     def draw(self, _context):
74         layout = self.layout
75         layout.menu("NLA_MT_view")
76         layout.menu("NLA_MT_select")
77         layout.menu("NLA_MT_marker")
78         layout.menu("NLA_MT_edit")
79         layout.menu("NLA_MT_add")
80
81
82 class NLA_MT_view(Menu):
83     bl_label = "View"
84
85     def draw(self, context):
86         layout = self.layout
87
88         st = context.space_data
89
90         layout.prop(st, "show_region_ui")
91         layout.separator()
92
93         layout.prop(st, "use_realtime_update")
94         layout.prop(st, "show_frame_indicator")
95
96         layout.prop(st, "show_seconds")
97         layout.prop(st, "show_locked_time")
98
99         layout.prop(st, "show_strip_curves")
100         layout.prop(st, "show_local_markers")
101         layout.prop(st, "show_marker_lines")
102
103         layout.separator()
104         layout.operator("anim.previewrange_set")
105         layout.operator("anim.previewrange_clear")
106         layout.operator("nla.previewrange_set")
107
108         layout.separator()
109         layout.operator("nla.view_all")
110         layout.operator("nla.view_selected")
111         layout.operator("nla.view_frame")
112
113         layout.separator()
114         layout.menu("INFO_MT_area")
115
116
117 class NLA_MT_select(Menu):
118     bl_label = "Select"
119
120     def draw(self, _context):
121         layout = self.layout
122
123         layout.operator("nla.select_all", text="All").action = 'SELECT'
124         layout.operator("nla.select_all", text="None").action = 'DESELECT'
125         layout.operator("nla.select_all", text="Invert").action = 'INVERT'
126
127         layout.separator()
128         layout.operator("nla.select_box").axis_range = False
129         layout.operator("nla.select_box", text="Border Axis Range").axis_range = True
130
131         layout.separator()
132         props = layout.operator("nla.select_leftright", text="Before Current Frame")
133         props.extend = False
134         props.mode = 'LEFT'
135         props = layout.operator("nla.select_leftright", text="After Current Frame")
136         props.extend = False
137         props.mode = 'RIGHT'
138
139
140 class NLA_MT_marker(Menu):
141     bl_label = "Marker"
142
143     def draw(self, context):
144         layout = self.layout
145
146         from .space_time import marker_menu_generic
147         marker_menu_generic(layout, context)
148
149
150 class NLA_MT_edit(Menu):
151     bl_label = "Edit"
152
153     def draw(self, context):
154         layout = self.layout
155
156         scene = context.scene
157
158         layout.menu("NLA_MT_edit_transform", text="Transform")
159
160         layout.operator_menu_enum("nla.snap", "type", text="Snap")
161
162         layout.separator()
163         layout.operator("nla.duplicate", text="Duplicate").linked = False
164         layout.operator("nla.duplicate", text="Linked Duplicate").linked = True
165         layout.operator("nla.split")
166         layout.operator("nla.delete")
167
168         layout.separator()
169         layout.operator("nla.mute_toggle")
170
171         layout.separator()
172         layout.operator("nla.apply_scale")
173         layout.operator("nla.clear_scale")
174         layout.operator("nla.action_sync_length").active = False
175
176         layout.separator()
177         layout.operator("nla.make_single_user")
178
179         layout.separator()
180         layout.operator("nla.swap")
181         layout.operator("nla.move_up")
182         layout.operator("nla.move_down")
183
184         # TODO: this really belongs more in a "channel" (or better, "track") menu
185         layout.separator()
186         layout.operator_menu_enum("anim.channels_move", "direction", text="Track Ordering...")
187         layout.operator("anim.channels_clean_empty")
188
189         layout.separator()
190         # TODO: names of these tools for 'tweak-mode' need changing?
191         if scene.is_nla_tweakmode:
192             layout.operator("nla.tweakmode_exit", text="Stop Editing Stashed Action").isolate_action = True
193             layout.operator("nla.tweakmode_exit", text="Stop Tweaking Strip Actions")
194         else:
195             layout.operator("nla.tweakmode_enter", text="Start Editing Stashed Action").isolate_action = True
196             layout.operator("nla.tweakmode_enter", text="Start Tweaking Strip Actions")
197
198
199 class NLA_MT_add(Menu):
200     bl_label = "Add"
201     bl_translation_context = i18n_contexts.operator_default
202
203     def draw(self, _context):
204         layout = self.layout
205
206         layout.operator("nla.actionclip_add")
207         layout.operator("nla.transition_add")
208         layout.operator("nla.soundclip_add")
209
210         layout.separator()
211         layout.operator("nla.meta_add")
212         layout.operator("nla.meta_remove")
213
214         layout.separator()
215         layout.operator("nla.tracks_add").above_selected = False
216         layout.operator("nla.tracks_add", text="Add Tracks Above Selected").above_selected = True
217
218         layout.separator()
219         layout.operator("nla.selected_objects_add")
220
221
222 class NLA_MT_edit_transform(Menu):
223     bl_label = "Transform"
224
225     def draw(self, _context):
226         layout = self.layout
227
228         layout.operator("transform.translate", text="Move")
229         layout.operator("transform.transform", text="Extend").mode = 'TIME_EXTEND'
230         layout.operator("transform.transform", text="Scale").mode = 'TIME_SCALE'
231
232
233 class NLA_MT_snap_pie(Menu):
234     bl_label = "Snap"
235
236     def draw(self, _context):
237         layout = self.layout
238         pie = layout.menu_pie()
239
240         pie.operator("nla.snap", text="Current Frame").type = 'CFRA'
241         pie.operator("nla.snap", text="Nearest Frame").type = 'NEAREST_FRAME'
242         pie.operator("nla.snap", text="Nearest Second").type = 'NEAREST_SECOND'
243         pie.operator("nla.snap", text="Nearest Marker").type = 'NEAREST_MARKER'
244
245
246 class NLA_MT_context_menu(Menu):
247     bl_label = "NLA Context Menu"
248
249     def draw(self, context):
250         layout = self.layout
251         scene = context.scene
252
253         if scene.is_nla_tweakmode:
254             layout.operator("nla.tweakmode_exit", text="Stop Editing Stashed Action").isolate_action = True
255             layout.operator("nla.tweakmode_exit", text="Stop Tweaking Strip Actions")
256         else:
257             layout.operator("nla.tweakmode_enter", text="Start Editing Stashed Action").isolate_action = True
258             layout.operator("nla.tweakmode_enter", text="Start Tweaking Strip Actions")
259
260         layout.separator()
261
262         layout.operator("nla.duplicate", text="Duplicate").linked = False
263         layout.operator("nla.duplicate", text="Linked Duplicate").linked = True
264
265         layout.separator()
266
267         layout.operator("nla.split")
268         layout.operator("nla.delete")
269
270         layout.separator()
271
272         layout.operator("nla.swap")
273
274         layout.separator()
275
276         layout.operator_menu_enum("nla.snap", "type", text="Snap")
277
278
279 class NLA_MT_channel_context_menu(Menu):
280     bl_label = "NLA Channel Context Menu"
281
282     def draw(self, context):
283         layout = self.layout
284
285         layout.operator_menu_enum("anim.channels_move", "direction", text="Track Ordering...")
286         layout.operator("anim.channels_clean_empty")
287
288
289 classes = (
290     NLA_HT_header,
291     NLA_MT_edit,
292     NLA_MT_editor_menus,
293     NLA_MT_view,
294     NLA_MT_select,
295     NLA_MT_marker,
296     NLA_MT_add,
297     NLA_MT_edit_transform,
298     NLA_MT_snap_pie,
299     NLA_MT_context_menu,
300     NLA_MT_channel_context_menu,
301     NLA_PT_filters,
302 )
303
304 if __name__ == "__main__":  # only for live edit.
305     from bpy.utils import register_class
306     for cls in classes:
307         register_class(cls)