more ui api changes.
[blender.git] / release / scripts / ui / space_sequencer.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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20 import bpy
21
22
23 def act_strip(context):
24     try:
25         return context.scene.sequence_editor.active_strip
26     except AttributeError:
27         return None
28
29
30 class SEQUENCER_HT_header(bpy.types.Header):
31     bl_space_type = 'SEQUENCE_EDITOR'
32
33     def draw(self, context):
34         layout = self.layout
35
36         st = context.space_data
37
38         row = layout.row(align=True)
39         row.template_header()
40
41         if context.area.show_menus:
42             sub = row.row(align=True)
43             sub.menu("SEQUENCER_MT_view")
44
45             row.separator()
46
47             if st.display_mode == 'SEQUENCER':
48                 sub.menu("SEQUENCER_MT_select")
49                 sub.menu("SEQUENCER_MT_marker")
50                 sub.menu("SEQUENCER_MT_add")
51                 sub.menu("SEQUENCER_MT_strip")
52
53         layout.prop(st, "display_mode", text="")
54
55         if st.display_mode == 'SEQUENCER':
56             layout.separator()
57             layout.operator("sequencer.refresh_all")
58         else:
59             layout.prop(st, "display_channel", text="Channel")
60
61
62 class SEQUENCER_MT_view(bpy.types.Menu):
63     bl_label = "View"
64
65     def draw(self, context):
66         layout = self.layout
67
68         st = context.space_data
69
70         layout.column()
71
72         """
73     uiBlock *block= uiBeginBlock(C, ar, "seq_viewmenu", UI_EMBOSSP);
74     short yco= 0, menuwidth=120;
75
76     if (sseq->mainb == SEQ_DRAW_SEQUENCE) {
77         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
78                  "Play Back Animation "
79                  "in all Sequence Areas|Alt A", 0, yco-=20,
80                  menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
81     }
82     else {
83         uiDefIconTextBut(block, BUTM, 1, ICON_MENU_PANEL,
84                  "Grease Pencil...", 0, yco-=20,
85                  menuwidth, 19, NULL, 0.0, 0.0, 1, 7, "");
86         uiDefMenuSep(block);
87
88         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
89                  "Play Back Animation "
90                  "in this window|Alt A", 0, yco-=20,
91                  menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
92     }
93     uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
94              "Play Back Animation in all "
95              "3D Views and Sequence Areas|Alt Shift A",
96              0, yco-=20,
97              menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
98
99         """
100         layout.separator()
101         layout.operator("sequencer.view_all")
102         layout.operator("sequencer.view_selected")
103         layout.separator()
104         layout.operator("screen.screen_full_area", text="Toggle Full Screen")
105         """
106
107
108     /* Lock Time */
109     uiDefIconTextBut(block, BUTM, 1, (v2d->flag & V2D_VIEWSYNC_SCREEN_TIME)?ICON_CHECKBOX_HLT:ICON_CHECKBOX_DEHLT,
110             "Lock Time to Other Windows|", 0, yco-=20,
111             menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
112
113     /* Draw time or frames.*/
114     uiDefMenuSep(block);
115         """
116
117         layout.prop(st, "draw_frames")
118         layout.prop(st, "show_cframe_indicator")
119         if st.display_mode == 'IMAGE':
120             layout.prop(st, "draw_safe_margin")
121         if st.display_mode == 'WAVEFORM':
122             layout.prop(st, "separate_color_preview")
123
124         """
125     if(!sa->full) uiDefIconTextBut(block, BUTM, B_FULL, ICON_BLANK1, "Maximize Window|Ctrl UpArrow", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0,0, "");
126     else uiDefIconTextBut(block, BUTM, B_FULL, ICON_BLANK1, "Tile Window|Ctrl DownArrow", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 0, "");
127
128         """
129
130
131 class SEQUENCER_MT_select(bpy.types.Menu):
132     bl_label = "Select"
133
134     def draw(self, context):
135         layout = self.layout
136
137         layout.column()
138         layout.operator("sequencer.select_active_side", text="Strips to the Left").side = 'LEFT'
139         layout.operator("sequencer.select_active_side", text="Strips to the Right").side = 'RIGHT'
140         layout.separator()
141         layout.operator("sequencer.select_handles", text="Surrounding Handles").side = 'BOTH'
142         layout.operator("sequencer.select_handles", text="Left Handle").side = 'LEFT'
143         layout.operator("sequencer.select_handles", text="Right Handle").side = 'RIGHT'
144         layout.separator()
145         layout.operator("sequencer.select_linked")
146         layout.operator("sequencer.select_all_toggle")
147         layout.operator("sequencer.select_inverse")
148
149
150 class SEQUENCER_MT_marker(bpy.types.Menu):
151     bl_label = "Marker (TODO)"
152
153     def draw(self, context):
154         layout = self.layout
155
156         layout.column()
157         layout.operator("marker.add", text="Add Marker")
158         layout.operator("marker.duplicate", text="Duplicate Marker")
159         layout.operator("marker.move", text="Grab/Move Marker")
160         layout.operator("marker.delete", text="Delete Marker")
161         layout.separator()
162         layout.label(text="ToDo: Name Marker")
163
164         #layout.operator("sequencer.sound_strip_add", text="Transform Markers") # toggle, will be rna - (sseq->flag & SEQ_MARKER_TRANS)
165
166
167 class SEQUENCER_MT_add(bpy.types.Menu):
168     bl_label = "Add"
169
170     def draw(self, context):
171         layout = self.layout
172         layout.operator_context = 'INVOKE_REGION_WIN'
173
174         layout.column()
175         layout.operator("sequencer.scene_strip_add", text="Scene")
176         layout.operator("sequencer.movie_strip_add", text="Movie")
177         layout.operator("sequencer.image_strip_add", text="Image")
178         layout.operator("sequencer.sound_strip_add", text="Sound")
179
180         layout.menu("SEQUENCER_MT_add_effect")
181
182
183 class SEQUENCER_MT_add_effect(bpy.types.Menu):
184     bl_label = "Effect Strip..."
185
186     def draw(self, context):
187         layout = self.layout
188         layout.operator_context = 'INVOKE_REGION_WIN'
189
190         layout.column()
191         layout.operator("sequencer.effect_strip_add").type = 'ADD'
192         layout.operator("sequencer.effect_strip_add").type = 'SUBTRACT'
193         layout.operator("sequencer.effect_strip_add").type = 'ALPHA_OVER'
194         layout.operator("sequencer.effect_strip_add").type = 'ALPHA_UNDER'
195         layout.operator("sequencer.effect_strip_add").type = 'GAMMA_CROSS'
196         layout.operator("sequencer.effect_strip_add").type = 'MULTIPLY'
197         layout.operator("sequencer.effect_strip_add").type = 'OVER_DROP'
198         layout.operator("sequencer.effect_strip_add").type = 'PLUGIN'
199         layout.operator("sequencer.effect_strip_add").type = 'WIPE'
200         layout.operator("sequencer.effect_strip_add").type = 'GLOW'
201         layout.operator("sequencer.effect_strip_add").type = 'TRANSFORM'
202         layout.operator("sequencer.effect_strip_add").type = 'COLOR'
203         layout.operator("sequencer.effect_strip_add").type = 'SPEED'
204
205
206 class SEQUENCER_MT_strip(bpy.types.Menu):
207     bl_label = "Strip"
208
209     def draw(self, context):
210         layout = self.layout
211
212         layout.operator_context = 'INVOKE_REGION_WIN'
213
214         layout.column()
215         layout.operator("tfm.transform", text="Grab/Move").mode = TRANSLATION
216         layout.operator("tfm.transform", text="Grab/Extend from frame").mode = TIME_EXTEND
217         #  uiItemO(layout, NULL, 0, "sequencer.strip_snap"); // TODO - add this operator
218         layout.separator()
219
220         layout.operator("sequencer.cut", text="Cut (hard) at frame").type = 'HARD'
221         layout.operator("sequencer.cut", text="Cut (soft) at frame").type = 'SOFT'
222         layout.operator("sequencer.images_separate")
223         layout.separator()
224
225         layout.operator("sequencer.duplicate")
226         layout.operator("sequencer.delete")
227
228         strip = act_strip(context)
229
230         if strip:
231             stype = strip.type
232
233             if  stype == 'EFFECT':
234                 layout.separator()
235                 layout.operator("sequencer.effect_change")
236                 layout.operator("sequencer.effect_reassign_inputs")
237             elif stype == 'IMAGE':
238                 layout.separator()
239                 layout.operator("sequencer.image_change")
240                 layout.operator("sequencer.rendersize")
241             elif stype == 'SCENE':
242                 layout.separator()
243                 layout.operator("sequencer.scene_change", text="Change Scene")
244             elif stype == 'MOVIE':
245                 layout.separator()
246                 layout.operator("sequencer.movie_change")
247                 layout.operator("sequencer.rendersize")
248
249         layout.separator()
250
251         layout.operator("sequencer.meta_make")
252         layout.operator("sequencer.meta_separate")
253
254         #if (ed && (ed->metastack.first || (ed->act_seq && ed->act_seq->type == SEQ_META))) {
255         #       uiItemS(layout);
256         #       uiItemO(layout, NULL, 0, "sequencer.meta_toggle");
257         #}
258
259         layout.separator()
260         layout.operator("sequencer.reload")
261         layout.separator()
262         layout.operator("sequencer.lock")
263         layout.operator("sequencer.unlock")
264         layout.operator("sequencer.mute")
265         layout.operator("sequencer.unmute")
266
267         layout.operator("sequencer.mute", text="Mute Deselected Strips").unselected = True
268
269         layout.operator("sequencer.snap")
270
271         layout.operator("sequencer.swap_right")
272         layout.operator("sequencer.swap_left")
273
274
275 class SequencerButtonsPanel(bpy.types.Panel):
276     bl_space_type = 'SEQUENCE_EDITOR'
277     bl_region_type = 'UI'
278
279     def poll(self, context):
280         return (context.space_data.display_mode == 'SEQUENCER') and (act_strip(context) is not None)
281
282
283 class SequencerButtonsPanel_Output(bpy.types.Panel):
284     bl_space_type = 'SEQUENCE_EDITOR'
285     bl_region_type = 'UI'
286
287     def poll(self, context):
288         return context.space_data.display_mode != 'SEQUENCER'
289
290
291 class SEQUENCER_PT_edit(SequencerButtonsPanel):
292     bl_label = "Edit Strip"
293
294     def draw(self, context):
295         layout = self.layout
296
297         strip = act_strip(context)
298
299         split = layout.split(percentage=0.3)
300         split.label(text="Name:")
301         split.prop(strip, "name", text="")
302
303         split = layout.split(percentage=0.3)
304         split.label(text="Type:")
305         split.prop(strip, "type", text="")
306
307         split = layout.split(percentage=0.3)
308         split.label(text="Blend:")
309         split.prop(strip, "blend_mode", text="")
310
311         row = layout.row()
312         if strip.mute == True:
313             row.prop(strip, "mute", toggle=True, icon='ICON_RESTRICT_VIEW_ON', text="")
314         elif strip.mute is False:
315             row.prop(strip, "mute", toggle=True, icon='ICON_RESTRICT_VIEW_OFF', text="")
316
317         sub = row.row()
318         sub.active = (not strip.mute)
319
320         sub.prop(strip, "blend_opacity", text="Opacity", slider=True)
321
322         row = layout.row()
323         row.prop(strip, "lock")
324         row.prop(strip, "frame_locked", text="Frame Lock")
325
326         col = layout.column()
327         col.enabled = not strip.lock
328         col.prop(strip, "channel")
329         col.prop(strip, "start_frame")
330         col.prop(strip, "length")
331
332         col = layout.column(align=True)
333         col.label(text="Offset:")
334         col.prop(strip, "start_offset", text="Start")
335         col.prop(strip, "end_offset", text="End")
336
337         col = layout.column(align=True)
338         col.label(text="Still:")
339         col.prop(strip, "start_still", text="Start")
340         col.prop(strip, "end_still", text="End")
341
342
343 class SEQUENCER_PT_effect(SequencerButtonsPanel):
344     bl_label = "Effect Strip"
345
346     def poll(self, context):
347         if context.space_data.display_mode != 'SEQUENCER':
348             return False
349
350         strip = act_strip(context)
351         if not strip:
352             return False
353
354         return strip.type in ('COLOR', 'WIPE', 'GLOW', 'SPEED', 'TRANSFORM')
355
356     def draw(self, context):
357         layout = self.layout
358
359         strip = act_strip(context)
360
361         if strip.type == 'COLOR':
362             layout.prop(strip, "color")
363
364         elif strip.type == 'WIPE':
365
366             col = layout.column()
367             col.prop(strip, "transition_type")
368             col.label(text="Direction:")
369             col.row().prop(strip, "direction", expand=True)
370
371             col = layout.column()
372             col.prop(strip, "blur_width", slider=True)
373             if strip.transition_type in ('SINGLE', 'DOUBLE'):
374                 col.prop(strip, "angle")
375
376         elif strip.type == 'GLOW':
377             flow = layout.column_flow()
378             flow.prop(strip, "threshold", slider=True)
379             flow.prop(strip, "clamp", slider=True)
380             flow.prop(strip, "boost_factor")
381             flow.prop(strip, "blur_distance")
382
383             row = layout.row()
384             row.prop(strip, "quality", slider=True)
385             row.prop(strip, "only_boost")
386
387         elif strip.type == 'SPEED':
388             layout.prop(strip, "global_speed")
389
390             flow = layout.column_flow()
391             flow.prop(strip, "curve_velocity")
392             flow.prop(strip, "curve_compress_y")
393             flow.prop(strip, "frame_blending")
394
395         elif strip.type == 'TRANSFORM':
396
397             col = layout.column()
398             col.prop(strip, "interpolation")
399             col.prop(strip, "translation_unit")
400
401             col = layout.column(align=True)
402             col.label(text="Position X:")
403             col.prop(strip, "translate_start_x", text="Start")
404             col.prop(strip, "translate_end_x", text="End")
405
406             col = layout.column(align=True)
407             col.label(text="Position Y:")
408             col.prop(strip, "translate_start_y", text="Start")
409             col.prop(strip, "translate_end_y", text="End")
410
411             layout.separator()
412
413             col = layout.column(align=True)
414             col.label(text="Scale X:")
415             col.prop(strip, "scale_start_x", text="Start")
416             col.prop(strip, "scale_end_x", text="End")
417
418             col = layout.column(align=True)
419             col.label(text="Scale Y:")
420             col.prop(strip, "scale_start_y", text="Start")
421             col.prop(strip, "scale_end_y", text="End")
422
423             layout.separator()
424
425             col = layout.column(align=True)
426             col.label(text="Rotation:")
427             col.prop(strip, "rotation_start", text="Start")
428             col.prop(strip, "rotation_end", text="End")
429
430         col = layout.column(align=True)
431         if strip.type == 'SPEED':
432             col.prop(strip, "speed_fader", text="Speed fader")
433         else:
434             col.prop(strip, "effect_fader", text="Effect fader")
435
436
437 class SEQUENCER_PT_input(SequencerButtonsPanel):
438     bl_label = "Strip Input"
439
440     def poll(self, context):
441         if context.space_data.display_mode != 'SEQUENCER':
442             return False
443
444         strip = act_strip(context)
445         if not strip:
446             return False
447
448         return strip.type in ('MOVIE', 'IMAGE')
449
450     def draw(self, context):
451         layout = self.layout
452
453         strip = act_strip(context)
454
455         split = layout.split(percentage=0.2)
456         col = split.column()
457         col.label(text="Path:")
458         col = split.column()
459         col.prop(strip, "directory", text="")
460
461         # Current element for the filename
462
463         elem = strip.getStripElem(context.scene.current_frame)
464         if elem:
465             split = layout.split(percentage=0.2)
466             col = split.column()
467             col.label(text="File:")
468             col = split.column()
469             col.prop(elem, "filename", text="") # strip.elements[0] could be a fallback
470
471         layout.prop(strip, "use_translation", text="Image Offset:")
472         if strip.transform:
473             col = layout.column(align=True)
474             col.active = strip.use_translation
475             col.prop(strip.transform, "offset_x", text="X")
476             col.prop(strip.transform, "offset_y", text="Y")
477
478         layout.prop(strip, "use_crop", text="Image Crop:")
479         if strip.crop:
480             col = layout.column(align=True)
481             col.active = strip.use_crop
482             col.prop(strip.crop, "top")
483             col.prop(strip.crop, "left")
484             col.prop(strip.crop, "bottom")
485             col.prop(strip.crop, "right")
486
487         col = layout.column(align=True)
488         col.label(text="Trim Duration:")
489         col.prop(strip, "animation_start_offset", text="Start")
490         col.prop(strip, "animation_end_offset", text="End")
491
492
493 class SEQUENCER_PT_sound(SequencerButtonsPanel):
494     bl_label = "Sound"
495
496     def poll(self, context):
497         if context.space_data.display_mode != 'SEQUENCER':
498             return False
499
500         strip = act_strip(context)
501         if not strip:
502             return False
503
504         return (strip.type == 'SOUND')
505
506     def draw(self, context):
507         layout = self.layout
508
509         strip = act_strip(context)
510
511         layout.template_ID(strip, "sound", open="sound.open")
512
513         layout.separator()
514         layout.prop(strip.sound, "filename", text="")
515
516         row = layout.row()
517         if strip.sound.packed_file:
518             row.operator("sound.unpack", icon='ICON_PACKAGE', text="Unpack")
519         else:
520             row.operator("sound.pack", icon='ICON_UGLYPACKAGE', text="Pack")
521
522         row.prop(strip.sound, "caching")
523
524         layout.prop(strip, "volume")
525         
526
527 class SEQUENCER_PT_scene(SequencerButtonsPanel):
528     bl_label = "Scene"
529
530     def poll(self, context):
531         if context.space_data.display_mode != 'SEQUENCER':
532             return False
533
534         strip = act_strip(context)
535         if not strip:
536             return False
537
538         return (strip.type == 'SCENE')
539
540     def draw(self, context):
541         layout = self.layout
542
543         strip = act_strip(context)
544         
545         layout.template_ID(strip, "scene")
546
547
548 class SEQUENCER_PT_filter(SequencerButtonsPanel):
549     bl_label = "Filter"
550
551     def poll(self, context):
552         if context.space_data.display_mode != 'SEQUENCER':
553             return False
554
555         strip = act_strip(context)
556         if not strip:
557             return False
558
559         return strip.type in ('MOVIE', 'IMAGE', 'SCENE', 'META')
560
561     def draw(self, context):
562         layout = self.layout
563
564         strip = act_strip(context)
565
566         col = layout.column()
567         col.label(text="Video:")
568         col.prop(strip, "strobe")
569         col.prop(strip, "de_interlace")
570
571         col = layout.column()
572         col.label(text="Colors:")
573         col.prop(strip, "multiply_colors", text="Multiply")
574         col.prop(strip, "premultiply")
575         col.prop(strip, "convert_float")
576
577         col = layout.column()
578         col.label(text="Flip:")
579         col.prop(strip, "flip_x", text="X")
580         col.prop(strip, "flip_y", text="Y")
581         col.prop(strip, "reverse_frames", text="Backwards")
582
583         layout.prop(strip, "use_color_balance")
584         if strip.color_balance: # TODO - need to add this somehow
585             row = layout.row()
586             row.active = strip.use_color_balance
587             col = row.column()
588             col.prop(strip.color_balance, "lift")
589             col.prop(strip.color_balance, "inverse_lift", text="Inverse")
590             col = row.column()
591             col.prop(strip.color_balance, "gamma")
592             col.prop(strip.color_balance, "inverse_gamma", text="Inverse")
593             col = row.column()
594             col.prop(strip.color_balance, "gain")
595             col.prop(strip.color_balance, "inverse_gain", text="Inverse")
596
597
598 class SEQUENCER_PT_proxy(SequencerButtonsPanel):
599     bl_label = "Proxy"
600
601     def poll(self, context):
602         if context.space_data.display_mode != 'SEQUENCER':
603             return False
604
605         strip = act_strip(context)
606         if not strip:
607             return False
608
609         return strip.type in ('MOVIE', 'IMAGE', 'SCENE', 'META')
610
611     def draw_header(self, context):
612         strip = act_strip(context)
613
614         self.layout.prop(strip, "use_proxy", text="")
615
616     def draw(self, context):
617         layout = self.layout
618
619         strip = act_strip(context)
620
621         flow = layout.column_flow()
622         flow.prop(strip, "proxy_custom_directory")
623         if strip.proxy: # TODO - need to add this somehow
624             flow.prop(strip.proxy, "directory")
625             flow.prop(strip.proxy, "file")
626
627
628 class SEQUENCER_PT_view(SequencerButtonsPanel_Output):
629     bl_label = "View Settings"
630
631     def draw(self, context):
632         layout = self.layout
633
634         st = context.space_data
635
636         col = layout.column()
637         col.prop(st, "draw_overexposed") # text="Zebra"
638         col.prop(st, "draw_safe_margin")
639
640 bpy.types.register(SEQUENCER_HT_header) # header/menu classes
641 bpy.types.register(SEQUENCER_MT_view)
642 bpy.types.register(SEQUENCER_MT_select)
643 bpy.types.register(SEQUENCER_MT_marker)
644 bpy.types.register(SEQUENCER_MT_add)
645 bpy.types.register(SEQUENCER_MT_add_effect)
646 bpy.types.register(SEQUENCER_MT_strip)
647
648 bpy.types.register(SEQUENCER_PT_edit) # sequencer panels
649 bpy.types.register(SEQUENCER_PT_effect)
650 bpy.types.register(SEQUENCER_PT_input)
651 bpy.types.register(SEQUENCER_PT_sound)
652 bpy.types.register(SEQUENCER_PT_scene)
653 bpy.types.register(SEQUENCER_PT_filter)
654 bpy.types.register(SEQUENCER_PT_proxy)
655
656 bpy.types.register(SEQUENCER_PT_view) # view panels