Skip to content

The only downloader you need. 下载器的集大成者。

修复内存泄露

XiaoYouChR73eba10299fb
diff --git a/app/components/add_task_dialog.py b/app/components/add_task_dialog.py
index b2ab6f04..e452bc41 100644
--- a/app/components/add_task_dialog.py
+++ b/app/components/add_task_dialog.py
@@ -8,9 +8,9 @@ from PySide6.QtGui import QColor
from PySide6.QtWidgets import QFileDialog, QTableWidgetItem
from qfluentwidgets import PushSettingCard, RangeSettingCard, MessageBox, InfoBar, InfoBarPosition, FluentStyleSheet
from qfluentwidgets.common.icon import FluentIcon as FIF
-from qfluentwidgets.components.dialog_box.mask_dialog_base import MaskDialogBase
from app.components.edit_headers_dialog import EditHeadersDialog # 添加导入
+from app.components.fixed_mask_dialog_base import MaskDialogBase
from .Ui_AddTaskOptionDialog import Ui_AddTaskOptionDialog
from ..common.config import cfg, Headers
from ..common.methods import getReadableSize, getLinkInfo
diff --git a/app/components/edit_headers_dialog.py b/app/components/edit_headers_dialog.py
index 0b303954..a939073a 100644
--- a/app/components/edit_headers_dialog.py
+++ b/app/components/edit_headers_dialog.py
@@ -1,10 +1,11 @@
from PySide6.QtCore import Signal
from PySide6.QtGui import QColor
from PySide6.QtWidgets import QVBoxLayout
-from qfluentwidgets import FluentStyleSheet, MaskDialogBase, InfoBar, InfoBarPosition, PrimaryPushButton, \
+from qfluentwidgets import FluentStyleSheet, InfoBar, InfoBarPosition, PrimaryPushButton, \
SubtitleLabel
from app.components.disabled_rich_text_edit import DisabledRichTextEdit
+from app.components.fixed_mask_dialog_base import MaskDialogBase
class EditHeadersDialog(MaskDialogBase):
diff --git a/app/components/fixed_mask_dialog_base.py b/app/components/fixed_mask_dialog_base.py
new file mode 100644
index 00000000..2348270d
--- /dev/null
+++ b/app/components/fixed_mask_dialog_base.py
@@ -0,0 +1,98 @@
+# coding:utf-8
+from PySide6.QtCore import QEasingCurve, QPropertyAnimation, Qt, QEvent
+from PySide6.QtGui import QColor, QResizeEvent
+from PySide6.QtWidgets import (QDialog, QGraphicsDropShadowEffect,
+ QGraphicsOpacityEffect, QHBoxLayout, QWidget, QFrame)
+from qfluentwidgets import isDarkTheme
+
+
+class MaskDialogBase(QDialog):
+ """ Dialog box base class with a mask """
+
+ def __init__(self, parent=None):
+ super().__init__(parent=parent)
+ self._isClosableOnMaskClicked = False
+ self._hBoxLayout = QHBoxLayout(self)
+ self.windowMask = QWidget(self)
+
+ # dialog box in the center of mask, all widgets take it as parent
+ self.widget = QFrame(self, objectName='centerWidget')
+ self.setWindowFlags(Qt.FramelessWindowHint)
+ self.setAttribute(Qt.WA_TranslucentBackground)
+ self.setGeometry(0, 0, parent.width(), parent.height())
+
+ c = 0 if isDarkTheme() else 255
+ self.windowMask.resize(self.size())
+ self.windowMask.setStyleSheet(f'background:rgba({c}, {c}, {c}, 0.6)')
+ self._hBoxLayout.addWidget(self.widget)
+ self.setShadowEffect()
+
+ self.window().installEventFilter(self)
+ self.windowMask.installEventFilter(self)
+
+ def setShadowEffect(self, blurRadius=60, offset=(0, 10), color=QColor(0, 0, 0, 100)):
+ """ add shadow to dialog """
+ shadowEffect = QGraphicsDropShadowEffect(self.widget)
+ shadowEffect.setBlurRadius(blurRadius)
+ shadowEffect.setOffset(*offset)
+ shadowEffect.setColor(color)
+ self.widget.setGraphicsEffect(None)
+ self.widget.setGraphicsEffect(shadowEffect)
+
+ def setMaskColor(self, color: QColor):
+ """ set the color of mask """
+ self.windowMask.setStyleSheet(f"""
+ background: rgba({color.red()}, {color.green()}, {color.blue()}, {color.alpha()})
+ """)
+
+ def showEvent(self, e):
+ """ fade in """
+ opacityEffect = QGraphicsOpacityEffect(self)
+ self.setGraphicsEffect(opacityEffect)
+ opacityAni = QPropertyAnimation(opacityEffect, b'opacity', self)
+ opacityAni.setStartValue(0)
+ opacityAni.setEndValue(1)
+ opacityAni.setDuration(200)
+ opacityAni.setEasingCurve(QEasingCurve.InSine)
+ opacityAni.finished.connect(lambda: self.setGraphicsEffect(None))
+ opacityAni.start()
+ super().showEvent(e)
+
+ def done(self, code):
+ """ fade out """
+ self.widget.setGraphicsEffect(None)
+ opacityEffect = QGraphicsOpacityEffect(self)
+ self.setGraphicsEffect(opacityEffect)
+ opacityAni = QPropertyAnimation(opacityEffect, b'opacity', self)
+ opacityAni.setStartValue(1)
+ opacityAni.setEndValue(0)
+ opacityAni.setDuration(100)
+ opacityAni.finished.connect(lambda: self._onDone(code))
+ opacityAni.finished.connect(opacityAni.deleteLater)
+ opacityAni.start()
+
+ def _onDone(self, code):
+ self.setGraphicsEffect(None)
+ QDialog.done(self, code)
+ self.deleteLater()
+
+ def isClosableOnMaskClicked(self):
+ return self._isClosableOnMaskClicked
+
+ def setClosableOnMaskClicked(self, isClosable: bool):
+ self._isClosableOnMaskClicked = isClosable
+
+ def resizeEvent(self, e):
+ self.windowMask.resize(self.size())
+
+ def eventFilter(self, obj, e: QEvent):
+ if obj is self.window():
+ if e.type() == QEvent.Resize:
+ re = QResizeEvent(e)
+ self.resize(re.size())
+ elif obj is self.windowMask:
+ if e.type() == QEvent.MouseButtonRelease and e.button() == Qt.LeftButton \
+ and self.isClosableOnMaskClicked():
+ self.reject()
+
+ return super().eventFilter(obj, e)
diff --git a/app/components/plan_task_dialog.py b/app/components/plan_task_dialog.py
index b2a86175..3294f9be 100644
--- a/app/components/plan_task_dialog.py
+++ b/app/components/plan_task_dialog.py
@@ -3,11 +3,12 @@ import sys
from PySide6.QtGui import QColor
from PySide6.QtWidgets import QFileDialog, QApplication
-from qfluentwidgets import FluentStyleSheet, MaskDialogBase
+from qfluentwidgets import FluentStyleSheet
from app.common.methods import openFile
from app.common.signal_bus import signalBus
from app.components.Ui_PlanTaskDialog import Ui_PlanTaskDialog
+from app.components.fixed_mask_dialog_base import MaskDialogBase
class PlanTaskDialog(MaskDialogBase, Ui_PlanTaskDialog):
diff --git a/app/components/update_dialog.py b/app/components/update_dialog.py
index 6e5744d8..06cba714 100644
--- a/app/components/update_dialog.py
+++ b/app/components/update_dialog.py
@@ -4,12 +4,12 @@ from PySide6.QtGui import QColor
from PySide6.QtWidgets import QTableWidgetItem
from loguru import logger
from qfluentwidgets import InfoBar, InfoBarPosition, FluentStyleSheet
-from qfluentwidgets.components.dialog_box.mask_dialog_base import MaskDialogBase
from app.common.config import VERSION, cfg, Headers
from app.common.methods import getProxy, getLocalTimeFromGithubApiTime, getReadableSize
from app.common.signal_bus import signalBus
from app.components.Ui_UpdateDialog import Ui_UpdateDialog
+from app.components.fixed_mask_dialog_base import MaskDialogBase
class GetUpdateThread(QThread):
diff --git a/app/view/setting_interface.py b/app/view/setting_interface.py
index 4bcf2580..2ed25d88 100644
--- a/app/view/setting_interface.py
+++ b/app/view/setting_interface.py
@@ -450,6 +450,8 @@ class SettingInterface(SmoothScrollArea):
# show view
w = Flyout.make(view, self.installExtensionGuidanceCard.button, self)
view.closed.connect(w.close)
+ view.closed.connect(w.deleteLater)
+ view.closed.connect(view.deleteLater)
def __onAutoRunCardChecked(self, value: bool):
""" Set auto run """