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