src/eric7/WebBrowser/Download/DownloadUtilities.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9653
e67609152c5e
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
11 11
12 12
13 def timeString(timeRemaining): 13 def timeString(timeRemaining):
14 """ 14 """
15 Module function to format the given time. 15 Module function to format the given time.
16 16
17 @param timeRemaining time to be formatted 17 @param timeRemaining time to be formatted
18 @type float 18 @type float
19 @return time string 19 @return time string
20 @rtype str 20 @rtype str
21 """ 21 """
22 if timeRemaining < 10: 22 if timeRemaining < 10:
23 return QCoreApplication.translate( 23 return QCoreApplication.translate("DownloadUtilities", "few seconds remaining")
24 "DownloadUtilities", "few seconds remaining") 24 elif timeRemaining < 60: # < 1 minute
25 elif timeRemaining < 60: # < 1 minute
26 seconds = int(timeRemaining) 25 seconds = int(timeRemaining)
27 return QCoreApplication.translate( 26 return QCoreApplication.translate(
28 "DownloadUtilities", "%n seconds remaining", "", seconds) 27 "DownloadUtilities", "%n seconds remaining", "", seconds
28 )
29 elif timeRemaining < 3600: # < 1 hour 29 elif timeRemaining < 3600: # < 1 hour
30 minutes = int(timeRemaining / 60) 30 minutes = int(timeRemaining / 60)
31 return QCoreApplication.translate( 31 return QCoreApplication.translate(
32 "DownloadUtilities", "%n minutes remaining", "", minutes) 32 "DownloadUtilities", "%n minutes remaining", "", minutes
33 )
33 else: 34 else:
34 hours = int(timeRemaining / 3600) 35 hours = int(timeRemaining / 3600)
35 return QCoreApplication.translate( 36 return QCoreApplication.translate(
36 "DownloadUtilities", "%n hours remaining", "", hours) 37 "DownloadUtilities", "%n hours remaining", "", hours
38 )
37 39
38 40
39 def dataString(size): 41 def dataString(size):
40 """ 42 """
41 Module function to generate a formatted size string. 43 Module function to generate a formatted size string.
42 44
43 @param size size to be formatted 45 @param size size to be formatted
44 @type int 46 @type int
45 @return formatted data string 47 @return formatted data string
46 @rtype str 48 @rtype str
47 """ 49 """
48 if size < 1024: 50 if size < 1024:
49 return QCoreApplication.translate( 51 return QCoreApplication.translate("DownloadUtilities", "{0:.1f} Bytes").format(
50 "DownloadUtilities", "{0:.1f} Bytes").format(size) 52 size
53 )
51 elif size < 1024 * 1024: 54 elif size < 1024 * 1024:
52 size /= 1024 55 size /= 1024
53 return QCoreApplication.translate( 56 return QCoreApplication.translate("DownloadUtilities", "{0:.1f} KiB").format(
54 "DownloadUtilities", "{0:.1f} KiB").format(size) 57 size
58 )
55 elif size < 1024 * 1024 * 1024: 59 elif size < 1024 * 1024 * 1024:
56 size /= 1024 * 1024 60 size /= 1024 * 1024
57 return QCoreApplication.translate( 61 return QCoreApplication.translate("DownloadUtilities", "{0:.2f} MiB").format(
58 "DownloadUtilities", "{0:.2f} MiB").format(size) 62 size
63 )
59 else: 64 else:
60 size /= 1024 * 1024 * 1024 65 size /= 1024 * 1024 * 1024
61 return QCoreApplication.translate( 66 return QCoreApplication.translate("DownloadUtilities", "{0:.2f} GiB").format(
62 "DownloadUtilities", "{0:.2f} GiB").format(size) 67 size
68 )
63 69
64 70
65 def speedString(speed): 71 def speedString(speed):
66 """ 72 """
67 Module function to generate a formatted speed string. 73 Module function to generate a formatted speed string.
68 74
69 @param speed speed to be formatted 75 @param speed speed to be formatted
70 @type float 76 @type float
71 @return formatted speed string 77 @return formatted speed string
72 @rtype str 78 @rtype str
73 """ 79 """
74 if speed < 0: 80 if speed < 0:
75 return QCoreApplication.translate("DownloadUtilities", "Unknown speed") 81 return QCoreApplication.translate("DownloadUtilities", "Unknown speed")
76 82
77 speed /= 1024 # kB 83 speed /= 1024 # kB
78 if speed < 1024: 84 if speed < 1024:
79 return QCoreApplication.translate( 85 return QCoreApplication.translate("DownloadUtilities", "{0:.1f} KiB/s").format(
80 "DownloadUtilities", "{0:.1f} KiB/s").format(speed) 86 speed
81 87 )
82 speed /= 1024 # MB 88
89 speed /= 1024 # MB
83 if speed < 1024: 90 if speed < 1024:
84 return QCoreApplication.translate( 91 return QCoreApplication.translate("DownloadUtilities", "{0:.2f} MiB/s").format(
85 "DownloadUtilities", "{0:.2f} MiB/s").format(speed) 92 speed
86 93 )
87 speed /= 1024 # GB 94
95 speed /= 1024 # GB
88 if speed < 1024: 96 if speed < 1024:
89 return QCoreApplication.translate( 97 return QCoreApplication.translate("DownloadUtilities", "{0:.2f} GiB/s").format(
90 "DownloadUtilities", "{0:.2f} GiB/s").format(speed) 98 speed
91 99 )
100
92 return "" 101 return ""

eric ide

mercurial