Globals/__init__.py

branch
conda
changeset 6682
4326e802ff56
parent 6645
ad476851d7e0
child 6914
5ae038f273c4
--- a/Globals/__init__.py	Tue Jan 29 19:48:13 2019 +0100
+++ b/Globals/__init__.py	Tue Jan 29 20:21:26 2019 +0100
@@ -412,6 +412,32 @@
     return QByteArray(txt)
 
 
+def dataString(size):
+    """
+    Module function to generate a formatted size string.
+    
+    @param size size to be formatted
+    @type int
+    @return formatted data string
+    @rtype str
+    """
+    if size < 1024:
+        return QCoreApplication.translate(
+            "Globals", "{0:.1f} Bytes").format(size)
+    elif size < 1024 * 1024:
+        size /= 1024
+        return QCoreApplication.translate(
+            "Globals", "{0:.1f} KiB").format(size)
+    elif size < 1024 * 1024 * 1024:
+        size /= 1024 * 1024
+        return QCoreApplication.translate(
+            "Globals", "{0:.2f} MiB").format(size)
+    else:
+        size /= 1024 * 1024 * 1024
+        return QCoreApplication.translate(
+            "Globals", "{0:.2f} GiB").format(size)
+
+
 ###############################################################################
 ## functions for converting QSetting return types to valid types
 ###############################################################################

eric ide

mercurial