diff --git a/src/bitmessagekivy/baseclass/draft.py b/src/bitmessagekivy/baseclass/draft.py index 44dd53a3..8bc82ad2 100644 --- a/src/bitmessagekivy/baseclass/draft.py +++ b/src/bitmessagekivy/baseclass/draft.py @@ -118,7 +118,7 @@ class Draft(Screen, HelperDraft): listItem.secondary_text = item["text"] listItem.theme_text_color = "Custom" listItem.text_color = ThemeClsColor - message_row.ids.avater_img.source = os.path.join(state.imageDir, 'avatar.png') + message_row.ids.avater_img.source = os.path.join(state.imageDir, 'draft-avatar.png') listItem.bind(on_release=partial( self.draft_detail, item['ackdata'], message_row)) message_row.ids.time_tag.text = str(ShowTimeHistoy(item['senttime'])) diff --git a/src/bitmessagekivy/baseclass/maildetail.py b/src/bitmessagekivy/baseclass/maildetail.py index 784ecb24..367f565b 100644 --- a/src/bitmessagekivy/baseclass/maildetail.py +++ b/src/bitmessagekivy/baseclass/maildetail.py @@ -133,7 +133,7 @@ class MailDetail(Screen): # pylint: disable=too-many-instance-attributes if len(data[0]) == 7: self.status = data[0][4] self.time_tag = ShowTimeHistoy(data[0][4]) if state.detailPageType == 'inbox' else ShowTimeHistoy(data[0][6]) - self.avatarImg = os.path.join(state.imageDir, 'avatar.png') if self.kivy_state.detailPageType == 'draft' else \ + self.avatarImg = os.path.join(state.imageDir, 'draft-avatar.png') if self.kivy_state.detailPageType == 'draft' else \ (os.path.join(state.imageDir, 'text_images', '{0}.png'.format(avatarImageFirstLetter(self.subject.strip())))) self.timeinseconds = data[0][4] if state.detailPageType == 'inbox' else data[0][6] diff --git a/src/bitmessagekivy/kv/msg_composer.kv b/src/bitmessagekivy/kv/msg_composer.kv index 8619af68..02610c8b 100644 --- a/src/bitmessagekivy/kv/msg_composer.kv +++ b/src/bitmessagekivy/kv/msg_composer.kv @@ -38,7 +38,7 @@ CustomSpinner: id: btn background_color: app.theme_cls.primary_dark - values: app.identity_list + # values: app.identity_list on_text: root.auto_fill_fromaddr() if self.text != 'Select' else '' option_cls: Factory.get("ComposerSpinnerOption") #background_color: color_button if self.state == 'normal' else color_button_pressed diff --git a/src/bitmessagekivy/main.kv b/src/bitmessagekivy/main.kv index 231f0dbe..34311f63 100644 --- a/src/bitmessagekivy/main.kv +++ b/src/bitmessagekivy/main.kv @@ -137,7 +137,7 @@ #text: app.tr._('Hello World') icon: 'email-open' divider: None - on_release: app.root.ids.scr_mngr.current = 'inbox' + on_release: app.set_screen('inbox') on_release: root.parent.set_state() on_press: app.load_screen(self) NavigationItem: diff --git a/src/bitmessagekivy/mpybit.py b/src/bitmessagekivy/mpybit.py index a40a4861..8efbb6fe 100644 --- a/src/bitmessagekivy/mpybit.py +++ b/src/bitmessagekivy/mpybit.py @@ -9,13 +9,15 @@ Bitmessage android(mobile) interface """ +import importlib +import json from bitmessagekivy.get_platform import platform import os from bitmessagekivy import identiconGeneration from bitmessagekivy import kivy_helper_search from bitmessagekivy.uikivysignaler import UIkivySignaler from bmconfigparser import BMConfigParser -# from debug import logger +from debug import logger from functools import partial from helper_sql import sqlExecute, sqlQuery from kivymd.app import MDApp @@ -57,7 +59,8 @@ from kivy.lang import Observable import ast from bitmessagekivy.baseclass.common import toast - +from bitmessagekivy.baseclass.login import * +from bitmessagekivy.baseclass.popup import * from qr_scanner.zbarcam import ZBarCam from pyzbar.pyzbar import ZBarSymbol @@ -83,13 +86,46 @@ elif platform == "android": t = Toast.makeText(context, text, length) t.show() +data_screen_dict = {} -with open(os.path.join(os.path.dirname(__file__), "screens_data.json")) as read_file: - all_data = ast.literal_eval(read_file.read()) - data_screens = list(all_data.keys()) +def load_screen_json(data_file="screens_data.json"): + """Load screens data from json""" -for modules in data_screens: - exec(all_data[modules]['Import']) + 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()) + + # global data_screen_dict + 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, 'success' + + + +# data_screen_dict['Trash'].Trash() +# with open(os.path.join(os.path.dirname(__file__), "screens_data.json")) as read_file: +# # all_data = ast.literal_eval(read_file.read()) +# 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() +# exec_import = importlib.import_module(import_from, import_to) +# exec_import +# import pdb; pdb.set_trace() + + # importlib.import_module("pybitmessage.bitmessagekivy.baseclass.trash", "Trash") + +# for modules in data_screens: +# exec(all_data[modules]['Import']) +# import pdb; pdb.set_trace() # pylint: disable=too-few-public-methods,too-many-arguments,attribute-defined-outside-init @@ -208,18 +244,25 @@ class CustomSpinner(Spinner): if BMConfigParser().get(str(addr), 'enabled') == 'true') +def get_identity_list(): + identity_list = ListProperty( + addr for addr in BMConfigParser().addresses() + if BMConfigParser().get(str(addr), 'enabled') == 'true' + ) + return identity_list + class NavigateApp(MDApp): """Navigation Layout of class""" # pylint: disable=too-many-public-methods,inconsistent-return-statements # theme_cls = ThemeManager() def __init__(self): super(NavigateApp, self).__init__() + self.data_screens, self.all_data, response = load_screen_json() self.kivy_state_obj = KivyStateVariables() previous_date = ObjectProperty() obj_1 = ObjectProperty() - identity_list = ListProperty(addr for addr in BMConfigParser().addresses() - if BMConfigParser().get(str(addr), 'enabled') == 'true') + identity_list = get_identity_list() nav_drawer = ObjectProperty() state.screen_density = Window.size window_size = state.screen_density @@ -236,13 +279,14 @@ class NavigateApp(MDApp): def build(self): """Method builds the widget""" - for kv in data_screens: + # for kv in self.data_screens: + for kv in self.data_screens: Builder.load_file( os.path.join( os.path.dirname(__file__), 'kv', # f'{all_data[kv]["kv_string"]}.kv', - '{0}.kv'.format(all_data[kv]["kv_string"]), + '{0}.kv'.format(self.all_data[kv]["kv_string"]), ) ) # self.obj_1 = AddressBook() @@ -314,13 +358,14 @@ class NavigateApp(MDApp): self.root.ids.sc4.loadSent(state.association) self.root.ids.sc16.clear_widgets() - self.root.ids.sc16.add_widget(Draft()) + self.root.ids.sc16.add_widget(data_screen_dict['Draft'].Draft()) self.root.ids.sc5.clear_widgets() - self.root.ids.sc5.add_widget(Trash()) + # import pdb; pdb.set_trace() + self.root.ids.sc5.add_widget(data_screen_dict['Trash'].Trash()) self.root.ids.sc17.clear_widgets() - self.root.ids.sc17.add_widget(Allmails()) + self.root.ids.sc17.add_widget(data_screen_dict['Allmails'].Allmails()) self.root.ids.id_myaddress.ids.ml.clear_widgets() self.root.ids.id_myaddress.init_ui() @@ -849,7 +894,7 @@ class NavigateApp(MDApp): self.root.ids.sc1.children[1].active = False elif instance.text == 'All Mails': self.root.ids.sc17.clear_widgets() - self.root.ids.sc17.add_widget(Allmails()) + self.root.ids.sc17.add_widget(data_screen_dict['Allmails'].Allmails()) try: self.root.ids.sc17.children[1].active = False except Exception: @@ -858,7 +903,7 @@ class NavigateApp(MDApp): # self.root.ids.sc5.ids.ml.clear_widgets() # self.root.ids.sc5.init_ui(0) self.root.ids.sc5.clear_widgets() - self.root.ids.sc5.add_widget(Trash()) + self.root.ids.sc5.add_widget(data_screen_dict['Trash'].Trash()) try: self.root.ids.sc5.children[1].active = False except Exception as e: @@ -963,7 +1008,7 @@ class NavigateApp(MDApp): def initiate_purchase(self, method_name): """initiate_purchase module""" - print("Purchasing {} through {}".format(self.product_id, method_name)) + logger.debug("Purchasing %s through %s", self.product_id, method_name) def _after_scan(self, text): # if platform == 'android': diff --git a/src/bitmessagekivy/screens_data.json b/src/bitmessagekivy/screens_data.json index bedda239..6ea6a117 100644 --- a/src/bitmessagekivy/screens_data.json +++ b/src/bitmessagekivy/screens_data.json @@ -2,77 +2,77 @@ "Inbox": { "kv_string": "inbox", "name_screen": "inbox", - "Import": "from bitmessagekivy.baseclass.inbox import Inbox", + "Import": "from bitmessagekivy.baseclass.inbox import Inbox" }, "Sent": { "kv_string": "sent", "name_screen": "sent", - "Import": "from bitmessagekivy.baseclass.sent import Sent", + "Import": "from bitmessagekivy.baseclass.sent import Sent" }, "Draft": { "kv_string": "draft", "name_screen": "draft", - "Import": "from bitmessagekivy.baseclass.draft import Draft", + "Import": "from bitmessagekivy.baseclass.draft import Draft" }, "Trash": { "kv_string": "trash", "name_screen": "trash", - "Import": "from bitmessagekivy.baseclass.trash import Trash", + "Import": "from bitmessagekivy.baseclass.trash import Trash" }, "All Mails": { "kv_string": "allmails", "name_screen": "allmails", - "Import": "from bitmessagekivy.baseclass.allmail import Allmails", + "Import": "from bitmessagekivy.baseclass.allmail import Allmails" }, "Address Book": { "kv_string": "addressbook", "name_screen": "addressbook", - "Import": "from bitmessagekivy.baseclass.addressbook import AddressBook", + "Import": "from bitmessagekivy.baseclass.addressbook import AddressBook" }, "Settings": { "kv_string": "settings", "name_screen": "set", - "Import": "from bitmessagekivy.baseclass.settings import Setting", + "Import": "from bitmessagekivy.baseclass.settings import Setting" }, "Payment": { "kv_string": "payment", "name_screen": "payment", - "Import": "from bitmessagekivy.baseclass.payment import Payment", + "Import": "from bitmessagekivy.baseclass.payment import Payment" }, "Network status": { "kv_string": "network", "name_screen": "networkstat", - "Import": "from bitmessagekivy.baseclass.network import NetworkStat", + "Import": "from bitmessagekivy.baseclass.network import NetworkStat" }, "My addresses": { "kv_string": "myaddress", "name_screen": "myaddress", - "Import": "from bitmessagekivy.baseclass.myaddress import MyAddress", + "Import": "from bitmessagekivy.baseclass.myaddress import MyAddress" }, "MailDetail": { "kv_string": "maildetail", "name_screen": "mailDetail", - "Import": "from bitmessagekivy.baseclass.maildetail import MailDetail", + "Import": "from bitmessagekivy.baseclass.maildetail import MailDetail" }, "Create": { "kv_string": "msg_composer", "name_screen": "create", - "Import": "from bitmessagekivy.baseclass.msg_composer import Create", + "Import": "from bitmessagekivy.baseclass.msg_composer import Create" }, "Login": { "kv_string": "login", - "Import": "from bitmessagekivy.baseclass.login import *", + "Import": "from bitmessagekivy.baseclass.login import *" }, "Scanner": { "kv_string": "scan_screen", - "Import": "from bitmessagekivy.baseclass.scan_screen import ScanScreen", + "Import": "from bitmessagekivy.baseclass.scan_screen import ScanScreen" }, "Popups": { "kv_string": "popup", - "Import": "from bitmessagekivy.baseclass.popup import *", + "Import": "from bitmessagekivy.baseclass.popup import *" }, "Qrcode": { "kv_string": "qrcode", - "Import": "from bitmessagekivy.baseclass.qrcode import ShowQRCode", - }, + "Import": "from bitmessagekivy.baseclass.qrcode import ShowQRCode" + } } diff --git a/src/images/kivy/avatar.png b/src/images/kivy/avatar.png deleted file mode 100644 index b006bfa2..00000000 Binary files a/src/images/kivy/avatar.png and /dev/null differ diff --git a/src/images/kivy/draft-avatar.png b/src/images/kivy/draft-avatar.png new file mode 100644 index 00000000..9fc38f31 Binary files /dev/null and b/src/images/kivy/draft-avatar.png differ