Globals/__init__.py

changeset 4241
545629046c45
parent 4021
195a471c327b
child 4343
afe0da217745
--- a/Globals/__init__.py	Sun Apr 26 16:22:42 2015 +0200
+++ b/Globals/__init__.py	Fri May 01 11:27:32 2015 +0200
@@ -12,7 +12,7 @@
 import sys
 import os
 
-from PyQt5.QtCore import QDir, QLibraryInfo
+from PyQt5.QtCore import QDir, QLibraryInfo, QByteArray
 
 # names of the various settings objects
 settingsNameOrganization = "Eric6"
@@ -241,3 +241,64 @@
                     interpreters.append(interpreter)
     
     return interpreters
+
+
+###############################################################################
+## functions for converting QSetting return types to valid types
+###############################################################################
+
+
+def toBool(value):
+    """
+    Module function to convert a value to bool.
+    
+    @param value value to be converted
+    @return converted data
+    """
+    if value in ["true", "1", "True"]:
+        return True
+    elif value in ["false", "0", "False"]:
+        return False
+    else:
+        return bool(value)
+
+
+def toList(value):
+    """
+    Module function to convert a value to a list.
+    
+    @param value value to be converted
+    @return converted data
+    """
+    if value is None:
+        return []
+    elif not isinstance(value, list):
+        return [value]
+    else:
+        return value
+
+
+def toByteArray(value):
+    """
+    Module function to convert a value to a byte array.
+    
+    @param value value to be converted
+    @return converted data
+    """
+    if value is None:
+        return QByteArray()
+    else:
+        return value
+
+
+def toDict(value):
+    """
+    Module function to convert a value to a dictionary.
+    
+    @param value value to be converted
+    @return converted data
+    """
+    if value is None:
+        return {}
+    else:
+        return value

eric ide

mercurial