forked from OpenShot/openshot-qt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebview.py
3176 lines (2634 loc) · 137 KB
/
webview.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
@file
@brief This file loads the interactive HTML timeline
@author Noah Figg <[email protected]>
@author Jonathan Thomas <[email protected]>
@author Olivier Girard <[email protected]>
@section LICENSE
Copyright (c) 2008-2018 OpenShot Studios, LLC
(http://www.openshotstudios.com). This file is part of
OpenShot Video Editor (http://www.openshot.org), an open-source project
dedicated to delivering high quality video editing and animation solutions
to the world.
OpenShot Video Editor is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenShot Video Editor is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
"""
import os
import time
from copy import deepcopy
from functools import partial
from random import uniform
from operator import itemgetter
import logging
import openshot # Python module for libopenshot (required video editing module installed separately)
from PyQt5.QtCore import QFileInfo, pyqtSlot, QUrl, Qt, QCoreApplication, QTimer
from PyQt5.QtGui import QCursor, QKeySequence, QColor
from PyQt5.QtWidgets import QMenu
from classes import info, updates
from classes import settings
from classes.app import get_app
from classes.logger import log
from classes.query import File, Clip, Transition, Track
from classes.waveform import get_audio_data
from classes.conversion import zoomToSeconds, secondsToZoom
import json
# Constants used by this file
JS_SCOPE_SELECTOR = "$('body').scope()"
MENU_FADE_NONE = 0
MENU_FADE_IN_FAST = 1
MENU_FADE_IN_SLOW = 2
MENU_FADE_OUT_FAST = 3
MENU_FADE_OUT_SLOW = 4
MENU_FADE_IN_OUT_FAST = 5
MENU_FADE_IN_OUT_SLOW = 6
MENU_ROTATE_NONE = 0
MENU_ROTATE_90_RIGHT = 1
MENU_ROTATE_90_LEFT = 2
MENU_ROTATE_180_FLIP = 3
MENU_LAYOUT_NONE = 0
MENU_LAYOUT_CENTER = 1
MENU_LAYOUT_TOP_LEFT = 2
MENU_LAYOUT_TOP_RIGHT = 3
MENU_LAYOUT_BOTTOM_LEFT = 4
MENU_LAYOUT_BOTTOM_RIGHT = 5
MENU_LAYOUT_ALL_WITH_ASPECT = 6
MENU_LAYOUT_ALL_WITHOUT_ASPECT = 7
MENU_ALIGN_LEFT = 0
MENU_ALIGN_RIGHT = 1
MENU_ANIMATE_NONE = 0
MENU_ANIMATE_IN_50_100 = 1
MENU_ANIMATE_IN_75_100 = 2
MENU_ANIMATE_IN_100_150 = 3
MENU_ANIMATE_OUT_100_75 = 4
MENU_ANIMATE_OUT_100_50 = 5
MENU_ANIMATE_OUT_150_100 = 6
MENU_ANIMATE_CENTER_TOP = 7
MENU_ANIMATE_CENTER_LEFT = 8
MENU_ANIMATE_CENTER_RIGHT = 9
MENU_ANIMATE_CENTER_BOTTOM = 10
MENU_ANIMATE_TOP_CENTER = 11
MENU_ANIMATE_LEFT_CENTER = 12
MENU_ANIMATE_RIGHT_CENTER = 13
MENU_ANIMATE_BOTTOM_CENTER = 14
MENU_ANIMATE_TOP_BOTTOM = 15
MENU_ANIMATE_LEFT_RIGHT = 16
MENU_ANIMATE_RIGHT_LEFT = 17
MENU_ANIMATE_BOTTOM_TOP = 18
MENU_ANIMATE_RANDOM = 19
MENU_VOLUME_NONE = 1
MENU_VOLUME_FADE_IN_FAST = 2
MENU_VOLUME_FADE_IN_SLOW = 3
MENU_VOLUME_FADE_OUT_FAST = 4
MENU_VOLUME_FADE_OUT_SLOW = 5
MENU_VOLUME_FADE_IN_OUT_FAST = 6
MENU_VOLUME_FADE_IN_OUT_SLOW = 7
MENU_VOLUME_LEVEL_100 = 100
MENU_VOLUME_LEVEL_90 = 90
MENU_VOLUME_LEVEL_80 = 80
MENU_VOLUME_LEVEL_70 = 70
MENU_VOLUME_LEVEL_60 = 60
MENU_VOLUME_LEVEL_50 = 50
MENU_VOLUME_LEVEL_40 = 40
MENU_VOLUME_LEVEL_30 = 30
MENU_VOLUME_LEVEL_20 = 20
MENU_VOLUME_LEVEL_10 = 10
MENU_VOLUME_LEVEL_0 = 0
MENU_TRANSFORM = 0
MENU_TIME_NONE = 0
MENU_TIME_FORWARD = 1
MENU_TIME_BACKWARD = 2
MENU_TIME_FREEZE = 3
MENU_TIME_FREEZE_ZOOM = 4
MENU_COPY_ALL = -1
MENU_COPY_CLIP = 0
MENU_COPY_KEYFRAMES_ALL = 1
MENU_COPY_KEYFRAMES_ALPHA = 2
MENU_COPY_KEYFRAMES_SCALE = 3
MENU_COPY_KEYFRAMES_ROTATE = 4
MENU_COPY_KEYFRAMES_LOCATION = 5
MENU_COPY_KEYFRAMES_TIME = 6
MENU_COPY_KEYFRAMES_VOLUME = 7
MENU_COPY_EFFECTS = 8
MENU_PASTE = 9
MENU_COPY_TRANSITION = 10
MENU_COPY_KEYFRAMES_BRIGHTNESS = 11
MENU_COPY_KEYFRAMES_CONTRAST = 12
MENU_SLICE_KEEP_BOTH = 0
MENU_SLICE_KEEP_LEFT = 1
MENU_SLICE_KEEP_RIGHT = 2
MENU_SPLIT_AUDIO_SINGLE = 0
MENU_SPLIT_AUDIO_MULTIPLE = 1
# Import shenanigans
WEBVIEW_LOADED = None
if info.WEB_BACKEND and info.WEB_BACKEND == "webkit":
from .webview_backend.webkit import TimelineWebKitView
WebViewClass = TimelineWebKitView
WEBVIEW_LOADED = True
elif info.WEB_BACKEND and info.WEB_BACKEND == "webengine":
from .webview_backend.webengine import TimelineWebEngineView
WebViewClass = TimelineWebEngineView
WEBVIEW_LOADED = True
else:
try:
from .webview_backend.webengine import TimelineWebEngineView as WebViewClass
WEBVIEW_LOADED = True
except ImportError as ex:
try:
from .webview_backend.webkit import TimelineWebKitView as WebViewClass
WEBVIEW_LOADED = True
except ImportError:
pass
finally:
if not WEBVIEW_LOADED:
raise RuntimeError(
"Need PyQt5.QtWebEngine (or PyQt5.QtWebView on Win32)"
) from ex
class TimelineWebView(updates.UpdateInterface, WebViewClass):
""" A Web(Engine)View QWidget used to load the Timeline """
# Path to html file
html_path = os.path.join(info.PATH, 'timeline', 'index.html')
@pyqtSlot()
def page_ready(self):
"""Document.Ready event has fired, and is initialized"""
self.document_is_ready = True
@pyqtSlot(result=str)
def get_thumb_address(self):
"""Return the thumbnail HTTP server address"""
thumb_server_details = self.window.http_server_thread.server_address
while not thumb_server_details:
log.info('No HTTP thumbnail server found yet... keep waiting...')
time.sleep(0.25)
thumb_server_details = self.window.http_server_thread.server_address
thumb_address = "http://%s:%s/thumbnails/" % (thumb_server_details[0], thumb_server_details[1])
return thumb_address
# This method is invoked by the UpdateManager each time a change happens (i.e UpdateInterface)
def changed(self, action):
# Remove unused action attribute (old_values)
action = deepcopy(action)
action.old_values = {}
# Send a JSON version of the UpdateAction to the timeline webview method: applyJsonDiff()
if action.type == "load":
# Set thumbnail server
self.run_js(JS_SCOPE_SELECTOR + ".setThumbAddress('" + self.get_thumb_address() + "');")
_ = get_app()._tr
# Initialize translated track name
self.run_js(JS_SCOPE_SELECTOR + ".setTrackLabel('" + _("Track %s") + "');")
# Load entire project data
self.run_js(JS_SCOPE_SELECTOR + ".loadJson(" + action.json() + ");")
elif action.key[0] != "files":
# Apply diff to part of project data
self.run_js(JS_SCOPE_SELECTOR + ".applyJsonDiff([" + action.json() + "]);")
# Reset the scale when loading new JSON
if action.type == "load":
# Set the scale again (to project setting)
initial_scale = get_app().project.get("scale") or 15
self.window.sliderZoom.setValue(secondsToZoom(initial_scale))
# The setValue() above doesn't trigger update_zoom when a project file is
# loaded on the command line (too early?), so also call the JS directly
self.run_js(JS_SCOPE_SELECTOR + ".setScale(" + str(initial_scale) + ", 0);")
# Javascript callable function to update the project data when a clip changes
@pyqtSlot(str, bool, bool, bool)
def update_clip_data(self, clip_json, only_basic_props=True, ignore_reader=False, ignore_refresh=False):
""" Create an updateAction and send it to the update manager """
# read clip json
try:
if not isinstance(clip_json, dict):
clip_data = json.loads(clip_json)
else:
clip_data = clip_json
except Exception:
# Failed to parse json, do nothing
log.warning('Failed to parse clip JSON data', exc_info=1)
# Search for matching clip in project data (if any)
existing_clip = Clip.get(id=clip_data["id"])
if not existing_clip:
# Create a new clip (if not exists)
existing_clip = Clip()
# Update clip data
existing_clip.data = clip_data
# Remove unneeded properties (since they don't change here... this is a performance boost)
if only_basic_props:
existing_clip.data = {}
existing_clip.data["id"] = clip_data["id"]
existing_clip.data["layer"] = clip_data["layer"]
existing_clip.data["position"] = clip_data["position"]
existing_clip.data["start"] = clip_data["start"]
existing_clip.data["end"] = clip_data["end"]
# Always remove the Reader attribute (since nothing updates it,
# and we are wrapping clips in FrameMappers anyway)
if ignore_reader and "reader" in existing_clip.data:
existing_clip.data.pop("reader")
# Save clip
existing_clip.save()
# Update the preview and reselect current frame in properties
if not ignore_refresh:
self.window.refreshFrameSignal.emit()
self.window.propertyTableView.select_frame(self.window.preview_thread.player.Position())
# Add missing transition
@pyqtSlot(str)
def add_missing_transition(self, transition_json):
transition_details = json.loads(transition_json)
# Get FPS from project
fps = get_app().project.get("fps")
fps_float = float(fps["num"]) / float(fps["den"])
# Open up QtImageReader for transition Image
transition_reader = openshot.QtImageReader(
os.path.join(info.PATH, "transitions", "common", "fade.svg"))
# Generate transition object
transition_object = openshot.Mask()
# Set brightness and contrast, to correctly transition for overlapping clips
brightness = transition_object.brightness
brightness.AddPoint(1, 1.0, openshot.BEZIER)
brightness.AddPoint(round(transition_details["end"] * fps_float) + 1, -1.0, openshot.BEZIER)
contrast = openshot.Keyframe(3.0)
# Create transition dictionary
transitions_data = {
"id": get_app().project.generate_id(),
"layer": transition_details["layer"],
"title": "Transition",
"type": "Mask",
"position": transition_details["position"],
"start": transition_details["start"],
"end": transition_details["end"],
"brightness": json.loads(brightness.Json()),
"contrast": json.loads(contrast.Json()),
"reader": json.loads(transition_reader.Json()),
"replace_image": False
}
# Send to update manager
self.update_transition_data(transitions_data, only_basic_props=False)
# Javascript callable function to update the project data when a transition changes
@pyqtSlot(str, bool, bool)
def update_transition_data(self, transition_json, only_basic_props=True, ignore_refresh=False):
""" Create an updateAction and send it to the update manager """
# read clip json
if not isinstance(transition_json, dict):
transition_data = json.loads(transition_json)
else:
transition_data = transition_json
# Search for matching clip in project data (if any)
existing_item = Transition.get(id=transition_data["id"])
needs_resize = True
if not existing_item:
# Create a new clip (if not exists)
existing_item = Transition()
needs_resize = False
existing_item.data = transition_data
# Get FPS from project
fps = get_app().project.get("fps")
fps_float = float(fps["num"]) / float(fps["den"])
duration = existing_item.data["end"] - existing_item.data["start"]
# Update the brightness and contrast keyframes to match the duration of the transition
# This is a hack until I can think of something better
brightness = None
contrast = None
if needs_resize:
# Adjust transition's brightness keyframes to match the size of the transition
brightness = existing_item.data["brightness"]
if len(brightness["Points"]) > 1:
# If multiple points, move the final one to the 'new' end
brightness["Points"][-1]["co"]["X"] = round(duration * fps_float) + 1
# Adjust transition's contrast keyframes to match the size of the transition
contrast = existing_item.data["contrast"]
if len(contrast["Points"]) > 1:
# If multiple points, move the final one to the 'new' end
contrast["Points"][-1]["co"]["X"] = round(duration * fps_float) + 1
else:
# Create new brightness and contrast Keyframes
b = openshot.Keyframe()
b.AddPoint(1, 1.0, openshot.BEZIER)
b.AddPoint(round(duration * fps_float) + 1, -1.0, openshot.BEZIER)
brightness = json.loads(b.Json())
# Only include the basic properties (performance boost)
if only_basic_props:
existing_item.data = {}
existing_item.data["id"] = transition_data["id"]
existing_item.data["layer"] = transition_data["layer"]
existing_item.data["position"] = transition_data["position"]
existing_item.data["start"] = transition_data["start"]
existing_item.data["end"] = transition_data["end"]
log.debug('transition start: %s' % transition_data["start"])
log.debug('transition end: %s' % transition_data["end"])
if brightness:
existing_item.data["brightness"] = brightness
if contrast:
existing_item.data["contrast"] = contrast
# Save transition
existing_item.save()
# Update the preview and reselct current frame in properties
if not ignore_refresh:
self.window.refreshFrameSignal.emit()
self.window.propertyTableView.select_frame(self.window.preview_thread.player.Position())
# Prevent default context menu, and ignore, so that javascript can intercept
def contextMenuEvent(self, event):
event.ignore()
# Javascript callable function to show clip or transition content menus, passing in type to show
@pyqtSlot(float)
def ShowPlayheadMenu(self, position=None):
log.debug('ShowPlayheadMenu: %s' % position)
# Get translation method
_ = get_app()._tr
# Get list of intercepting clips with position (if any)
intersecting_clips = Clip.filter(intersect=position)
intersecting_trans = Transition.filter(intersect=position)
menu = QMenu(self)
if intersecting_clips or intersecting_trans:
# Get list of clip ids
clip_ids = [c.id for c in intersecting_clips]
trans_ids = [t.id for t in intersecting_trans]
# Add split clip menu
Slice_Menu = QMenu(_("Slice All"), self)
Slice_Keep_Both = Slice_Menu.addAction(_("Keep Both Sides"))
Slice_Keep_Both.setShortcut(QKeySequence(self.window.getShortcutByName("sliceAllKeepBothSides")))
Slice_Keep_Both.triggered.connect(partial(
self.Slice_Triggered, MENU_SLICE_KEEP_BOTH, clip_ids, trans_ids, position))
Slice_Keep_Left = Slice_Menu.addAction(_("Keep Left Side"))
Slice_Keep_Left.setShortcut(QKeySequence(self.window.getShortcutByName("sliceAllKeepLeftSide")))
Slice_Keep_Left.triggered.connect(partial(
self.Slice_Triggered, MENU_SLICE_KEEP_LEFT, clip_ids, trans_ids, position))
Slice_Keep_Right = Slice_Menu.addAction(_("Keep Right Side"))
Slice_Keep_Right.setShortcut(QKeySequence(self.window.getShortcutByName("sliceAllKeepRightSide")))
Slice_Keep_Right.triggered.connect(partial(
self.Slice_Triggered, MENU_SLICE_KEEP_RIGHT, clip_ids, trans_ids, position))
menu.addMenu(Slice_Menu)
return menu.popup(QCursor.pos())
@pyqtSlot(str)
def ShowEffectMenu(self, effect_id=None):
log.debug('ShowEffectMenu: %s' % effect_id)
# Set the selected clip (if needed)
self.window.addSelection(effect_id, 'effect', True)
menu = QMenu(self)
# Properties
menu.addAction(self.window.actionProperties)
# Remove Effect Menu
menu.addSeparator()
menu.addAction(self.window.actionRemoveEffect)
return menu.popup(QCursor.pos())
@pyqtSlot(float, int)
def ShowTimelineMenu(self, position, layer_id):
log.debug('ShowTimelineMenu: position: %s, layer: %s' % (position, layer_id))
# Get translation method
_ = get_app()._tr
# Get list of clipboard items (that are complete clips or transitions)
# i.e. ignore partial clipboard items (keyframes / effects / etc...)
clipboard_clip_ids = [k for k, v in self.copy_clipboard.items() if v.get('id')]
clipboard_tran_ids = [k for k, v in self.copy_transition_clipboard.items() if v.get('id')]
# Paste Menu (if entire clips or transitions are copied)
have_clipboard = (
(self.copy_clipboard or self.copy_transition_clipboard)
and (len(clipboard_clip_ids) + len(clipboard_tran_ids) > 0)
)
if not have_clipboard:
return
menu = QMenu(self)
Paste_Clip = menu.addAction(_("Paste"))
Paste_Clip.setShortcut(QKeySequence(self.window.getShortcutByName("pasteAll")))
Paste_Clip.triggered.connect(
partial(self.Paste_Triggered, MENU_PASTE, float(position), int(layer_id), [], [])
)
return menu.popup(QCursor.pos())
@pyqtSlot(str)
def ShowClipMenu(self, clip_id=None):
log.debug('ShowClipMenu: %s' % clip_id)
# Get translation method
_ = get_app()._tr
# Get existing clip object
clip = Clip.get(id=clip_id)
if not clip:
# Not a valid clip id
return
# Set the selected clip (if needed)
if clip_id not in self.window.selected_clips:
self.window.addSelection(clip_id, 'clip')
# Get list of selected clips
clip_ids = self.window.selected_clips
tran_ids = self.window.selected_transitions
# Get framerate
fps = get_app().project.get("fps")
fps_float = float(fps["num"]) / float(fps["den"])
# Get playhead position
playhead_position = float(self.window.preview_thread.current_frame) / fps_float
# Create blank context menu
menu = QMenu(self)
# Copy Menu
if len(tran_ids) + len(clip_ids) > 1:
# Show Copy All menu (clips and transitions are selected)
Copy_All = menu.addAction(_("Copy"))
Copy_All.setShortcut(QKeySequence(self.window.getShortcutByName("copyAll")))
Copy_All.triggered.connect(partial(self.Copy_Triggered, MENU_COPY_ALL, clip_ids, tran_ids))
else:
# Only a single clip is selected (Show normal copy menus)
Copy_Menu = QMenu(_("Copy"), self)
Copy_Clip = Copy_Menu.addAction(_("Clip"))
Copy_Clip.setShortcut(QKeySequence(self.window.getShortcutByName("copyAll")))
Copy_Clip.triggered.connect(partial(self.Copy_Triggered, MENU_COPY_CLIP, [clip_id], []))
Keyframe_Menu = QMenu(_("Keyframes"), self)
Copy_Keyframes_All = Keyframe_Menu.addAction(_("All"))
Copy_Keyframes_All.triggered.connect(partial(
self.Copy_Triggered, MENU_COPY_KEYFRAMES_ALL, [clip_id], []))
Keyframe_Menu.addSeparator()
Copy_Keyframes_Alpha = Keyframe_Menu.addAction(_("Alpha"))
Copy_Keyframes_Alpha.triggered.connect(partial(
self.Copy_Triggered, MENU_COPY_KEYFRAMES_ALPHA, [clip_id], []))
Copy_Keyframes_Scale = Keyframe_Menu.addAction(_("Scale"))
Copy_Keyframes_Scale.triggered.connect(partial(
self.Copy_Triggered, MENU_COPY_KEYFRAMES_SCALE, [clip_id], []))
Copy_Keyframes_Rotate = Keyframe_Menu.addAction(_("Rotation"))
Copy_Keyframes_Rotate.triggered.connect(partial(
self.Copy_Triggered, MENU_COPY_KEYFRAMES_ROTATE, [clip_id], []))
Copy_Keyframes_Locate = Keyframe_Menu.addAction(_("Location"))
Copy_Keyframes_Locate.triggered.connect(partial(
self.Copy_Triggered, MENU_COPY_KEYFRAMES_LOCATION, [clip_id], []))
Copy_Keyframes_Time = Keyframe_Menu.addAction(_("Time"))
Copy_Keyframes_Time.triggered.connect(partial(
self.Copy_Triggered, MENU_COPY_KEYFRAMES_TIME, [clip_id], []))
Copy_Keyframes_Volume = Keyframe_Menu.addAction(_("Volume"))
Copy_Keyframes_Volume.triggered.connect(partial(
self.Copy_Triggered, MENU_COPY_KEYFRAMES_VOLUME, [clip_id], []))
# Only add copy->effects and copy->keyframes if 1 clip is selected
Copy_Effects = Copy_Menu.addAction(_("Effects"))
Copy_Effects.triggered.connect(partial(
self.Copy_Triggered, MENU_COPY_EFFECTS, [clip_id], []))
Copy_Menu.addMenu(Keyframe_Menu)
menu.addMenu(Copy_Menu)
# Get list of clipboard items (that are complete clips or transitions)
# i.e. ignore partial clipboard items (keyframes / effects / etc...)
clipboard_clip_ids = [k for k, v in self.copy_clipboard.items() if v.get('id')]
clipboard_tran_ids = [k for k, v in self.copy_transition_clipboard.items() if v.get('id')]
# Determine if the paste menu should be shown
if self.copy_clipboard and len(clipboard_clip_ids) + len(clipboard_tran_ids) == 0:
# Paste Menu (Only show if partial clipboard available)
Paste_Clip = menu.addAction(_("Paste"))
Paste_Clip.triggered.connect(partial(self.Paste_Triggered, MENU_PASTE, 0.0, 0, clip_ids, []))
menu.addSeparator()
# Alignment Menu (if multiple selections)
if len(clip_ids) > 1:
Alignment_Menu = QMenu(_("Align"), self)
Align_Left = Alignment_Menu.addAction(_("Left"))
Align_Left.triggered.connect(partial(self.Align_Triggered, MENU_ALIGN_LEFT, clip_ids, tran_ids))
Align_Right = Alignment_Menu.addAction(_("Right"))
Align_Right.triggered.connect(partial(self.Align_Triggered, MENU_ALIGN_RIGHT, clip_ids, tran_ids))
# Add menu to parent
menu.addMenu(Alignment_Menu)
# Fade In Menu
Fade_Menu = QMenu(_("Fade"), self)
Fade_None = Fade_Menu.addAction(_("No Fade"))
Fade_None.triggered.connect(partial(self.Fade_Triggered, MENU_FADE_NONE, clip_ids))
Fade_Menu.addSeparator()
for position, position_label in [
("Start of Clip", _("Start of Clip")),
("End of Clip", _("End of Clip")),
("Entire Clip", _("Entire Clip"))
]:
Position_Menu = QMenu(position_label, self)
if position == "Start of Clip":
Fade_In_Fast = Position_Menu.addAction(_("Fade In (Fast)"))
Fade_In_Fast.triggered.connect(partial(
self.Fade_Triggered, MENU_FADE_IN_FAST, clip_ids, position))
Fade_In_Slow = Position_Menu.addAction(_("Fade In (Slow)"))
Fade_In_Slow.triggered.connect(partial(
self.Fade_Triggered, MENU_FADE_IN_SLOW, clip_ids, position))
elif position == "End of Clip":
Fade_Out_Fast = Position_Menu.addAction(_("Fade Out (Fast)"))
Fade_Out_Fast.triggered.connect(partial(
self.Fade_Triggered, MENU_FADE_OUT_FAST, clip_ids, position))
Fade_Out_Slow = Position_Menu.addAction(_("Fade Out (Slow)"))
Fade_Out_Slow.triggered.connect(partial(
self.Fade_Triggered, MENU_FADE_OUT_SLOW, clip_ids, position))
else:
Fade_In_Out_Fast = Position_Menu.addAction(_("Fade In and Out (Fast)"))
Fade_In_Out_Fast.triggered.connect(partial(
self.Fade_Triggered, MENU_FADE_IN_OUT_FAST, clip_ids, position))
Fade_In_Out_Slow = Position_Menu.addAction(_("Fade In and Out (Slow)"))
Fade_In_Out_Slow.triggered.connect(partial(
self.Fade_Triggered, MENU_FADE_IN_OUT_SLOW, clip_ids, position))
Position_Menu.addSeparator()
Fade_In_Slow = Position_Menu.addAction(_("Fade In (Entire Clip)"))
Fade_In_Slow.triggered.connect(partial(
self.Fade_Triggered, MENU_FADE_IN_SLOW, clip_ids, position))
Fade_Out_Slow = Position_Menu.addAction(_("Fade Out (Entire Clip)"))
Fade_Out_Slow.triggered.connect(partial(
self.Fade_Triggered, MENU_FADE_OUT_SLOW, clip_ids, position))
Fade_Menu.addMenu(Position_Menu)
menu.addMenu(Fade_Menu)
# Animate Menu
Animate_Menu = QMenu(_("Animate"), self)
Animate_None = Animate_Menu.addAction(_("No Animation"))
Animate_None.triggered.connect(partial(self.Animate_Triggered, MENU_ANIMATE_NONE, clip_ids))
Animate_Menu.addSeparator()
for position, position_label in [
("Start of Clip", _("Start of Clip")),
("End of Clip", _("End of Clip")),
("Entire Clip", _("Entire Clip"))
]:
Position_Menu = QMenu(position_label, self)
# Scale
Scale_Menu = QMenu(_("Zoom"), self)
Animate_In_50_100 = Scale_Menu.addAction(_("Zoom In (50% to 100%)"))
Animate_In_50_100.triggered.connect(partial(
self.Animate_Triggered, MENU_ANIMATE_IN_50_100, clip_ids, position))
Animate_In_75_100 = Scale_Menu.addAction(_("Zoom In (75% to 100%)"))
Animate_In_75_100.triggered.connect(partial(
self.Animate_Triggered, MENU_ANIMATE_IN_75_100, clip_ids, position))
Animate_In_100_150 = Scale_Menu.addAction(_("Zoom In (100% to 150%)"))
Animate_In_100_150.triggered.connect(partial(
self.Animate_Triggered, MENU_ANIMATE_IN_100_150, clip_ids, position))
Animate_Out_100_75 = Scale_Menu.addAction(_("Zoom Out (100% to 75%)"))
Animate_Out_100_75.triggered.connect(partial(
self.Animate_Triggered, MENU_ANIMATE_OUT_100_75, clip_ids, position))
Animate_Out_100_50 = Scale_Menu.addAction(_("Zoom Out (100% to 50%)"))
Animate_Out_100_50.triggered.connect(partial(
self.Animate_Triggered, MENU_ANIMATE_OUT_100_50, clip_ids, position))
Animate_Out_150_100 = Scale_Menu.addAction(_("Zoom Out (150% to 100%)"))
Animate_Out_150_100.triggered.connect(partial(
self.Animate_Triggered, MENU_ANIMATE_OUT_150_100, clip_ids, position))
Position_Menu.addMenu(Scale_Menu)
# Center to Edge
Center_Edge_Menu = QMenu(_("Center to Edge"), self)
Animate_Center_Top = Center_Edge_Menu.addAction(_("Center to Top"))
Animate_Center_Top.triggered.connect(partial(
self.Animate_Triggered, MENU_ANIMATE_CENTER_TOP, clip_ids, position))
Animate_Center_Left = Center_Edge_Menu.addAction(_("Center to Left"))
Animate_Center_Left.triggered.connect(partial(
self.Animate_Triggered, MENU_ANIMATE_CENTER_LEFT, clip_ids, position))
Animate_Center_Right = Center_Edge_Menu.addAction(_("Center to Right"))
Animate_Center_Right.triggered.connect(partial(
self.Animate_Triggered, MENU_ANIMATE_CENTER_RIGHT, clip_ids, position))
Animate_Center_Bottom = Center_Edge_Menu.addAction(_("Center to Bottom"))
Animate_Center_Bottom.triggered.connect(partial(
self.Animate_Triggered, MENU_ANIMATE_CENTER_BOTTOM, clip_ids, position))
Position_Menu.addMenu(Center_Edge_Menu)
# Edge to Center
Edge_Center_Menu = QMenu(_("Edge to Center"), self)
Animate_Top_Center = Edge_Center_Menu.addAction(_("Top to Center"))
Animate_Top_Center.triggered.connect(partial(
self.Animate_Triggered, MENU_ANIMATE_TOP_CENTER, clip_ids, position))
Animate_Left_Center = Edge_Center_Menu.addAction(_("Left to Center"))
Animate_Left_Center.triggered.connect(partial(
self.Animate_Triggered, MENU_ANIMATE_LEFT_CENTER, clip_ids, position))
Animate_Right_Center = Edge_Center_Menu.addAction(_("Right to Center"))
Animate_Right_Center.triggered.connect(partial(
self.Animate_Triggered, MENU_ANIMATE_RIGHT_CENTER, clip_ids, position))
Animate_Bottom_Center = Edge_Center_Menu.addAction(_("Bottom to Center"))
Animate_Bottom_Center.triggered.connect(partial(
self.Animate_Triggered, MENU_ANIMATE_BOTTOM_CENTER, clip_ids, position))
Position_Menu.addMenu(Edge_Center_Menu)
# Edge to Edge
Edge_Edge_Menu = QMenu(_("Edge to Edge"), self)
Animate_Top_Bottom = Edge_Edge_Menu.addAction(_("Top to Bottom"))
Animate_Top_Bottom.triggered.connect(partial(
self.Animate_Triggered, MENU_ANIMATE_TOP_BOTTOM, clip_ids, position))
Animate_Left_Right = Edge_Edge_Menu.addAction(_("Left to Right"))
Animate_Left_Right.triggered.connect(partial(
self.Animate_Triggered, MENU_ANIMATE_LEFT_RIGHT, clip_ids, position))
Animate_Right_Left = Edge_Edge_Menu.addAction(_("Right to Left"))
Animate_Right_Left.triggered.connect(partial(
self.Animate_Triggered, MENU_ANIMATE_RIGHT_LEFT, clip_ids, position))
Animate_Bottom_Top = Edge_Edge_Menu.addAction(_("Bottom to Top"))
Animate_Bottom_Top.triggered.connect(partial(
self.Animate_Triggered, MENU_ANIMATE_BOTTOM_TOP, clip_ids, position))
Position_Menu.addMenu(Edge_Edge_Menu)
# Random Animation
Position_Menu.addSeparator()
Random = Position_Menu.addAction(_("Random"))
Random.triggered.connect(partial(self.Animate_Triggered, MENU_ANIMATE_RANDOM, clip_ids, position))
# Add Sub-Menu's to Position menu
Animate_Menu.addMenu(Position_Menu)
# Add Each position menu
menu.addMenu(Animate_Menu)
# Rotate Menu
Rotation_Menu = QMenu(_("Rotate"), self)
Rotation_None = Rotation_Menu.addAction(_("No Rotation"))
Rotation_None.triggered.connect(partial(
self.Rotate_Triggered, MENU_ROTATE_NONE, clip_ids))
Rotation_Menu.addSeparator()
Rotation_90_Right = Rotation_Menu.addAction(_("Rotate 90 (Right)"))
Rotation_90_Right.triggered.connect(partial(
self.Rotate_Triggered, MENU_ROTATE_90_RIGHT, clip_ids))
Rotation_90_Left = Rotation_Menu.addAction(_("Rotate 90 (Left)"))
Rotation_90_Left.triggered.connect(partial(
self.Rotate_Triggered, MENU_ROTATE_90_LEFT, clip_ids))
Rotation_180_Flip = Rotation_Menu.addAction(_("Rotate 180 (Flip)"))
Rotation_180_Flip.triggered.connect(partial(
self.Rotate_Triggered, MENU_ROTATE_180_FLIP, clip_ids))
menu.addMenu(Rotation_Menu)
# Layout Menu
Layout_Menu = QMenu(_("Layout"), self)
Layout_None = Layout_Menu.addAction(_("Reset Layout"))
Layout_None.triggered.connect(partial(
self.Layout_Triggered, MENU_LAYOUT_NONE, clip_ids))
Layout_Menu.addSeparator()
Layout_Center = Layout_Menu.addAction(_("1/4 Size - Center"))
Layout_Center.triggered.connect(partial(
self.Layout_Triggered, MENU_LAYOUT_CENTER, clip_ids))
Layout_Top_Left = Layout_Menu.addAction(_("1/4 Size - Top Left"))
Layout_Top_Left.triggered.connect(partial(
self.Layout_Triggered, MENU_LAYOUT_TOP_LEFT, clip_ids))
Layout_Top_Right = Layout_Menu.addAction(_("1/4 Size - Top Right"))
Layout_Top_Right.triggered.connect(partial(
self.Layout_Triggered, MENU_LAYOUT_TOP_RIGHT, clip_ids))
Layout_Bottom_Left = Layout_Menu.addAction(_("1/4 Size - Bottom Left"))
Layout_Bottom_Left.triggered.connect(partial(
self.Layout_Triggered, MENU_LAYOUT_BOTTOM_LEFT, clip_ids))
Layout_Bottom_Right = Layout_Menu.addAction(_("1/4 Size - Bottom Right"))
Layout_Bottom_Right.triggered.connect(partial(
self.Layout_Triggered, MENU_LAYOUT_BOTTOM_RIGHT, clip_ids))
Layout_Menu.addSeparator()
Layout_Bottom_All_With_Aspect = Layout_Menu.addAction(_("Show All (Maintain Ratio)"))
Layout_Bottom_All_With_Aspect.triggered.connect(partial(
self.Layout_Triggered, MENU_LAYOUT_ALL_WITH_ASPECT, clip_ids))
Layout_Bottom_All_Without_Aspect = Layout_Menu.addAction(_("Show All (Distort)"))
Layout_Bottom_All_Without_Aspect.triggered.connect(partial(
self.Layout_Triggered, MENU_LAYOUT_ALL_WITHOUT_ASPECT, clip_ids))
menu.addMenu(Layout_Menu)
# Time Menu
Time_Menu = QMenu(_("Time"), self)
Time_None = Time_Menu.addAction(_("Reset Time"))
Time_None.triggered.connect(partial(self.Time_Triggered, MENU_TIME_NONE, clip_ids, '1X'))
Time_Menu.addSeparator()
for speed, speed_values in [
(_("Normal"), ['1X']),
(_("Fast"), ['2X', '4X', '8X', '16X']),
(_("Slow"), ['1/2X', '1/4X', '1/8X', '1/16X'])
]:
Speed_Menu = QMenu(speed, self)
for direction, direction_value in [
(_("Forward"), MENU_TIME_FORWARD),
(_("Backward"), MENU_TIME_BACKWARD)
]:
Direction_Menu = QMenu(direction, self)
for actual_speed in speed_values:
# Add menu option
Time_Option = Direction_Menu.addAction(_(actual_speed))
Time_Option.triggered.connect(
partial(self.Time_Triggered, direction_value, clip_ids, actual_speed))
# Add menu to parent
Speed_Menu.addMenu(Direction_Menu)
# Add menu to parent
Time_Menu.addMenu(Speed_Menu)
# Add Freeze menu options
Time_Menu.addSeparator()
for freeze_type, trigger_type in [
(_("Freeze"), MENU_TIME_FREEZE),
(_("Freeze && Zoom"), MENU_TIME_FREEZE_ZOOM)
]:
Freeze_Menu = QMenu(freeze_type, self)
for freeze_seconds in [2, 4, 6, 8, 10, 20, 30]:
# Add menu option
Time_Option = Freeze_Menu.addAction(_('{} seconds').format(freeze_seconds))
Time_Option.triggered.connect(
partial(self.Time_Triggered, trigger_type, clip_ids, freeze_seconds, playhead_position))
# Add menu to parent
Time_Menu.addMenu(Freeze_Menu)
# Add menu to parent
menu.addMenu(Time_Menu)
# Volume Menu
Volume_Menu = QMenu(_("Volume"), self)
Volume_None = Volume_Menu.addAction(_("Reset Volume"))
Volume_None.triggered.connect(partial(self.Volume_Triggered, MENU_VOLUME_NONE, clip_ids))
Volume_Menu.addSeparator()
for position, position_label in [
("Start of Clip", _("Start of Clip")),
("End of Clip", _("End of Clip")),
("Entire Clip", _("Entire Clip"))
]:
Position_Menu = QMenu(position_label, self)
if position == "Start of Clip":
Fade_In_Fast = Position_Menu.addAction(_("Fade In (Fast)"))
Fade_In_Fast.triggered.connect(partial(
self.Volume_Triggered, MENU_VOLUME_FADE_IN_FAST, clip_ids, position))
Fade_In_Slow = Position_Menu.addAction(_("Fade In (Slow)"))
Fade_In_Slow.triggered.connect(partial(
self.Volume_Triggered, MENU_VOLUME_FADE_IN_SLOW, clip_ids, position))
elif position == "End of Clip":
Fade_Out_Fast = Position_Menu.addAction(_("Fade Out (Fast)"))
Fade_Out_Fast.triggered.connect(partial(
self.Volume_Triggered, MENU_VOLUME_FADE_OUT_FAST, clip_ids, position))
Fade_Out_Slow = Position_Menu.addAction(_("Fade Out (Slow)"))
Fade_Out_Slow.triggered.connect(partial(
self.Volume_Triggered, MENU_VOLUME_FADE_OUT_SLOW, clip_ids, position))
else:
Fade_In_Out_Fast = Position_Menu.addAction(_("Fade In and Out (Fast)"))
Fade_In_Out_Fast.triggered.connect(partial(
self.Volume_Triggered, MENU_VOLUME_FADE_IN_OUT_FAST, clip_ids, position))
Fade_In_Out_Slow = Position_Menu.addAction(_("Fade In and Out (Slow)"))
Fade_In_Out_Slow.triggered.connect(partial(
self.Volume_Triggered, MENU_VOLUME_FADE_IN_OUT_SLOW, clip_ids, position))
Position_Menu.addSeparator()
Fade_In_Slow = Position_Menu.addAction(_("Fade In (Entire Clip)"))
Fade_In_Slow.triggered.connect(partial(
self.Volume_Triggered, MENU_VOLUME_FADE_IN_SLOW, clip_ids, position))
Fade_Out_Slow = Position_Menu.addAction(_("Fade Out (Entire Clip)"))
Fade_Out_Slow.triggered.connect(partial(
self.Volume_Triggered, MENU_VOLUME_FADE_OUT_SLOW, clip_ids, position))
# Add levels (100% to 0%)
Position_Menu.addSeparator()
Volume_100 = Position_Menu.addAction(_("Level 100%"))
Volume_100.triggered.connect(partial(
self.Volume_Triggered, MENU_VOLUME_LEVEL_100, clip_ids, position))
Volume_90 = Position_Menu.addAction(_("Level 90%"))
Volume_90.triggered.connect(partial(
self.Volume_Triggered, MENU_VOLUME_LEVEL_90, clip_ids, position))
Volume_80 = Position_Menu.addAction(_("Level 80%"))
Volume_80.triggered.connect(partial(
self.Volume_Triggered, MENU_VOLUME_LEVEL_80, clip_ids, position))
Volume_70 = Position_Menu.addAction(_("Level 70%"))
Volume_70.triggered.connect(partial(
self.Volume_Triggered, MENU_VOLUME_LEVEL_70, clip_ids, position))
Volume_60 = Position_Menu.addAction(_("Level 60%"))
Volume_60.triggered.connect(partial(
self.Volume_Triggered, MENU_VOLUME_LEVEL_60, clip_ids, position))
Volume_50 = Position_Menu.addAction(_("Level 50%"))
Volume_50.triggered.connect(partial(
self.Volume_Triggered, MENU_VOLUME_LEVEL_50, clip_ids, position))
Volume_40 = Position_Menu.addAction(_("Level 40%"))
Volume_40.triggered.connect(partial(
self.Volume_Triggered, MENU_VOLUME_LEVEL_40, clip_ids, position))
Volume_30 = Position_Menu.addAction(_("Level 30%"))
Volume_30.triggered.connect(partial(
self.Volume_Triggered, MENU_VOLUME_LEVEL_30, clip_ids, position))
Volume_20 = Position_Menu.addAction(_("Level 20%"))
Volume_20.triggered.connect(partial(
self.Volume_Triggered, MENU_VOLUME_LEVEL_20, clip_ids, position))
Volume_10 = Position_Menu.addAction(_("Level 10%"))
Volume_10.triggered.connect(partial(
self.Volume_Triggered, MENU_VOLUME_LEVEL_10, clip_ids, position))
Volume_0 = Position_Menu.addAction(_("Level 0%"))
Volume_0.triggered.connect(partial(
self.Volume_Triggered, MENU_VOLUME_LEVEL_0, clip_ids, position))
Volume_Menu.addMenu(Position_Menu)
menu.addMenu(Volume_Menu)
# Add separate audio menu
Split_Audio_Channels_Menu = QMenu(_("Separate Audio"), self)
Split_Single_Clip = Split_Audio_Channels_Menu.addAction(_("Single Clip (all channels)"))
Split_Single_Clip.triggered.connect(partial(
self.Split_Audio_Triggered, MENU_SPLIT_AUDIO_SINGLE, clip_ids))
Split_Multiple_Clips = Split_Audio_Channels_Menu.addAction(_("Multiple Clips (each channel)"))
Split_Multiple_Clips.triggered.connect(partial(
self.Split_Audio_Triggered, MENU_SPLIT_AUDIO_MULTIPLE, clip_ids))
menu.addMenu(Split_Audio_Channels_Menu)
# If Playhead overlapping clip
if clip:
start_of_clip = float(clip.data["start"])
end_of_clip = float(clip.data["end"])
position_of_clip = float(clip.data["position"])
if (
playhead_position >= position_of_clip
and playhead_position <= (position_of_clip + (end_of_clip - start_of_clip))
):
# Add split clip menu
Slice_Menu = QMenu(_("Slice"), self)
Slice_Keep_Both = Slice_Menu.addAction(_("Keep Both Sides"))
Slice_Keep_Both.triggered.connect(partial(
self.Slice_Triggered, MENU_SLICE_KEEP_BOTH, [clip_id], [], playhead_position))
Slice_Keep_Left = Slice_Menu.addAction(_("Keep Left Side"))
Slice_Keep_Left.triggered.connect(partial(
self.Slice_Triggered, MENU_SLICE_KEEP_LEFT, [clip_id], [], playhead_position))
Slice_Keep_Right = Slice_Menu.addAction(_("Keep Right Side"))
Slice_Keep_Right.triggered.connect(partial(
self.Slice_Triggered, MENU_SLICE_KEEP_RIGHT, [clip_id], [], playhead_position))
menu.addMenu(Slice_Menu)
# Transform menu
Transform_Action = self.window.actionTransform
Transform_Action.triggered.connect(
partial(self.Transform_Triggered, MENU_TRANSFORM, clip_ids))
menu.addAction(Transform_Action)
# Add clip display menu (waveform or thumbnail)
menu.addSeparator()
Waveform_Menu = QMenu(_("Display"), self)
ShowWaveform = Waveform_Menu.addAction(_("Show Waveform"))
ShowWaveform.triggered.connect(partial(self.Show_Waveform_Triggered, clip_ids))
HideWaveform = Waveform_Menu.addAction(_("Show Thumbnail"))
HideWaveform.triggered.connect(partial(self.Hide_Waveform_Triggered, clip_ids))
menu.addMenu(Waveform_Menu)
# Properties
menu.addAction(self.window.actionProperties)
# Remove Clip Menu
menu.addSeparator()
menu.addAction(self.window.actionRemoveClip)
# Show Context menu
return menu.popup(QCursor.pos())
def Transform_Triggered(self, action, clip_ids):
log.debug("Transform_Triggered")
# Emit signal to transform this clip (for the 1st clip id)
if clip_ids:
# Transform first clip in list
self.window.TransformSignal.emit(clip_ids[0])
else:
# Clear transform
self.window.TransformSignal.emit("")
def Show_Waveform_Triggered(self, clip_ids):
"""Show a waveform for the selected clip"""
# Loop through each selected clip
for clip_id in clip_ids:
# Get existing clip object
clip = Clip.get(id=clip_id)
if not clip:
# Invalid clip, skip to next item
continue
file_path = clip.data["reader"]["path"]
# Find actual clip object from libopenshot
c = self.window.timeline_sync.timeline.GetClip(clip_id)
if c and c.Reader() and not c.Reader().info.has_single_image:
# Find frame 1 channel_filter property
channel_filter = c.channel_filter.GetInt(1)
# Set cursor to waiting
get_app().setOverrideCursor(QCursor(Qt.WaitCursor))
# Get audio data in a separate thread (so it doesn't block the UI)
channel_filter = channel_filter
get_audio_data(clip_id, file_path, channel_filter, c.volume)
def Hide_Waveform_Triggered(self, clip_ids):
"""Hide the waveform for the selected clip"""
# Loop through each selected clip
for clip_id in clip_ids:
# Get existing clip object
clip = Clip.get(id=clip_id)
if clip:
# Pass to javascript timeline (and render)
self.run_js(JS_SCOPE_SELECTOR + ".hideAudioData('" + clip_id + "');")