2022-08-19 18:13:41 +02:00
|
|
|
# pylint: disable=no-name-in-module, too-few-public-methods, import-error, unused-argument, unused-import
|
|
|
|
# pylint: disable=attribute-defined-outside-init, global-variable-not-assigned, unused-variable, too-many-ancestors
|
2022-08-04 18:29:02 +02:00
|
|
|
|
2021-06-11 19:14:57 +02:00
|
|
|
"""
|
2022-08-04 18:29:02 +02:00
|
|
|
Bitmessage android(mobile) interface
|
2021-06-11 19:14:57 +02:00
|
|
|
"""
|
|
|
|
|
2022-08-04 18:29:02 +02:00
|
|
|
import os
|
2022-08-16 09:57:44 +02:00
|
|
|
import json
|
2022-08-08 12:56:08 +02:00
|
|
|
import importlib
|
2022-08-18 12:51:24 +02:00
|
|
|
import logging
|
2022-08-23 15:41:46 +02:00
|
|
|
from functools import partial
|
2022-08-04 18:29:02 +02:00
|
|
|
|
2022-08-23 15:41:46 +02:00
|
|
|
from kivy.clock import Clock
|
2022-08-05 13:08:37 +02:00
|
|
|
from kivy.lang import Builder
|
2022-08-08 18:02:00 +02:00
|
|
|
from kivy.properties import (
|
2022-08-10 13:44:13 +02:00
|
|
|
ListProperty
|
2022-08-08 18:02:00 +02:00
|
|
|
)
|
|
|
|
from kivy.uix.boxlayout import BoxLayout
|
2022-08-04 18:29:02 +02:00
|
|
|
|
2022-08-05 13:08:37 +02:00
|
|
|
from kivymd.app import MDApp
|
2022-08-19 18:13:41 +02:00
|
|
|
from kivymd.uix.label import MDLabel
|
2022-08-22 18:14:12 +02:00
|
|
|
from kivymd.uix.dialog import MDDialog
|
2022-08-08 18:02:00 +02:00
|
|
|
from kivymd.uix.list import (
|
2022-08-22 10:06:40 +02:00
|
|
|
IRightBodyTouch
|
2022-08-08 18:02:00 +02:00
|
|
|
)
|
2022-08-22 18:14:12 +02:00
|
|
|
from kivymd.uix.button import MDRaisedButton
|
2022-08-16 17:29:37 +02:00
|
|
|
from kivymd.uix.bottomsheet import MDCustomBottomSheet
|
|
|
|
|
2022-08-05 13:08:37 +02:00
|
|
|
from pybitmessage.bitmessagekivy.kivy_state import KivyStateVariables
|
2022-08-19 18:13:41 +02:00
|
|
|
from pybitmessage.bitmessagekivy.base_navigation import (
|
|
|
|
BaseLanguage, BaseNavigationItem, BaseNavigationDrawerDivider,
|
|
|
|
BaseNavigationDrawerSubheader, BaseContentNavigationDrawer,
|
2022-08-22 10:08:19 +02:00
|
|
|
BaseIdentitySpinner
|
2022-08-19 18:13:41 +02:00
|
|
|
)
|
2022-08-08 18:02:00 +02:00
|
|
|
from pybitmessage.bmconfigparser import config
|
2022-08-22 18:14:12 +02:00
|
|
|
from pybitmessage.bitmessagekivy.get_platform import platform
|
|
|
|
from pybitmessage.bitmessagekivy.baseclass.common import toast
|
|
|
|
from pybitmessage.bitmessagekivy.baseclass.popup import AddAddressPopup
|
2022-08-18 12:51:24 +02:00
|
|
|
|
|
|
|
logger = logging.getLogger('default')
|
|
|
|
|
|
|
|
data_screen_dict = {}
|
2022-08-17 16:03:37 +02:00
|
|
|
|
2022-08-04 18:29:02 +02:00
|
|
|
|
2022-08-18 18:41:09 +02:00
|
|
|
def load_screen_json(data_file="screens_data.json"):
|
2022-08-17 16:03:37 +02:00
|
|
|
"""Load screens data from json"""
|
2022-08-18 12:51:24 +02:00
|
|
|
|
|
|
|
with open(os.path.join(os.path.dirname(__file__), data_file)) as read_file:
|
2022-08-17 16:03:37 +02:00
|
|
|
all_data = json.load(read_file)
|
|
|
|
data_screens = list(all_data.keys())
|
2022-08-04 18:29:02 +02:00
|
|
|
|
2022-08-17 16:03:37 +02:00
|
|
|
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()
|
2022-08-18 12:51:24 +02:00
|
|
|
data_screen_dict[import_to] = importlib.import_module(import_from, import_to)
|
2022-08-18 18:41:09 +02:00
|
|
|
return data_screens, all_data, 'success'
|
2022-08-04 18:29:02 +02:00
|
|
|
|
|
|
|
|
2022-08-18 12:51:24 +02:00
|
|
|
def get_identity_list():
|
|
|
|
"""Get list of identities and access 'identity_list' variable in .kv file"""
|
|
|
|
identity_list = ListProperty(
|
|
|
|
addr for addr in config.addresses() if config.getboolean(str(addr), 'enabled')
|
|
|
|
)
|
|
|
|
return identity_list
|
|
|
|
|
2022-08-22 10:06:40 +02:00
|
|
|
|
2022-08-19 18:13:41 +02:00
|
|
|
class Lang(BaseLanguage):
|
2022-08-05 13:08:37 +02:00
|
|
|
"""UI Language"""
|
|
|
|
|
2022-08-08 18:02:00 +02:00
|
|
|
|
2022-08-19 18:13:41 +02:00
|
|
|
class NavigationItem(BaseNavigationItem):
|
|
|
|
"""NavigationItem class for kivy Ui"""
|
2022-08-08 18:02:00 +02:00
|
|
|
|
|
|
|
|
2022-08-19 18:13:41 +02:00
|
|
|
class NavigationDrawerDivider(BaseNavigationDrawerDivider):
|
2022-08-08 18:02:00 +02:00
|
|
|
"""
|
2022-08-19 18:13:41 +02:00
|
|
|
A small full-width divider that can be placed
|
|
|
|
in the :class:`MDNavigationDrawer`
|
2022-08-08 18:02:00 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
2022-08-19 18:13:41 +02:00
|
|
|
class NavigationDrawerSubheader(BaseNavigationDrawerSubheader):
|
2022-08-08 18:02:00 +02:00
|
|
|
"""
|
|
|
|
A subheader for separating content in :class:`MDNavigationDrawer`
|
2022-08-19 18:13:41 +02:00
|
|
|
|
2022-08-08 18:02:00 +02:00
|
|
|
Works well alongside :class:`NavigationDrawerDivider`
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
2022-08-19 18:13:41 +02:00
|
|
|
class ContentNavigationDrawer(BaseContentNavigationDrawer):
|
|
|
|
"""ContentNavigationDrawer class for kivy Uir"""
|
2022-08-08 18:02:00 +02:00
|
|
|
|
|
|
|
|
2022-08-19 18:13:41 +02:00
|
|
|
class BadgeText(IRightBodyTouch, MDLabel):
|
|
|
|
"""BadgeText class for kivy Ui"""
|
2022-08-08 18:02:00 +02:00
|
|
|
|
|
|
|
|
2022-08-22 10:08:19 +02:00
|
|
|
class IdentitySpinner(BaseIdentitySpinner):
|
2022-08-22 10:06:40 +02:00
|
|
|
"""Identity Dropdown in Side Navigation bar"""
|
2022-08-08 18:02:00 +02:00
|
|
|
|
|
|
|
|
2022-08-04 18:29:02 +02:00
|
|
|
class NavigateApp(MDApp):
|
|
|
|
"""Navigation Layout of class"""
|
2022-08-10 13:44:13 +02:00
|
|
|
|
2022-08-04 18:29:02 +02:00
|
|
|
title = "PyBitmessage"
|
2022-08-18 12:51:24 +02:00
|
|
|
identity_list = get_identity_list()
|
2022-08-09 14:09:35 +02:00
|
|
|
image_path = KivyStateVariables().image_dir
|
2022-08-04 18:29:02 +02:00
|
|
|
tr = Lang("en") # for changing in franch replace en with fr
|
|
|
|
|
2022-08-22 18:14:12 +02:00
|
|
|
def __init__(self):
|
|
|
|
super(NavigateApp, self).__init__()
|
|
|
|
self.data_screens, self.all_data, response = load_screen_json()
|
|
|
|
self.kivy_state_obj = KivyStateVariables()
|
|
|
|
|
2022-08-22 10:06:40 +02:00
|
|
|
def build(self):
|
2021-06-11 19:14:57 +02:00
|
|
|
"""Method builds the widget"""
|
2022-08-17 16:03:37 +02:00
|
|
|
for kv in self.data_screens:
|
2022-08-04 18:29:02 +02:00
|
|
|
Builder.load_file(
|
|
|
|
os.path.join(
|
|
|
|
os.path.dirname(__file__),
|
|
|
|
'kv',
|
2022-08-17 16:03:37 +02:00
|
|
|
'{0}.kv'.format(self.all_data[kv]["kv_string"]),
|
2022-08-04 18:29:02 +02:00
|
|
|
)
|
|
|
|
)
|
2022-08-05 13:08:37 +02:00
|
|
|
return Builder.load_file(os.path.join(os.path.dirname(__file__), 'main.kv'))
|
2022-08-04 18:29:02 +02:00
|
|
|
|
|
|
|
def set_screen(self, screen_name):
|
2022-08-05 13:08:37 +02:00
|
|
|
"""Set the screen name when navigate to other screens"""
|
2022-08-04 18:29:02 +02:00
|
|
|
self.root.ids.scr_mngr.current = screen_name
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
"""Running the widgets"""
|
2022-08-09 14:09:35 +02:00
|
|
|
self.kivy_state_obj.kivyui_ready.set()
|
2022-08-04 18:29:02 +02:00
|
|
|
super(NavigateApp, self).run()
|
2022-08-08 18:02:00 +02:00
|
|
|
|
2022-08-22 18:14:12 +02:00
|
|
|
def addingtoaddressbook(self):
|
|
|
|
"""Dialog for saving address"""
|
|
|
|
width = .85 if platform == 'android' else .8
|
|
|
|
self.add_popup = MDDialog(
|
|
|
|
title='Add contact',
|
|
|
|
type="custom",
|
|
|
|
size_hint=(width, .23),
|
|
|
|
content_cls=AddAddressPopup(),
|
|
|
|
buttons=[
|
|
|
|
MDRaisedButton(
|
|
|
|
text="Save",
|
|
|
|
on_release=self.savecontact,
|
|
|
|
),
|
|
|
|
MDRaisedButton(
|
|
|
|
text="Cancel",
|
|
|
|
on_release=self.close_pop,
|
|
|
|
),
|
|
|
|
MDRaisedButton(
|
|
|
|
text="Scan QR code",
|
|
|
|
on_release=self.scan_qr_code,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
self.add_popup.auto_dismiss = False
|
|
|
|
self.add_popup.open()
|
|
|
|
|
|
|
|
def scan_qr_code(self, instance):
|
|
|
|
"""this method is used for showing QR code scanner"""
|
|
|
|
if self.is_camara_attached():
|
|
|
|
self.add_popup.dismiss()
|
|
|
|
self.root.ids.id_scanscreen.get_screen(self.root.ids.scr_mngr.current, self.add_popup)
|
|
|
|
self.root.ids.scr_mngr.current = 'scanscreen'
|
|
|
|
else:
|
|
|
|
alert_text = (
|
|
|
|
'Currently this feature is not avaialbe!' if platform == 'android' else 'Camera is not available!')
|
|
|
|
self.add_popup.dismiss()
|
|
|
|
toast(alert_text)
|
|
|
|
|
|
|
|
def is_camara_attached(self):
|
|
|
|
"""This method is for checking the camera is available or not"""
|
|
|
|
self.root.ids.id_scanscreen.check_camera()
|
|
|
|
is_available = self.root.ids.id_scanscreen.camera_available
|
|
|
|
return is_available
|
|
|
|
|
|
|
|
def savecontact(self, instance):
|
|
|
|
"""Method is used for saving contacts"""
|
|
|
|
pupup_obj = self.add_popup.content_cls
|
|
|
|
label = pupup_obj.ids.label.text.strip()
|
|
|
|
address = pupup_obj.ids.address.text.strip()
|
|
|
|
if label == '' and address == '':
|
|
|
|
pupup_obj.ids.label.focus = True
|
|
|
|
pupup_obj.ids.address.focus = True
|
|
|
|
elif address == '':
|
|
|
|
pupup_obj.ids.address.focus = True
|
|
|
|
elif label == '':
|
|
|
|
pupup_obj.ids.label.focus = True
|
|
|
|
else:
|
|
|
|
pupup_obj.ids.address.focus = True
|
|
|
|
|
|
|
|
def close_pop(self, instance):
|
|
|
|
"""Close the popup"""
|
|
|
|
self.add_popup.dismiss()
|
|
|
|
toast('Canceled')
|
|
|
|
|
2022-08-08 18:02:00 +02:00
|
|
|
def loadMyAddressScreen(self, action):
|
|
|
|
"""loadMyAddressScreen method spin the loader"""
|
2022-08-09 14:09:35 +02:00
|
|
|
if len(self.root.ids.id_myaddress.children) <= 2:
|
|
|
|
self.root.ids.id_myaddress.children[0].active = action
|
2022-08-08 18:02:00 +02:00
|
|
|
else:
|
2022-08-09 14:09:35 +02:00
|
|
|
self.root.ids.id_myaddress.children[1].active = action
|
2022-08-10 13:44:13 +02:00
|
|
|
|
2022-08-23 15:41:46 +02:00
|
|
|
def load_screen(self, instance):
|
|
|
|
"""This method is used for loading screen on every click"""
|
|
|
|
if instance.text == 'Trash':
|
|
|
|
self.root.ids.scr_mngr.current = 'trash'
|
|
|
|
try:
|
|
|
|
self.root.ids.id_trash.children[1].active = True
|
|
|
|
except Exception as e:
|
|
|
|
self.root.ids.id_trash.children[0].children[1].active = True
|
|
|
|
Clock.schedule_once(partial(self.load_screen_callback, instance), 1)
|
|
|
|
|
|
|
|
def load_screen_callback(self, instance, dt=0):
|
|
|
|
"""This method is rotating loader for few seconds"""
|
|
|
|
if instance.text == 'Trash':
|
|
|
|
self.root.ids.id_trash.clear_widgets()
|
|
|
|
self.root.ids.id_trash.add_widget(data_screen_dict['Trash'].Trash())
|
|
|
|
try:
|
|
|
|
self.root.ids.id_trash.children[1].active = False
|
|
|
|
except Exception as e:
|
|
|
|
self.root.ids.id_trash.children[0].children[1].active = False
|
|
|
|
|
2022-08-10 13:44:13 +02:00
|
|
|
def reset_login_screen(self):
|
|
|
|
"""This method is used for clearing the widgets of random screen"""
|
|
|
|
if self.root.ids.id_newidentity.ids.add_random_bx.children:
|
|
|
|
self.root.ids.id_newidentity.ids.add_random_bx.clear_widgets()
|
2022-08-16 17:29:37 +02:00
|
|
|
|
|
|
|
def open_payment_layout(self, sku):
|
|
|
|
"""It basically open up a payment layout for kivy UI"""
|
|
|
|
pml = PaymentMethodLayout()
|
|
|
|
self.product_id = sku
|
|
|
|
self.custom_sheet = MDCustomBottomSheet(screen=pml)
|
|
|
|
self.custom_sheet.open()
|
|
|
|
|
|
|
|
def initiate_purchase(self, method_name):
|
|
|
|
"""initiate_purchase module"""
|
2022-08-17 16:03:37 +02:00
|
|
|
logger.debug("Purchasing %s through %s", self.product_id, method_name)
|
2022-08-16 17:29:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
class PaymentMethodLayout(BoxLayout):
|
|
|
|
"""PaymentMethodLayout class for kivy Ui"""
|
2022-08-18 18:41:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
NavigateApp().run()
|