-
Notifications
You must be signed in to change notification settings - Fork 1
/
gui.py
80 lines (73 loc) · 3.1 KB
/
gui.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
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from PySide.QtGui import QWidget, QBoxLayout, QFileDialog, QPushButton, QLabel, QFrame
import os
from correlate import correlate
class MainWindow(QWidget, object):
# noinspection PyUnresolvedReferences
def __init__(self):
super(MainWindow, self).__init__()
self.clip_filename = None
self.audio_filename = None
layout = QBoxLayout(QBoxLayout.TopToBottom)
clip_row = QBoxLayout(QBoxLayout.LeftToRight)
self.clip_button = QPushButton()
self.clip_button.clicked.connect(self.open_clip)
self.clip_button.setText(self.tr("Open clip"))
clip_row.addWidget(self.clip_button)
self.clip_view = QLabel()
clip_row.addWidget(self.clip_view)
clip_frame = QFrame()
clip_frame.setLayout(clip_row)
layout.addWidget(clip_frame)
audio_row = QBoxLayout(QBoxLayout.LeftToRight)
self.audio_button = QPushButton()
self.audio_button.clicked.connect(self.open_audio)
self.audio_button.setText(self.tr("Open audio"))
audio_row.addWidget(self.audio_button)
self.audio_view = QLabel()
audio_row.addWidget(self.audio_view)
audio_frame = QFrame()
audio_frame.setLayout(audio_row)
layout.addWidget(audio_frame)
save_row = QBoxLayout(QBoxLayout.LeftToRight)
self.save_button = QPushButton()
self.save_button.clicked.connect(self.save)
self.save_button.setText(self.tr("Save synced clip"))
save_row.addWidget(self.save_button)
save_frame = QFrame()
save_frame.setLayout(save_row)
layout.addWidget(save_frame)
self.update_save_button()
layout.addStretch()
self.setLayout(layout)
self.show()
def open_clip(self):
self.clip_filename = QFileDialog.getOpenFileName(
self,
self.tr("Open Clip"),
os.getcwd(),
self.tr("Video Files [.mp4, .ogv, .mkv, .avi, .mov] (*.mp4 *.ogv *.mkv *.avi *.mov);;" +
"Audio Files [.flac, .ogg, .wav, .mp3] (*.flac *.ogg *.wav *.mp3)"))[0]
self.clip_view.setText(self.clip_filename)
self.update_save_button()
def open_audio(self):
self.audio_filename = QFileDialog.getOpenFileName(
self,
self.tr("Open Audio"),
os.getcwd(),
self.tr("Audio Files [.flac, .ogg, .wav, .mp3] (*.flac *.ogg *.wav *.mp3)"))[0]
self.audio_view.setText(self.audio_filename)
self.update_save_button()
def update_save_button(self):
self.save_button.setEnabled(bool(self.clip_filename and self.audio_filename))
def save(self):
dialog = QFileDialog(self)
dialog.setFileMode(QFileDialog.AnyFile)
dialog.setAcceptMode(QFileDialog.AcceptSave)
dialog.setDefaultSuffix("avi")
dialog.setDirectory(os.getcwd())
dialog.setNameFilter(self.tr("Video Files [.avi] (*.avi)"))
if dialog.exec_():
output_file_name = dialog.selectedFiles()[0]
correlate(self.clip_filename, self.audio_filename, output_file_name)