Merge with trunk, revision 28528 - 28976.
[blender-staging.git] / release / scripts / 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
22
23 class TIME_HT_header(bpy.types.Header):
24     bl_space_type = 'TIMELINE'
25
26     def draw(self, context):
27         layout = self.layout
28
29         scene = context.scene
30         tools = context.tool_settings
31         screen = context.screen
32
33         row = layout.row(align=True)
34         row.template_header()
35
36         if context.area.show_menus:
37             sub = row.row(align=True)
38             sub.menu("TIME_MT_view")
39             sub.menu("TIME_MT_frame")
40             sub.menu("TIME_MT_playback")
41
42         layout.prop(scene, "use_preview_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, "preview_range_frame_start", text="Start")
50             row.prop(scene, "preview_range_frame_end", text="End")
51
52         layout.prop(scene, "frame_current", text="")
53
54         layout.separator()
55
56         row = layout.row(align=True)
57         row.operator("screen.frame_jump", text="", icon='REW').end = False
58         row.operator("screen.keyframe_jump", text="", icon='PREV_KEYFRAME').next = False
59         if not screen.animation_playing:
60             row.operator("screen.animation_play", text="", icon='PLAY_REVERSE').reverse = True
61             row.operator("screen.animation_play", text="", icon='PLAY')
62         else:
63             sub = row.row()
64             sub.scale_x = 2.0
65             sub.operator("screen.animation_play", text="", icon='PAUSE')
66         row.operator("screen.keyframe_jump", text="", icon='NEXT_KEYFRAME').next = True
67         row.operator("screen.frame_jump", text="", icon='FF').end = True
68
69         row = layout.row(align=True)
70         row.prop(tools, "use_auto_keying", text="", toggle=True)
71         if screen.animation_playing and tools.use_auto_keying:
72             subsub = row.row()
73             subsub.prop(tools, "record_with_nla", toggle=True)
74
75         layout.prop(scene, "sync_mode", text="")
76
77         layout.separator()
78
79         row = layout.row(align=True)
80         row.prop_object(scene, "active_keying_set", scene, "all_keying_sets", text="")
81         row.operator("anim.keyframe_insert", text="", icon='KEY_HLT')
82         row.operator("anim.keyframe_delete", text="", icon='KEY_DEHLT')
83
84
85 class TIME_MT_view(bpy.types.Menu):
86     bl_label = "View"
87
88     def draw(self, context):
89         layout = self.layout
90
91         st = context.space_data
92
93         layout.operator("anim.time_toggle")
94         layout.operator("time.view_all")
95
96         layout.separator()
97
98         layout.prop(st, "show_cframe_indicator")
99         layout.prop(st, "only_selected")
100
101         layout.separator()
102
103         layout.operator("marker.camera_bind")
104
105
106 class TIME_MT_frame(bpy.types.Menu):
107     bl_label = "Frame"
108
109     def draw(self, context):
110         layout = self.layout
111         # tools = context.tool_settings
112
113         layout.operator("marker.add", text="Add Marker")
114         layout.operator("marker.duplicate", text="Duplicate Marker")
115         layout.operator("marker.move", text="Grab/Move Marker")
116         layout.operator("marker.delete", text="Delete Marker")
117
118         # it was ok for riscos... ok TODO, operator
119         for marker in context.scene.timeline_markers:
120             if marker.selected:
121                 layout.separator()
122                 layout.prop(marker, "name", text="", icon='MARKER_HLT')
123                 break
124
125         layout.separator()
126
127         layout.operator("time.start_frame_set")
128         layout.operator("time.end_frame_set")
129
130         layout.separator()
131
132         sub = layout.row()
133         sub.menu("TIME_MT_autokey")
134
135
136 class TIME_MT_playback(bpy.types.Menu):
137     bl_label = "Playback"
138
139     def draw(self, context):
140         layout = self.layout
141
142         st = context.space_data
143         scene = context.scene
144
145         layout.prop(st, "play_top_left")
146         layout.prop(st, "play_all_3d")
147         layout.prop(st, "play_anim")
148         layout.prop(st, "play_buttons")
149         layout.prop(st, "play_image")
150         layout.prop(st, "play_sequencer")
151         layout.prop(st, "play_nodes")
152
153         layout.separator()
154
155         layout.prop(scene, "frame_drop", text="Frame Dropping")
156         layout.prop(scene, "sync_audio", text="AV-sync", icon='SPEAKER')
157         layout.prop(scene, "mute_audio")
158         layout.prop(scene, "scrub_audio")
159
160
161 class TIME_MT_autokey(bpy.types.Menu):
162     bl_label = "Auto-Keyframing Mode"
163
164     def draw(self, context):
165         layout = self.layout
166         tools = context.tool_settings
167
168         layout.prop_enum(tools, "autokey_mode", 'ADD_REPLACE_KEYS')
169         layout.prop_enum(tools, "autokey_mode", 'REPLACE_KEYS')
170
171 classes = [
172     TIME_HT_header,
173     TIME_MT_view,
174     TIME_MT_frame,
175     TIME_MT_autokey,
176     TIME_MT_playback]
177
178
179 def register():
180     register = bpy.types.register
181     for cls in classes:
182         register(cls)
183
184
185 def unregister():
186     unregister = bpy.types.unregister
187     for cls in classes:
188         unregister(cls)
189
190 if __name__ == "__main__":
191     register()