The only downloader you need. 下载器的集大成者。
TypeScript asyncasynciobittorentbtcross-platformdownload-managerdownloaderfluent-designftphttp3magnetpyqtpyside6pythonqtquicreactsoftwarestreaming
refactor(components): CustomAcrylicMenu
XiaoYouChR225d82dad137
diff --git a/app/components/custom_components.py b/app/components/custom_components.pyindex fd7f0584..678b21f7 100644--- a/app/components/custom_components.py+++ b/app/components/custom_components.py@@ -1,9 +1,9 @@-from PySide6.QtCore import QSize, QRect-from PySide6.QtGui import QPainter-from PySide6.QtWidgets import QWidget, QHBoxLayout-from qfluentwidgets import BodyLabel, FluentIconBase, drawIcon, ProgressBar-from qfluentwidgets.common.screen import getCurrentScreenGeometry-from qfluentwidgets.components.material import AcrylicMenu+from PySide6.QtCore import QSize, QRect, QTimer+from PySide6.QtGui import QPainter, Qt, QIcon+from PySide6.QtWidgets import QWidget, QHBoxLayout, QStyleFactory, QStyle, QProxyStyle, QMenu+from qfluentwidgets import BodyLabel, FluentIconBase, drawIcon, ProgressBar, RoundMenu, FluentStyleSheet+from qfluentwidgets.components.widgets.menu import MenuActionListWidget+from qframelesswindow import WindowEffect# 我是傻逼@@ -87,21 +87,84 @@ class TaskProgressBar(QWidget):for e, i in enumerate(content): # 更改 Stretchself.HBoxLayout.setStretch(e, int((i["end"] - i["start"]) / 1048576)) # 除以1MB+class CustomMenuStyle(QProxyStyle):+ """ Custom menu style """-class FixedAcrylicMenu(AcrylicMenu):- """ 修复背景获取偏移、位置偏移的问题 """+ def __init__(self, iconSize=14):+ """+ Parameters+ ----------+ iconSizeL int+ the size of icon+ """+ super().__init__()+ self.iconSize = iconSize- def adjustPosition(self):- m = self.layout().contentsMargins()- rect = getCurrentScreenGeometry()- w, h = self.layout().sizeHint().width() + 5, self.layout().sizeHint().height()+ def pixelMetric(self, metric, option, widget):+ if metric == QStyle.PixelMetric.PM_SmallIconSize:+ return self.iconSize- x = min(self.x() - m.left(), rect.right() - w)- y = self.y() - 45+ return super().pixelMetric(metric, option, widget)- self.move(x, y)+ def polish(self, app, /):+ QStyleFactory.create("fusion").polish(app)- def showEvent(self, e):- super().showEvent(e)- self.adjustPosition()- # self.view.acrylicBrush.grabImage(QRect(self.pos() + self.view.pos(), self.view.size()))+ def unpolish(self, app, /):+ QStyleFactory.create("fusion").polish(app)+++class CustomAcrylicMenu(RoundMenu):+ """ Win32API 绘制 Acrylic/Aero Menu """++ def __init__(self, title="", parent=None):+ QMenu.__init__(self, parent)+ self.setTitle(title)+ self._icon = QIcon()+ self._actions = [] # type: List[QAction]+ self._subMenus = []++ self.isSubMenu = False+ self.parentMenu = None+ self.menuItem = None+ self.lastHoverItem = None+ self.lastHoverSubMenuItem = None+ self.isHideBySystem = True+ self.itemHeight = 28++ self.hBoxLayout = QHBoxLayout(self)+ self.view = MenuActionListWidget(self)+ self.windowEffect = WindowEffect(self)++ self.aniManager = None+ self.timer = QTimer(self)++ self.__initWidgets()++ def __initWidgets(self):+ self.setWindowFlags(Qt.WindowType.Popup | Qt.WindowType.FramelessWindowHint |+ Qt.WindowType.NoDropShadowWindowHint)+ self.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground)+ self.setMouseTracking(True)++ self.setStyle(CustomMenuStyle())++ self.timer.setSingleShot(True)+ self.timer.setInterval(400)+ self.timer.timeout.connect(self._onShowMenuTimeOut)++ self.hBoxLayout.addWidget(self.view, 1, Qt.AlignCenter)++ self.hBoxLayout.setContentsMargins(0, 0, 0, 0)+ FluentStyleSheet.MENU.apply(self)+ self.view.setProperty("transparent", True)++ self.view.itemClicked.connect(self._onItemClicked)+ self.view.itemEntered.connect(self._onItemEntered)++ def showEvent(self, event, /):+ self.windowEffect.addMenuShadowEffect(self.winId())+ self.windowEffect.addShadowEffect(self.winId())+ self.windowEffect.enableBlurBehindWindow(self.winId())+ self.windowEffect.setAcrylicEffect(self.winId())++ super().showEvent(event)diff --git a/app/components/custom_tray.py b/app/components/custom_tray.pyindex 740e03a6..7c00b145 100644--- a/app/components/custom_tray.py+++ b/app/components/custom_tray.py@@ -4,7 +4,7 @@ from qfluentwidgets import Actionfrom qfluentwidgets import FluentIcon as FIFfrom app.common.methods import bringWindowToTop-from app.components.custom_components import FixedAcrylicMenu+from app.components.custom_components import CustomAcrylicMenuclass CustomSystemTrayIcon(QSystemTrayIcon):@@ -14,7 +14,7 @@ class CustomSystemTrayIcon(QSystemTrayIcon):self.setIcon(parent.windowIcon())self.setToolTip('Ghost Downloader 🥰')- self.menu = FixedAcrylicMenu(parent=parent)+ self.menu = CustomAcrylicMenu(parent=parent)self.showAction = Action(QIcon(":/image/logo_withoutBackground.png"), self.tr('仪表盘'), self.menu)self.showAction.triggered.connect(self.__onShowActionTriggered)