The only downloader you need. 下载器的集大成者。
TypeScript asyncasynciobittorentbtcross-platformdownload-managerdownloaderfluent-designftphttp3magnetpyqtpyside6pythonqtquicreactsoftwarestreaming
计划任务功能
XiaoYouChRa441e99dc239
diff --git a/app/common/signal_bus.py b/app/common/signal_bus.pyindex 9e657e26..b4e5958e 100644--- a/app/common/signal_bus.py+++ b/app/common/signal_bus.py@@ -5,7 +5,6 @@ from PySide6.QtCore import QObject, Signalclass SignalBus(QObject):""" Signal bus """addTaskSignal = Signal(str, str, int, str, str, bool) # url, filePath, maxBlockNum, name, status, autoStart- Tasks = []-+ allTaskFinished = Signal()signalBus = SignalBus()diff --git a/app/components/Ui_PlanTaskDialog.py b/app/components/Ui_PlanTaskDialog.pynew file mode 100644index 00000000..c7ab6058--- /dev/null+++ b/app/components/Ui_PlanTaskDialog.py@@ -0,0 +1,71 @@+# -*- coding: utf-8 -*-++################################################################################+## Form generated from reading UI file 'PlanTaskDialog.ui'+##+## Created by: Qt User Interface Compiler version 6.7.2+##+## WARNING! All changes made in this file will be lost when recompiling UI file!+################################################################################++from PySide6.QtCore import (QCoreApplication, QRect,+ QSize)+from qfluentwidgets import FluentIcon as FIF+from qfluentwidgets import (LineEdit, PrimaryPushButton, PrimaryToolButton, PushButton,+ RadioButton, SubtitleLabel)+++class Ui_PlanTaskDialog(object):+ def setupUi(self, Form):+ if not Form.objectName():+ Form.setObjectName(u"PlanTaskDialog")+ Form.resize(410, 225)+ Form.setFixedSize(QSize(410, 225))++ self.powerOffButton = RadioButton(Form)+ self.powerOffButton.setObjectName(u"powerOffButton")+ self.powerOffButton.setGeometry(QRect(30, 55, 112, 24))+ self.powerOffButton.setChecked(True)++ self.quitButton = RadioButton(Form)+ self.quitButton.setObjectName(u"quitButton")+ self.quitButton.setGeometry(QRect(230, 55, 112, 24))++ self.openFileButton = RadioButton(Form)+ self.openFileButton.setObjectName(u"openFileButton")+ self.openFileButton.setGeometry(QRect(30, 95, 112, 24))++ self.filePathEdit = LineEdit(Form)+ self.filePathEdit.setObjectName(u"filePathEdit")+ self.filePathEdit.setGeometry(QRect(20, 130, 326, 33))+ self.filePathEdit.setReadOnly(True)+ self.filePathEdit.setEnabled(False)++ self.selectFileButton = PrimaryToolButton(Form)+ self.selectFileButton.setObjectName(u"selectFileButton")+ self.selectFileButton.setGeometry(QRect(350, 130, 33, 33))+ self.selectFileButton.setEnabled(False)+ self.selectFileButton.setIcon(FIF.FOLDER)++ self.yesButton = PrimaryPushButton(Form)+ self.yesButton.setObjectName(u"yesButton")+ self.yesButton.setGeometry(QRect(212, 180, 181, 32))++ self.noButton = PushButton(Form)+ self.noButton.setObjectName(u"noButton")+ self.noButton.setGeometry(QRect(20, 180, 181, 32))++ self.SubtitleLabel = SubtitleLabel(Form)+ self.SubtitleLabel.setObjectName(u"SubtitleLabel")+ self.SubtitleLabel.setGeometry(QRect(20, 10, 131, 38))++ self.retranslateUi(Form)++ def retranslateUi(self, Form):+ Form.setWindowTitle(QCoreApplication.translate("Form", u"Form", None))+ self.powerOffButton.setText(QCoreApplication.translate("Form", u"\u5173\u673a", None))+ self.quitButton.setText(QCoreApplication.translate("Form", u"\u9000\u51fa\u7a0b\u5e8f", None))+ self.openFileButton.setText(QCoreApplication.translate("Form", u"\u6253\u5f00", None))+ self.yesButton.setText(QCoreApplication.translate("Form", u"\u8bbe\u7f6e\u8ba1\u5212\u4efb\u52a1", None))+ self.noButton.setText(QCoreApplication.translate("Form", u"\u53d6\u6d88", None))+ self.SubtitleLabel.setText(QCoreApplication.translate("Form", u"\u8bbe\u7f6e\u8ba1\u5212\u4efb\u52a1", None))diff --git a/app/components/plan_task_dialog.py b/app/components/plan_task_dialog.pynew file mode 100644index 00000000..535f5cd9--- /dev/null+++ b/app/components/plan_task_dialog.py@@ -0,0 +1,69 @@+import os+import sys++from PySide6.QtGui import QColor+from PySide6.QtWidgets import QFileDialog, QApplication+from qfluentwidgets import FluentStyleSheet, MaskDialogBase++from app.common.methods import openFile+from app.common.signal_bus import signalBus+from app.components.Ui_PlanTaskDialog import Ui_PlanTaskDialog+++class PlanTaskDialog(MaskDialogBase, Ui_PlanTaskDialog):+ def __init__(self, parent=None):+ super().__init__(parent)++ FluentStyleSheet.DIALOG.apply(self.widget)++ self.setShadowEffect(60, (0, 10), QColor(0, 0, 0, 50))+ self.setMaskColor(QColor(0, 0, 0, 76))+ self.setClosableOnMaskClicked(True)++ self.setupUi(self.widget)++ # Connect signals to slots+ self.powerOffButton.toggled.connect(self.updateControls)+ self.quitButton.toggled.connect(self.updateControls)+ self.openFileButton.toggled.connect(self.updateControls)+ self.selectFileButton.clicked.connect(self.selectFile)+ self.yesButton.clicked.connect(self.__onYesButtonClicked)+ self.noButton.clicked.connect(self.__onNoButtonClicked)++ def updateControls(self):+ # Disable selectFileButton and filePathEdit if powerOffButton or quitButton is selected+ if self.powerOffButton.isChecked() or self.quitButton.isChecked():+ self.selectFileButton.setEnabled(False)+ self.filePathEdit.setEnabled(False)+ else:+ self.selectFileButton.setEnabled(True)+ self.filePathEdit.setEnabled(True)++ # Disable selectFileButton and filePathEdit until openFileButton is checked+ if not self.openFileButton.isChecked():+ self.selectFileButton.setEnabled(False)+ self.filePathEdit.setEnabled(False)++ def selectFile(self):+ # Open file dialog and set file path to filePathEdit+ filePath, _ = QFileDialog.getOpenFileName(None, "选择文件")+ if filePath:+ self.filePathEdit.setText(filePath)++ def __onYesButtonClicked(self):+ self.setEnabled(False)+ if self.powerOffButton.isChecked():+ if sys.platform == "win32":+ signalBus.allTaskFinished.connect(lambda :os.system('shutdown /s /f /t 0'))+ elif sys.platform == "linux" or sys.platform == "darwin":+ signalBus.allTaskFinished.connect(lambda :os.system('shutdown -h now'))+ if self.quitButton.isChecked():+ signalBus.allTaskFinished.connect(QApplication.quit)+ if self.openFileButton.isChecked():+ signalBus.allTaskFinished.connect(lambda :openFile(self.filePathEdit.text()))++ self.accept()++ def __onNoButtonClicked(self):+ self.setEnabled(False)+ self.reject()\ No newline at end of filediff --git a/app/view/task_interface.py b/app/view/task_interface.pyindex 068d3e80..01f9682b 100644--- a/app/view/task_interface.py+++ b/app/view/task_interface.py@@ -1,10 +1,11 @@from PySide6.QtCore import Qtfrom PySide6.QtWidgets import QWidget, QFrame, QHBoxLayout, QVBoxLayout, QSpacerItem, QSizePolicyfrom qfluentwidgets import FluentIcon as FIF, SmoothScrollArea, TitleLabel, PrimaryPushButton, PushButton, InfoBar, \- InfoBarPosition+ InfoBarPosition, ToggleButtonfrom ..common.signal_bus import signalBusfrom ..components.del_dialog import DelDialog+from ..components.plan_task_dialog import PlanTaskDialogfrom ..components.task_card import TaskCard@@ -20,6 +21,7 @@ class TaskInterface(SmoothScrollArea):self.allStartButton.clicked.connect(self.allStartTasks)self.allPauseButton.clicked.connect(self.allPauseTasks)self.allDeleteButton.clicked.connect(self.allCancelTasks)+ self.planTaskToggleButton.clicked.connect(self.__onPlanTaskToggleBtnClicked)self.setWidget(self.scrollWidget)self.setWidgetResizable(True)@@ -70,11 +72,17 @@ class TaskInterface(SmoothScrollArea):self.allDeleteButton.setIcon(FIF.DELETE)self.horizontalLayout.addWidget(self.allDeleteButton)+ self.planTaskToggleButton = ToggleButton(self)+ self.planTaskToggleButton.setObjectName(u"planTaskToggleButton")+ self.planTaskToggleButton.setIcon(FIF.CALENDAR)+ self.horizontalLayout.addWidget(self.planTaskToggleButton)+self.horizontalLayout.addSpacerItem(QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum))self.allStartButton.setText("全部开始")self.allPauseButton.setText("全部暂停")self.allDeleteButton.setText("全部删除")+ self.planTaskToggleButton.setText("计划任务")self.expandLayout.addLayout(self.horizontalLayout)@@ -139,7 +147,7 @@ class TaskInterface(SmoothScrollArea):self.__sortTask()- def __sortTask(self): # 将任务按照状态 working waiting paused 排序+ def __sortTask(self): # 将任务按照状态 working waiting paused finished 排序statusOrder = {"working": 0, "waiting": 1, "paused": 2, "finished": 3}items = []@@ -156,6 +164,10 @@ class TaskInterface(SmoothScrollArea):if not items:self.expandLayout.addWidget(self.noTaskLabel)self.noTaskLabel.show()+ return++ if all(card.status == "finished" for card in self.cards): # 全部任务完成+ signalBus.allTaskFinished.emit()def allStartTasks(self):for card in self.cards:@@ -184,3 +196,12 @@ class TaskInterface(SmoothScrollArea):del cardsdialog.deleteLater()++ def __onPlanTaskToggleBtnClicked(self):+ if not self.planTaskToggleButton.isChecked(): # 取消计划任务+ signalBus.allTaskFinished.disconnect()+ if self.planTaskToggleButton.isChecked(): # 设定计划任务+ if PlanTaskDialog(self.window()).exec():+ self.planTaskToggleButton.setChecked(True)+ else:+ self.planTaskToggleButton.setChecked(False)\ No newline at end of filediff --git a/main.py b/main.pyindex d2164b9b..5802f981 100644--- a/main.py+++ b/main.py@@ -65,7 +65,6 @@ import warningsimport darkdetectfrom PySide6.QtGui import QColor-from PySide6.QtCore import Qtfrom loguru import loggerfrom qframelesswindow.utils import getSystemAccentColor