This repository has been archived on 2024-12-16. You can view files and clone it, but cannot push or open issues or pull requests.
PyBitmessage-2024-12-16/src/bitmessagekivy/mpybit.py

173 lines
5.2 KiB
Python
Raw Normal View History

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
"""
2022-08-04 18:29:02 +02:00
Bitmessage android(mobile) interface
"""
2022-08-04 18:29:02 +02:00
import os
import json
2022-08-08 12:56:08 +02:00
import importlib
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
from kivy.clock import Clock
from kivy.properties import (
BooleanProperty,
NumericProperty,
2022-08-10 13:44:13 +02:00
StringProperty,
ListProperty
)
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-19 18:13:41 +02:00
from kivymd.uix.label import MDLabel
from kivymd.uix.list import (
OneLineAvatarIconListItem,
2022-08-19 18:13:41 +02:00
IRightBodyTouch,
)
2022-08-19 18:13:41 +02:00
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,
BaseCustomSpinner
)
from pybitmessage.bmconfigparser import config
logger = logging.getLogger('default')
data_screen_dict = {}
2022-08-04 18:29:02 +02:00
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())
2022-08-04 18:29:02 +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()
data_screen_dict[import_to] = importlib.import_module(import_from, import_to)
return data_screens, all_data, 'success'
2022-08-04 18:29:02 +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-19 18:13:41 +02:00
class Lang(BaseLanguage):
2022-08-05 13:08:37 +02:00
"""UI Language"""
2022-08-19 18:13:41 +02:00
class NavigationItem(BaseNavigationItem):
"""NavigationItem class for kivy Ui"""
2022-08-19 18:13:41 +02:00
class NavigationDrawerDivider(BaseNavigationDrawerDivider):
"""
2022-08-19 18:13:41 +02:00
A small full-width divider that can be placed
in the :class:`MDNavigationDrawer`
"""
2022-08-19 18:13:41 +02:00
class NavigationDrawerSubheader(BaseNavigationDrawerSubheader):
"""
A subheader for separating content in :class:`MDNavigationDrawer`
2022-08-19 18:13:41 +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-19 18:13:41 +02:00
class BadgeText(IRightBodyTouch, MDLabel):
"""BadgeText class for kivy Ui"""
2022-08-19 18:13:41 +02:00
class CustomSpinner(BaseCustomSpinner):
"""CustomSpinner class for kivy Ui"""
2022-08-04 18:29:02 +02:00
class NavigateApp(MDApp):
"""Navigation Layout of class"""
2022-08-10 13:44:13 +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-04 18:29:02 +02:00
title = "PyBitmessage"
identity_list = get_identity_list()
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
"""Method builds the widget"""
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',
'{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"""
self.kivy_state_obj.kivyui_ready.set()
2022-08-04 18:29:02 +02:00
super(NavigateApp, self).run()
def loadMyAddressScreen(self, action):
"""loadMyAddressScreen method spin the loader"""
if len(self.root.ids.id_myaddress.children) <= 2:
self.root.ids.id_myaddress.children[0].active = action
else:
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"""
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"""
if __name__ == '__main__':
NavigateApp().run()