Cleanup: use 'tool_settings' name everywhere in UI scripts
[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
22
23
24 class TIME_HT_header(Header):
25     bl_space_type = 'TIMELINE'
26
27     def draw(self, context):
28         layout = self.layout
29
30         scene = context.scene
31         tool_settings = context.tool_settings
32         screen = context.screen
33         userprefs = context.user_preferences
34
35         row = layout.row(align=True)
36         row.template_header()
37
38         TIME_MT_editor_menus.draw_collapsible(context, layout)
39
40         row = layout.row(align=True)
41         row.prop(scene, "use_preview_range", text="", toggle=True)
42         row.prop(scene, "lock_frame_selection_to_range", text="", toggle=True)
43
44         row = layout.row(align=True)
45         if not scene.use_preview_range:
46             row.prop(scene, "frame_start", text="Start")
47             row.prop(scene, "frame_end", text="End")
48         else:
49             row.prop(scene, "frame_preview_start", text="Start")
50             row.prop(scene, "frame_preview_end", text="End")
51
52         if scene.show_subframe:
53             layout.prop(scene, "frame_float", text="")
54         else:
55             layout.prop(scene, "frame_current", text="")
56
57         layout.separator()
58
59         row = layout.row(align=True)
60         row.operator("screen.frame_jump", text="", icon='REW').end = False
61         row.operator("screen.keyframe_jump", text="", icon='PREV_KEYFRAME').next = False
62         if not screen.is_animation_playing:
63             # if using JACK and A/V sync:
64             #   hide the play-reversed button
65             #   since JACK transport doesn't support reversed playback
66             if scene.sync_mode == 'AUDIO_SYNC' and context.user_preferences.system.audio_device == 'JACK':
67                 sub = row.row(align=True)
68                 sub.scale_x = 2.0
69                 sub.operator("screen.animation_play", text="", icon='PLAY')
70             else:
71                 row.operator("screen.animation_play", text="", icon='PLAY_REVERSE').reverse = True
72                 row.operator("screen.animation_play", text="", icon='PLAY')
73         else:
74             sub = row.row(align=True)
75             sub.scale_x = 2.0
76             sub.operator("screen.animation_play", text="", icon='PAUSE')
77         row.operator("screen.keyframe_jump", text="", icon='NEXT_KEYFRAME').next = True
78         row.operator("screen.frame_jump", text="", icon='FF').end = True
79
80         layout.prop(scene, "sync_mode", text="")
81
82         layout.separator()
83
84         row = layout.row(align=True)
85         row.prop(tool_settings, "use_keyframe_insert_auto", text="", toggle=True)
86         if tool_settings.use_keyframe_insert_auto:
87             row.prop(tool_settings, "use_keyframe_insert_keyingset", text="", toggle=True)
88
89             if screen.is_animation_playing and not userprefs.edit.use_keyframe_insert_available:
90                 subsub = row.row(align=True)
91                 subsub.prop(tool_settings, "use_record_with_nla", toggle=True)
92
93         layout.prop(tool_settings, "keyframe_type", text="", icon_only=True)
94
95         row = layout.row(align=True)
96         row.prop_search(scene.keying_sets_all, "active", scene, "keying_sets_all", text="")
97         row.operator("anim.keyframe_insert", text="", icon='KEY_HLT')
98         row.operator("anim.keyframe_delete", text="", icon='KEY_DEHLT')
99
100
101 class TIME_MT_editor_menus(Menu):
102     bl_idname = "TIME_MT_editor_menus"
103     bl_label = ""
104
105     def draw(self, context):
106         self.draw_menus(self.layout, context)
107
108     @staticmethod
109     def draw_menus(layout, context):
110         layout.menu("TIME_MT_view")
111         layout.menu("TIME_MT_marker")
112         layout.menu("TIME_MT_frame")
113         layout.menu("TIME_MT_playback")
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         layout.prop(scene, "show_subframe")
142
143         layout.separator()
144
145         layout.menu("TIME_MT_cache")
146
147         layout.separator()
148
149         layout.operator("time.view_all")
150         layout.operator("time.view_frame")
151
152         layout.separator()
153
154         layout.operator("marker.camera_bind")
155
156         layout.separator()
157
158         layout.operator("screen.area_dupli")
159         layout.operator("screen.screen_full_area")
160         layout.operator("screen.screen_full_area", text="Toggle Fullscreen Area").use_hide_panels = True
161
162
163 class TIME_MT_cache(Menu):
164     bl_label = "Cache"
165
166     def draw(self, context):
167         layout = self.layout
168
169         st = context.space_data
170
171         layout.prop(st, "show_cache")
172
173         layout.separator()
174
175         col = layout.column()
176         col.enabled = st.show_cache
177         col.prop(st, "cache_softbody")
178         col.prop(st, "cache_particles")
179         col.prop(st, "cache_cloth")
180         col.prop(st, "cache_smoke")
181         col.prop(st, "cache_dynamicpaint")
182         col.prop(st, "cache_rigidbody")
183
184
185 class TIME_MT_frame(Menu):
186     bl_label = "Frame"
187
188     def draw(self, context):
189         layout = self.layout
190
191         layout.operator("anim.previewrange_clear")
192         layout.operator("anim.previewrange_set")
193         layout.separator()
194         layout.operator("time.end_frame_set")
195         layout.operator("time.start_frame_set")
196
197         layout.separator()
198
199         layout.menu("TIME_MT_autokey")
200
201
202 class TIME_MT_playback(Menu):
203     bl_label = "Playback"
204
205     def draw(self, context):
206         layout = self.layout
207
208         screen = context.screen
209         scene = context.scene
210
211         layout.prop(screen, "use_play_top_left_3d_editor")
212         layout.prop(screen, "use_play_3d_editors")
213         layout.prop(screen, "use_play_animation_editors")
214         layout.prop(screen, "use_play_properties_editors")
215         layout.prop(screen, "use_play_image_editors")
216         layout.prop(screen, "use_play_sequence_editors")
217         layout.prop(screen, "use_play_node_editors")
218         layout.prop(screen, "use_play_clip_editors")
219
220         layout.separator()
221         layout.prop(screen, "use_follow")
222         layout.separator()
223
224         layout.prop(scene, "use_frame_drop", text="Frame Dropping")
225         layout.prop(scene, "use_audio_sync", text="AV-sync", icon='SPEAKER')
226         layout.prop(scene, "use_audio")
227         layout.prop(scene, "use_audio_scrub")
228
229
230 class TIME_MT_autokey(Menu):
231     bl_label = "Auto-Keyframing Mode"
232
233     def draw(self, context):
234         layout = self.layout
235         tool_settings = context.tool_settings
236
237         layout.prop_enum(tool_settings, "auto_keying_mode", 'ADD_REPLACE_KEYS')
238         layout.prop_enum(tool_settings, "auto_keying_mode", 'REPLACE_KEYS')
239
240
241 def marker_menu_generic(layout):
242     from bpy import context
243
244     # layout.operator_context = 'EXEC_REGION_WIN'
245
246     layout.column()
247     layout.operator("marker.add", "Add Marker")
248     layout.operator("marker.duplicate", text="Duplicate Marker")
249
250     if len(bpy.data.scenes) > 10:
251         layout.operator_context = 'INVOKE_DEFAULT'
252         layout.operator("marker.make_links_scene", text="Duplicate Marker to Scene...", icon='OUTLINER_OB_EMPTY')
253     else:
254         layout.operator_menu_enum("marker.make_links_scene", "scene", text="Duplicate Marker to Scene")
255
256     layout.operator("marker.delete", text="Delete Marker")
257
258     layout.separator()
259
260     layout.operator("marker.rename", text="Rename Marker")
261     layout.operator("marker.move", text="Grab/Move Marker")
262
263     layout.separator()
264
265     layout.operator("screen.marker_jump", text="Jump to Next Marker").next = True
266     layout.operator("screen.marker_jump", text="Jump to Previous Marker").next = False
267
268     layout.separator()
269     tool_settings = context.tool_settings
270     layout.prop(tool_settings, "lock_markers")
271
272
273 classes = (
274     TIME_HT_header,
275     TIME_MT_editor_menus,
276     TIME_MT_marker,
277     TIME_MT_view,
278     TIME_MT_cache,
279     TIME_MT_frame,
280     TIME_MT_playback,
281     TIME_MT_autokey,
282 )
283
284 if __name__ == "__main__":  # only for live edit.
285     from bpy.utils import register_class
286     for cls in classes:
287         register_class(cls)