Add a dict to hold the imports and access Allmails(), Draft() and Trash() with dict and import the * from login and popup

This commit is contained in:
shekhar-cis 2022-08-18 15:55:42 +05:30
parent e47e61741d
commit cf4161eab3
Signed by untrusted user: shekhar-cis
GPG Key ID: F4F00AB04E83F9A7
8 changed files with 83 additions and 38 deletions

View File

@ -118,7 +118,7 @@ class Draft(Screen, HelperDraft):
listItem.secondary_text = item["text"] listItem.secondary_text = item["text"]
listItem.theme_text_color = "Custom" listItem.theme_text_color = "Custom"
listItem.text_color = ThemeClsColor 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( listItem.bind(on_release=partial(
self.draft_detail, item['ackdata'], message_row)) self.draft_detail, item['ackdata'], message_row))
message_row.ids.time_tag.text = str(ShowTimeHistoy(item['senttime'])) message_row.ids.time_tag.text = str(ShowTimeHistoy(item['senttime']))

View File

@ -133,7 +133,7 @@ class MailDetail(Screen): # pylint: disable=too-many-instance-attributes
if len(data[0]) == 7: if len(data[0]) == 7:
self.status = data[0][4] self.status = data[0][4]
self.time_tag = ShowTimeHistoy(data[0][4]) if state.detailPageType == 'inbox' else ShowTimeHistoy(data[0][6]) 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())))) (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] self.timeinseconds = data[0][4] if state.detailPageType == 'inbox' else data[0][6]

View File

@ -38,7 +38,7 @@
CustomSpinner: CustomSpinner:
id: btn id: btn
background_color: app.theme_cls.primary_dark 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 '' on_text: root.auto_fill_fromaddr() if self.text != 'Select' else ''
option_cls: Factory.get("ComposerSpinnerOption") option_cls: Factory.get("ComposerSpinnerOption")
#background_color: color_button if self.state == 'normal' else color_button_pressed #background_color: color_button if self.state == 'normal' else color_button_pressed

View File

@ -137,7 +137,7 @@
#text: app.tr._('Hello World') #text: app.tr._('Hello World')
icon: 'email-open' icon: 'email-open'
divider: None divider: None
on_release: app.root.ids.scr_mngr.current = 'inbox' on_release: app.set_screen('inbox')
on_release: root.parent.set_state() on_release: root.parent.set_state()
on_press: app.load_screen(self) on_press: app.load_screen(self)
NavigationItem: NavigationItem:

View File

@ -9,13 +9,15 @@
Bitmessage android(mobile) interface Bitmessage android(mobile) interface
""" """
import importlib
import json
from bitmessagekivy.get_platform import platform from bitmessagekivy.get_platform import platform
import os import os
from bitmessagekivy import identiconGeneration from bitmessagekivy import identiconGeneration
from bitmessagekivy import kivy_helper_search from bitmessagekivy import kivy_helper_search
from bitmessagekivy.uikivysignaler import UIkivySignaler from bitmessagekivy.uikivysignaler import UIkivySignaler
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
# from debug import logger from debug import logger
from functools import partial from functools import partial
from helper_sql import sqlExecute, sqlQuery from helper_sql import sqlExecute, sqlQuery
from kivymd.app import MDApp from kivymd.app import MDApp
@ -57,7 +59,8 @@ from kivy.lang import Observable
import ast import ast
from bitmessagekivy.baseclass.common import toast from bitmessagekivy.baseclass.common import toast
from bitmessagekivy.baseclass.login import *
from bitmessagekivy.baseclass.popup import *
from qr_scanner.zbarcam import ZBarCam from qr_scanner.zbarcam import ZBarCam
from pyzbar.pyzbar import ZBarSymbol from pyzbar.pyzbar import ZBarSymbol
@ -83,13 +86,46 @@ elif platform == "android":
t = Toast.makeText(context, text, length) t = Toast.makeText(context, text, length)
t.show() t.show()
data_screen_dict = {}
with open(os.path.join(os.path.dirname(__file__), "screens_data.json")) as read_file: def load_screen_json(data_file="screens_data.json"):
all_data = ast.literal_eval(read_file.read()) """Load screens data from json"""
data_screens = list(all_data.keys())
for modules in data_screens: with open(os.path.join(os.path.dirname(__file__), data_file)) as read_file:
exec(all_data[modules]['Import']) 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 # 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') 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): class NavigateApp(MDApp):
"""Navigation Layout of class""" """Navigation Layout of class"""
# pylint: disable=too-many-public-methods,inconsistent-return-statements # pylint: disable=too-many-public-methods,inconsistent-return-statements
# theme_cls = ThemeManager() # theme_cls = ThemeManager()
def __init__(self): def __init__(self):
super(NavigateApp, self).__init__() super(NavigateApp, self).__init__()
self.data_screens, self.all_data, response = load_screen_json()
self.kivy_state_obj = KivyStateVariables() self.kivy_state_obj = KivyStateVariables()
previous_date = ObjectProperty() previous_date = ObjectProperty()
obj_1 = ObjectProperty() obj_1 = ObjectProperty()
identity_list = ListProperty(addr for addr in BMConfigParser().addresses() identity_list = get_identity_list()
if BMConfigParser().get(str(addr), 'enabled') == 'true')
nav_drawer = ObjectProperty() nav_drawer = ObjectProperty()
state.screen_density = Window.size state.screen_density = Window.size
window_size = state.screen_density window_size = state.screen_density
@ -236,13 +279,14 @@ class NavigateApp(MDApp):
def build(self): def build(self):
"""Method builds the widget""" """Method builds the widget"""
for kv in data_screens: # for kv in self.data_screens:
for kv in self.data_screens:
Builder.load_file( Builder.load_file(
os.path.join( os.path.join(
os.path.dirname(__file__), os.path.dirname(__file__),
'kv', 'kv',
# f'{all_data[kv]["kv_string"]}.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() # self.obj_1 = AddressBook()
@ -314,13 +358,14 @@ class NavigateApp(MDApp):
self.root.ids.sc4.loadSent(state.association) self.root.ids.sc4.loadSent(state.association)
self.root.ids.sc16.clear_widgets() 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.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.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.ids.ml.clear_widgets()
self.root.ids.id_myaddress.init_ui() self.root.ids.id_myaddress.init_ui()
@ -849,7 +894,7 @@ class NavigateApp(MDApp):
self.root.ids.sc1.children[1].active = False self.root.ids.sc1.children[1].active = False
elif instance.text == 'All Mails': elif instance.text == 'All Mails':
self.root.ids.sc17.clear_widgets() 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: try:
self.root.ids.sc17.children[1].active = False self.root.ids.sc17.children[1].active = False
except Exception: except Exception:
@ -858,7 +903,7 @@ class NavigateApp(MDApp):
# self.root.ids.sc5.ids.ml.clear_widgets() # self.root.ids.sc5.ids.ml.clear_widgets()
# self.root.ids.sc5.init_ui(0) # self.root.ids.sc5.init_ui(0)
self.root.ids.sc5.clear_widgets() 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: try:
self.root.ids.sc5.children[1].active = False self.root.ids.sc5.children[1].active = False
except Exception as e: except Exception as e:
@ -963,7 +1008,7 @@ class NavigateApp(MDApp):
def initiate_purchase(self, method_name): def initiate_purchase(self, method_name):
"""initiate_purchase module""" """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): def _after_scan(self, text):
# if platform == 'android': # if platform == 'android':

View File

@ -2,77 +2,77 @@
"Inbox": { "Inbox": {
"kv_string": "inbox", "kv_string": "inbox",
"name_screen": "inbox", "name_screen": "inbox",
"Import": "from bitmessagekivy.baseclass.inbox import Inbox", "Import": "from bitmessagekivy.baseclass.inbox import Inbox"
}, },
"Sent": { "Sent": {
"kv_string": "sent", "kv_string": "sent",
"name_screen": "sent", "name_screen": "sent",
"Import": "from bitmessagekivy.baseclass.sent import Sent", "Import": "from bitmessagekivy.baseclass.sent import Sent"
}, },
"Draft": { "Draft": {
"kv_string": "draft", "kv_string": "draft",
"name_screen": "draft", "name_screen": "draft",
"Import": "from bitmessagekivy.baseclass.draft import Draft", "Import": "from bitmessagekivy.baseclass.draft import Draft"
}, },
"Trash": { "Trash": {
"kv_string": "trash", "kv_string": "trash",
"name_screen": "trash", "name_screen": "trash",
"Import": "from bitmessagekivy.baseclass.trash import Trash", "Import": "from bitmessagekivy.baseclass.trash import Trash"
}, },
"All Mails": { "All Mails": {
"kv_string": "allmails", "kv_string": "allmails",
"name_screen": "allmails", "name_screen": "allmails",
"Import": "from bitmessagekivy.baseclass.allmail import Allmails", "Import": "from bitmessagekivy.baseclass.allmail import Allmails"
}, },
"Address Book": { "Address Book": {
"kv_string": "addressbook", "kv_string": "addressbook",
"name_screen": "addressbook", "name_screen": "addressbook",
"Import": "from bitmessagekivy.baseclass.addressbook import AddressBook", "Import": "from bitmessagekivy.baseclass.addressbook import AddressBook"
}, },
"Settings": { "Settings": {
"kv_string": "settings", "kv_string": "settings",
"name_screen": "set", "name_screen": "set",
"Import": "from bitmessagekivy.baseclass.settings import Setting", "Import": "from bitmessagekivy.baseclass.settings import Setting"
}, },
"Payment": { "Payment": {
"kv_string": "payment", "kv_string": "payment",
"name_screen": "payment", "name_screen": "payment",
"Import": "from bitmessagekivy.baseclass.payment import Payment", "Import": "from bitmessagekivy.baseclass.payment import Payment"
}, },
"Network status": { "Network status": {
"kv_string": "network", "kv_string": "network",
"name_screen": "networkstat", "name_screen": "networkstat",
"Import": "from bitmessagekivy.baseclass.network import NetworkStat", "Import": "from bitmessagekivy.baseclass.network import NetworkStat"
}, },
"My addresses": { "My addresses": {
"kv_string": "myaddress", "kv_string": "myaddress",
"name_screen": "myaddress", "name_screen": "myaddress",
"Import": "from bitmessagekivy.baseclass.myaddress import MyAddress", "Import": "from bitmessagekivy.baseclass.myaddress import MyAddress"
}, },
"MailDetail": { "MailDetail": {
"kv_string": "maildetail", "kv_string": "maildetail",
"name_screen": "mailDetail", "name_screen": "mailDetail",
"Import": "from bitmessagekivy.baseclass.maildetail import MailDetail", "Import": "from bitmessagekivy.baseclass.maildetail import MailDetail"
}, },
"Create": { "Create": {
"kv_string": "msg_composer", "kv_string": "msg_composer",
"name_screen": "create", "name_screen": "create",
"Import": "from bitmessagekivy.baseclass.msg_composer import Create", "Import": "from bitmessagekivy.baseclass.msg_composer import Create"
}, },
"Login": { "Login": {
"kv_string": "login", "kv_string": "login",
"Import": "from bitmessagekivy.baseclass.login import *", "Import": "from bitmessagekivy.baseclass.login import *"
}, },
"Scanner": { "Scanner": {
"kv_string": "scan_screen", "kv_string": "scan_screen",
"Import": "from bitmessagekivy.baseclass.scan_screen import ScanScreen", "Import": "from bitmessagekivy.baseclass.scan_screen import ScanScreen"
}, },
"Popups": { "Popups": {
"kv_string": "popup", "kv_string": "popup",
"Import": "from bitmessagekivy.baseclass.popup import *", "Import": "from bitmessagekivy.baseclass.popup import *"
}, },
"Qrcode": { "Qrcode": {
"kv_string": "qrcode", "kv_string": "qrcode",
"Import": "from bitmessagekivy.baseclass.qrcode import ShowQRCode", "Import": "from bitmessagekivy.baseclass.qrcode import ShowQRCode"
}, }
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB