The only downloader you need. 下载器的集大成者。
TypeScript asyncasynciobittorentbtcross-platformdownload-managerdownloaderfluent-designftphttp3magnetpyqtpyside6pythonqtquicreactsoftwarestreaming
feat(TaskCard): 已完成任务的文件可直接拖出
XiaoYouChR4bb575c24692
diff --git a/app/platform/desktop.py b/app/platform/desktop.pyindex 2e12bffc..e25875d5 100644--- a/app/platform/desktop.py+++ b/app/platform/desktop.py@@ -4,8 +4,9 @@ import sysfrom os import PathLikefrom pathlib import Path-from PySide6.QtCore import QProcess, QUrl, Qt-from PySide6.QtGui import QDesktopServices+from PySide6.QtCore import QMimeData, QProcess, QUrl, Qt+from PySide6.QtGui import QDesktopServices, QDrag+from PySide6.QtWidgets import QWidgetfrom loguru import logger@@ -260,3 +261,86 @@ def raiseWindow(window) -> None:win32process.AttachThreadInput(currentThreadId, foregroundThreadId, False)except Exception as e:logger.opt(exception=e).warning("Failed to raise window on Windows")+++def startFileDrag(paths: list[Path], source: QWidget) -> None:+ if sys.platform == "win32":+ try:+ hwnd = int(source.window().winId())+ _startFileDragWin32([str(p) for p in paths], hwnd)+ return+ except Exception as e:+ logger.opt(exception=e).debug("COM drag failed, falling back to Qt")+ _startFileDragQt(paths, source)+++def _startFileDragQt(paths: list[Path], source: QWidget) -> None:+ mimeData = QMimeData()+ mimeData.setUrls([QUrl.fromLocalFile(str(p)) for p in paths])+ drag = QDrag(source)+ drag.setMimeData(mimeData)+ drag.exec(Qt.DropAction.CopyAction | Qt.DropAction.MoveAction)+++def _startFileDragWin32(paths: list[str], hwnd: int) -> None:+ import ctypes+ import uuid++ shell32 = ctypes.windll.shell32+ shell32.SHParseDisplayName.restype = ctypes.HRESULT+ shell32.SHCreateShellItemArrayFromIDLists.restype = ctypes.HRESULT+ shell32.SHDoDragDrop.restype = ctypes.HRESULT+ shell32.SHDoDragDrop.argtypes = [+ ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p,+ ctypes.c_ulong, ctypes.POINTER(ctypes.c_ulong),+ ]++ def toGuid(text: str) -> ctypes.Array:+ return (ctypes.c_ubyte * 16).from_buffer_copy(uuid.UUID(text).bytes_le)++ def release(pUnknown: ctypes.c_void_p) -> None:+ vtable = ctypes.cast(+ ctypes.cast(pUnknown, ctypes.POINTER(ctypes.c_void_p))[0],+ ctypes.POINTER(ctypes.c_void_p),+ )+ ctypes.WINFUNCTYPE(ctypes.c_ulong, ctypes.c_void_p)(vtable[2])(pUnknown)++ # 拖拽图标与 DropDescription 靠 IDataObject::SetData 私有格式传递,+ # 剪贴板数据对象不支持 SetData,必须从 shell item 构建数据对象+ pidls: list[ctypes.c_void_p] = []+ try:+ for p in paths:+ pidl = ctypes.c_void_p()+ shell32.SHParseDisplayName(p, None, ctypes.byref(pidl), 0, None)+ pidls.append(pidl)++ pidlArray = (ctypes.c_void_p * len(pidls))(*(p.value for p in pidls))+ pItemArray = ctypes.c_void_p()+ shell32.SHCreateShellItemArrayFromIDLists(+ len(pidls), pidlArray, ctypes.byref(pItemArray))+ try:+ vtable = ctypes.cast(+ ctypes.cast(pItemArray, ctypes.POINTER(ctypes.c_void_p))[0],+ ctypes.POINTER(ctypes.c_void_p),+ )+ BindToHandler = ctypes.WINFUNCTYPE(+ ctypes.HRESULT, ctypes.c_void_p, ctypes.c_void_p,+ ctypes.c_void_p, ctypes.c_void_p, ctypes.POINTER(ctypes.c_void_p),+ )(vtable[3])+ pDataObj = ctypes.c_void_p()+ BindToHandler(+ pItemArray, None,+ toGuid("B8C0BD9F-ED24-455C-83E6-D5390C4FE8C4"), # BHID_DataObject+ toGuid("0000010E-0000-0000-C000-000000000046"), # IID_IDataObject+ ctypes.byref(pDataObj),+ )+ try:+ dwEffect = ctypes.c_ulong(0)+ shell32.SHDoDragDrop(hwnd, pDataObj, None, 7, ctypes.byref(dwEffect))+ finally:+ release(pDataObj)+ finally:+ release(pItemArray)+ finally:+ for pidl in pidls:+ shell32.ILFree(pidl)diff --git a/app/view/cards/task_cards.py b/app/view/cards/task_cards.pyindex 47746664..32896699 100644--- a/app/view/cards/task_cards.py+++ b/app/view/cards/task_cards.py@@ -3,7 +3,7 @@ from __future__ import annotationsfrom pathlib import Pathfrom typing import TYPE_CHECKING-from PySide6.QtCore import Signal, Qt+from PySide6.QtCore import QPoint, Signal, Qtfrom PySide6.QtGui import QColor, QPainter, QPenfrom PySide6.QtWidgets import QHBoxLayout, QVBoxLayout, QApplicationfrom qfluentwidgets import (@@ -27,12 +27,16 @@ if TYPE_CHECKING:class TaskCard(CardWidget):ROW_HEIGHT = 60selectionChanged = Signal(bool, bool)+ dragRequested = Signal(str)def __init__(self, task: Task, parent=None):super().__init__(parent)self._task = taskself._selectionMode = Falseself._fileMissing = False+ self._isDragPending = False+ self._hasDragged = False+ self._dragStartPos = QPoint()self.checkBox = CheckBox(self)self.checkBox.setFixedSize(23, 23)@@ -100,9 +104,31 @@ class TaskCard(CardWidget):LiveEditDialog(self._task, featureService.editCards(self._task, self.window()), self.window()).exec()self.refresh()+ def _canDrag(self) -> bool:+ return (self._task.status == TaskStatus.COMPLETED+ and self._task.hasOutputFile+ and Path(self._task.outputPath).exists())++ def mousePressEvent(self, e) -> None:+ super().mousePressEvent(e)+ self._hasDragged = False+ if e.button() == Qt.MouseButton.LeftButton and self._canDrag():+ self._isDragPending = True+ self._dragStartPos = e.position().toPoint()++ def mouseMoveEvent(self, e) -> None:+ if self._isDragPending:+ if (e.position().toPoint() - self._dragStartPos).manhattanLength() >= QApplication.startDragDistance():+ self._isDragPending = False+ self._hasDragged = True+ self.dragRequested.emit(self._task.taskId)+ return+ super().mouseMoveEvent(e)+def mouseReleaseEvent(self, e) -> None:+ self._isDragPending = Falsesuper().mouseReleaseEvent(e)- if e.button() == Qt.MouseButton.LeftButton:+ if e.button() == Qt.MouseButton.LeftButton and not self._hasDragged:extend = bool(e.modifiers() & Qt.KeyboardModifier.ShiftModifier)checked = True if extend or not self._selectionMode else not self.isChecked()self.selectionChanged.emit(checked, extend)