-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui.py
92 lines (72 loc) · 2.79 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
81
82
83
84
85
86
87
88
89
90
91
92
import mimetypes
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton, QLabel, QFileDialog, QMessageBox
from main import ARUCODetector
mimetypes.init()
def isMediaFile(fileName):
"""
Check if file is video
:param fileName: path to file
:return:
"""
mimestart = mimetypes.guess_type(fileName)[0]
if mimestart != None:
mimestart = mimestart.split('/')[0]
if mimestart in ['video']:
return True
return False
class App(QMainWindow):
def __init__(self):
super().__init__()
# Time axis
self.left = 10
self.top = 50
self.title = 'Lab4 v1.2.0'
# bar with buttons and checkbox
self.filepath = ''
self.btnStart = QPushButton('Start', self)
self.btnLoad = QPushButton('Загрузить видео', self)
self.infoLabel = QLabel('©Dostoyewski & Amgaran, THEORHECH INC.\n'
'All output files will be saved to\napp launch directory', self)
self.statusLabel = QLabel('', self)
self.widthp = 384
self.heightp = 240
self.initUI()
def initUI(self):
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.widthp, self.heightp)
self.btnLoad.move(100, 20)
self.btnLoad.clicked.connect(self.openFileNameDialog)
self.statusLabel.move(100, 100)
self.btnStart.move(100, 70)
self.infoLabel.resize(250, 40)
self.infoLabel.move(100, 180)
self.btnStart.clicked.connect(self.start)
self.show()
def start(self):
detector = ARUCODetector(self.filepath)
self.statusLabel.setText('Обрабатываю...')
detector.run()
self.statusLabel.setText('Готово!')
def openFileNameDialog(self):
"""
Select scenario file
:return:
"""
options = QFileDialog.Options()
options |= QFileDialog.DontUseNativeDialog
filename, _ = QFileDialog.getOpenFileNames(self, "Загрузить видео", "", "", options=options)
if filename and isMediaFile(filename[0]):
self.filepath = filename[0]
else:
msg = QMessageBox()
msg.setIcon(QMessageBox.Critical)
msg.setText("Вы уверены, что это видео?")
msg.setInformativeText('Хм. По-моему, это какая-то ботва, а не видео. Перепроверьте то, что вы '
'скармливаете программе. Лучше всего *.mp4.')
msg.setWindowTitle("Эй, помедленнее!")
msg.exec_()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = App()
sys.exit(app.exec_())