eric6/Helpviewer/Download/DownloadUtilities.py

changeset 6942
2602857055c5
parent 6645
ad476851d7e0
equal deleted inserted replaced
6941:f99d60d6b59b 6942:2602857055c5
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2010 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing some utility functions for the Download package.
8 """
9
10 from __future__ import unicode_literals
11
12 from PyQt5.QtCore import QCoreApplication
13
14 from Globals import translate
15
16
17 def timeString(timeRemaining):
18 """
19 Module function to format the given time.
20
21 @param timeRemaining time to be formatted (float)
22 @return time string (string)
23 """
24 if timeRemaining > 60:
25 minutes = int(timeRemaining / 60)
26 seconds = int(timeRemaining % 60)
27 remaining = translate(
28 "DownloadUtilities",
29 "%n:{0:02} minutes remaining", "",
30 minutes).format(seconds)
31 else:
32 seconds = int(timeRemaining)
33 remaining = translate(
34 "DownloadUtilities",
35 "%n seconds remaining", "", seconds)
36
37 return remaining
38
39
40 def dataString(size):
41 """
42 Module function to generate a formatted size string.
43
44 @param size size to be formatted (integer)
45 @return formatted data string (string)
46 """
47 unit = ""
48 if size < 1024:
49 unit = QCoreApplication.translate("DownloadUtilities", "Bytes")
50 elif size < 1024 * 1024:
51 size /= 1024
52 unit = QCoreApplication.translate("DownloadUtilities", "KiB")
53 elif size < 1024 * 1024 * 1024:
54 size /= 1024 * 1024
55 unit = QCoreApplication.translate("DownloadUtilities", "MiB")
56 else:
57 size /= 1024 * 1024 * 1024
58 unit = QCoreApplication.translate("DownloadUtilities", "GiB")
59 return "{0:.1f} {1}".format(size, unit)

eric ide

mercurial