2022-08-08 18:02:00 +02:00
|
|
|
# pylint: disable=no-name-in-module, too-few-public-methods, import-error, unused-argument
|
2022-08-18 12:51:24 +02:00
|
|
|
# pylint: disable=attribute-defined-outside-init, global-variable-not-assigned
|
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-04 18:29:02 +02:00
|
|
|
|
2022-08-05 13:08:37 +02:00
|
|
|
from kivy.lang import Builder
|
2022-08-04 18:29:02 +02:00
|
|
|
from kivy.lang import Observable
|
2022-08-08 18:02:00 +02:00
|
|
|
from kivy.clock import Clock
|
|
|
|
from kivy.properties import (
|
|
|
|
BooleanProperty,
|
|
|
|
NumericProperty,
|
2022-08-10 13:44:13 +02:00
|
|
|
StringProperty,
|
|
|
|
ListProperty
|
2022-08-08 18:02:00 +02:00
|
|
|
)
|
|
|
|
from kivy.metrics import dp
|
|
|
|
from kivy.uix.boxlayout import BoxLayout
|
|
|
|
from kivy.uix.spinner import Spinner
|
|
|
|
from kivy.core.window import Window
|
|
|
|
|
2022-08-04 18:29:02 +02:00
|
|
|
|
2022-08-05 13:08:37 +02:00
|
|
|
from kivymd.app import MDApp
|
2022-08-08 18:02:00 +02:00
|
|
|
from kivymd.uix.list import (
|
|
|
|
OneLineAvatarIconListItem,
|
|
|
|
OneLineListItem
|
|
|
|
)
|
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-08 18:02:00 +02:00
|
|
|
from pybitmessage.bmconfigparser import config
|
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-17 16:03:37 +02:00
|
|
|
def load_screen_json():
|
|
|
|
"""Load screens data from json"""
|
2022-08-18 12:51:24 +02:00
|
|
|
|
|
|
|
data_file = "screens_data.json"
|
|
|
|
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-18 12:51:24 +02:00
|
|
|
global data_screen_dict
|
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-17 16:03:37 +02:00
|
|
|
return data_screens, all_data
|
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-04 18:29:02 +02:00
|
|
|
class Lang(Observable):
|
2022-08-05 13:08:37 +02:00
|
|
|
"""UI Language"""
|
|
|
|
|
2022-08-04 18:29:02 +02:00
|
|
|
observers = []
|
|
|
|
lang = None
|
|
|
|
|
|
|
|
def __init__(self, defaultlang):
|
|
|
|
super(Lang, self).__init__()
|
|
|
|
self.ugettext = None
|
|
|
|
self.lang = defaultlang
|
|
|
|
|
2022-08-05 13:08:37 +02:00
|
|
|
@staticmethod
|
|
|
|
def _(text):
|
2022-08-04 18:29:02 +02:00
|
|
|
return text
|
|
|
|
|
|
|
|
|
2022-08-08 18:02:00 +02:00
|
|
|
class NavigationItem(OneLineAvatarIconListItem):
|
2022-08-09 14:09:35 +02:00
|
|
|
"""UI for NavigationItem class on Side Navigation bar"""
|
2022-08-08 18:02:00 +02:00
|
|
|
badge_text = StringProperty()
|
|
|
|
icon = StringProperty()
|
|
|
|
active = BooleanProperty(False)
|
|
|
|
|
|
|
|
def currentlyActive(self):
|
|
|
|
"""Currenly active"""
|
|
|
|
for nav_obj in self.parent.children:
|
|
|
|
nav_obj.active = False
|
|
|
|
self.active = True
|
|
|
|
|
|
|
|
|
|
|
|
class NavigationDrawerDivider(OneLineListItem):
|
|
|
|
"""
|
2022-08-09 14:09:35 +02:00
|
|
|
A small full-width divider line for Side Navigation bar
|
2022-08-08 18:02:00 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
disabled = True
|
|
|
|
divider = None
|
|
|
|
_txt_top_pad = NumericProperty(dp(8))
|
|
|
|
_txt_bot_pad = NumericProperty(dp(8))
|
|
|
|
|
|
|
|
def __init__(self, **kwargs):
|
|
|
|
# pylint: disable=bad-super-call
|
|
|
|
super(OneLineListItem, self).__init__(**kwargs)
|
|
|
|
self.height = dp(16)
|
|
|
|
|
|
|
|
|
|
|
|
class NavigationDrawerSubheader(OneLineListItem):
|
|
|
|
"""
|
|
|
|
A subheader for separating content in :class:`MDNavigationDrawer`
|
|
|
|
Works well alongside :class:`NavigationDrawerDivider`
|
|
|
|
"""
|
|
|
|
|
|
|
|
disabled = True
|
|
|
|
divider = None
|
|
|
|
theme_text_color = 'Secondary'
|
|
|
|
|
|
|
|
|
|
|
|
class ContentNavigationDrawer(BoxLayout):
|
2022-08-09 14:09:35 +02:00
|
|
|
"""Helper for Side navigation bar which contains screen names"""
|
2022-08-08 18:02:00 +02:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2022-08-09 14:09:35 +02:00
|
|
|
"""Method used for to initialize side navbar"""
|
2022-08-08 18:02:00 +02:00
|
|
|
super(ContentNavigationDrawer, self).__init__(*args, **kwargs)
|
|
|
|
Clock.schedule_once(self.init_ui, 0)
|
|
|
|
|
|
|
|
def init_ui(self, dt=0):
|
|
|
|
"""Clock Schdule for class contentNavigationDrawer"""
|
|
|
|
self.ids.scroll_y.bind(scroll_y=self.check_scroll_y)
|
|
|
|
|
|
|
|
def check_scroll_y(self, instance, somethingelse):
|
|
|
|
"""show data on scroll down"""
|
2022-08-16 09:57:44 +02:00
|
|
|
if self.ids.identity_dropdown.is_open:
|
|
|
|
self.ids.identity_dropdown.is_open = False
|
2022-08-08 18:02:00 +02:00
|
|
|
|
|
|
|
|
|
|
|
class CustomSpinner(Spinner):
|
2022-08-09 14:09:35 +02:00
|
|
|
"""
|
|
|
|
A Dropdown on side navigation bar which hold the identity and can switch to other identity
|
|
|
|
"""
|
2022-08-08 18:02:00 +02:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
"""Method used for setting size of spinner"""
|
|
|
|
super(CustomSpinner, self).__init__(*args, **kwargs)
|
|
|
|
self.dropdown_cls.max_height = Window.size[1] / 3
|
|
|
|
self.values = list(addr for addr in config.addresses()
|
2022-08-17 16:03:37 +02:00
|
|
|
if config.getboolean(str(addr), 'enabled'))
|
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-05-05 12:35:14 +02:00
|
|
|
def __init__(self):
|
|
|
|
super(NavigateApp, self).__init__()
|
2022-08-17 16:03:37 +02:00
|
|
|
self.data_screens, self.all_data = load_screen_json()
|
2022-05-05 12:35:14 +02:00
|
|
|
self.kivy_state_obj = KivyStateVariables()
|
2021-06-11 19:14:57 +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-05 13:08:37 +02:00
|
|
|
def build(self): # pylint:disable=no-self-use
|
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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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"""
|