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