--- a/WebBrowser/Download/DownloadItem.py Thu Jan 18 11:10:57 2018 +0100 +++ b/WebBrowser/Download/DownloadItem.py Thu Jan 18 18:57:40 2018 +0100 @@ -64,10 +64,15 @@ self.progressBar.setMaximum(0) + self.pauseButton.setIcon(UI.PixmapCache.getIcon("pause.png")) self.stopButton.setIcon(UI.PixmapCache.getIcon("stopLoading.png")) self.openButton.setIcon(UI.PixmapCache.getIcon("open.png")) self.openButton.setEnabled(False) self.openButton.setVisible(False) + if not hasattr(QWebEngineDownloadItem, "pause"): + # pause/resume was defined in Qt 5.10.0 / PyQt 5.10.0 + self.pauseButton.setEnabled(False) + self.pauseButton.setVisible(False) self.__state = DownloadItem.Downloading @@ -314,13 +319,18 @@ name += '.' + endName return name, origName - def __open(self): - """ - Private slot to open the downloaded file. + @pyqtSlot(bool) + def on_pauseButton_clicked(self, checked): """ - info = QFileInfo(self.__fileName) - url = QUrl.fromLocalFile(info.absoluteFilePath()) - QDesktopServices.openUrl(url) + Private slot to pause the download. + + @param checked flag indicating the state of the button + @type bool + """ + if checked: + self.__downloadItem.pause() + else: + self.__downloadItem.resume() @pyqtSlot() def on_stopButton_clicked(self): @@ -338,6 +348,8 @@ self.stopButton.setVisible(False) self.openButton.setEnabled(False) self.openButton.setVisible(False) + self.pauseButton.setEnabled(False) + self.pauseButton.setVisible(False) self.setUpdatesEnabled(True) self.__state = DownloadItem.DownloadCancelled self.__downloadItem.cancel() @@ -508,6 +520,8 @@ QWebEngineDownloadItem.DownloadCompleted) self.progressBar.setVisible(False) + self.pauseButton.setEnabled(False) + self.pauseButton.setVisible(False) self.stopButton.setEnabled(False) self.stopButton.setVisible(False) self.openButton.setEnabled(noError) @@ -522,7 +536,7 @@ self.downloadFinished.emit() if self.__autoOpen: - self.__open() + self.openFile() def canceledFileSelect(self): """ @@ -560,41 +574,49 @@ """ Public method to get the relevant download data. - @return tuple of URL, save location, flag, the - URL of the related web page and the date and time - of the download - @rtype tuple of (QUrl, str, bool, QUrl, QDateTime) + @return dictionary containing the URL, save location, done flag, + the URL of the related web page and the date and time of the + download + @rtype dict of {"URL": QUrl, "Location": str, "Done": bool, + "PageURL": QUrl, "Downloaded": QDateTime} """ - return (self.__url, QFileInfo(self.__fileName).filePath(), - self.downloadedSuccessfully(), self.__pageUrl, - self.__downloadedDateTime) + return { + "URL": self.__url, + "Location": QFileInfo(self.__fileName).filePath(), + "Done": self.downloadedSuccessfully(), + "PageURL": self.__pageUrl, + "Downloaded": self.__downloadedDateTime + } def setData(self, data): """ Public method to set the relevant download data. - @param data tuple of URL, save location, flag, the - URL of the related web page and the date and time - of the download - @type QUrl, str, bool, QUrl, QDateTime + @param data dictionary containing the URL, save location, done flag, + the URL of the related web page and the date and time of the + download + @type dict of {"URL": QUrl, "Location": str, "Done": bool, + "PageURL": QUrl, "Downloaded": QDateTime} """ - self.__url = data[0] - self.__fileName = data[1] - self.__pageUrl = data[3] + self.__url = data["URL"] + self.__fileName = data["Location"] + self.__pageUrl = data["PageURL"] self.filenameLabel.setText(QFileInfo(self.__fileName).fileName()) self.infoLabel.setText(self.__fileName) - if len(data) == 5: - self.__setDateTime(data[4]) - else: + try: + self.__setDateTime(data["Downloaded"]) + except KeyError: self.__setDateTime(QDateTime()) + self.pauseButton.setEnabled(False) + self.pauseButton.setVisible(False) self.stopButton.setEnabled(False) self.stopButton.setVisible(False) - self.openButton.setEnabled(data[2]) - self.openButton.setVisible(data[2]) - if data[2]: + self.openButton.setEnabled(data["Done"]) + self.openButton.setVisible(data["Done"]) + if data["Done"]: self.__state = DownloadItem.DownloadSuccessful else: self.__state = DownloadItem.DownloadCancelled