Helpviewer/Download/DownloadUtilities.py

changeset 668
b0061a6f7484
child 791
9ec2ac20e54e
diff -r fdd568d3533d -r b0061a6f7484 Helpviewer/Download/DownloadUtilities.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Helpviewer/Download/DownloadUtilities.py	Sun Oct 10 21:12:43 2010 +0200
@@ -0,0 +1,47 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2010 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+from PyQt4.QtCore import QCoreApplication
+
+def timeString(timeRemaining):
+    """
+    Module function to format the given time.
+    
+    @param timeRemaining time to be formatted (float)
+    @return time string (string)
+    """
+    if timeRemaining > 60:
+        minutes = int(timeRemaining / 60)
+        seconds = int(timeRemaining % 60)
+        remaining = QCoreApplication.translate("DownloadUtilities",
+            "%n:{0:02} minutes remaining""", "", QCoreApplication.UnicodeUTF8, minutes)\
+            .format(seconds)
+    else:
+        seconds = int(timeRemaining)
+        remaining = QCoreApplication.translate("DownloadUtilities",
+            "%n seconds remaining", "", QCoreApplication.UnicodeUTF8, seconds)
+    
+    return remaining
+
+def dataString(size):
+    """
+    Module function to generate a formatted size string.
+    
+    @param size size to be formatted (integer)
+    @return formatted data string (string)
+    """
+    unit = ""
+    if size < 1024:
+        unit = QCoreApplication.translate("DownloadUtilities", "Bytes")
+    elif size < 1024 * 1024:
+        size /= 1024
+        unit = QCoreApplication.translate("DownloadUtilities", "KiB")
+    elif size < 1024 * 1024 * 1024:
+        size /= 1024 * 1024
+        unit = QCoreApplication.translate("DownloadUtilities", "MiB")
+    else:
+        size /= 1024 * 1024 * 1024
+        unit = QCoreApplication.translate("DownloadUtilities", "GiB")
+    return "{0:.1f} {1}".format(size, unit)

eric ide

mercurial