summaryrefslogtreecommitdiff
path: root/src/main/python/utils/app.py
diff options
context:
space:
mode:
authorBlaine2020-06-09 04:53:48 +0530
committerBlaine2020-06-09 04:53:48 +0530
commit994a0f5c1fb80d0065b8fd3134111ca8790b46bd (patch)
tree420407e3c38806ca9e1461713c31bc890dcf3f89 /src/main/python/utils/app.py
parentbfa6cdf2e858e4a08e7e51dbf6d6cddc8d4183b7 (diff)
downloadChemical-PFD-994a0f5c1fb80d0065b8fd3134111ca8790b46bd.tar.gz
Chemical-PFD-994a0f5c1fb80d0065b8fd3134111ca8790b46bd.tar.bz2
Chemical-PFD-994a0f5c1fb80d0065b8fd3134111ca8790b46bd.zip
conflicted commits
Diffstat (limited to 'src/main/python/utils/app.py')
-rw-r--r--src/main/python/utils/app.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/main/python/utils/app.py b/src/main/python/utils/app.py
index 4ee11c3..aa1ce28 100644
--- a/src/main/python/utils/app.py
+++ b/src/main/python/utils/app.py
@@ -4,6 +4,7 @@ Declare fbs application so that it can be imported in other modules.
from fbs_runtime.application_context.PyQt5 import ApplicationContext
from PyQt5.QtCore import QSettings
+from json import JSONEncoder, dumps, loads
app = ApplicationContext()
settings = QSettings(QSettings.IniFormat, QSettings.UserScope ,"FOSSEE", "Chemical-PFD")
@@ -11,3 +12,37 @@ settings = QSettings(QSettings.IniFormat, QSettings.UserScope ,"FOSSEE", "Chemic
def fileImporter(file):
# Helper function to fetch files from src/main/resources
return app.get_resource(file)
+
+class JSON_Encoder:
+
+ def _encode(obj):
+ if isinstance(obj, dict):
+ ## We'll need to iterate not just the value that default() usually gets passed
+ ## But also iterate manually over each key: value pair in order to trap the keys.
+
+ for key, val in list(obj.items()):
+ if isinstance(val, dict):
+ val = loads(dumps(val, cls=JSON_Typer)) # This, is a EXTREMELY ugly hack..
+ # But it's the only quick way I can think of to
+ # trigger a encoding of sub-dictionaries. (I'm also very tired, yolo!)
+ else:
+ val = JSON_Encoder._encode(val)
+ del(obj[key])
+ obj[JSON_Encoder._encode(key)] = val
+ return obj
+ elif hasattr(obj, '__getstate__'):
+ return obj.__getstate__()
+ elif isinstance(obj, (list, set, tuple)):
+ r = []
+ for item in obj:
+ r.append(loads(dumps(item, cls=JSON_Typer)))
+ return r
+ else:
+ return obj
+
+class JSON_Typer(JSONEncoder):
+ def _encode(self, obj):
+ return JSON_Encoder._encode(obj)
+
+ def encode(self, obj):
+ return super(JSON_Typer, self).encode(self._encode(obj)) \ No newline at end of file