src/eric7/WebBrowser/Download/DownloadItem.py

Fri, 25 Oct 2024 17:58:59 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Fri, 25 Oct 2024 17:58:59 +0200
branch
eric7
changeset 11006
a671918232f3
parent 10439
21c28b0f9e41
child 11090
f5f5f5803935
permissions
-rw-r--r--

Modified modal dialog usage to always include a valid parent (needed for Wayland).

668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
10439
21c28b0f9e41 Updated copyright for 2024.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10436
diff changeset
3 # Copyright (c) 2010 - 2024 Detlev Offenbach <detlev@die-offenbachs.de>
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a widget controlling a download.
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
8563
3c6547443fb2 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8556
diff changeset
10 import enum
5194
4750c83cc718 Added an 'unselect' alternative for Qt < 5.7.0 to the new web browser and added possibility to save the current page in various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5033
diff changeset
11 import os
9153
506e35e424d5 Finished replacing the use of "QFileInfo()" with Python equivalents.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8881
diff changeset
12 import pathlib
5194
4750c83cc718 Added an 'unselect' alternative for Qt < 5.7.0 to the new web browser and added possibility to save the current page in various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5033
diff changeset
13
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
14 from PyQt6.QtCore import QDateTime, QStandardPaths, QTime, QUrl, pyqtSignal, pyqtSlot
8872
ee64dbfefd5f Changed the web browser download items to use a transparent background and adapt some colors to the lightness of the palette.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8856
diff changeset
15 from PyQt6.QtGui import QDesktopServices
8556
766e1566cb74 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8553
diff changeset
16 from PyQt6.QtWebEngineCore import QWebEngineDownloadRequest
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
17 from PyQt6.QtWidgets import QDialog, QStyle, QWidget
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
19 from eric7.EricGui import EricPixmapCache
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
20 from eric7.EricWidgets import EricFileDialog
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
21 from eric7.EricWidgets.EricApplication import ericApp
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
22 from eric7.Utilities import MimeTypes
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
23 from eric7.WebBrowser.WebBrowserWindow import WebBrowserWindow
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
25 from .DownloadUtilities import dataString, speedString, timeString
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
26 from .Ui_DownloadItem import Ui_DownloadItem
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
28
8563
3c6547443fb2 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8556
diff changeset
29 class DownloadState(enum.Enum):
3c6547443fb2 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8556
diff changeset
30 """
3c6547443fb2 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8556
diff changeset
31 Class implementing the various download states.
3c6547443fb2 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8556
diff changeset
32 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
33
8563
3c6547443fb2 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8556
diff changeset
34 Downloading = 0
3c6547443fb2 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8556
diff changeset
35 Successful = 1
3c6547443fb2 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8556
diff changeset
36 Cancelled = 2
3c6547443fb2 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8556
diff changeset
37
3c6547443fb2 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8556
diff changeset
38
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 class DownloadItem(QWidget, Ui_DownloadItem):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 Class implementing a widget controlling a download.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
42
757
d3daf1d8f058 Fixed the handling of 'javascript' schemes in the web browser and enhanced the download manager a bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 679
diff changeset
43 @signal statusChanged() emitted upon a status change of a download
6224
08875555771a Web Browser (NG): some more improvements of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6221
diff changeset
44 @signal downloadFinished(success) emitted when a download finished
757
d3daf1d8f058 Fixed the handling of 'javascript' schemes in the web browser and enhanced the download manager a bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 679
diff changeset
45 @signal progress(int, int) emitted to signal the download progress
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
47
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 statusChanged = pyqtSignal()
6224
08875555771a Web Browser (NG): some more improvements of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6221
diff changeset
49 downloadFinished = pyqtSignal(bool)
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 progress = pyqtSignal(int, int)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
51
8556
766e1566cb74 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8553
diff changeset
52 def __init__(self, downloadRequest=None, pageUrl=None, parent=None):
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 Constructor
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
55
8556
766e1566cb74 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8553
diff changeset
56 @param downloadRequest reference to the download object containing the
4769
2b6f7e026cdc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4768
diff changeset
57 download data.
8556
766e1566cb74 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8553
diff changeset
58 @type QWebEngineDownloadRequest
6134
cb0985e8da91 Introduced a navigation bar button to open the downloads manager window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6091
diff changeset
59 @param pageUrl URL of the calling page
cb0985e8da91 Introduced a navigation bar button to open the downloads manager window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6091
diff changeset
60 @type QUrl
cb0985e8da91 Introduced a navigation bar button to open the downloads manager window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6091
diff changeset
61 @param parent reference to the parent widget
cb0985e8da91 Introduced a navigation bar button to open the downloads manager window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6091
diff changeset
62 @type QWidget
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 """
8218
7c09585bd960 Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8205
diff changeset
64 super().__init__(parent)
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 self.setupUi(self)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
66
8872
ee64dbfefd5f Changed the web browser download items to use a transparent background and adapt some colors to the lightness of the palette.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8856
diff changeset
67 self.fileIcon.setStyleSheet("background-color: transparent")
ee64dbfefd5f Changed the web browser download items to use a transparent background and adapt some colors to the lightness of the palette.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8856
diff changeset
68 self.datetimeLabel.setStyleSheet("background-color: transparent")
ee64dbfefd5f Changed the web browser download items to use a transparent background and adapt some colors to the lightness of the palette.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8856
diff changeset
69 self.filenameLabel.setStyleSheet("background-color: transparent")
ee64dbfefd5f Changed the web browser download items to use a transparent background and adapt some colors to the lightness of the palette.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8856
diff changeset
70 if ericApp().usesDarkPalette():
ee64dbfefd5f Changed the web browser download items to use a transparent background and adapt some colors to the lightness of the palette.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8856
diff changeset
71 self.infoLabel.setStyleSheet(
ee64dbfefd5f Changed the web browser download items to use a transparent background and adapt some colors to the lightness of the palette.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8856
diff changeset
72 "color: #c0c0c0; background-color: transparent"
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
73 ) # light gray
8872
ee64dbfefd5f Changed the web browser download items to use a transparent background and adapt some colors to the lightness of the palette.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8856
diff changeset
74 else:
ee64dbfefd5f Changed the web browser download items to use a transparent background and adapt some colors to the lightness of the palette.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8856
diff changeset
75 self.infoLabel.setStyleSheet(
ee64dbfefd5f Changed the web browser download items to use a transparent background and adapt some colors to the lightness of the palette.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8856
diff changeset
76 "color: #808080; background-color: transparent"
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
77 ) # dark gray
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
78
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 self.progressBar.setMaximum(0)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
80
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
81 self.pauseButton.setIcon(EricPixmapCache.getIcon("pause"))
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
82 self.stopButton.setIcon(EricPixmapCache.getIcon("stopLoading"))
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
83 self.openButton.setIcon(EricPixmapCache.getIcon("open"))
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 self.openButton.setEnabled(False)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 self.openButton.setVisible(False)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
86
8563
3c6547443fb2 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8556
diff changeset
87 self.__state = DownloadState.Downloading
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
88
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
89 icon = self.style().standardIcon(QStyle.StandardPixmap.SP_FileIcon)
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 self.fileIcon.setPixmap(icon.pixmap(48, 48))
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
91
8556
766e1566cb74 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8553
diff changeset
92 self.__downloadRequest = downloadRequest
6286
2c8a751d6137 DownloadManager: fixed an issue getting the main window
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6224
diff changeset
93 if pageUrl is None:
2c8a751d6137 DownloadManager: fixed an issue getting the main window
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6224
diff changeset
94 self.__pageUrl = QUrl()
2c8a751d6137 DownloadManager: fixed an issue getting the main window
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6224
diff changeset
95 else:
2c8a751d6137 DownloadManager: fixed an issue getting the main window
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6224
diff changeset
96 self.__pageUrl = pageUrl
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 self.__bytesReceived = 0
679
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
98 self.__bytesTotal = -1
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 self.__downloadTime = QTime()
670
bb833c4bcf28 Some fixes to the download manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 668
diff changeset
100 self.__fileName = ""
1094
743900906d8e Added a puse button to the web browser download.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
101 self.__originalFileName = ""
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 self.__finishedDownloading = False
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 self.__gettingFileName = False
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 self.__canceledFileSelect = False
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 self.__autoOpen = False
5928
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5920
diff changeset
106 self.__downloadedDateTime = QDateTime()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
107
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 self.__initialize()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
109
4769
2b6f7e026cdc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4768
diff changeset
110 def __initialize(self):
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 """
4769
2b6f7e026cdc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4768
diff changeset
112 Private method to initialize the widget.
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 """
8556
766e1566cb74 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8553
diff changeset
114 if self.__downloadRequest is None:
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
116
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 self.__finishedDownloading = False
679
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
118 self.__bytesReceived = 0
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
119 self.__bytesTotal = -1
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
120
670
bb833c4bcf28 Some fixes to the download manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 668
diff changeset
121 # start timer for the download estimation
8318
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
122 self.__downloadTime = QTime.currentTime()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
123
4769
2b6f7e026cdc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4768
diff changeset
124 # attach to the download item object
8556
766e1566cb74 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8553
diff changeset
125 self.__url = self.__downloadRequest.url()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
126 self.__downloadRequest.receivedBytesChanged.connect(self.__downloadProgress)
8556
766e1566cb74 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8553
diff changeset
127 self.__downloadRequest.isFinishedChanged.connect(self.__finished)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
128
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 # reset info
5928
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5920
diff changeset
130 self.datetimeLabel.clear()
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5920
diff changeset
131 self.datetimeLabel.hide()
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 self.infoLabel.clear()
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 self.progressBar.setValue(0)
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
134 if (
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
135 self.__downloadRequest.state()
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
136 == QWebEngineDownloadRequest.DownloadState.DownloadRequested
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
137 ):
5530
93f95c4b3153 Started upgrading the new web browser to the Qt 5.8 offerings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5526
diff changeset
138 self.__getFileName()
93f95c4b3153 Started upgrading the new web browser to the Qt 5.8 offerings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5526
diff changeset
139 if not self.__fileName:
8556
766e1566cb74 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8553
diff changeset
140 self.__downloadRequest.cancel()
5530
93f95c4b3153 Started upgrading the new web browser to the Qt 5.8 offerings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5526
diff changeset
141 else:
8556
766e1566cb74 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8553
diff changeset
142 self.__downloadRequest.setDownloadFileName(self.__fileName)
766e1566cb74 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8553
diff changeset
143 self.__downloadRequest.accept()
4769
2b6f7e026cdc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4768
diff changeset
144 else:
8556
766e1566cb74 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8553
diff changeset
145 fileName = self.__downloadRequest.downloadFileName()
5530
93f95c4b3153 Started upgrading the new web browser to the Qt 5.8 offerings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5526
diff changeset
146 self.__setFileName(fileName)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
147
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 def __getFileName(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 """
2954
bf0215fe12d1 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2523
diff changeset
150 Private method to get the file name to save to from the user.
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 """
9482
a2bc06a54d9d Corrected/acknowledged some bad import style and removed some obsolete code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
152 from .DownloadAskActionDialog import DownloadAskActionDialog
a2bc06a54d9d Corrected/acknowledged some bad import style and removed some obsolete code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
153
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 if self.__gettingFileName:
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
156
8556
766e1566cb74 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8553
diff changeset
157 savePage = self.__downloadRequest.isSavePageDownload()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
158
5194
4750c83cc718 Added an 'unselect' alternative for Qt < 5.7.0 to the new web browser and added possibility to save the current page in various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5033
diff changeset
159 documentLocation = QStandardPaths.writableLocation(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
160 QStandardPaths.StandardLocation.DocumentsLocation
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
161 )
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
162 downloadDirectory = WebBrowserWindow.downloadManager().downloadDirectory()
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
163
670
bb833c4bcf28 Some fixes to the download manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 668
diff changeset
164 if self.__fileName:
bb833c4bcf28 Some fixes to the download manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 668
diff changeset
165 fileName = self.__fileName
1094
743900906d8e Added a puse button to the web browser download.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
166 originalFileName = self.__originalFileName
670
bb833c4bcf28 Some fixes to the download manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 668
diff changeset
167 self.__toDownload = True
bb833c4bcf28 Some fixes to the download manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 668
diff changeset
168 ask = False
bb833c4bcf28 Some fixes to the download manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 668
diff changeset
169 else:
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
170 defaultFileName, originalFileName = self.__saveFileName(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
171 documentLocation if savePage else downloadDirectory
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
172 )
670
bb833c4bcf28 Some fixes to the download manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 668
diff changeset
173 fileName = defaultFileName
1094
743900906d8e Added a puse button to the web browser download.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
174 self.__originalFileName = originalFileName
670
bb833c4bcf28 Some fixes to the download manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 668
diff changeset
175 ask = True
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 self.__autoOpen = False
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
177
5194
4750c83cc718 Added an 'unselect' alternative for Qt < 5.7.0 to the new web browser and added possibility to save the current page in various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5033
diff changeset
178 if not savePage:
8556
766e1566cb74 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8553
diff changeset
179 url = self.__downloadRequest.url()
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
180 mimetype = MimeTypes.mimeType(originalFileName)
5033
d1c2651060ec Added the 'Save as' functionality to the new web browser (for Qt 5.7+)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
181 dlg = DownloadAskActionDialog(
9153
506e35e424d5 Finished replacing the use of "QFileInfo()" with Python equivalents.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8881
diff changeset
182 pathlib.Path(originalFileName).name,
5033
d1c2651060ec Added the 'Save as' functionality to the new web browser (for Qt 5.7+)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
183 mimetype,
d1c2651060ec Added the 'Save as' functionality to the new web browser (for Qt 5.7+)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
184 "{0}://{1}".format(url.scheme(), url.authority()),
11006
a671918232f3 Modified modal dialog usage to always include a valid parent (needed for Wayland).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10439
diff changeset
185 parent=self,
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
186 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
187
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
188 if dlg.exec() == QDialog.DialogCode.Rejected or dlg.getAction() == "cancel":
5033
d1c2651060ec Added the 'Save as' functionality to the new web browser (for Qt 5.7+)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
189 self.progressBar.setVisible(False)
d1c2651060ec Added the 'Save as' functionality to the new web browser (for Qt 5.7+)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
190 self.on_stopButton_clicked()
d1c2651060ec Added the 'Save as' functionality to the new web browser (for Qt 5.7+)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
191 self.filenameLabel.setText(
d1c2651060ec Added the 'Save as' functionality to the new web browser (for Qt 5.7+)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
192 self.tr("Download canceled: {0}").format(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
193 pathlib.Path(defaultFileName).name
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
194 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
195 )
5033
d1c2651060ec Added the 'Save as' functionality to the new web browser (for Qt 5.7+)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
196 self.__canceledFileSelect = True
5928
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5920
diff changeset
197 self.__setDateTime()
5033
d1c2651060ec Added the 'Save as' functionality to the new web browser (for Qt 5.7+)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
198 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
199
5033
d1c2651060ec Added the 'Save as' functionality to the new web browser (for Qt 5.7+)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
200 if dlg.getAction() == "scan":
d1c2651060ec Added the 'Save as' functionality to the new web browser (for Qt 5.7+)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
201 self.__mainWindow.requestVirusTotalScan(url)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
202
5033
d1c2651060ec Added the 'Save as' functionality to the new web browser (for Qt 5.7+)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
203 self.progressBar.setVisible(False)
d1c2651060ec Added the 'Save as' functionality to the new web browser (for Qt 5.7+)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
204 self.on_stopButton_clicked()
d1c2651060ec Added the 'Save as' functionality to the new web browser (for Qt 5.7+)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
205 self.filenameLabel.setText(
d1c2651060ec Added the 'Save as' functionality to the new web browser (for Qt 5.7+)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
206 self.tr("VirusTotal scan scheduled: {0}").format(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
207 pathlib.Path(defaultFileName).name
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
208 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
209 )
5033
d1c2651060ec Added the 'Save as' functionality to the new web browser (for Qt 5.7+)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
210 self.__canceledFileSelect = True
d1c2651060ec Added the 'Save as' functionality to the new web browser (for Qt 5.7+)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
211 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
212
5033
d1c2651060ec Added the 'Save as' functionality to the new web browser (for Qt 5.7+)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
213 self.__autoOpen = dlg.getAction() == "open"
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
214
5194
4750c83cc718 Added an 'unselect' alternative for Qt < 5.7.0 to the new web browser and added possibility to save the current page in various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5033
diff changeset
215 tempLocation = QStandardPaths.writableLocation(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
216 QStandardPaths.StandardLocation.TempLocation
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
217 )
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
218 fileName = tempLocation + "/" + pathlib.Path(fileName).stem
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
219
5194
4750c83cc718 Added an 'unselect' alternative for Qt < 5.7.0 to the new web browser and added possibility to save the current page in various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5033
diff changeset
220 if ask and not self.__autoOpen:
4750c83cc718 Added an 'unselect' alternative for Qt < 5.7.0 to the new web browser and added possibility to save the current page in various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5033
diff changeset
221 self.__gettingFileName = True
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
222 fileName = EricFileDialog.getSaveFileName(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
223 None, self.tr("Save File"), defaultFileName, ""
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
224 )
5194
4750c83cc718 Added an 'unselect' alternative for Qt < 5.7.0 to the new web browser and added possibility to save the current page in various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5033
diff changeset
225 self.__gettingFileName = False
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
226
5194
4750c83cc718 Added an 'unselect' alternative for Qt < 5.7.0 to the new web browser and added possibility to save the current page in various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5033
diff changeset
227 if not fileName:
4750c83cc718 Added an 'unselect' alternative for Qt < 5.7.0 to the new web browser and added possibility to save the current page in various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5033
diff changeset
228 self.progressBar.setVisible(False)
4750c83cc718 Added an 'unselect' alternative for Qt < 5.7.0 to the new web browser and added possibility to save the current page in various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5033
diff changeset
229 self.on_stopButton_clicked()
4750c83cc718 Added an 'unselect' alternative for Qt < 5.7.0 to the new web browser and added possibility to save the current page in various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5033
diff changeset
230 self.filenameLabel.setText(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
231 self.tr("Download canceled: {0}").format(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
232 pathlib.Path(defaultFileName).name
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
233 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
234 )
5194
4750c83cc718 Added an 'unselect' alternative for Qt < 5.7.0 to the new web browser and added possibility to save the current page in various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5033
diff changeset
235 self.__canceledFileSelect = True
5928
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5920
diff changeset
236 self.__setDateTime()
5194
4750c83cc718 Added an 'unselect' alternative for Qt < 5.7.0 to the new web browser and added possibility to save the current page in various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5033
diff changeset
237 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
238
5530
93f95c4b3153 Started upgrading the new web browser to the Qt 5.8 offerings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5526
diff changeset
239 self.__setFileName(fileName)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
240
5530
93f95c4b3153 Started upgrading the new web browser to the Qt 5.8 offerings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5526
diff changeset
241 def __setFileName(self, fileName):
93f95c4b3153 Started upgrading the new web browser to the Qt 5.8 offerings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5526
diff changeset
242 """
93f95c4b3153 Started upgrading the new web browser to the Qt 5.8 offerings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5526
diff changeset
243 Private method to set the file name to save the download into.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
244
5530
93f95c4b3153 Started upgrading the new web browser to the Qt 5.8 offerings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5526
diff changeset
245 @param fileName name of the file to save into
93f95c4b3153 Started upgrading the new web browser to the Qt 5.8 offerings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5526
diff changeset
246 @type str
93f95c4b3153 Started upgrading the new web browser to the Qt 5.8 offerings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5526
diff changeset
247 """
9153
506e35e424d5 Finished replacing the use of "QFileInfo()" with Python equivalents.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8881
diff changeset
248 fpath = pathlib.Path(fileName)
9566
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
249 WebBrowserWindow.downloadManager().setDownloadDirectory(
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
250 str(fpath.parent.resolve())
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
251 )
9153
506e35e424d5 Finished replacing the use of "QFileInfo()" with Python equivalents.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8881
diff changeset
252 self.filenameLabel.setText(fpath.name)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
253
9153
506e35e424d5 Finished replacing the use of "QFileInfo()" with Python equivalents.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8881
diff changeset
254 self.__fileName = str(fpath)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
255
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
256 # check file path for saving
9566
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
257 saveDirPath = pathlib.Path(self.__fileName).parent
9153
506e35e424d5 Finished replacing the use of "QFileInfo()" with Python equivalents.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8881
diff changeset
258 if not saveDirPath.exists():
506e35e424d5 Finished replacing the use of "QFileInfo()" with Python equivalents.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8881
diff changeset
259 saveDirPath.mkdir(parents=True)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
260
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
261 def __saveFileName(self, directory):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
262 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
263 Private method to calculate a name for the file to download.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
264
10436
f6881d10e995 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
265 @param directory name of the directory to store the file into
f6881d10e995 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
266 @type str
f6881d10e995 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
267 @return proposed filename and original filename
f6881d10e995 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
268 @rtype tuple of (str, str)
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
269 """
9153
506e35e424d5 Finished replacing the use of "QFileInfo()" with Python equivalents.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8881
diff changeset
270 fpath = pathlib.Path(self.__downloadRequest.downloadFileName())
506e35e424d5 Finished replacing the use of "QFileInfo()" with Python equivalents.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8881
diff changeset
271 origName = fpath.name
506e35e424d5 Finished replacing the use of "QFileInfo()" with Python equivalents.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8881
diff changeset
272 name = os.path.join(directory, origName)
1094
743900906d8e Added a puse button to the web browser download.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
273 return name, origName
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
274
6085
7e48a0d98cce Added the capability to pause/resume download (Qt 5.10.0/PyQt 5.10.0).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
275 @pyqtSlot(bool)
7e48a0d98cce Added the capability to pause/resume download (Qt 5.10.0/PyQt 5.10.0).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
276 def on_pauseButton_clicked(self, checked):
7e48a0d98cce Added the capability to pause/resume download (Qt 5.10.0/PyQt 5.10.0).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
277 """
7e48a0d98cce Added the capability to pause/resume download (Qt 5.10.0/PyQt 5.10.0).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
278 Private slot to pause the download.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
279
6085
7e48a0d98cce Added the capability to pause/resume download (Qt 5.10.0/PyQt 5.10.0).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
280 @param checked flag indicating the state of the button
7e48a0d98cce Added the capability to pause/resume download (Qt 5.10.0/PyQt 5.10.0).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
281 @type bool
7e48a0d98cce Added the capability to pause/resume download (Qt 5.10.0/PyQt 5.10.0).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
282 """
7e48a0d98cce Added the capability to pause/resume download (Qt 5.10.0/PyQt 5.10.0).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
283 if checked:
8556
766e1566cb74 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8553
diff changeset
284 self.__downloadRequest.pause()
6085
7e48a0d98cce Added the capability to pause/resume download (Qt 5.10.0/PyQt 5.10.0).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
285 else:
8556
766e1566cb74 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8553
diff changeset
286 self.__downloadRequest.resume()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
287
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
288 @pyqtSlot()
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
289 def on_stopButton_clicked(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
290 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
291 Private slot to stop the download.
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
292 """
679
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
293 self.cancelDownload()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
294
679
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
295 def cancelDownload(self):
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
296 """
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
297 Public slot to stop the download.
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
298 """
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
299 self.setUpdatesEnabled(False)
4769
2b6f7e026cdc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4768
diff changeset
300 self.stopButton.setEnabled(False)
2b6f7e026cdc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4768
diff changeset
301 self.stopButton.setVisible(False)
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
302 self.openButton.setEnabled(False)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
303 self.openButton.setVisible(False)
6085
7e48a0d98cce Added the capability to pause/resume download (Qt 5.10.0/PyQt 5.10.0).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
304 self.pauseButton.setEnabled(False)
7e48a0d98cce Added the capability to pause/resume download (Qt 5.10.0/PyQt 5.10.0).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
305 self.pauseButton.setVisible(False)
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
306 self.setUpdatesEnabled(True)
8563
3c6547443fb2 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8556
diff changeset
307 self.__state = DownloadState.Cancelled
8556
766e1566cb74 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8553
diff changeset
308 self.__downloadRequest.cancel()
5928
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5920
diff changeset
309 self.__setDateTime()
6224
08875555771a Web Browser (NG): some more improvements of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6221
diff changeset
310 self.downloadFinished.emit(False)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
311
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
312 @pyqtSlot()
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
313 def on_openButton_clicked(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
314 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
315 Private slot to open the downloaded file.
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
316 """
679
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
317 self.openFile()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
318
679
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
319 def openFile(self):
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
320 """
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
321 Public slot to open the downloaded file.
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
322 """
9566
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
323 url = QUrl.fromLocalFile(str(pathlib.Path(self.__fileName).resolve()))
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
324 QDesktopServices.openUrl(url)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
325
679
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
326 def openFolder(self):
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
327 """
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
328 Public slot to open the folder containing the downloaded file.
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
329 """
9566
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
330 url = QUrl.fromLocalFile(str(pathlib.Path(self.__fileName).resolve().parent))
679
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
331 QDesktopServices.openUrl(url)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
332
8556
766e1566cb74 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8553
diff changeset
333 @pyqtSlot()
766e1566cb74 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8553
diff changeset
334 def __downloadProgress(self):
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
335 """
8556
766e1566cb74 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8553
diff changeset
336 Private slot to show the download progress.
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
337 """
8556
766e1566cb74 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8553
diff changeset
338 self.__bytesReceived = self.__downloadRequest.receivedBytes()
766e1566cb74 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8553
diff changeset
339 self.__bytesTotal = self.__downloadRequest.totalBytes()
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
340 currentValue = 0
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
341 totalValue = 0
8556
766e1566cb74 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8553
diff changeset
342 if self.__bytesTotal > 0:
8856
df77fbfc150f Corrected some Python 3.10 precision related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8563
diff changeset
343 currentValue = self.__bytesReceived * 100 // self.__bytesTotal
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
344 totalValue = 100
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
345 self.progressBar.setValue(currentValue)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
346 self.progressBar.setMaximum(totalValue)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
347
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
348 self.progress.emit(currentValue, totalValue)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
349 self.__updateInfoLabel()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
350
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6134
diff changeset
351 def downloadProgress(self):
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6134
diff changeset
352 """
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6134
diff changeset
353 Public method to get the download progress.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
354
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6134
diff changeset
355 @return current download progress
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6134
diff changeset
356 @rtype int
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6134
diff changeset
357 """
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6134
diff changeset
358 return self.progressBar.value()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
359
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
360 def bytesTotal(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
361 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
362 Public method to get the total number of bytes of the download.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
363
10436
f6881d10e995 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
364 @return total number of bytes
f6881d10e995 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
365 @rtype int
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
366 """
679
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
367 if self.__bytesTotal == -1:
8556
766e1566cb74 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8553
diff changeset
368 self.__bytesTotal = self.__downloadRequest.totalBytes()
679
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
369 return self.__bytesTotal
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
370
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
371 def bytesReceived(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
372 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
373 Public method to get the number of bytes received.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
374
10436
f6881d10e995 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
375 @return number of bytes received
f6881d10e995 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
376 @rtype int
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
377 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
378 return self.__bytesReceived
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
379
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
380 def remainingTime(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
381 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
382 Public method to get an estimation for the remaining time.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
383
10436
f6881d10e995 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
384 @return estimation for the remaining time
f6881d10e995 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
385 @rtype float
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
386 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
387 if not self.downloading():
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
388 return -1.0
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
389
679
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
390 if self.bytesTotal() == -1:
673
1c1f3a125e68 Fixed a few issues with the download manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 670
diff changeset
391 return -1.0
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
392
4443
f7f61a66dc38 A little fix in the download item for a situation causing a division by zero.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4326
diff changeset
393 cSpeed = self.currentSpeed()
8260
2161475d9639 Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8227
diff changeset
394 timeRemaining = (
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
395 (self.bytesTotal() - self.bytesReceived()) / cSpeed if cSpeed != 0 else 1
8260
2161475d9639 Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8227
diff changeset
396 )
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
397
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
398 # ETA should never be 0
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
399 if timeRemaining == 0:
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
400 timeRemaining = 1
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
401
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
402 return timeRemaining
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
403
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
404 def currentSpeed(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
405 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
406 Public method to get an estimation for the download speed.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
407
10436
f6881d10e995 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
408 @return estimation for the download speed
f6881d10e995 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
409 @rtype float
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
410 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
411 if not self.downloading():
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
412 return -1.0
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
413
8318
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
414 return (
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
415 self.__bytesReceived
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
416 * 1000.0
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
417 / self.__downloadTime.msecsTo(QTime.currentTime())
8318
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
418 )
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
419
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
420 def __updateInfoLabel(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
421 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
422 Private method to update the info label.
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
423 """
673
1c1f3a125e68 Fixed a few issues with the download manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 670
diff changeset
424 bytesTotal = self.bytesTotal()
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
425 running = not self.downloadedSuccessfully()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
426
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
427 speed = self.currentSpeed()
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
428 timeRemaining = self.remainingTime()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
429
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
430 info = ""
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
431 if running:
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
432 remaining = ""
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
433
679
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
434 if bytesTotal > 0:
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
435 remaining = timeString(timeRemaining)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
436
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
437 info = self.tr("{0} of {1} ({2}/sec) {3}").format(
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
438 dataString(self.__bytesReceived),
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
439 bytesTotal == -1 and self.tr("?") or dataString(bytesTotal),
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
440 speedString(speed),
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
441 remaining,
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
442 )
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
443 else:
8205
4a0f1f896341 Applied some code simplifications suggested by the new Simplify checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8143
diff changeset
444 if bytesTotal in (self.__bytesReceived, -1):
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
445 info = self.tr("{0} downloaded").format(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
446 dataString(self.__bytesReceived)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
447 )
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
448 else:
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
449 info = self.tr("{0} of {1} - Stopped").format(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
450 dataString(self.__bytesReceived), dataString(bytesTotal)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
451 )
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
452 self.infoLabel.setText(info)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
453
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
454 def downloading(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
455 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
456 Public method to determine, if a download is in progress.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
457
10436
f6881d10e995 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
458 @return flag indicating a download is in progress
f6881d10e995 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
459 @rtype bool
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
460 """
8563
3c6547443fb2 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8556
diff changeset
461 return self.__state == DownloadState.Downloading
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
462
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
463 def downloadedSuccessfully(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
464 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
465 Public method to check for a successful download.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
466
10436
f6881d10e995 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
467 @return flag indicating a successful download
f6881d10e995 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
468 @rtype bool
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
469 """
8563
3c6547443fb2 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8556
diff changeset
470 return self.__state == DownloadState.Successful
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
471
679
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
472 def downloadCanceled(self):
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
473 """
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
474 Public method to check, if the download was cancelled.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
475
10436
f6881d10e995 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
476 @return flag indicating a canceled download
f6881d10e995 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
477 @rtype bool
679
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
478 """
8563
3c6547443fb2 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8556
diff changeset
479 return self.__state == DownloadState.Cancelled
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
480
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
481 def __finished(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
482 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
483 Private slot to handle the download finished.
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
484 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
485 self.__finishedDownloading = True
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
486
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
487 noError = (
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
488 self.__downloadRequest.state()
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
489 == QWebEngineDownloadRequest.DownloadState.DownloadCompleted
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
490 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
491
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
492 self.progressBar.setVisible(False)
6085
7e48a0d98cce Added the capability to pause/resume download (Qt 5.10.0/PyQt 5.10.0).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
493 self.pauseButton.setEnabled(False)
7e48a0d98cce Added the capability to pause/resume download (Qt 5.10.0/PyQt 5.10.0).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
494 self.pauseButton.setVisible(False)
4769
2b6f7e026cdc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4768
diff changeset
495 self.stopButton.setEnabled(False)
2b6f7e026cdc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4768
diff changeset
496 self.stopButton.setVisible(False)
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
497 self.openButton.setEnabled(noError)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
498 self.openButton.setVisible(noError)
8563
3c6547443fb2 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8556
diff changeset
499 self.__state = DownloadState.Successful
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
500 self.__updateInfoLabel()
5928
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5920
diff changeset
501 self.__setDateTime()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
502
5928
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5920
diff changeset
503 self.__adjustSize()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
504
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
505 self.statusChanged.emit()
6224
08875555771a Web Browser (NG): some more improvements of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6221
diff changeset
506 self.downloadFinished.emit(True)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
507
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
508 if self.__autoOpen:
6091
7b989321d74c Improved maintainability of the DownloadItem code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6090
diff changeset
509 self.openFile()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
510
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
511 def canceledFileSelect(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
512 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
513 Public method to check, if the user canceled the file selection.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
514
10436
f6881d10e995 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
515 @return flag indicating cancellation
f6881d10e995 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
516 @rtype bool
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
517 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
518 return self.__canceledFileSelect
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
519
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
520 def setIcon(self, icon):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
521 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
522 Public method to set the download icon.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
523
10436
f6881d10e995 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
524 @param icon reference to the icon to be set
f6881d10e995 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
525 @type QIcon
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
526 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
527 self.fileIcon.setPixmap(icon.pixmap(48, 48))
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
528
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
529 def fileName(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
530 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
531 Public method to get the name of the output file.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
532
10436
f6881d10e995 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
533 @return name of the output file
f6881d10e995 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
534 @rtype str
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
535 """
670
bb833c4bcf28 Some fixes to the download manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 668
diff changeset
536 return self.__fileName
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
537
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
538 def absoluteFilePath(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
539 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
540 Public method to get the absolute path of the output file.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
541
10436
f6881d10e995 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
542 @return absolute path of the output file
f6881d10e995 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
543 @rtype str
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
544 """
9566
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
545 return str(pathlib.Path(self.__fileName).resolve())
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
546
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
547 def getData(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
548 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
549 Public method to get the relevant download data.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
550
6091
7b989321d74c Improved maintainability of the DownloadItem code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6090
diff changeset
551 @return dictionary containing the URL, save location, done flag,
7b989321d74c Improved maintainability of the DownloadItem code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6090
diff changeset
552 the URL of the related web page and the date and time of the
7b989321d74c Improved maintainability of the DownloadItem code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6090
diff changeset
553 download
7b989321d74c Improved maintainability of the DownloadItem code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6090
diff changeset
554 @rtype dict of {"URL": QUrl, "Location": str, "Done": bool,
7b989321d74c Improved maintainability of the DownloadItem code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6090
diff changeset
555 "PageURL": QUrl, "Downloaded": QDateTime}
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
556 """
6091
7b989321d74c Improved maintainability of the DownloadItem code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6090
diff changeset
557 return {
7b989321d74c Improved maintainability of the DownloadItem code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6090
diff changeset
558 "URL": self.__url,
9153
506e35e424d5 Finished replacing the use of "QFileInfo()" with Python equivalents.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8881
diff changeset
559 "Location": self.__fileName,
6091
7b989321d74c Improved maintainability of the DownloadItem code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6090
diff changeset
560 "Done": self.downloadedSuccessfully(),
7b989321d74c Improved maintainability of the DownloadItem code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6090
diff changeset
561 "PageURL": self.__pageUrl,
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
562 "Downloaded": self.__downloadedDateTime,
6091
7b989321d74c Improved maintainability of the DownloadItem code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6090
diff changeset
563 }
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
564
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
565 def setData(self, data):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
566 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
567 Public method to set the relevant download data.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
568
6091
7b989321d74c Improved maintainability of the DownloadItem code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6090
diff changeset
569 @param data dictionary containing the URL, save location, done flag,
7b989321d74c Improved maintainability of the DownloadItem code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6090
diff changeset
570 the URL of the related web page and the date and time of the
7b989321d74c Improved maintainability of the DownloadItem code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6090
diff changeset
571 download
7b989321d74c Improved maintainability of the DownloadItem code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6090
diff changeset
572 @type dict of {"URL": QUrl, "Location": str, "Done": bool,
7b989321d74c Improved maintainability of the DownloadItem code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6090
diff changeset
573 "PageURL": QUrl, "Downloaded": QDateTime}
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
574 """
6091
7b989321d74c Improved maintainability of the DownloadItem code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6090
diff changeset
575 self.__url = data["URL"]
7b989321d74c Improved maintainability of the DownloadItem code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6090
diff changeset
576 self.__fileName = data["Location"]
7b989321d74c Improved maintainability of the DownloadItem code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6090
diff changeset
577 self.__pageUrl = data["PageURL"]
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
578
9566
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
579 self.__state = (
9576
be9f8e7e42e0 Corrected some 'wrong' string quotes caused by the Black line merging.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9566
diff changeset
580 DownloadState.Successful if data["Done"] else DownloadState.Cancelled
9566
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
581 )
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
582
6091
7b989321d74c Improved maintainability of the DownloadItem code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6090
diff changeset
583 try:
7b989321d74c Improved maintainability of the DownloadItem code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6090
diff changeset
584 self.__setDateTime(data["Downloaded"])
7b989321d74c Improved maintainability of the DownloadItem code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6090
diff changeset
585 except KeyError:
5928
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5920
diff changeset
586 self.__setDateTime(QDateTime())
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
587
6085
7e48a0d98cce Added the capability to pause/resume download (Qt 5.10.0/PyQt 5.10.0).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
588 self.pauseButton.setEnabled(False)
7e48a0d98cce Added the capability to pause/resume download (Qt 5.10.0/PyQt 5.10.0).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
589 self.pauseButton.setVisible(False)
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
590 self.stopButton.setEnabled(False)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
591 self.stopButton.setVisible(False)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
592 self.progressBar.setVisible(False)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
593
9566
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
594 self.updateButtonsAndLabels()
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
595
5928
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5920
diff changeset
596 self.__adjustSize()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
597
9566
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
598 @pyqtSlot()
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
599 def __setFileLabels(self):
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
600 """
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
601 Private slot to set and format the info label.
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
602 """
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
603 self.infoLabel.setText(self.__fileName)
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
604 if self.downloadedSuccessfully() and not os.path.exists(self.__fileName):
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
605 self.filenameLabel.setText(
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
606 self.tr("{0} - deleted").format(pathlib.Path(self.__fileName).name)
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
607 )
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
608 font = self.filenameLabel.font()
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
609 font.setItalic(True)
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
610 self.filenameLabel.setFont(font)
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
611
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
612 font = self.infoLabel.font()
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
613 font.setItalic(True)
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
614 font.setStrikeOut(True)
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
615 self.infoLabel.setFont(font)
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
616 else:
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
617 self.filenameLabel.setText(pathlib.Path(self.__fileName).name)
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
618
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
619 def getInfoData(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
620 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
621 Public method to get the text of the info label.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
622
10436
f6881d10e995 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
623 @return text of the info label
f6881d10e995 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
624 @rtype str
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
625 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
626 return self.infoLabel.text()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
627
679
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
628 def getPageUrl(self):
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
629 """
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
630 Public method to get the URL of the download page.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
631
10436
f6881d10e995 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
632 @return URL of the download page
f6881d10e995 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
633 @rtype QUrl
679
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
634 """
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
635 return self.__pageUrl
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
636
5928
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5920
diff changeset
637 def __adjustSize(self):
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5920
diff changeset
638 """
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5920
diff changeset
639 Private method to adjust the size of the download item.
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5920
diff changeset
640 """
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5920
diff changeset
641 self.ensurePolished()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
642
5928
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5920
diff changeset
643 msh = self.minimumSizeHint()
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5920
diff changeset
644 self.resize(max(self.width(), msh.width()), msh.height())
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
645
5928
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5920
diff changeset
646 def __setDateTime(self, dateTime=None):
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5920
diff changeset
647 """
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5920
diff changeset
648 Private method to set the download date and time.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
649
5928
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5920
diff changeset
650 @param dateTime date and time to be set
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5920
diff changeset
651 @type QDateTime
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5920
diff changeset
652 """
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5920
diff changeset
653 if dateTime is None:
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5920
diff changeset
654 self.__downloadedDateTime = QDateTime.currentDateTime()
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5920
diff changeset
655 else:
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5920
diff changeset
656 self.__downloadedDateTime = dateTime
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5920
diff changeset
657 if self.__downloadedDateTime.isValid():
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5920
diff changeset
658 labelText = self.__downloadedDateTime.toString("yyyy-MM-dd hh:mm")
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5920
diff changeset
659 self.datetimeLabel.setText(labelText)
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5920
diff changeset
660 self.datetimeLabel.show()
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5920
diff changeset
661 else:
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5920
diff changeset
662 self.datetimeLabel.clear()
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5920
diff changeset
663 self.datetimeLabel.hide()
9566
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
664
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
665 def exists(self):
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
666 """
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
667 Public method to check, if the downloaded file exists.
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
668
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
669 @return flag indicating the existence of the downloaded file
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
670 @rtype bool
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
671 """
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
672 return self.downloadedSuccessfully() and os.path.exists(self.__fileName)
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
673
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
674 def updateButtonsAndLabels(self):
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
675 """
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
676 Public method to update the buttons.
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
677 """
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
678 self.openButton.setEnabled(self.exists())
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
679 self.openButton.setVisible(self.exists())
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
680
d4986df5d2e4 Some bug fixes and snall improvements to the web browser download manager and its parts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
681 self.__setFileLabels()

eric ide

mercurial