-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.py
356 lines (297 loc) · 15.6 KB
/
main.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
# This is a sample Python script.
import sys
import threading
import time
from PySide6.QtCore import Qt
from PySide6.QtWidgets import QLabel, QFileDialog
import configparser
import StripchatRecorder
from StripchatRecorder import startRecording
from PySide6 import QtCore, QtWidgets
import Utils
# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
class StripchatUI(QtWidgets.QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("StripchatRecorder")
self.selectedFiles = []
self.setMinimumSize(800, 500)
self.runProg = True
# Create tabs
self.recList = [[],[]]
self.tabs = QtWidgets.QTabWidget()
self.recThread = threading.Thread(target=StripchatRecorder.startRecording, args=(self.recList,))
# Create Tab 1
self.tab1 = QtWidgets.QWidget()
self.tab1Layout = QtWidgets.QHBoxLayout(self.tab1)
self.Config = configparser.ConfigParser()
# Create Left Panel
self.leftPanel = QtWidgets.QVBoxLayout()
self.mainDir = sys.path[0]
self.Config.read(self.mainDir + '/config.conf')
self.wanted_model = open(self.Config.get('paths', 'wishlist'), 'r').read().splitlines()
# Create the layout and add the first QLineEdit widget
self.lineEditsLayout = QtWidgets.QVBoxLayout()
self.lineEdits = [QtWidgets.QLineEdit() for _ in range(len(self.wanted_model)+1)]
# print(len(self.wanted_model))
self.lineEditsWidget = QtWidgets.QWidget()
self.lineEditsVbox = QtWidgets.QVBoxLayout()
self.lineEditsWidget.setLayout(self.lineEditsVbox)
self.lineEditsScrollArea = QtWidgets.QScrollArea()
self.lineEditsScrollArea.setWidget(self.lineEditsWidget)
self.lineEditsScrollArea.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
self.lineEditsScrollArea.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.lineEditsScrollArea.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
self.lineEditsScrollArea.setWidgetResizable(True)
self.lineEditsScrollArea.setStyleSheet("QWidget {border: 1px solid gray; border-radius: 5px;}")
# Create the button to add new QLineEdit widgets
self.addButton = QtWidgets.QPushButton("Add Model")
self.addButton.clicked.connect(self.addLineEdit)
# self.addButton.setAlignment(Qt.AlignmentFlag.AlignBottom)
# Create a widget to hold the line edits layout
# Create a scroll area to hold the line edits widget
# Add the scroll area to the left panel
self.leftPanel.addWidget(self.lineEditsScrollArea)
for i in (range(len(self.lineEdits))):
if i < len(self.wanted_model):
# print(i)
self.lineEdits[i].setText(self.wanted_model[i])
self.lineEditsVbox.addWidget(self.lineEdits[i])
# Add the button to the left panel
# self.leftPanel.addWidget(self.addButton, alignment=QtCore.Qt.AlignBottom)
# Create TextInput Box
self.inputStream = QtWidgets.QLineEdit()
self.inputStream.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
# Create Start Button
self.startButton = QtWidgets.QPushButton("Start")
self.startButton.clicked.connect(self.startRecording)
# Create Stop Button
self.stopButton = QtWidgets.QPushButton("Stop")
self.stopButton.clicked.connect(self.stopRecording)
self.applyModelsButton = QtWidgets.QPushButton("Apply Changes")
self.applyModelsButton.clicked.connect(self.applyModel)
# self.stopButton.clicked.connect(self.stopRecording)
# Add TextInput Box and Start Button to Left Panel
# self.leftPanel.addWidget(self.inputStream, 2)
self.tab1ActionRows = QtWidgets.QHBoxLayout()
self.tab1InputRows = QtWidgets.QHBoxLayout()
self.tab1InputRows.addWidget(self.addButton, 1)
self.tab1InputRows.addWidget(self.applyModelsButton, 1)
self.tab1ActionRows.addWidget(self.startButton, 1)
self.tab1ActionRows.addWidget(self.stopButton, 1)
self.leftPanel.addLayout(self.tab1InputRows, 1)
self.leftPanel.addLayout(self.tab1ActionRows, 1)
# self.leftPanel.addWidget(self.startButton, 1)
# Create Right Panel
self.rightPanel = QtWidgets.QVBoxLayout()
# Create Bordered Textbox
self.streamerBox = QtWidgets.QGroupBox("Recording Streamer")
self.streamerBox.setStyleSheet("QGroupBox {border: 1px solid gray; border-radius: 5px; padding-top: 10px}")
# Create Label
self.streamerLabel = QtWidgets.QLabel("No streamer selected")
self.streamerLabel.setAlignment(QtCore.Qt.AlignTop)
self.recordingBox = QtWidgets.QWidget()
self.recordingBox.setStyleSheet("QWidget {border: 1px solid gray; border-radius: 5px; padding-top: 10px}")
self.recordingBoxLayout = QtWidgets.QVBoxLayout()
self.recordingBox.setLayout(self.recordingBoxLayout)
# self.recordingHistory = QtWidgets.QLabel("Recording History")
# self.recordingHistory.setAlignment(QtCore.Qt.AlignTop)
# Add Label to Bordered Textbox
self.streamerLayout = QtWidgets.QVBoxLayout(self.streamerBox)
self.streamerLayout.addWidget(self.streamerLabel)
self.streamerDisplayWidget = QtWidgets.QWidget()
self.streamerDisplayVbox = QtWidgets.QVBoxLayout()
self.streamerDisplayWidget.setLayout(self.streamerDisplayVbox)
self.recordingScrollArea = QtWidgets.QScrollArea(self.recordingBox)
self.recordingScrollArea.setWidget(self.streamerDisplayWidget)
self.recordingScrollArea.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
self.recordingScrollArea.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
# self.recordingScrollArea.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
self.recordingScrollArea.setWidgetResizable(True)
self.recordingScrollArea.setStyleSheet("QWidget {border: 1px solid gray; border-radius: 5px;}")
# Add Bordered Textbox to Right Panel
self.rightPanel.addWidget(self.streamerBox, 1)
self.rightPanel.addWidget(self.recordingScrollArea, 1)
# Add Left and Right Panel to Tab 1
self.tab1Layout.addLayout(self.leftPanel, 1)
self.tab1Layout.addLayout(self.rightPanel, 1)
self.fixVideoTabWidget = QtWidgets.QWidget()
self.fixVideoTabLayout = QtWidgets.QHBoxLayout()
self.fixVideoTabWidget.setLayout(self.fixVideoTabLayout)
self.addFileBtn = QtWidgets.QPushButton("Select Files")
# self.btn.clicked.connect(self.getfile)
self.flineEditsWidget = QtWidgets.QWidget()
self.flineEditsVbox = QtWidgets.QVBoxLayout()
self.flineEditsVbox.setAlignment(Qt.AlignmentFlag.AlignTop)
self.flineEditsWidget.setLayout(self.flineEditsVbox)
self.flineEditsScrollArea = QtWidgets.QScrollArea()
self.flineEditsScrollArea.setWidget(self.flineEditsWidget)
self.flineEditsScrollArea.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
self.flineEditsScrollArea.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.flineEditsScrollArea.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
self.flineEditsScrollArea.setWidgetResizable(True)
self.flineEditsScrollArea.setStyleSheet("QWidget {border: 1px solid gray; border-radius: 5px;}")
self.fAddButton = QtWidgets.QPushButton("Select Video")
self.fAddButton.clicked.connect(self.getfiles)
self.fClearButton = QtWidgets.QPushButton("Clear Selection")
self.fClearButton.clicked.connect(self.clearSelection)
self.fRunButton = QtWidgets.QPushButton("Start Fix")
self.fRunButton.clicked.connect(self.startFix)
self.fixVideoButtonWidget1 = QtWidgets.QWidget()
self.fixVideoButtonLayout1 = QtWidgets.QHBoxLayout()
self.fixVideoButtonWidget1.setLayout(self.fixVideoButtonLayout1)
self.fixVideoButtonLayout1.addWidget(self.fAddButton)
self.fixVideoButtonLayout1.addWidget(self.fClearButton)
self.fixVideoButtonWidget2 = QtWidgets.QWidget()
self.fixVideoButtonLayout2 = QtWidgets.QHBoxLayout()
self.fixVideoButtonWidget2.setLayout(self.fixVideoButtonLayout2)
self.fixVideoButtonLayout2.addWidget(self.fRunButton)
self.PPLeftPanelWidget = QtWidgets.QWidget()
self.PPLeftPanelLayout = QtWidgets.QVBoxLayout()
self.PPLeftPanelLayout.addWidget(self.flineEditsScrollArea)
self.PPLeftPanelLayout.addWidget(self.fixVideoButtonWidget1)
self.PPLeftPanelLayout.addWidget(self.fixVideoButtonWidget2)
# self.PPLeftPanelWidget.setStyleSheet("background-color: yellow")
self.PPLeftPanelWidget.setLayout(self.PPLeftPanelLayout)
self.PPRightPanelWidget = QtWidgets.QWidget()
self.PPRightPanelLayout = QtWidgets.QVBoxLayout()
# self.PPRightPanelWidget.setStyleSheet("background-color: red")
self.PPRightPanelWidget.setLayout(self.PPRightPanelLayout)
self.fixVideoTabLayout.addWidget(self.PPLeftPanelWidget, 1)
self.fixVideoTabLayout.addWidget(self.PPRightPanelWidget, 1)
self.tabSetting = QtWidgets.QWidget()
self.tabSettingLayout = QtWidgets.QVBoxLayout()
self.tabFormLayout = QtWidgets.QFormLayout()
self.tabSetting.setLayout(self.tabSettingLayout)
self.targetDirTextEdit = QtWidgets.QLineEdit()
self.targetDirTextEdit.setText(self.Config.get('paths', 'save_directory'))
self.wantedModelDirTextEdit = QtWidgets.QLineEdit()
self.wantedModelDirTextEdit.setText(self.Config.get('paths', 'wishlist'))
self.tabFormLayout.addRow("Save Recording Directory", self.targetDirTextEdit)
self.tabFormLayout.addRow("Wanted Model File Directory", self.wantedModelDirTextEdit)
self.applySetting = QtWidgets.QPushButton("Apply")
self.applySetting.clicked.connect(self.applyConfig)
self.settingActionRow = QtWidgets.QHBoxLayout();
self.settingActionRow.addWidget(self.applySetting)
self.tabSettingLayout.addLayout(self.tabFormLayout)
self.tabSettingLayout.addLayout(self.settingActionRow)
# Add Tab 1 to the tabs
self.tabs.addTab(self.tab1, "Recording")
self.tabs.addTab(self.fixVideoTabWidget, "Fix Videos")
self.tabs.addTab(self.tabSetting, "Setting")
# Add tabs to the main window
self.setCentralWidget(self.tabs)
# Set window properties
self.setWindowTitle("StripchatUI")
self.setGeometry(100, 100, 800, 600)
# Update the text every second
self.timer = QtCore.QTimer()
self.timer.timeout.connect(self.updateUI)
self.timer.start(1000)
def addLineEdit(self):
# Add a new QLineEdit widget to the list and layout
newLineEdit = QtWidgets.QLineEdit()
self.lineEdits.append(newLineEdit)
self.lineEditsVbox.addWidget(newLineEdit)
# for wid in self.lineEdits:
# wid.setStyleSheet("background-color: yellow")
def addSelectedFile(self, filename):
# Add a new QLineEdit widget to the list and layout
newLineEdit = QtWidgets.QLineEdit()
newLineEdit.setText(filename)
self.selectedFiles.append(filename)
self.fixSelectedFileListLayout.addWidget(newLineEdit)
# for wid in self.lineEdits:
# wid.setStyleSheet("background-color: yellow")
def applyModel(self):
with open(self.Config.get('paths', 'wishlist'), 'w') as file:
file.write('\n'.join(i.text() for i in self.lineEdits))
def applyConfig(self):
self.Config.set('paths', 'wishlist', self.wantedModelDirTextEdit.text())
self.Config.set('paths', 'save_directory', self.targetDirTextEdit.text())
with open(self.mainDir + '/config.conf', 'w') as configfile:
self.Config.write(configfile)
def updateUI(self):
print(Utils.format_model_to_UI(self.recList[0]))
self.streamerLabel.setText(Utils.format_model_to_UI(self.recList[0]))
for i in reversed(range(self.streamerDisplayVbox.count())):
self.streamerDisplayVbox.itemAt(i).widget().setParent(None)
for history in self.recList[1]:
label = QLabel(Utils.format_recording_history_to_UI(history))
label.setAlignment(QtCore.Qt.AlignTop)
if history["status"] == "Stopped Recording":
label.setStyleSheet("background-color: rgba(168, 0, 0, 204);")
self.streamerDisplayVbox.addWidget(label)
# self.recordingHistory.setText(Utils.format_recording_history_to_UI(self.recList[1]))
def startRecording(self):
self.runProg = True
self.recThread.start()
def getfiles(self):
dlg = QFileDialog()
dlg.setFileMode(QFileDialog.FileMode.ExistingFiles)
dlg.setMimeTypeFilters(
{
"video/mp4"
}
)
filenames = []
if dlg.exec_():
filenames = dlg.selectedFiles()
for file in filenames:
if file not in self.selectedFiles:
self.selectedFiles.append(file)
for i in reversed(range(self.flineEditsVbox.count())):
self.flineEditsVbox.itemAt(i).widget().setParent(None)
for filename in self.selectedFiles:
label = QLabel(filename)
label.setAlignment(QtCore.Qt.AlignTop)
delButton = QtWidgets.QPushButton("Remove")
delButton.clicked.connect(self.addLineEdit)
selectedFileItemWidget = QtWidgets.QWidget()
selectedFileItemLayout = QtWidgets.QHBoxLayout()
selectedFileItemLayout.addWidget(label)
selectedFileItemLayout.addWidget(delButton)
selectedFileItemWidget.setLayout(selectedFileItemLayout)
# selectedFileItemWidget.setStyleSheet("background-color: yellow")
newLineEdit = QtWidgets.QLineEdit()
newLineEdit.setText(filename)
newLineEdit.setEnabled(False)
self.flineEditsVbox.addWidget(newLineEdit)
#self.fixSelectedFileListLayout.addWidget(selectedFileItemWidget)
print(filename)
# newLineEdit = QtWidgets.QLineEdit()
# self.lineEdits.append(newLineEdit)
# self.lineEditsVbox.addWidget(newLineEdit)
def startFix(self):
print("Start Fixing")
for file in self.selectedFiles:
print("START REPAIR THREAD")
def target():
Utils.repair_mp4_file_ffmpeg(file)
# output_file = Utils.repair_mp4_file_ffmpeg(file)
thread = threading.Thread(target=target)
thread.daemon = True
thread.start()
def clearSelection(self):
print("Clear Selection")
self.selectedFiles.clear()
def stopRecording(self):
print("STOP")
StripchatRecorder.stopRecording()
self.recThread = threading.Thread(target=StripchatRecorder.startRecording, args=(self.recList,))
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
# recList = [[]]
# Start recording on a separate thread
# recThread = threading.Thread(target=startRecording, args=(recList,))
# recThread.start()
# while True:
# print("reclist: ", recList[0])
# time.sleep(1)
app = QtWidgets.QApplication([])
app.setStyle('Fusion')
ui = StripchatUI()
ui.show()
app.exec_()
# See PyCharm help at https://www.jetbrains.com/help/pycharm/