The only downloader you need. 下载器的集大成者。
TypeScript asyncasynciobittorentbtcross-platformdownload-managerdownloaderfluent-designftphttp3magnetpyqtpyside6pythonqtquicreactsoftwarestreaming
改进 TaskCard,增加剩余时长显示等
XiaoYouChRd0848197fe53
diff --git a/app/components/Ui_TaskCard.py b/app/components/Ui_TaskCard.pyindex 43e90102..46e79d24 100644--- a/app/components/Ui_TaskCard.py+++ b/app/components/Ui_TaskCard.py@@ -1,7 +1,7 @@# -*- coding: utf-8 -*-################################################################################-## Form generated from reading UI file 'TaskCard.ui'+## 你猜是不是 UIC 生成的#### Created by: Qt User Interface Compiler version 6.4.3##@@ -9,12 +9,11 @@################################################################################from PySide6.QtCore import (QCoreApplication, QMetaObject, QSize, Qt)-from PySide6.QtWidgets import (QHBoxLayout, QSizePolicy, QSpacerItem,- QVBoxLayout)--from qfluentwidgets import (BodyLabel, PixmapLabel, TitleLabel, ToolButton, PrimaryToolButton)-+from PySide6.QtWidgets import (QHBoxLayout, QSizePolicy, QVBoxLayout)from qfluentwidgets import FluentIcon as FIF+from qfluentwidgets import (PixmapLabel, TitleLabel, ToolButton, PrimaryToolButton)++from app.components.icon_label import IconBodyLabelclass Ui_TaskCard(object):@@ -24,8 +23,8 @@ class Ui_TaskCard(object):TaskCard.resize(793, 119)TaskCard.setMinimumSize(QSize(793, 119))TaskCard.setMaximumSize(QSize(16777215, 119))- self.horizontalLayout_3 = QHBoxLayout(TaskCard)- self.horizontalLayout_3.setObjectName(u"horizontalLayout_3")+ self.cardHorizontalLayout = QHBoxLayout(TaskCard)+ self.cardHorizontalLayout.setObjectName(u"cardHorizontalLayout")self.LogoPixmapLabel = PixmapLabel(TaskCard)self.LogoPixmapLabel.setObjectName(u"LogoPixmapLabel")self.LogoPixmapLabel.setMinimumSize(QSize(91, 91))@@ -33,7 +32,7 @@ class Ui_TaskCard(object):self.LogoPixmapLabel.setScaledContents(True)self.LogoPixmapLabel.setAlignment(Qt.AlignCenter)- self.horizontalLayout_3.addWidget(self.LogoPixmapLabel)+ self.cardHorizontalLayout.addWidget(self.LogoPixmapLabel)self.verticalLayout = QVBoxLayout()self.verticalLayout.setSpacing(0)@@ -53,9 +52,57 @@ class Ui_TaskCard(object):self.horizontalLayout = QHBoxLayout()self.horizontalLayout.setObjectName(u"horizontalLayout")self.horizontalLayout.setSpacing(6)- self.horizontalSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)- self.horizontalLayout.addItem(self.horizontalSpacer)+ self.verticalLayout.addSpacing(15) # 把整体往下撑++ # 还需要把 statusHorizonLayout 在 horizonLayout 里面往下撑, 要不然非常难看!+ self.verticalLayout_2 = QVBoxLayout()+ self.verticalLayout_2.setSpacing(0)+ self.verticalLayout_2.setObjectName(u"verticalLayout_2")++ self.verticalLayout_2.addSpacing(15)++ self.statusHorizonLayout = QHBoxLayout()+ self.statusHorizonLayout.setObjectName(u"statusHorizonLayout")+ self.statusHorizonLayout.setSpacing(8)+ self.speedLabel = IconBodyLabel("下载速度", FIF.SPEED_HIGH, TaskCard)+ self.speedLabel.setObjectName(u"speedLabel")+ self.speedLabel.setMinimumSize(QSize(0, 19))+ self.speedLabel.setMaximumSize(QSize(16777215, 19))++ self.statusHorizonLayout.addWidget(self.speedLabel)++ self.leftTimeLabel = IconBodyLabel("剩余时间", FIF.STOP_WATCH, TaskCard)+ self.leftTimeLabel.setObjectName(u"leftTimeLabel")+ self.leftTimeLabel.setMinimumSize(QSize(0, 19))+ self.leftTimeLabel.setMaximumSize(QSize(16777215, 19))++ self.statusHorizonLayout.addWidget(self.leftTimeLabel)++ self.processLabel = IconBodyLabel("下载进度", FIF.LIBRARY, TaskCard)+ self.processLabel.setObjectName(u"processLabel")+ self.processLabel.setMinimumSize(QSize(0, 19))+ self.processLabel.setMaximumSize(QSize(16777215, 19))++ self.statusHorizonLayout.addWidget(self.processLabel)+ self.statusHorizonLayout.addSpacing(1677215)++ self.verticalLayout_2.addLayout(self.statusHorizonLayout) # 先加入 后期代码处理++ self.infoHorizonLayout = QHBoxLayout(TaskCard)+ self.infoHorizonLayout.setObjectName(u"infoHorizonLayout")+ self.infoHorizonLayout.setSpacing(8)++ self.infoLabel = IconBodyLabel("若任务初始化过久,请检查网络连接后重试.", FIF.INFO, TaskCard)+ self.infoLabel.setObjectName(u"infoLabel")+ self.infoLabel.setMinimumSize(QSize(0, 19))+ self.infoLabel.setMaximumSize(QSize(16777215, 19))++ self.infoHorizonLayout.addWidget(self.infoLabel)++ self.verticalLayout_2.addLayout(self.infoHorizonLayout)++ self.horizontalLayout.addLayout(self.verticalLayout_2)self.pauseButton = PrimaryToolButton(TaskCard)self.pauseButton.setObjectName(u"pauseButton")@@ -80,39 +127,9 @@ class Ui_TaskCard(object):self.verticalLayout.addLayout(self.horizontalLayout)- self.horizontalLayout_2 = QHBoxLayout()- self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")- self.speedLable = BodyLabel(TaskCard)- self.speedLable.setObjectName(u"speedLable")- self.speedLable.setMinimumSize(QSize(0, 19))- self.speedLable.setMaximumSize(QSize(601, 19))-- self.horizontalLayout_2.addWidget(self.speedLable)-- self.leftTimeLabel = BodyLabel(TaskCard)- self.leftTimeLabel.setObjectName(u"leftTimeLabel")- self.leftTimeLabel.setMinimumSize(QSize(0, 19))- self.leftTimeLabel.setMaximumSize(QSize(151, 19))-- self.horizontalLayout_2.addWidget(self.leftTimeLabel)-- self.horizontalSpacer_2 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)-- self.horizontalLayout_2.addItem(self.horizontalSpacer_2)-- self.processLabel = BodyLabel(TaskCard)- self.processLabel.setObjectName(u"processLabel")- self.processLabel.setMinimumSize(QSize(0, 19))- self.processLabel.setMaximumSize(QSize(201, 19))-- self.horizontalLayout_2.addWidget(self.processLabel)-- self.verticalLayout.addLayout(self.horizontalLayout_2)-- self.horizontalLayout_3.addLayout(self.verticalLayout)+ self.cardHorizontalLayout.addLayout(self.verticalLayout)# 初始化 Icon 类-self.pauseButton.setIcon(FIF.PAUSE)self.cancelButton.setIcon(FIF.DELETE)self.folderButton.setIcon(FIF.FOLDER)@@ -125,8 +142,4 @@ class Ui_TaskCard(object):def retranslateUi(self, TaskCard):TaskCard.setWindowTitle(QCoreApplication.translate("TaskCard", u"Form", None))- self.pauseButton.setText("")- self.cancelButton.setText("")- self.folderButton.setText("")- self.processLabel.setText("")# retranslateUidiff --git a/app/components/custom_tray.py b/app/components/custom_tray.pyindex 73a59031..3365ecd2 100644--- a/app/components/custom_tray.py+++ b/app/components/custom_tray.py@@ -32,7 +32,7 @@ class CustomSystemTrayIcon(QSystemTrayIcon):self.allPauseAction.triggered.connect(self.__onAllStartActionTriggered)self.menu.addAction(self.allPauseAction)- self.allPauseAction = Action(FIF.STOP_WATCH, '全部暂停', self.menu)+ self.allPauseAction = Action(FIF.PAUSE, '全部暂停', self.menu)self.allPauseAction.triggered.connect(self.__onAllPauseActionTriggered)self.menu.addAction(self.allPauseAction)diff --git a/app/components/task_card.py b/app/components/task_card.pyindex 1a83423d..ef48d8d1 100644--- a/app/components/task_card.py+++ b/app/components/task_card.py@@ -15,7 +15,7 @@ from .del_dialog import DelDialogfrom .task_progress_bar import TaskProgressBarfrom ..common.config import cfgfrom ..common.download_task import DownloadTask-from ..common.methods import getProxy, getReadableSize, retry, openFile+from ..common.methods import getProxy, getReadableSize, openFileHeaders = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36 Edg/112.0.1722.64"}@@ -59,7 +59,8 @@ class TaskCard(CardWidget, Ui_TaskCard):self.autoCreated = autoCreated# Show Information- self.speedLable.setText("若任务初始化过久,请检查网络连接后重试.")++ self.__showInfo("若任务初始化过久,请检查网络连接后重试.")self.TitleLabel.setText("正在初始化任务...")self.LogoPixmapLabel.setPixmap(QPixmap(":/image/logo.png"))@@ -79,7 +80,7 @@ class TaskCard(CardWidget, Ui_TaskCard):self.__onTaskInited()if self.status == "paused":- self.speedLable.setText("任务已经暂停")+ self.__showInfo("任务已经暂停")else:self.task = DownloadTask(url, maxBlockNum, path)@@ -113,7 +114,7 @@ class TaskCard(CardWidget, Ui_TaskCard):self.pauseButton.setIcon(FIF.PLAY)def __onTaskError(self, exception: str):- self.speedLable.setText(f"Error: {exception}")+ self.__showInfo(f"Error: {exception}")def __onTaskInited(self):self.fileName = self.task.fileName@@ -170,7 +171,7 @@ class TaskCard(CardWidget, Ui_TaskCard):f.write(_)finally:- self.speedLable.setText("任务已经暂停")+ self.__showInfo("任务已经暂停")self.status = "paused"self.pauseButton.setEnabled(True)@@ -202,12 +203,10 @@ class TaskCard(CardWidget, Ui_TaskCard):f.write(_)finally:- self.speedLable.setText("任务正在开始")+ self.__showInfo("任务正在开始")self.status = "working"self.pauseButton.setEnabled(True)-- @retry(3, 0.1)def cancelTask(self, surely=False, completely=False):if not surely:@@ -259,7 +258,24 @@ class TaskCard(CardWidget, Ui_TaskCard):self.parent().parent().parent().expandLayout.removeWidget(self)self.hide()- def __changeInfo(self, content: list):+ def __showInfo(self, content:str):+ # 隐藏 statusHorizontalLayout+ self.speedLabel.hide()+ self.leftTimeLabel.hide()+ self.processLabel.hide()++ # 显示 infoLayout+ self.infoLabel.show()+ self.infoLabel.setText(content)++ def __hideInfo(self):+ self.infoLabel.hide()++ self.speedLabel.show()+ self.leftTimeLabel.show()+ self.processLabel.show()++ def __changeStatus(self, content: list):# 理论来说 worker 直增不减 所以ProgressBar不用考虑线程减少的问题_ = len(content) - self.progressBar.blockNum@@ -274,9 +290,19 @@ class TaskCard(CardWidget, Ui_TaskCard):duringLastSecondProcess = process - self.lastProcess- self.speedLable.setText(f"{getReadableSize(duringLastSecondProcess)}/s")+ # 如果还在显示消息状态,则调用 __hideInfo+ if self.infoLabel.isVisible():+ self.__hideInfo()++ self.speedLabel.setText(f"{getReadableSize(duringLastSecondProcess)}/s")self.processLabel.setText(f"{getReadableSize(process)}/{getReadableSize(self.task.fileSize)}")- # self.ProgressBar.setValue((process / self.task.fileSize) * 100)++ # 计算剩余时间,并转换为 MM:SS+ try:+ leftTime = (self.task.fileSize - process) / duringLastSecondProcess+ self.leftTimeLabel.setText(f"{int(leftTime // 60):02d}:{int(leftTime % 60):02d}")+ except ZeroDivisionError:+ self.leftTimeLabel.setText("Infinity")self.lastProcess = process@@ -286,7 +312,7 @@ class TaskCard(CardWidget, Ui_TaskCard):self.clicked.connect(lambda: openFile(f"{self.filePath}/{self.fileName}"))- self.speedLable.setText("任务已经完成")+ self.__showInfo("任务已经完成")try: # 程序启动时不要发self.window().tray.showMessage(self.window().windowTitle(), f"任务 {self.fileName} 已完成!", self.window().windowIcon())@@ -323,16 +349,15 @@ class TaskCard(CardWidget, Ui_TaskCard):self.pauseButton.setDisabled(False)self.cancelButton.setDisabled(False)-def runClacTask(self):- self.speedLable.setText("正在校验MD5...")+ self.__showInfo("正在校验MD5...")self.clacTask = ClacMD5Thread(f"{self.filePath}/{self.fileName}")- self.clacTask.returnMD5.connect(lambda x: self.speedLable.setText(f"校验完成!文件的MD5值是:{x}"))+ self.clacTask.returnMD5.connect(lambda x: self.__showInfo(f"校验完成!文件的MD5值是:{x}"))self.clacTask.start()def __connectSignalToSlot(self):self.task.taskInited.connect(self.__onTaskInited)- self.task.workerInfoChange.connect(self.__changeInfo)+ self.task.workerInfoChange.connect(self.__changeStatus)self.task.taskFinished.connect(self.__onTaskFinished)self.task.taskFinished.connect(self.taskFinished)diff --git a/app/view/task_interface.py b/app/view/task_interface.pyindex 44eaafae..9e213e43 100644--- a/app/view/task_interface.py+++ b/app/view/task_interface.py@@ -68,7 +68,7 @@ class TaskInterface(ScrollArea):self.allPauseButton = PushButton(self.toolsBar)self.allPauseButton.setObjectName(u"allPauseButton")- self.allPauseButton.setIcon(FIF.STOP_WATCH)+ self.allPauseButton.setIcon(FIF.PAUSE)self.horizontalLayout.addWidget(self.allPauseButton)self.allDeleteButton = PushButton(self.toolsBar)