|
20 | 20 | import sys
|
21 | 21 | import os
|
22 | 22 | from PySide6.QtCore import QUrl, Qt
|
23 |
| -from PySide6.QtWidgets import QWidget, QHBoxLayout, QSplitter, QApplication |
| 23 | +from PySide6.QtWidgets import QWidget, QHBoxLayout, QSplitter, QApplication, QFileDialog |
24 | 24 | from PySide6.QtGui import QIcon, QColor, QKeySequence, QShortcut, QCursor
|
25 | 25 | from PySide6.QtWebEngineWidgets import QWebEngineView
|
26 |
| -from PySide6.QtWebEngineCore import QWebEnginePage |
| 26 | +from PySide6.QtWebEngineCore import QWebEnginePage, QWebEngineDownloadRequest |
27 | 27 |
|
28 | 28 | from bbv.globaldata import ICON, TITLE
|
29 | 29 |
|
@@ -74,6 +74,18 @@ def __init__(self):
|
74 | 74 | self.splitter2 = QSplitter(Qt.Horizontal)
|
75 | 75 | self.hbox.addWidget(self.splitter)
|
76 | 76 | self.setLayout(self.hbox)
|
| 77 | + self.web.page().profile().downloadRequested.connect(self.onDownloadRequested) |
| 78 | + |
| 79 | + def onDownloadRequested(self, download: QWebEngineDownloadRequest): |
| 80 | + home_directory = os.path.expanduser('~') |
| 81 | + |
| 82 | + save_path, _ = QFileDialog.getSaveFileName(self, download.suggestedFileName(), os.path.join(home_directory, download.suggestedFileName())) |
| 83 | + if save_path: |
| 84 | + save_directory = os.path.dirname(save_path) |
| 85 | + save_filename = os.path.basename(save_path) |
| 86 | + download.setDownloadDirectory(save_directory) |
| 87 | + download.setDownloadFileName(save_filename) |
| 88 | + download.accept() |
77 | 89 |
|
78 | 90 | def onFeature(self, url, feature):
|
79 | 91 | if feature in (
|
|
0 commit comments