change python scripts so modules which register with blender have a register() functi...
[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 class DOPESHEET_HT_header(bpy.types.Header):
25     bl_space_type = 'DOPESHEET_EDITOR'
26
27     def draw(self, context):
28         layout = self.layout
29
30         st = context.space_data
31
32         row = layout.row(align=True)
33         row.template_header()
34
35         if context.area.show_menus:
36             sub = row.row(align=True)
37
38             sub.menu("DOPESHEET_MT_view")
39             sub.menu("DOPESHEET_MT_select")
40
41             if st.mode == 'DOPESHEET' or (st.mode == 'ACTION' and st.action != None):
42                 sub.menu("DOPESHEET_MT_channel")
43             elif st.mode == 'GPENCIL':
44                 # gpencil Channel menu
45                 pass
46
47             if st.mode != 'GPENCIL':
48                 sub.menu("DOPESHEET_MT_key")
49
50         layout.prop(st, "mode", text="")
51         layout.prop(st.dopesheet, "display_summary", text="Summary")
52
53         if st.mode == 'DOPESHEET':
54             layout.template_dopesheet_filter(st.dopesheet)
55         elif st.mode == 'ACTION':
56             layout.template_ID(st, "action", new="action.new")
57
58         if st.mode != 'GPENCIL':
59             layout.prop(st, "autosnap", text="")
60
61         row = layout.row(align=True)
62         row.operator("action.copy", text="", icon='COPYDOWN')
63         row.operator("action.paste", text="", icon='PASTEDOWN')
64
65
66 class DOPESHEET_MT_view(bpy.types.Menu):
67     bl_label = "View"
68
69     def draw(self, context):
70         layout = self.layout
71
72         st = context.space_data
73
74         layout.column()
75
76         layout.prop(st, "realtime_updates")
77         layout.prop(st, "show_cframe_indicator")
78         layout.prop(st, "show_sliders")
79         layout.prop(st, "automerge_keyframes")
80
81         if st.show_seconds:
82             layout.operator("anim.time_toggle", text="Show Frames")
83         else:
84             layout.operator("anim.time_toggle", text="Show Seconds")
85
86         layout.separator()
87         layout.operator("anim.previewrange_set")
88         layout.operator("anim.previewrange_clear")
89         layout.operator("action.previewrange_set")
90
91         layout.separator()
92         layout.operator("action.frame_jump")
93         layout.operator("action.view_all")
94
95         layout.separator()
96         layout.operator("screen.area_dupli")
97         layout.operator("screen.screen_full_area")
98
99
100 class DOPESHEET_MT_select(bpy.types.Menu):
101     bl_label = "Select"
102
103     def draw(self, context):
104         layout = self.layout
105
106         layout.column()
107         # This is a bit misleading as the operator's default text is "Select All" while it actually *toggles* All/None
108         layout.operator("action.select_all_toggle")
109         layout.operator("action.select_all_toggle", text="Invert Selection").invert = True
110
111         layout.separator()
112         layout.operator("action.select_border")
113         layout.operator("action.select_border", text="Border Axis Range").axis_range = True
114
115         layout.separator()
116         layout.operator("action.select_column", text="Columns on Selected Keys").mode = 'KEYS'
117         layout.operator("action.select_column", text="Column on Current Frame").mode = 'CFRA'
118
119         layout.operator("action.select_column", text="Columns on Selected Markers").mode = 'MARKERS_COLUMN'
120         layout.operator("action.select_column", text="Between Selected Markers").mode = 'MARKERS_BETWEEN'
121
122         layout.separator()
123         layout.operator("action.select_more")
124         layout.operator("action.select_less")
125
126
127 class DOPESHEET_MT_channel(bpy.types.Menu):
128     bl_label = "Channel"
129
130     def draw(self, context):
131         layout = self.layout
132
133         layout.operator_context = 'INVOKE_REGION_CHANNELS'
134
135         layout.column()
136         layout.operator("anim.channels_setting_toggle")
137         layout.operator("anim.channels_setting_enable")
138         layout.operator("anim.channels_setting_disable")
139
140         layout.separator()
141         layout.operator("anim.channels_editable_toggle")
142
143         layout.separator()
144         layout.operator("anim.channels_expand")
145         layout.operator("anim.channels_collapse")
146
147
148 class DOPESHEET_MT_key(bpy.types.Menu):
149     bl_label = "Key"
150
151     def draw(self, context):
152         layout = self.layout
153
154         layout.column()
155         layout.menu("DOPESHEET_MT_key_transform", text="Transform")
156
157         layout.operator_menu_enum("action.snap", property="type", text="Snap")
158         layout.operator_menu_enum("action.mirror", property="type", text="Mirror")
159
160         layout.separator()
161         layout.operator("action.keyframe_insert")
162
163         layout.separator()
164         layout.operator("action.duplicate")
165         layout.operator("action.delete")
166
167         layout.separator()
168         layout.operator_menu_enum("action.keyframe_type", property="type", text="Keyframe Type")
169         layout.operator_menu_enum("action.handle_type", property="type", text="Handle Type")
170         layout.operator_menu_enum("action.interpolation_type", property="type", text="Interpolation Mode")
171         layout.operator_menu_enum("action.extrapolation_type", property="type", text="Extrapolation Mode")
172
173         layout.separator()
174         layout.operator("action.clean")
175         layout.operator("action.sample")
176
177         layout.separator()
178         layout.operator("action.copy")
179         layout.operator("action.paste")
180
181
182 class DOPESHEET_MT_key_transform(bpy.types.Menu):
183     bl_label = "Transform"
184
185     def draw(self, context):
186         layout = self.layout
187
188         layout.column()
189         layout.operator("transform.translate", text="Grab/Move")
190         layout.operator("transform.transform", text="Extend").mode = 'TIME_EXTEND'
191         layout.operator("transform.resize", text="Scale")
192
193
194 classes = [
195     DOPESHEET_HT_header, # header/menu classes
196     DOPESHEET_MT_view,
197     DOPESHEET_MT_select,
198     DOPESHEET_MT_channel,
199     DOPESHEET_MT_key,
200     DOPESHEET_MT_key_transform]
201
202
203 def register():
204     register = bpy.types.register
205     for cls in classes:
206         register(cls)
207
208 def unregister():
209     unregister = bpy.types.unregister
210     for cls in classes:
211         unregister(cls)