-
Notifications
You must be signed in to change notification settings - Fork 0
/
GUI.py
106 lines (90 loc) · 3.59 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
import sys
from PyQt6.QtWidgets import (
QApplication,
QWidget,
QPushButton,
QVBoxLayout,
QProgressBar,
QLabel,
QFileDialog,
QComboBox,
)
from PyQt6.QtCore import QTimer, Qt
import file_deal
import time
from PyQt6.QtGui import QIcon
from PyQt6.QtCore import QRunnable, pyqtSignal, QObject,QThreadPool
from qfluentwidgets import PushButton,ComboBox,ProgressBar,FolderListDialog
class WorkerSignals(QObject):
progress = pyqtSignal(int, float) # 进度百分比和开始时间
class Worker(QRunnable):
def __init__(self, file_path, option):
super(Worker, self).__init__()
self.file_path = file_path
self.option = option
self.signals = WorkerSignals()
def run(self):
for progress_percentage, start_time in file_deal.deal(self.file_path, self.option):
self.signals.progress.emit(progress_percentage, start_time)
class MainWindow(QWidget):
def __init__(self):
super().__init__()
self.threadpool = QThreadPool()
self.initUI()
def initUI(self):
self.layout = QVBoxLayout()
# 设置窗口标题
self.setWindowTitle("Smartinput Upscaling")
# 设置窗口大小
self.resize(300, 150)
# 设置窗口图标
# 文件选择按钮
self.fileButton = PushButton("Select ☆ File(PDF/png/jpg)")
self.fileButton.clicked.connect(self.openFileDialog)
self.layout.addWidget(self.fileButton)
# 选择按钮
self.comboBox = ComboBox(self)
self.comboBox.addItem("realesr-animevideov3")
self.comboBox.addItem("realesrgan-x4plus")
self.comboBox.addItem("realesrgan-x4plus-anime")
self.comboBox.setCurrentIndex(2) # 设置默认选项为 realesrgan-x4plus-anime
self.layout.addWidget(self.comboBox)
# 进度条
self.progressBar = ProgressBar(self)
self.layout.addWidget(self.progressBar)
# 文字显示区域
self.textLabel = QLabel("Time left:Unknown☆")
self.layout.addWidget(self.textLabel)
self.setLayout(self.layout)
def openFileDialog(self):
# 打开文件对话框并获取文件路径,暂时限制为.pdf,.jpg,.png,.jpeg,返回路径让程序自行判断
file_path, _ = QFileDialog.getOpenFileName(
self, "Select File", "", "Files (*.pdf *.jpg *.png *.jpeg)"
)
if file_path:
self.fileButton.setEnabled(False) # 禁用文件选择按钮
self.startProcessing(file_path)
def startProcessing(self, file_path):
self.textLabel.setText('/ᐠ。ꞈ。ᐟ\Start Processing......')
worker = Worker(file_path, self.comboBox.currentText())
worker.signals.progress.connect(self.updateProgress)
self.threadpool.start(worker)
def updateProgress(self, progress, start_time):
self.progressBar.setValue(progress)
elapsed_time = time.time() - start_time
if progress > 0:
total_estimated_time = elapsed_time / (progress / 100)
remaining_time = total_estimated_time - elapsed_time
if remaining_time < 60:
self.textLabel.setText(f'Time left: {remaining_time:.2f} S')
else:
self.textLabel.setText(f'Time left: {remaining_time // 60:.0f} M {remaining_time % 60:.2f} S')
if progress >= 100:
self.fileButton.setEnabled(True)
self.textLabel.setText('Done☆(ᕑᗢᓫ∗)')
if __name__ == "__main__":
app = QApplication(sys.argv)
ex = MainWindow()
ex.setWindowIcon = (QIcon("./icon.png"))
ex.show()
sys.exit(app.exec())