Merge branch 'master' into blender2.8
[blender.git] / release / scripts / startup / bl_ui / space_time.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 import bpy
21 from bpy.types import Header, Menu, Panel
22
23
24 # Header buttons for timeline header (play, etc.)
25 class TIME_HT_editor_buttons(Header):
26     bl_idname = "TIME_HT_editor_buttons"
27     bl_space_type = 'DOPESHEET_EDITOR'
28     bl_label = ""
29
30     def draw(self, context):
31         pass
32
33     @staticmethod
34     def draw_header(context, layout):
35         scene = context.scene
36         tool_settings = context.tool_settings
37         screen = context.screen
38
39         layout.separator_spacer()
40
41         layout.prop(tool_settings, "use_keyframe_insert_auto", text="", toggle=True)
42
43         row = layout.row(align=True)
44         row.operator("screen.frame_jump", text="", icon='REW').end = False
45         row.operator("screen.keyframe_jump", text="", icon='PREV_KEYFRAME').next = False
46         if not screen.is_animation_playing:
47             # if using JACK and A/V sync:
48             #   hide the play-reversed button
49             #   since JACK transport doesn't support reversed playback
50             if scene.sync_mode == 'AUDIO_SYNC' and context.user_preferences.system.audio_device == 'JACK':
51                 sub = row.row(align=True)
52                 sub.scale_x = 1.4
53                 sub.operator("screen.animation_play", text="", icon='PLAY')
54             else:
55                 row.operator("screen.animation_play", text="", icon='PLAY_REVERSE').reverse = True
56                 row.operator("screen.animation_play", text="", icon='PLAY')
57         else:
58             sub = row.row(align=True)
59             sub.scale_x = 1.4
60             sub.operator("screen.animation_play", text="", icon='PAUSE')
61         row.operator("screen.keyframe_jump", text="", icon='NEXT_KEYFRAME').next = True
62         row.operator("screen.frame_jump", text="", icon='FF').end = True
63
64         layout.separator_spacer()
65
66         row = layout.row()
67         row.scale_x = 0.95
68         if scene.show_subframe:
69             row.prop(scene, "frame_float", text="")
70         else:
71             row.prop(scene, "frame_current", text="")
72
73         row = layout.row(align=True)
74         row.prop(scene, "use_preview_range", text="", toggle=True)
75         sub = row.row(align=True)
76         sub.scale_x = 0.8
77         if not scene.use_preview_range:
78             sub.prop(scene, "frame_start", text="Start")
79             sub.prop(scene, "frame_end", text="End")
80         else:
81             sub.prop(scene, "frame_preview_start", text="Start")
82             sub.prop(scene, "frame_preview_end", text="End")
83
84
85 class TIME_MT_editor_menus(Menu):
86     bl_idname = "TIME_MT_editor_menus"
87     bl_label = ""
88
89     def draw(self, context):
90         self.draw_menus(self.layout, context, horizontal=False)
91
92     @staticmethod
93     def draw_menus(layout, context, horizontal=True):
94         if horizontal:
95             row = layout.row()
96             sub = row.row(align=True)
97         else:
98             sub = layout
99
100         sub.popover(
101             panel="TIME_PT_playback",
102             text="Playback",
103         )
104         sub.popover(
105             panel="TIME_PT_keyframing_settings",
106             text="Keying",
107         )
108
109         if horizontal:
110             sub = row.row(align=True)
111
112         sub.menu("TIME_MT_view")
113         sub.menu("TIME_MT_marker")
114
115
116 class TIME_MT_marker(Menu):
117     bl_label = "Marker"
118
119     def draw(self, context):
120         layout = self.layout
121
122         marker_menu_generic(layout)
123
124
125 class TIME_MT_view(Menu):
126     bl_label = "View"
127
128     def draw(self, context):
129         layout = self.layout
130
131         scene = context.scene
132         st = context.space_data
133
134         layout.prop(st, "show_seconds")
135         layout.prop(st, "show_locked_time")
136
137         layout.separator()
138
139         layout.prop(st, "show_frame_indicator")
140         layout.prop(scene, "show_keys_from_selected_only")
141
142         layout.separator()
143
144         layout.menu("TIME_MT_cache")
145
146         layout.separator()
147
148         # NOTE: "action" now, since timeline is in the dopesheet editor, instead of as own editor
149         layout.operator("action.view_all")
150         layout.operator("action.view_frame")
151
152         layout.separator()
153
154         layout.menu("INFO_MT_area")
155
156
157 class TIME_MT_cache(Menu):
158     bl_label = "Cache"
159
160     def draw(self, context):
161         layout = self.layout
162
163         st = context.space_data
164
165         layout.prop(st, "show_cache")
166
167         layout.separator()
168
169         col = layout.column()
170         col.enabled = st.show_cache
171         col.prop(st, "cache_softbody")
172         col.prop(st, "cache_particles")
173         col.prop(st, "cache_cloth")
174         col.prop(st, "cache_smoke")
175         col.prop(st, "cache_dynamicpaint")
176         col.prop(st, "cache_rigidbody")
177
178
179 def marker_menu_generic(layout):
180     from bpy import context
181
182     # layout.operator_context = 'EXEC_REGION_WIN'
183
184     layout.column()
185     layout.operator("marker.add", text="Add Marker")
186     layout.operator("marker.duplicate", text="Duplicate Marker")
187
188     if len(bpy.data.scenes) > 10:
189         layout.operator_context = 'INVOKE_DEFAULT'
190         layout.operator("marker.make_links_scene", text="Duplicate Marker to Scene...", icon='OUTLINER_OB_EMPTY')
191     else:
192         layout.operator_menu_enum("marker.make_links_scene", "scene", text="Duplicate Marker to Scene")
193
194     layout.operator("marker.delete", text="Delete Marker")
195
196     layout.separator()
197
198     layout.operator("marker.rename", text="Rename Marker")
199     layout.operator("marker.move", text="Move Marker")
200
201     layout.separator()
202
203     layout.operator("marker.camera_bind")
204
205     layout.separator()
206
207     layout.operator("screen.marker_jump", text="Jump to Next Marker").next = True
208     layout.operator("screen.marker_jump", text="Jump to Previous Marker").next = False
209
210     layout.separator()
211     tool_settings = context.tool_settings
212     layout.prop(tool_settings, "lock_markers")
213
214 ###################################
215
216
217 class TimelinePanelButtons:
218     bl_space_type = 'DOPESHEET_EDITOR'
219     bl_region_type = 'UI'
220
221     @staticmethod
222     def has_timeline(context):
223         return context.space_data.mode == 'TIMELINE'
224
225
226 class TIME_PT_playback(TimelinePanelButtons, Panel):
227     bl_label = "Playback"
228     bl_region_type = 'HEADER'
229
230     def draw(self, context):
231         layout = self.layout
232
233         screen = context.screen
234         scene = context.scene
235
236         layout.prop(scene, "sync_mode", text="")
237         layout.prop(scene, "use_audio_scrub")
238         layout.prop(scene, "use_audio", text="Mute Audio")
239
240         layout.prop(scene, "show_subframe", text="Subframes")
241
242         layout.prop(scene, "lock_frame_selection_to_range", text="Limit Playhead to Frame Range")
243         layout.prop(screen, "use_follow", text="Follow Playhead")
244
245         layout.separator()
246
247         col = layout.column()
248         col.label(text="Play Animation In:")
249         layout.prop(screen, "use_play_top_left_3d_editor", text="Active Editor Only")
250         layout.prop(screen, "use_play_3d_editors")
251         layout.prop(screen, "use_play_animation_editors")
252         layout.prop(screen, "use_play_properties_editors")
253         layout.prop(screen, "use_play_image_editors")
254         layout.prop(screen, "use_play_sequence_editors")
255         layout.prop(screen, "use_play_node_editors")
256         layout.prop(screen, "use_play_clip_editors")
257
258         layout.separator()
259
260         row = layout.row(align=True)
261         row.operator("anim.start_frame_set")
262         row.operator("anim.end_frame_set")
263
264
265 class TIME_PT_keyframing_settings(TimelinePanelButtons, Panel):
266     bl_label = "Keyframing Settings"
267     bl_options = {'HIDE_HEADER'}
268     bl_region_type = 'HEADER'
269
270     @classmethod
271     def poll(cls, context):
272         # only for timeline editor
273         return cls.has_timeline(context)
274
275     def draw(self, context):
276         layout = self.layout
277
278         scene = context.scene
279         tool_settings = context.tool_settings
280         userprefs = context.user_preferences
281
282         col = layout.column(align=True)
283         col.label(text="Active Keying Set:")
284         row = col.row(align=True)
285         row.prop_search(scene.keying_sets_all, "active", scene, "keying_sets_all", text="")
286         row.operator("anim.keyframe_insert", text="", icon='KEY_HLT')
287         row.operator("anim.keyframe_delete", text="", icon='KEY_DEHLT')
288
289         col = layout.column(align=True)
290         col.label(text="New Keyframe Type:")
291         col.prop(tool_settings, "keyframe_type", text="")
292
293         col = layout.column(align=True)
294         col.label(text="Auto Keyframing:")
295         row = col.row()
296         row.prop(tool_settings, "auto_keying_mode", text="")
297         row.prop(tool_settings, "use_keyframe_insert_keyingset", text="")
298         if not userprefs.edit.use_keyframe_insert_available:
299             col.prop(tool_settings, "use_record_with_nla", text="Layered Recording")
300
301         layout.prop(tool_settings, "use_keyframe_cycle_aware")
302
303
304 ###################################
305
306 classes = (
307     TIME_HT_editor_buttons,
308     TIME_MT_editor_menus,
309     TIME_MT_marker,
310     TIME_MT_view,
311     TIME_MT_cache,
312     TIME_PT_playback,
313     TIME_PT_keyframing_settings,
314 )
315
316 if __name__ == "__main__":  # only for live edit.
317     from bpy.utils import register_class
318     for cls in classes:
319         register_class(cls)