Merged changes in the trunk up to revision 34193.
[blender.git] / release / scripts / ui / space_dopesheet.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
21 import bpy
22
23
24 # used for DopeSheet, NLA, and Graph Editors
25 def dopesheet_filter(layout, context):
26     dopesheet = context.space_data.dopesheet
27     is_nla = context.area.type == 'NLA_EDITOR'
28
29     row = layout.row(align=True)
30     row.prop(dopesheet, "show_only_selected", text="")
31     row.prop(dopesheet, "show_hidden", text="")
32
33     row = layout.row(align=True)
34     row.prop(dopesheet, "show_transforms", text="")
35
36     if is_nla:
37         row.prop(dopesheet, "show_missing_nla", text="")
38
39     row = layout.row(align=True)
40     row.prop(dopesheet, "show_scenes", text="")
41     row.prop(dopesheet, "show_worlds", text="")
42     row.prop(dopesheet, "show_nodes", text="")
43
44     if bpy.data.meshes:
45         row.prop(dopesheet, "show_meshes", text="")
46     if bpy.data.shape_keys:
47         row.prop(dopesheet, "show_shapekeys", text="")
48     if bpy.data.materials:
49         row.prop(dopesheet, "show_materials", text="")
50     if bpy.data.lamps:
51         row.prop(dopesheet, "show_lamps", text="")
52     if bpy.data.textures:
53         row.prop(dopesheet, "show_textures", text="")
54     if bpy.data.cameras:
55         row.prop(dopesheet, "show_cameras", text="")
56     if bpy.data.curves:
57         row.prop(dopesheet, "show_curves", text="")
58     if bpy.data.metaballs:
59         row.prop(dopesheet, "show_metaballs", text="")
60     if bpy.data.lattices:
61         row.prop(dopesheet, "show_lattices", text="")
62     if bpy.data.armatures:
63         row.prop(dopesheet, "show_armatures", text="")
64     if bpy.data.particles:
65         row.prop(dopesheet, "show_particles", text="")
66     if bpy.data.linestyles:
67         row.prop(dopesheet, "show_linestyles", text="")
68
69     if bpy.data.groups:
70         row = layout.row(align=True)
71         row.prop(dopesheet, "show_only_group_objects", text="")
72         if dopesheet.show_only_group_objects:
73             row.prop(dopesheet, "filter_group", text="")
74
75
76 class DOPESHEET_HT_header(bpy.types.Header):
77     bl_space_type = 'DOPESHEET_EDITOR'
78
79     def draw(self, context):
80         layout = self.layout
81
82         st = context.space_data
83
84         row = layout.row(align=True)
85         row.template_header()
86
87         if context.area.show_menus:
88             sub = row.row(align=True)
89
90             sub.menu("DOPESHEET_MT_view")
91             sub.menu("DOPESHEET_MT_select")
92             sub.menu("DOPESHEET_MT_marker")
93
94             if st.mode == 'DOPESHEET' or (st.mode == 'ACTION' and st.action != None):
95                 sub.menu("DOPESHEET_MT_channel")
96             elif st.mode == 'GPENCIL':
97                 # gpencil Channel menu
98                 pass
99
100             if st.mode != 'GPENCIL':
101                 sub.menu("DOPESHEET_MT_key")
102
103         layout.prop(st, "mode", text="")
104         layout.prop(st.dopesheet, "show_summary", text="Summary")
105
106         if st.mode == 'DOPESHEET':
107             dopesheet_filter(layout, context)
108
109         elif st.mode in ('ACTION', 'SHAPEKEY'):
110             layout.template_ID(st, "action", new="action.new")
111
112         if st.mode != 'GPENCIL':
113             layout.prop(st, "auto_snap", text="")
114
115         row = layout.row(align=True)
116         row.operator("action.copy", text="", icon='COPYDOWN')
117         row.operator("action.paste", text="", icon='PASTEDOWN')
118
119
120 class DOPESHEET_MT_view(bpy.types.Menu):
121     bl_label = "View"
122
123     def draw(self, context):
124         layout = self.layout
125
126         st = context.space_data
127
128         layout.column()
129
130         layout.prop(st, "use_realtime_update")
131         layout.prop(st, "show_frame_indicator")
132         layout.prop(st, "show_sliders")
133         layout.prop(st, "use_auto_merge_keyframes")
134         layout.prop(st, "use_marker_sync")
135
136         if st.show_seconds:
137             layout.operator("anim.time_toggle", text="Show Frames")
138         else:
139             layout.operator("anim.time_toggle", text="Show Seconds")
140
141         layout.separator()
142         layout.operator("anim.previewrange_set")
143         layout.operator("anim.previewrange_clear")
144         layout.operator("action.previewrange_set")
145
146         layout.separator()
147         layout.operator("action.frame_jump")
148         layout.operator("action.view_all")
149
150         layout.separator()
151         layout.operator("screen.area_dupli")
152         layout.operator("screen.screen_full_area")
153
154
155 class DOPESHEET_MT_select(bpy.types.Menu):
156     bl_label = "Select"
157
158     def draw(self, context):
159         layout = self.layout
160
161         layout.column()
162         # This is a bit misleading as the operator's default text is "Select All" while it actually *toggles* All/None
163         layout.operator("action.select_all_toggle")
164         layout.operator("action.select_all_toggle", text="Invert Selection").invert = True
165
166         layout.separator()
167         layout.operator("action.select_border")
168         layout.operator("action.select_border", text="Border Axis Range").axis_range = True
169
170         layout.separator()
171         layout.operator("action.select_column", text="Columns on Selected Keys").mode = 'KEYS'
172         layout.operator("action.select_column", text="Column on Current Frame").mode = 'CFRA'
173
174         layout.operator("action.select_column", text="Columns on Selected Markers").mode = 'MARKERS_COLUMN'
175         layout.operator("action.select_column", text="Between Selected Markers").mode = 'MARKERS_BETWEEN'
176
177         layout.separator()
178         layout.operator("action.select_more")
179         layout.operator("action.select_less")
180
181         layout.separator()
182         layout.operator("action.select_linked")
183
184 class DOPESHEET_MT_marker(bpy.types.Menu):
185     bl_label = "Marker"
186     
187     def draw(self, context):
188         layout = self.layout
189         
190         #layout.operator_context = 'EXEC_REGION_WIN'
191         
192         layout.column()
193         layout.operator("marker.add", "Add Marker")
194         layout.operator("marker.duplicate", text="Duplicate Marker")
195         layout.operator("marker.delete", text="Delete Marker")
196
197         layout.separator()
198         
199         layout.operator("marker.rename", text="Rename Marker")
200         layout.operator("marker.move", text="Grab/Move Marker")
201         
202         # TODO: pose markers for action edit mode only?
203
204 class DOPESHEET_MT_channel(bpy.types.Menu):
205     bl_label = "Channel"
206
207     def draw(self, context):
208         layout = self.layout
209
210         layout.operator_context = 'INVOKE_REGION_CHANNELS'
211
212         layout.column()
213         layout.operator("anim.channels_delete")
214
215         layout.separator()
216         layout.operator("anim.channels_setting_toggle")
217         layout.operator("anim.channels_setting_enable")
218         layout.operator("anim.channels_setting_disable")
219
220         layout.separator()
221         layout.operator("anim.channels_editable_toggle")
222
223         layout.separator()
224         layout.operator("anim.channels_expand")
225         layout.operator("anim.channels_collapse")
226
227         layout.separator()
228         layout.operator_menu_enum("anim.channels_move", "direction", text="Move...")
229
230         layout.separator()
231         layout.operator("anim.channels_fcurves_enable")
232
233
234 class DOPESHEET_MT_key(bpy.types.Menu):
235     bl_label = "Key"
236
237     def draw(self, context):
238         layout = self.layout
239
240         layout.column()
241         layout.menu("DOPESHEET_MT_key_transform", text="Transform")
242
243         layout.operator_menu_enum("action.snap", "type", text="Snap")
244         layout.operator_menu_enum("action.mirror", "type", text="Mirror")
245
246         layout.separator()
247         layout.operator("action.keyframe_insert")
248
249         layout.separator()
250         layout.operator("action.duplicate")
251         layout.operator("action.delete")
252
253         layout.separator()
254         layout.operator_menu_enum("action.keyframe_type", "type", text="Keyframe Type")
255         layout.operator_menu_enum("action.handle_type", "type", text="Handle Type")
256         layout.operator_menu_enum("action.interpolation_type", "type", text="Interpolation Mode")
257         layout.operator_menu_enum("action.extrapolation_type", "type", text="Extrapolation Mode")
258
259         layout.separator()
260         layout.operator("action.clean")
261         layout.operator("action.sample")
262
263         layout.separator()
264         layout.operator("action.copy")
265         layout.operator("action.paste")
266
267
268 class DOPESHEET_MT_key_transform(bpy.types.Menu):
269     bl_label = "Transform"
270
271     def draw(self, context):
272         layout = self.layout
273
274         layout.column()
275         layout.operator("transform.transform", text="Grab/Move").mode = 'TIME_TRANSLATE'
276         layout.operator("transform.transform", text="Extend").mode = 'TIME_EXTEND'
277         layout.operator("transform.transform", text="Slide").mode = 'TIME_SLIDE'
278         layout.operator("transform.transform", text="Scale").mode = 'TIME_SCALE'
279
280
281 def register():
282     pass
283
284
285 def unregister():
286     pass
287
288 if __name__ == "__main__":
289     register()