Code cleanup: unused python vars & imports
[blender-staging.git] / release / scripts / startup / bl_ui / space_dopesheet.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 import bpy
22 from bpy.types import Header, Menu
23
24
25 #######################################
26 # DopeSheet Filtering
27
28 # used for DopeSheet, NLA, and Graph Editors
29 def dopesheet_filter(layout, context, genericFiltersOnly=False):
30     dopesheet = context.space_data.dopesheet
31     is_nla = context.area.type == 'NLA_EDITOR'
32
33     row = layout.row(align=True)
34     row.prop(dopesheet, "show_only_selected", text="")
35     row.prop(dopesheet, "show_hidden", text="")
36
37     if is_nla:
38         row.prop(dopesheet, "show_missing_nla", text="")
39     else:  # graph and dopesheet editors - F-Curves and drivers only
40         row.prop(dopesheet, "show_only_errors", text="")
41
42     if not genericFiltersOnly:
43         if bpy.data.groups:
44             row = layout.row(align=True)
45             row.prop(dopesheet, "show_only_group_objects", text="")
46             if dopesheet.show_only_group_objects:
47                 row.prop(dopesheet, "filter_group", text="")
48
49     if not is_nla:
50         row = layout.row(align=True)
51         row.prop(dopesheet, "show_only_matching_fcurves", text="")
52         if dopesheet.show_only_matching_fcurves:
53             row.prop(dopesheet, "filter_fcurve_name", text="")
54
55     if not genericFiltersOnly:
56         row = layout.row(align=True)
57         row.prop(dopesheet, "show_datablock_filters", text="Filters")
58
59         if dopesheet.show_datablock_filters:
60             row.prop(dopesheet, "show_scenes", text="")
61             row.prop(dopesheet, "show_worlds", text="")
62             row.prop(dopesheet, "show_nodes", text="")
63
64             row.prop(dopesheet, "show_transforms", text="")
65
66             if bpy.data.meshes:
67                 row.prop(dopesheet, "show_meshes", text="")
68             if bpy.data.shape_keys:
69                 row.prop(dopesheet, "show_shapekeys", text="")
70             if bpy.data.meshes:
71                 row.prop(dopesheet, "show_modifiers", text="")
72             if bpy.data.materials:
73                 row.prop(dopesheet, "show_materials", text="")
74             if bpy.data.lamps:
75                 row.prop(dopesheet, "show_lamps", text="")
76             if bpy.data.textures:
77                 row.prop(dopesheet, "show_textures", text="")
78             if bpy.data.cameras:
79                 row.prop(dopesheet, "show_cameras", text="")
80             if bpy.data.curves:
81                 row.prop(dopesheet, "show_curves", text="")
82             if bpy.data.metaballs:
83                 row.prop(dopesheet, "show_metaballs", text="")
84             if bpy.data.lattices:
85                 row.prop(dopesheet, "show_lattices", text="")
86             if bpy.data.armatures:
87                 row.prop(dopesheet, "show_armatures", text="")
88             if bpy.data.particles:
89                 row.prop(dopesheet, "show_particles", text="")
90             if bpy.data.speakers:
91                 row.prop(dopesheet, "show_speakers", text="")
92             if bpy.data.linestyles:
93                 row.prop(dopesheet, "show_linestyles", text="")
94
95
96 #######################################
97 # DopeSheet Editor - General/Standard UI
98
99 class DOPESHEET_HT_header(Header):
100     bl_space_type = 'DOPESHEET_EDITOR'
101
102     def draw(self, context):
103         layout = self.layout
104
105         st = context.space_data
106
107         row = layout.row(align=True)
108         row.template_header()
109
110         DOPESHEET_MT_editor_menus.draw_collapsible(context, layout)
111
112         layout.prop(st, "mode", text="")
113         layout.prop(st.dopesheet, "show_summary", text="Summary")
114
115         if st.mode == 'DOPESHEET':
116             dopesheet_filter(layout, context)
117         elif st.mode == 'ACTION':
118             # 'genericFiltersOnly' limits the options to only the relevant 'generic' subset of
119             # filters which will work here and are useful (especially for character animation)
120             dopesheet_filter(layout, context, genericFiltersOnly=True)
121
122         if st.mode in {'ACTION', 'SHAPEKEY'}:
123             layout.template_ID(st, "action", new="action.new")
124
125         # Grease Pencil mode doesn't need snapping, as it's frame-aligned only
126         if st.mode != 'GPENCIL':
127             layout.prop(st, "auto_snap", text="")
128
129         row = layout.row(align=True)
130         row.operator("action.copy", text="", icon='COPYDOWN')
131         row.operator("action.paste", text="", icon='PASTEDOWN')
132
133
134 class DOPESHEET_MT_editor_menus(Menu):
135     bl_idname = "DOPESHEET_MT_editor_menus"
136     bl_label = ""
137
138     def draw(self, context):
139         self.draw_menus(self.layout, context)
140
141     @staticmethod
142     def draw_menus(layout, context):
143         st = context.space_data
144
145         layout.menu("DOPESHEET_MT_view")
146         layout.menu("DOPESHEET_MT_select")
147         layout.menu("DOPESHEET_MT_marker")
148
149         if st.mode == 'DOPESHEET' or (st.mode == 'ACTION' and st.action is not None):
150             layout.menu("DOPESHEET_MT_channel")
151         elif st.mode == 'GPENCIL':
152             layout.menu("DOPESHEET_MT_gpencil_channel")
153
154         if st.mode != 'GPENCIL':
155             layout.menu("DOPESHEET_MT_key")
156         else:
157             layout.menu("DOPESHEET_MT_gpencil_frame")
158
159
160 class DOPESHEET_MT_view(Menu):
161     bl_label = "View"
162
163     def draw(self, context):
164         layout = self.layout
165
166         st = context.space_data
167
168         layout.prop(st, "use_realtime_update")
169         layout.prop(st, "show_frame_indicator")
170         layout.prop(st, "show_sliders")
171         layout.prop(st, "show_group_colors")
172         layout.prop(st, "use_auto_merge_keyframes")
173         layout.prop(st, "use_marker_sync")
174
175         layout.prop(st, "show_seconds")
176
177         layout.separator()
178         layout.operator("anim.previewrange_set")
179         layout.operator("anim.previewrange_clear")
180         layout.operator("action.previewrange_set")
181
182         layout.separator()
183         layout.operator("action.view_all")
184         layout.operator("action.view_selected")
185
186         layout.separator()
187         layout.operator("screen.area_dupli")
188         layout.operator("screen.screen_full_area")
189
190
191 class DOPESHEET_MT_select(Menu):
192     bl_label = "Select"
193
194     def draw(self, context):
195         layout = self.layout
196
197         # This is a bit misleading as the operator's default text is "Select All" while it actually *toggles* All/None
198         layout.operator("action.select_all_toggle").invert = False
199         layout.operator("action.select_all_toggle", text="Invert Selection").invert = True
200
201         layout.separator()
202         layout.operator("action.select_border").axis_range = False
203         layout.operator("action.select_border", text="Border Axis Range").axis_range = True
204
205         layout.separator()
206         layout.operator("action.select_column", text="Columns on Selected Keys").mode = 'KEYS'
207         layout.operator("action.select_column", text="Column on Current Frame").mode = 'CFRA'
208
209         layout.operator("action.select_column", text="Columns on Selected Markers").mode = 'MARKERS_COLUMN'
210         layout.operator("action.select_column", text="Between Selected Markers").mode = 'MARKERS_BETWEEN'
211
212         layout.separator()
213         layout.operator("action.select_leftright", text="Before Current Frame").mode = 'LEFT'
214         layout.operator("action.select_leftright", text="After Current Frame").mode = 'RIGHT'
215
216         # FIXME: grease pencil mode isn't supported for these yet, so skip for that mode only
217         if context.space_data.mode != 'GPENCIL':
218             layout.separator()
219             layout.operator("action.select_more")
220             layout.operator("action.select_less")
221
222             layout.separator()
223             layout.operator("action.select_linked")
224
225
226 class DOPESHEET_MT_marker(Menu):
227     bl_label = "Marker"
228
229     def draw(self, context):
230         layout = self.layout
231
232         from bl_ui.space_time import marker_menu_generic
233         marker_menu_generic(layout)
234
235         st = context.space_data
236
237         if st.mode in {'ACTION', 'SHAPEKEY'} and st.action:
238             layout.separator()
239             layout.prop(st, "show_pose_markers")
240
241             if st.show_pose_markers is False:
242                 layout.operator("action.markers_make_local")
243
244
245 #######################################
246 # Keyframe Editing
247
248 class DOPESHEET_MT_channel(Menu):
249     bl_label = "Channel"
250
251     def draw(self, context):
252         layout = self.layout
253
254         layout.operator_context = 'INVOKE_REGION_CHANNELS'
255
256         layout.operator("anim.channels_delete")
257
258         layout.separator()
259         layout.operator("anim.channels_group")
260         layout.operator("anim.channels_ungroup")
261
262         layout.separator()
263         layout.operator_menu_enum("anim.channels_setting_toggle", "type")
264         layout.operator_menu_enum("anim.channels_setting_enable", "type")
265         layout.operator_menu_enum("anim.channels_setting_disable", "type")
266
267         layout.separator()
268         layout.operator("anim.channels_editable_toggle")
269         layout.operator_menu_enum("action.extrapolation_type", "type", text="Extrapolation Mode")
270
271         layout.separator()
272         layout.operator("anim.channels_expand")
273         layout.operator("anim.channels_collapse")
274
275         layout.separator()
276         layout.operator_menu_enum("anim.channels_move", "direction", text="Move...")
277
278         layout.separator()
279         layout.operator("anim.channels_fcurves_enable")
280
281
282 class DOPESHEET_MT_key(Menu):
283     bl_label = "Key"
284
285     def draw(self, context):
286         layout = self.layout
287
288         layout.menu("DOPESHEET_MT_key_transform", text="Transform")
289
290         layout.operator_menu_enum("action.snap", "type", text="Snap")
291         layout.operator_menu_enum("action.mirror", "type", text="Mirror")
292
293         layout.separator()
294         layout.operator("action.keyframe_insert")
295
296         layout.separator()
297         layout.operator("action.frame_jump")
298
299         layout.separator()
300         layout.operator("action.duplicate_move")
301         layout.operator("action.delete")
302
303         layout.separator()
304         layout.operator_menu_enum("action.keyframe_type", "type", text="Keyframe Type")
305         layout.operator_menu_enum("action.handle_type", "type", text="Handle Type")
306         layout.operator_menu_enum("action.interpolation_type", "type", text="Interpolation Mode")
307
308         layout.separator()
309         layout.operator("action.clean")
310         layout.operator("action.sample")
311
312         layout.separator()
313         layout.operator("action.copy")
314         layout.operator("action.paste")
315
316
317 class DOPESHEET_MT_key_transform(Menu):
318     bl_label = "Transform"
319
320     def draw(self, context):
321         layout = self.layout
322
323         layout.operator("transform.transform", text="Grab/Move").mode = 'TIME_TRANSLATE'
324         layout.operator("transform.transform", text="Extend").mode = 'TIME_EXTEND'
325         layout.operator("transform.transform", text="Slide").mode = 'TIME_SLIDE'
326         layout.operator("transform.transform", text="Scale").mode = 'TIME_SCALE'
327
328
329 #######################################
330 # Grease Pencil Editing
331
332 class DOPESHEET_MT_gpencil_channel(Menu):
333     bl_label = "Channel"
334
335     def draw(self, context):
336         layout = self.layout
337
338         layout.operator_context = 'INVOKE_REGION_CHANNELS'
339
340         layout.operator("anim.channels_delete")
341
342         layout.separator()
343         layout.operator("anim.channels_setting_toggle")
344         layout.operator("anim.channels_setting_enable")
345         layout.operator("anim.channels_setting_disable")
346
347         layout.separator()
348         layout.operator("anim.channels_editable_toggle")
349
350         # XXX: to be enabled when these are ready for use!
351         #layout.separator()
352         #layout.operator("anim.channels_expand")
353         #layout.operator("anim.channels_collapse")
354
355         #layout.separator()
356         #layout.operator_menu_enum("anim.channels_move", "direction", text="Move...")
357
358
359 class DOPESHEET_MT_gpencil_frame(Menu):
360     bl_label = "Frame"
361
362     def draw(self, context):
363         layout = self.layout
364
365         layout.menu("DOPESHEET_MT_key_transform", text="Transform")
366
367         #layout.operator_menu_enum("action.snap", "type", text="Snap")
368         #layout.operator_menu_enum("action.mirror", "type", text="Mirror")
369
370         layout.separator()
371         layout.operator("action.duplicate")
372         layout.operator("action.delete")
373
374         #layout.separator()
375         #layout.operator("action.copy")
376         #layout.operator("action.paste")
377
378 if __name__ == "__main__":  # only for live edit.
379     bpy.utils.register_module(__name__)