使用 ProgressInfoBar 替代原有方案
This commit is contained in:
@@ -3,11 +3,13 @@ from functools import wraps
|
||||
from typing import Callable, Literal
|
||||
|
||||
from PySide6.QtCore import Qt, Signal, QThread
|
||||
from PySide6.QtWidgets import QVBoxLayout, QFileDialog, QHBoxLayout, QProgressBar
|
||||
from PySide6.QtWidgets import QVBoxLayout, QFileDialog, QHBoxLayout
|
||||
from qfluentwidgets import GroupHeaderCardWidget, FluentIcon, PushButton, LineEdit, IconWidget, InfoBarIcon, BodyLabel, \
|
||||
PrimaryPushButton, SwitchButton, MessageBox, InfoBar, InfoBarPosition, IndeterminateProgressBar
|
||||
PrimaryPushButton, SwitchButton
|
||||
|
||||
from module import LOGLEVEL
|
||||
from module.worker import ARGWorker
|
||||
from ui.components.infobar import ProgressInfoBar
|
||||
from ui.components.widget import Widget
|
||||
|
||||
|
||||
@@ -120,12 +122,14 @@ class AchievementWidget(Widget):
|
||||
|
||||
# =================================
|
||||
|
||||
self.infoBar = None
|
||||
self.pib = ProgressInfoBar(parent=self, isClosable=False, duration=-1)
|
||||
self.pib.hide()
|
||||
|
||||
# =================================
|
||||
|
||||
self.thread = None
|
||||
self.worker = None
|
||||
self.successFlag = True
|
||||
|
||||
# ==================================
|
||||
|
||||
@@ -187,12 +191,13 @@ class AchievementWidget(Widget):
|
||||
|
||||
self.outputGroup.startButton.setEnabled(False)
|
||||
|
||||
# 线程启动与信号连接
|
||||
self.thread.started.connect(self.worker.run)
|
||||
|
||||
self.show_info_bar('')
|
||||
self.worker.error.connect(self.show_error)
|
||||
self.show_info_bar()
|
||||
self.successFlag = True
|
||||
|
||||
self.worker.info.connect(self.show_info)
|
||||
self.worker.error.connect(self.show_error)
|
||||
self.worker.finished.connect(self.thread.quit)
|
||||
self.worker.finished.connect(self.worker.deleteLater)
|
||||
self.thread.finished.connect(self.thread.deleteLater)
|
||||
@@ -207,37 +212,27 @@ class AchievementWidget(Widget):
|
||||
self.worker = None
|
||||
|
||||
def after_generate(self):
|
||||
self.outputGroup.startButton.setEnabled(True)
|
||||
if self.outputGroup.autoOpenSwitch.isChecked():
|
||||
if self.outputGroup.autoOpenSwitch.isChecked() and self.successFlag:
|
||||
try:
|
||||
os.startfile(self.output_file_path + "/" + self.output_file_name + ".docx")
|
||||
except Exception as e:
|
||||
self.show_error("?? 不好出错了", str(e))
|
||||
if self.infoBar:
|
||||
self.infoBar.close()
|
||||
self.infoBar = InfoBar.success(
|
||||
title='成功!',
|
||||
content="正在打开文件" if self.outputGroup.autoOpenSwitch.isChecked() else "文件已保存",
|
||||
orient=Qt.Horizontal,
|
||||
isClosable=True,
|
||||
position=InfoBarPosition.BOTTOM,
|
||||
duration=5000,
|
||||
parent=self
|
||||
)
|
||||
if self.successFlag:
|
||||
self.pib.show_success(
|
||||
content="正在打开文件" if self.outputGroup.autoOpenSwitch.isChecked() else "文件已保存")
|
||||
else:
|
||||
self.pib.show_error()
|
||||
self.outputGroup.startButton.setEnabled(True)
|
||||
|
||||
def show_error(self, title: str, content: str):
|
||||
self.successFlag = False
|
||||
self.error.emit(title, content)
|
||||
|
||||
def show_info_bar(self, info: str):
|
||||
self.infoBar = InfoBar(
|
||||
icon=InfoBarIcon.INFORMATION,
|
||||
title='请稍后',
|
||||
content=info,
|
||||
orient=Qt.Horizontal,
|
||||
isClosable=False,
|
||||
position=InfoBarPosition.BOTTOM,
|
||||
duration=-1,
|
||||
parent=self
|
||||
)
|
||||
self.infoBar.addWidget(IndeterminateProgressBar(start=True))
|
||||
self.infoBar.show()
|
||||
def show_info_bar(self):
|
||||
self.pib.set_title('请稍后')
|
||||
self.pib.show()
|
||||
self.pib.set_progress(101)
|
||||
|
||||
def show_info(self, content: str, level: str):
|
||||
if level == LOGLEVEL.INFO:
|
||||
self.pib.set_title(content)
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
from typing import Literal, Callable
|
||||
from functools import wraps
|
||||
from typing import Literal, Callable
|
||||
|
||||
from PySide6.QtCore import Qt, Signal, QThread
|
||||
from PySide6.QtWidgets import QHBoxLayout, QVBoxLayout, QFileDialog
|
||||
from qfluentwidgets import GroupHeaderCardWidget, PushButton, IconWidget, InfoBarIcon, \
|
||||
BodyLabel, PrimaryPushButton, FluentIcon, LineEdit, InfoBar, InfoBarPosition, ProgressBar, IndeterminateProgressBar
|
||||
BodyLabel, PrimaryPushButton, FluentIcon, LineEdit
|
||||
|
||||
from module.worker import DTGWorker
|
||||
from ui.components.infobar import ProgressInfoBar
|
||||
from ui.components.widget import Widget
|
||||
|
||||
|
||||
@@ -121,8 +122,8 @@ class DefenseWidget(Widget):
|
||||
self.vbox.addWidget(self.exportCard)
|
||||
self.vbox.addStretch(1)
|
||||
|
||||
self.infoBar = None
|
||||
self.pb = None
|
||||
self.pib = ProgressInfoBar(parent=self, isClosable=False, duration=-1)
|
||||
self.pib.hide()
|
||||
|
||||
self.thread = None
|
||||
self.worker = None
|
||||
@@ -142,40 +143,16 @@ class DefenseWidget(Widget):
|
||||
self.exportCard.startSignal.connect(self.start_generate)
|
||||
|
||||
def show_info_bar(self):
|
||||
self.infoBar = InfoBar(
|
||||
icon=InfoBarIcon.INFORMATION,
|
||||
title='请稍后',
|
||||
content="",
|
||||
orient=Qt.Horizontal,
|
||||
isClosable=False,
|
||||
position=InfoBarPosition.BOTTOM,
|
||||
duration=-1,
|
||||
parent=self
|
||||
)
|
||||
self.pb = ProgressBar(self.infoBar)
|
||||
self.infoBar.addWidget(self.pb)
|
||||
self.infoBar.show()
|
||||
self.pib.show()
|
||||
self.pib.set_title('请稍后')
|
||||
|
||||
def set_pb_value(self, value: int) -> None:
|
||||
if self.pb:
|
||||
self.pb.setValue(value)
|
||||
if value == 100:
|
||||
self.infoBar.close()
|
||||
self.infoBar = InfoBar(
|
||||
icon=InfoBarIcon.INFORMATION,
|
||||
title='正在转换文件',
|
||||
content="",
|
||||
orient=Qt.Horizontal,
|
||||
isClosable=False,
|
||||
position=InfoBarPosition.BOTTOM,
|
||||
duration=-1,
|
||||
parent=self
|
||||
)
|
||||
self.infoBar.addWidget(IndeterminateProgressBar(start=True))
|
||||
self.infoBar.show()
|
||||
self.pb = None
|
||||
elif value == -1:
|
||||
self.successFlag = False
|
||||
self.pib.set_progress(value)
|
||||
if value == 100:
|
||||
self.pib.set_progress(101)
|
||||
self.pib.set_title('正在转换文件')
|
||||
elif value == -1:
|
||||
self.successFlag = False
|
||||
|
||||
def enable_start_check(func: Callable):
|
||||
@wraps(func)
|
||||
@@ -254,27 +231,10 @@ class DefenseWidget(Widget):
|
||||
|
||||
def after_generate(self):
|
||||
self.exportCard.startButton.setEnabled(True)
|
||||
self.infoBar.close()
|
||||
if self.successFlag:
|
||||
self.infoBar = InfoBar.success(
|
||||
title='成功!',
|
||||
content="正在打开文件...",
|
||||
orient=Qt.Horizontal,
|
||||
isClosable=True,
|
||||
position=InfoBarPosition.BOTTOM,
|
||||
duration=5000,
|
||||
parent=self
|
||||
)
|
||||
self.pib.show_success(content="正在打开文件...")
|
||||
else:
|
||||
self.infoBar = InfoBar.error(
|
||||
title='失败!',
|
||||
content="",
|
||||
orient=Qt.Horizontal,
|
||||
isClosable=True,
|
||||
position=InfoBarPosition.BOTTOM,
|
||||
duration=5000,
|
||||
parent=self
|
||||
)
|
||||
self.pib.show_error()
|
||||
|
||||
def show_error(self, title: str, content: str):
|
||||
self.errorSignal.emit(title, content)
|
||||
|
||||
Reference in New Issue
Block a user