eric6/WebBrowser/Download/DownloadItem.py

branch
maintenance
changeset 8273
698ae46f40a4
parent 8176
31965986ecd1
parent 8260
2161475d9639
equal deleted inserted replaced
8190:fb0ef164f536 8273:698ae46f40a4
53 @param pageUrl URL of the calling page 53 @param pageUrl URL of the calling page
54 @type QUrl 54 @type QUrl
55 @param parent reference to the parent widget 55 @param parent reference to the parent widget
56 @type QWidget 56 @type QWidget
57 """ 57 """
58 super(DownloadItem, self).__init__(parent) 58 super().__init__(parent)
59 self.setupUi(self) 59 self.setupUi(self)
60 60
61 p = self.infoLabel.palette() 61 p = self.infoLabel.palette()
62 p.setColor(QPalette.ColorRole.Text, Qt.GlobalColor.darkGray) 62 p.setColor(QPalette.ColorRole.Text, Qt.GlobalColor.darkGray)
63 self.infoLabel.setPalette(p) 63 self.infoLabel.setPalette(p)
243 243
244 self.__fileName = fileName 244 self.__fileName = fileName
245 245
246 # check file path for saving 246 # check file path for saving
247 saveDirPath = QFileInfo(self.__fileName).dir() 247 saveDirPath = QFileInfo(self.__fileName).dir()
248 if not saveDirPath.exists(): 248 if (
249 if not saveDirPath.mkpath(saveDirPath.absolutePath()): 249 not saveDirPath.exists() and
250 self.progressBar.setVisible(False) 250 not saveDirPath.mkpath(saveDirPath.absolutePath())
251 self.on_stopButton_clicked() 251 ):
252 self.infoLabel.setText(self.tr( 252 self.progressBar.setVisible(False)
253 "Download directory ({0}) couldn't be created.") 253 self.on_stopButton_clicked()
254 .format(saveDirPath.absolutePath())) 254 self.infoLabel.setText(self.tr(
255 self.__setDateTime() 255 "Download directory ({0}) couldn't be created.")
256 return 256 .format(saveDirPath.absolutePath()))
257 self.__setDateTime()
258 return
257 259
258 self.filenameLabel.setText(QFileInfo(self.__fileName).fileName()) 260 self.filenameLabel.setText(QFileInfo(self.__fileName).fileName())
259 261
260 def __saveFileName(self, directory): 262 def __saveFileName(self, directory):
261 """ 263 """
396 398
397 if self.bytesTotal() == -1: 399 if self.bytesTotal() == -1:
398 return -1.0 400 return -1.0
399 401
400 cSpeed = self.currentSpeed() 402 cSpeed = self.currentSpeed()
401 if cSpeed != 0: 403 timeRemaining = (
402 timeRemaining = (self.bytesTotal() - self.bytesReceived()) / cSpeed 404 (self.bytesTotal() - self.bytesReceived()) / cSpeed
403 else: 405 if cSpeed != 0 else
404 timeRemaining = 1 406 1
407 )
405 408
406 # ETA should never be 0 409 # ETA should never be 0
407 if timeRemaining == 0: 410 if timeRemaining == 0:
408 timeRemaining = 1 411 timeRemaining = 1
409 412
445 dataString(bytesTotal), 448 dataString(bytesTotal),
446 speedString(speed), 449 speedString(speed),
447 remaining 450 remaining
448 ) 451 )
449 else: 452 else:
450 if self.__bytesReceived == bytesTotal or bytesTotal == -1: 453 if bytesTotal in (self.__bytesReceived, -1):
451 info = self.tr( 454 info = self.tr(
452 "{0} downloaded" 455 "{0} downloaded"
453 ).format(dataString(self.__bytesReceived)) 456 ).format(dataString(self.__bytesReceived))
454 else: 457 else:
455 info = self.tr( 458 info = self.tr(

eric ide

mercurial