Helpviewer/Download/DownloadItem.py

changeset 945
8cd4d08fa9f6
parent 882
34b86be88bf0
child 978
11f8adbcac97
equal deleted inserted replaced
944:1b59c4ba121e 945:8cd4d08fa9f6
20 20
21 from .DownloadUtilities import timeString, dataString 21 from .DownloadUtilities import timeString, dataString
22 22
23 import UI.PixmapCache 23 import UI.PixmapCache
24 import Preferences 24 import Preferences
25
25 26
26 class DownloadItem(QWidget, Ui_DownloadItem): 27 class DownloadItem(QWidget, Ui_DownloadItem):
27 """ 28 """
28 Class implementing a widget controlling a download. 29 Class implementing a widget controlling a download.
29 30
33 """ 34 """
34 statusChanged = pyqtSignal() 35 statusChanged = pyqtSignal()
35 downloadFinished = pyqtSignal() 36 downloadFinished = pyqtSignal()
36 progress = pyqtSignal(int, int) 37 progress = pyqtSignal(int, int)
37 38
38 def __init__(self, reply = None, requestFilename = False, webPage = None, 39 def __init__(self, reply=None, requestFilename=False, webPage=None,
39 download = False, parent = None): 40 download=False, parent=None):
40 """ 41 """
41 Constructor 42 Constructor
42 43
43 @param reply reference to the network reply object (QNetworkReply) 44 @param reply reference to the network reply object (QNetworkReply)
44 @param requestFilename flag indicating to ask the user for a filename (boolean) 45 @param requestFilename flag indicating to ask the user for a filename (boolean)
45 @param webPage reference to the web page object the download originated 46 @param webPage reference to the web page object the download originated
46 from (QWebPage) 47 from (QWebPage)
47 @param download flag indicating a download operation (boolean) 48 @param download flag indicating a download operation (boolean)
48 @param parent reference to the parent widget (QWidget) 49 @param parent reference to the parent widget (QWidget)
49 """ 50 """
50 QWidget.__init__(self, parent) 51 QWidget.__init__(self, parent)
86 if not requestFilename: 87 if not requestFilename:
87 self.__requestFilename = Preferences.getUI("RequestDownloadFilename") 88 self.__requestFilename = Preferences.getUI("RequestDownloadFilename")
88 89
89 self.__initialize() 90 self.__initialize()
90 91
91 def __initialize(self, tryAgain = False): 92 def __initialize(self, tryAgain=False):
92 """ 93 """
93 Private method to (re)initialize the widget. 94 Private method to (re)initialize the widget.
94 95
95 @param tryAgain flag indicating a retry (boolean) 96 @param tryAgain flag indicating a retry (boolean)
96 """ 97 """
284 reply = nam.get(QNetworkRequest(self.__url)) 285 reply = nam.get(QNetworkRequest(self.__url))
285 if self.__output.exists(): 286 if self.__output.exists():
286 self.__output.remove() 287 self.__output.remove()
287 self.__output = QFile() 288 self.__output = QFile()
288 self.__reply = reply 289 self.__reply = reply
289 self.__initialize(tryAgain = True) 290 self.__initialize(tryAgain=True)
290 self.statusChanged.emit() 291 self.statusChanged.emit()
291 292
292 @pyqtSlot() 293 @pyqtSlot()
293 def on_stopButton_clicked(self): 294 def on_stopButton_clicked(self):
294 """ 295 """
475 if bytesTotal > 0: 476 if bytesTotal > 0:
476 remaining = timeString(timeRemaining) 477 remaining = timeString(timeRemaining)
477 478
478 info = self.trUtf8("{0} of {1} ({2}/sec) - {3}")\ 479 info = self.trUtf8("{0} of {1} ({2}/sec) - {3}")\
479 .format( 480 .format(
480 dataString(self.__bytesReceived), 481 dataString(self.__bytesReceived),
481 bytesTotal == -1 and self.trUtf8("?") \ 482 bytesTotal == -1 and self.trUtf8("?") \
482 or dataString(bytesTotal), 483 or dataString(bytesTotal),
483 dataString(int(speed)), 484 dataString(int(speed)),
484 remaining) 485 remaining)
485 else: 486 else:
486 if self.__bytesReceived == bytesTotal or bytesTotal == -1: 487 if self.__bytesReceived == bytesTotal or bytesTotal == -1:
487 info = self.trUtf8("{0} downloaded")\ 488 info = self.trUtf8("{0} downloaded")\
488 .format(dataString(self.__output.size())) 489 .format(dataString(self.__output.size()))
489 else: 490 else:
490 info = self.trUtf8("{0} of {1} - Stopped")\ 491 info = self.trUtf8("{0} of {1} - Stopped")\
491 .format(dataString(self.__bytesReceived), 492 .format(dataString(self.__bytesReceived),
492 dataString(bytesTotal)) 493 dataString(bytesTotal))
493 self.infoLabel.setText(info) 494 self.infoLabel.setText(info)
494 495
495 def downloading(self): 496 def downloading(self):
496 """ 497 """
576 Public method to get the relevant download data. 577 Public method to get the relevant download data.
577 578
578 @return tuple of URL, save location, flag and the 579 @return tuple of URL, save location, flag and the
579 URL of the related web page (QUrl, string, boolean,QUrl) 580 URL of the related web page (QUrl, string, boolean,QUrl)
580 """ 581 """
581 return (self.__url, QFileInfo(self.__fileName).filePath(), 582 return (self.__url, QFileInfo(self.__fileName).filePath(),
582 self.downloadedSuccessfully(), self.__pageUrl) 583 self.downloadedSuccessfully(), self.__pageUrl)
583 584
584 def setData(self, data): 585 def setData(self, data):
585 """ 586 """
586 Public method to set the relevant download data. 587 Public method to set the relevant download data.

eric ide

mercurial