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