Cleanup: use staticmethod where appropriate
[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.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         layout = self.layout
91         horizontal = (layout.direction == 'VERTICAL')
92         if horizontal:
93             row = layout.row()
94             sub = row.row(align=True)
95         else:
96             sub = layout
97
98         sub.popover(
99             panel="TIME_PT_playback",
100             text="Playback",
101         )
102         sub.popover(
103             panel="TIME_PT_keyframing_settings",
104             text="Keying",
105         )
106
107         if horizontal:
108             sub = row.row(align=True)
109
110         sub.menu("TIME_MT_view")
111         sub.menu("TIME_MT_marker")
112
113
114 class TIME_MT_marker(Menu):
115     bl_label = "Marker"
116
117     def draw(self, context):
118         layout = self.layout
119
120         marker_menu_generic(layout, context)
121
122
123 class TIME_MT_view(Menu):
124     bl_label = "View"
125
126     def draw(self, context):
127         layout = self.layout
128
129         scene = context.scene
130         st = context.space_data
131
132         layout.prop(st, "show_seconds")
133         layout.prop(st, "show_locked_time")
134
135         layout.separator()
136
137         layout.prop(st, "show_marker_lines")
138         layout.prop(st, "show_frame_indicator")
139         layout.prop(scene, "show_keys_from_selected_only")
140
141         layout.separator()
142
143         layout.menu("TIME_MT_cache")
144
145         layout.separator()
146
147         # NOTE: "action" now, since timeline is in the dopesheet editor, instead of as own editor
148         layout.operator("action.view_all")
149         layout.operator("action.view_frame")
150
151         layout.separator()
152
153         layout.menu("INFO_MT_area")
154
155
156 class TIME_MT_cache(Menu):
157     bl_label = "Cache"
158
159     def draw(self, context):
160         layout = self.layout
161
162         st = context.space_data
163
164         layout.prop(st, "show_cache")
165
166         layout.separator()
167
168         col = layout.column()
169         col.enabled = st.show_cache
170         col.prop(st, "cache_softbody")
171         col.prop(st, "cache_particles")
172         col.prop(st, "cache_cloth")
173         col.prop(st, "cache_smoke")
174         col.prop(st, "cache_dynamicpaint")
175         col.prop(st, "cache_rigidbody")
176
177
178 def marker_menu_generic(layout, context):
179
180     # layout.operator_context = 'EXEC_REGION_WIN'
181
182     layout.column()
183     layout.operator("marker.add", text="Add Marker")
184     layout.operator("marker.duplicate", text="Duplicate Marker")
185
186     if len(bpy.data.scenes) > 10:
187         layout.operator_context = 'INVOKE_DEFAULT'
188         layout.operator("marker.make_links_scene", text="Duplicate Marker to Scene...", icon='OUTLINER_OB_EMPTY')
189     else:
190         layout.operator_menu_enum("marker.make_links_scene", "scene", text="Duplicate Marker to Scene")
191
192     layout.operator("marker.delete", text="Delete Marker")
193
194     layout.separator()
195
196     layout.operator("marker.rename", text="Rename Marker")
197     layout.operator("marker.move", text="Move Marker")
198
199     layout.separator()
200
201     layout.operator("marker.camera_bind")
202
203     layout.separator()
204
205     layout.operator("screen.marker_jump", text="Jump to Next Marker").next = True
206     layout.operator("screen.marker_jump", text="Jump to Previous Marker").next = False
207
208     layout.separator()
209     tool_settings = context.tool_settings
210     layout.prop(tool_settings, "lock_markers")
211
212 ###################################
213
214
215 class TimelinePanelButtons:
216     bl_space_type = 'DOPESHEET_EDITOR'
217     bl_region_type = 'UI'
218
219     @staticmethod
220     def has_timeline(context):
221         return context.space_data.mode == 'TIMELINE'
222
223
224 class TIME_PT_playback(TimelinePanelButtons, Panel):
225     bl_label = "Playback"
226     bl_region_type = 'HEADER'
227
228     def draw(self, context):
229         layout = self.layout
230
231         screen = context.screen
232         scene = context.scene
233
234         layout.prop(scene, "sync_mode", text="")
235         layout.prop(scene, "use_audio_scrub")
236         layout.prop(scene, "use_audio", text="Mute Audio")
237
238         layout.prop(scene, "show_subframe", text="Subframes")
239
240         layout.prop(scene, "lock_frame_selection_to_range", text="Limit Playhead to Frame Range")
241         layout.prop(screen, "use_follow", text="Follow Playhead")
242
243         layout.separator()
244
245         col = layout.column()
246         col.label(text="Play Animation In:")
247         layout.prop(screen, "use_play_top_left_3d_editor", text="Active Editor Only")
248         layout.prop(screen, "use_play_3d_editors")
249         layout.prop(screen, "use_play_animation_editors")
250         layout.prop(screen, "use_play_properties_editors")
251         layout.prop(screen, "use_play_image_editors")
252         layout.prop(screen, "use_play_sequence_editors")
253         layout.prop(screen, "use_play_node_editors")
254         layout.prop(screen, "use_play_clip_editors")
255
256         layout.separator()
257
258         row = layout.row(align=True)
259         row.operator("anim.start_frame_set")
260         row.operator("anim.end_frame_set")
261
262
263 class TIME_PT_keyframing_settings(TimelinePanelButtons, Panel):
264     bl_label = "Keyframing Settings"
265     bl_options = {'HIDE_HEADER'}
266     bl_region_type = 'HEADER'
267
268     @classmethod
269     def poll(cls, context):
270         # only for timeline editor
271         return cls.has_timeline(context)
272
273     def draw(self, context):
274         layout = self.layout
275
276         scene = context.scene
277         tool_settings = context.tool_settings
278         prefs = context.preferences
279
280         col = layout.column(align=True)
281         col.label(text="Active Keying Set:")
282         row = col.row(align=True)
283         row.prop_search(scene.keying_sets_all, "active", scene, "keying_sets_all", text="")
284         row.operator("anim.keyframe_insert", text="", icon='KEY_HLT')
285         row.operator("anim.keyframe_delete", text="", icon='KEY_DEHLT')
286
287         col = layout.column(align=True)
288         col.label(text="New Keyframe Type:")
289         col.prop(tool_settings, "keyframe_type", text="")
290
291         col = layout.column(align=True)
292         col.label(text="Auto Keyframing:")
293         row = col.row()
294         row.prop(tool_settings, "auto_keying_mode", text="")
295         row.prop(tool_settings, "use_keyframe_insert_keyingset", text="")
296         if not prefs.edit.use_keyframe_insert_available:
297             col.prop(tool_settings, "use_record_with_nla", text="Layered Recording")
298
299         layout.prop(tool_settings, "use_keyframe_cycle_aware")
300
301
302 ###################################
303
304 classes = (
305     TIME_HT_editor_buttons,
306     TIME_MT_editor_menus,
307     TIME_MT_marker,
308     TIME_MT_view,
309     TIME_MT_cache,
310     TIME_PT_playback,
311     TIME_PT_keyframing_settings,
312 )
313
314 if __name__ == "__main__":  # only for live edit.
315     from bpy.utils import register_class
316     for cls in classes:
317         register_class(cls)