From 8d72ab380dbb27db46234c34314ccc47110a3618 Mon Sep 17 00:00:00 2001 From: shekhar-cis Date: Thu, 1 Sep 2022 13:56:47 +0530 Subject: [PATCH] Add separate function to load json --- setup.py | 2 +- src/bitmessagekivy/load_kivy_screens_data.py | 25 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/bitmessagekivy/load_kivy_screens_data.py diff --git a/setup.py b/setup.py index 85c83ce1..3ec478e3 100644 --- a/setup.py +++ b/setup.py @@ -140,7 +140,7 @@ if __name__ == "__main__": package_data={'': [ 'bitmessageqt/*.ui', 'bitmsghash/*.cl', 'sslkeys/*.pem', 'translations/*.ts', 'translations/*.qm', 'default.ini', 'sql/*.sql', - 'images/*.png', 'images/*.ico', 'images/*.icns' + 'images/*.png', 'images/*.ico', 'images/*.icns', 'bitmessagekivy/screens_data.json' ]}, data_files=data_files, ext_modules=[bitmsghash], diff --git a/src/bitmessagekivy/load_kivy_screens_data.py b/src/bitmessagekivy/load_kivy_screens_data.py new file mode 100644 index 00000000..b4132927 --- /dev/null +++ b/src/bitmessagekivy/load_kivy_screens_data.py @@ -0,0 +1,25 @@ +""" + Load kivy screens data from json +""" +import os +import json +import importlib + + +data_screen_dict = {} + + +def load_screen_json(data_file="screens_data.json"): + """Load screens data from json""" + + with open(os.path.join(os.path.dirname(__file__), data_file)) as read_file: + all_data = json.load(read_file) + data_screens = list(all_data.keys()) + + for key in all_data: + if all_data[key]['Import']: + import_data = all_data.get(key)['Import'] + import_to = import_data.split("import")[1].strip() + import_from = import_data.split("import")[0].split('from')[1].strip() + data_screen_dict[import_to] = importlib.import_module(import_from, import_to) + return data_screens, all_data, data_screen_dict, 'success'