-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui.py
176 lines (141 loc) · 6.35 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
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
import sys
import os
from PyQt5.QtWidgets import (QApplication, QWidget, QVBoxLayout, QHBoxLayout, QLabel, QLineEdit, QPushButton,
QFileDialog, QSpinBox, QComboBox, QMessageBox)
from PyQt5.QtCore import Qt
# Import the encoding and decoding functions
from lazyown_infinitestorage import encode_file_to_video, decode_video_to_file
class MainWindow(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setWindowTitle("LazyOwn Infinite Storage")
self.layout = QVBoxLayout()
self.mode_combobox = QComboBox()
self.mode_combobox.addItems(["encode", "decode"])
self.mode_combobox.currentIndexChanged.connect(self.change_mode)
self.layout.addWidget(QLabel("Mode:"))
self.layout.addWidget(self.mode_combobox)
self.encode_ui = None
self.decode_ui = None
self.create_common_ui()
self.change_mode()
self.setLayout(self.layout)
def create_encode_ui(self):
encode_ui = QVBoxLayout()
self.input_file_label = QLabel("Select ZIP file:")
self.input_file_edit = QLineEdit()
self.input_file_button = QPushButton("Browse")
self.input_file_button.clicked.connect(self.browse_input_file)
self.output_file_label = QLabel("Video name:")
self.output_file_edit = QLineEdit()
file_layout = QHBoxLayout()
file_layout.addWidget(self.input_file_edit)
file_layout.addWidget(self.input_file_button)
encode_ui.addWidget(self.input_file_label)
encode_ui.addLayout(file_layout)
encode_ui.addWidget(self.output_file_label)
encode_ui.addWidget(self.output_file_edit)
self.fps_label = QLabel("Frames per second:")
self.fps_spinbox = QSpinBox()
self.fps_spinbox.setRange(1, 60)
self.fps_spinbox.setValue(30)
encode_ui.addWidget(self.fps_label)
encode_ui.addWidget(self.fps_spinbox)
return encode_ui
def create_decode_ui(self):
decode_ui = QVBoxLayout()
self.input_file_label = QLabel("Select Video file:")
self.input_file_edit = QLineEdit()
self.input_file_button = QPushButton("Browse")
self.input_file_button.clicked.connect(self.browse_input_file)
self.output_file_label = QLabel("Recovery ZIP file name:")
self.output_file_edit = QLineEdit()
file_layout = QHBoxLayout()
file_layout.addWidget(self.input_file_edit)
file_layout.addWidget(self.input_file_button)
decode_ui.addWidget(self.input_file_label)
decode_ui.addLayout(file_layout)
decode_ui.addWidget(self.output_file_label)
decode_ui.addWidget(self.output_file_edit)
return decode_ui
def create_common_ui(self):
self.frame_size_label = QLabel("Frame size (width height):")
self.width_spinbox = QSpinBox()
self.width_spinbox.setRange(1, 10000)
self.width_spinbox.setValue(640)
self.height_spinbox = QSpinBox()
self.height_spinbox.setRange(1, 10000)
self.height_spinbox.setValue(480)
frame_size_layout = QHBoxLayout()
frame_size_layout.addWidget(self.width_spinbox)
frame_size_layout.addWidget(self.height_spinbox)
self.layout.addWidget(self.frame_size_label)
self.layout.addLayout(frame_size_layout)
self.block_size_label = QLabel("Block size:")
self.block_size_spinbox = QSpinBox()
self.block_size_spinbox.setRange(1, 100)
self.block_size_spinbox.setValue(4)
self.layout.addWidget(self.block_size_label)
self.layout.addWidget(self.block_size_spinbox)
self.start_button = QPushButton("Start")
self.start_button.clicked.connect(self.start_process)
self.layout.addWidget(self.start_button)
def change_mode(self):
mode = self.mode_combobox.currentText()
if self.encode_ui:
self.clear_layout(self.encode_ui)
self.layout.removeItem(self.encode_ui)
if self.decode_ui:
self.clear_layout(self.decode_ui)
self.layout.removeItem(self.decode_ui)
if mode == "encode":
self.encode_ui = self.create_encode_ui()
self.layout.insertLayout(2, self.encode_ui)
self.fps_label.show()
self.fps_spinbox.show()
else:
self.decode_ui = self.create_decode_ui()
self.layout.insertLayout(2, self.decode_ui)
self.fps_label.hide()
self.fps_spinbox.hide()
def clear_layout(self, layout):
while layout.count():
child = layout.takeAt(0)
if child.widget():
child.widget().deleteLater()
def browse_input_file(self):
options = QFileDialog.Options()
options |= QFileDialog.ReadOnly
if self.mode_combobox.currentText() == "encode":
file, _ = QFileDialog.getOpenFileName(self, "Select ZIP file", "", "ZIP Files (*.zip);;All Files (*)", options=options)
else:
file, _ = QFileDialog.getOpenFileName(self, "Select Video file", "", "Video Files (*.mp4);;All Files (*)", options=options)
if file:
self.input_file_edit.setText(file)
def start_process(self):
input_file = self.input_file_edit.text()
output_file = self.output_file_edit.text()
frame_size = (self.width_spinbox.value(), self.height_spinbox.value())
block_size = self.block_size_spinbox.value()
mode = self.mode_combobox.currentText()
try:
if mode == "encode":
fps = self.fps_spinbox.value()
output_file_with_resolution = f"{os.path.splitext(output_file)[0]}_{frame_size[0]}x{frame_size[1]}.mp4"
encode_file_to_video(input_file, output_file_with_resolution, frame_size, fps, block_size)
elif mode == "decode":
decode_video_to_file(input_file, output_file, block_size)
self.show_message("Process completed successfully!")
except Exception as e:
self.show_message(f"An error occurred: {str(e)}")
def show_message(self, message):
message_box = QMessageBox()
message_box.setText(message)
message_box.exec_()
if __name__ == "__main__":
app = QApplication(sys.argv)
main_win = MainWindow()
main_win.show()
sys.exit(app.exec_())