The only downloader you need. 下载器的集大成者。
TypeScript asyncasynciobittorentbtcross-platformdownload-managerdownloaderfluent-designftphttp3magnetpyqtpyside6pythonqtquicreactsoftwarestreaming
添加 PopUpWindowManager 防止弹窗重叠,并修复 PopUpWindow 被内存回收和导致程序崩溃的问题
XiaoYouChR26f5df0695c7
diff --git a/app/components/task_card.py b/app/components/task_card.pyindex f8467e51..aa0aaad9 100644--- a/app/components/task_card.py+++ b/app/components/task_card.py@@ -352,7 +352,7 @@ class TaskCard(CardWidget, Ui_TaskCard):try: # 程序启动时不要发if self.window().tray:- PopUpWindow(f"{self.filePath}/{self.fileName}", self.window())+ PopUpWindow.showPopUpWindow(f"{self.filePath}/{self.fileName}", self.window())except:passdiff --git a/app/view/pop_up_window.py b/app/view/pop_up_window.pyindex c95f132e..7edf6339 100644--- a/app/view/pop_up_window.py+++ b/app/view/pop_up_window.py@@ -1,6 +1,7 @@+import weakreffrom os.path import dirname, basename-from PySide6.QtCore import Qt, QUrl, QTimer, QEasingCurve, QPropertyAnimation, QRect, QFileInfo+from PySide6.QtCore import Qt, QUrl, QTimer, QEasingCurve, QPropertyAnimation, QRect, QFileInfo, QObjectfrom PySide6.QtGui import QPixmap, QPainter, QColor, QPainterPathfrom PySide6.QtMultimedia import QSoundEffectfrom PySide6.QtWidgets import QWidget, QFileIconProvider@@ -96,8 +97,11 @@ class PopUpWindow(QWidget, Ui_PopUpWindow):self.openPathBtn.clicked.connect(lambda: openFile(dirname(fileResolvePath)))self.screenGeometry = getCurrentScreenGeometry()self.move(self.screenGeometry.width(), self.screenGeometry.height() - self.height() - 13)+ self.__manager = PopUpWindowManager()+ self.__manager.add(self)self.show()+def paintEvent(self, e):# 解决鼠标穿透问题paint = QPainter(self)@@ -106,6 +110,7 @@ class PopUpWindow(QWidget, Ui_PopUpWindow):paint.drawPath(self.globalPath)super().paintEvent(e)+def showEvent(self, event):self.raise_()QTimer.singleShot(50, self.__moveIn)@@ -115,6 +120,7 @@ class PopUpWindow(QWidget, Ui_PopUpWindow):self.closeTimer.start(10000)super().showEvent(event)+def __moveIn(self):# 设置音效self.soundEffect = QSoundEffect(self)@@ -125,18 +131,24 @@ class PopUpWindow(QWidget, Ui_PopUpWindow):self.geometryAnimation = QPropertyAnimation(self, b"geometry")self.geometryAnimation.setDuration(500)self.geometryAnimation.setStartValue(self.geometry())- self.geometryAnimation.setEndValue(QRect(self.screenGeometry.width() - self.width() - 13, self.screenGeometry.height() - self.height() - 13, self.width(), self.height()))+ self.geometryAnimation.setEndValue(QRect(self.screenGeometry.width() - self.width() - 13, self.y(), self.width(), self.height()))self.geometryAnimation.setEasingCurve(QEasingCurve.OutCubic)self.geometryAnimation.start()+def __moveOut(self):self.geometryAnimation.setDuration(500)self.geometryAnimation.setStartValue(self.geometry())- self.geometryAnimation.setEndValue(QRect(self.screenGeometry.width(), self.screenGeometry.height() - self.height() - 13, self.width(), self.height()))+ self.geometryAnimation.setEndValue(QRect(self.screenGeometry.width(), self.y(), self.width(), self.height()))self.geometryAnimation.finished.connect(self.close)self.geometryAnimation.start()+ def closeEvent(self, event):+ self.__manager.remove(self)+ super().closeEvent(event)++def mousePressEvent(self, event):if event.button() == Qt.LeftButton:self.dragStartPosition = event.globalPosition().toPoint()@@ -167,7 +179,49 @@ class PopUpWindow(QWidget, Ui_PopUpWindow):self.geometryAnimation.stop()self.geometryAnimation.setDuration(200)self.geometryAnimation.setStartValue(self.geometry())- self.geometryAnimation.setEndValue(QRect(self.screenGeometry.width() - self.width() - 13, self.screenGeometry.height() - self.height() - 13, self.width(), self.height()))+ self.geometryAnimation.setEndValue(QRect(self.screenGeometry.width() - self.width() - 13, self.y(), self.width(), self.height()))self.geometryAnimation.start()super().mouseReleaseEvent(event)+++ @classmethod+ def showPopUpWindow(cls, fileResolvePath:str, mainWindow=None):+ print("PopUpWindow Created")+ return cls(fileResolvePath, mainWindow)+++class PopUpWindowManager(QObject):+ """当多个 PopUpWindow 同时出现时,使用 PopUpWindowManager 来管理它们"""++ _instance = None+ _initialized = False++ def __new__(cls, *args, **kwargs):+ if not cls._instance:+ cls._instance = super().__new__(cls, *args, **kwargs)+ return cls._instance++ def __init__(self):+ if PopUpWindowManager._initialized:+ return+ super().__init__()+ self.popUpWindows = [] # 强引用列表+ PopUpWindowManager._initialized = True++ def add(self, popUpWindow: PopUpWindow):+ print("PopUpWindow Added")+ if popUpWindow not in self.popUpWindows:+ self.popUpWindows.append(popUpWindow)+ # 按照 PopUpWindow 的数量移动 PopUpWindow 的 y 坐标+ if len(self.popUpWindows) > 1:+ for i, popUp in enumerate(self.popUpWindows):+ popUp.move(popUp.x(), getCurrentScreenGeometry().height() - ((popUp.height() + 13) * (len(self.popUpWindows) - i)))++ def remove(self, popUpWindow: PopUpWindow):+ print("PopUpWindow Destroyed")+ if popUpWindow in self.popUpWindows:+ self.popUpWindows.remove(popUpWindow)+ # 按照 PopUpWindow 的数量移动 PopUpWindow 的 y 坐标+ for i, popUp in enumerate(self.popUpWindows):+ popUp.move(popUp.x(), getCurrentScreenGeometry().height() - ((popUp.height() + 13) * (len(self.popUpWindows) - i)))diff --git a/tests/test_pop_up_window.py b/tests/test_pop_up_window.pyindex e96d27d5..c31255f6 100644--- a/tests/test_pop_up_window.py+++ b/tests/test_pop_up_window.py@@ -1,4 +1,5 @@import sys+from time import sleepfrom PySide6.QtWidgets import QApplication@@ -9,6 +10,7 @@ import Res_rcapp = QApplication(sys.argv)-popUp = PopUpWindow(r"F:\Class-Widget\audio\attend_class.wav")+for i in range(10):+ PopUpWindow.showPopUpWindow(r"F:\Class-Widget\audio\attend_class.wav")app.exec()