Add myaddress_widget
This commit is contained in:
parent
b2fd30c338
commit
216f2e0900
|
@ -1,8 +1,15 @@
|
||||||
from bitmessagekivy.get_platform import platform
|
# pylint: disable=unused-argument, consider-using-f-string, import-error
|
||||||
|
# pylint: disable=unnecessary-comprehension, no-member, no-name-in-module
|
||||||
|
"""
|
||||||
|
myaddress.py
|
||||||
|
==============
|
||||||
|
All generated addresses are managed in MyAddress
|
||||||
|
"""
|
||||||
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
from bitmessagekivy.get_platform import platform
|
||||||
from bmconfigparser import BMConfigParser
|
from bmconfigparser import BMConfigParser
|
||||||
from kivy.clock import Clock
|
from kivy.clock import Clock
|
||||||
# from kivy.metrics import dp
|
|
||||||
from kivy.properties import (
|
from kivy.properties import (
|
||||||
ListProperty,
|
ListProperty,
|
||||||
StringProperty
|
StringProperty
|
||||||
|
@ -25,6 +32,7 @@ from bitmessagekivy.baseclass.common import (
|
||||||
)
|
)
|
||||||
from bitmessagekivy.baseclass.popup import MyaddDetailPopup
|
from bitmessagekivy.baseclass.popup import MyaddDetailPopup
|
||||||
|
|
||||||
|
from bitmessagekivy.baseclass.myaddress_widgets import HelperMyAddress
|
||||||
|
|
||||||
class ToggleBtn(IRightBodyTouch, MDSwitch):
|
class ToggleBtn(IRightBodyTouch, MDSwitch):
|
||||||
"""ToggleBtn class for kivy Ui"""
|
"""ToggleBtn class for kivy Ui"""
|
||||||
|
@ -34,11 +42,11 @@ class CustomTwoLineAvatarIconListItem(TwoLineAvatarIconListItem):
|
||||||
"""CustomTwoLineAvatarIconListItem class for kivy Ui"""
|
"""CustomTwoLineAvatarIconListItem class for kivy Ui"""
|
||||||
|
|
||||||
|
|
||||||
class BadgeText(IRightBodyTouch, MDLabel):
|
# class BadgeText(IRightBodyTouch, MDLabel):
|
||||||
"""BadgeText class for kivy Ui"""
|
# """BadgeText class for kivy Ui"""
|
||||||
|
|
||||||
|
|
||||||
class MyAddress(Screen):
|
class MyAddress(Screen, HelperMyAddress):
|
||||||
"""MyAddress screen class for kivy Ui"""
|
"""MyAddress screen class for kivy Ui"""
|
||||||
|
|
||||||
address_label = StringProperty()
|
address_label = StringProperty()
|
||||||
|
@ -72,15 +80,15 @@ class MyAddress(Screen):
|
||||||
self.set_mdList(0, 15)
|
self.set_mdList(0, 15)
|
||||||
self.ids.refresh_layout.bind(scroll_y=self.check_scroll_y)
|
self.ids.refresh_layout.bind(scroll_y=self.check_scroll_y)
|
||||||
else:
|
else:
|
||||||
content = MDLabel(
|
# content = MDLabel(
|
||||||
font_style='Caption',
|
# font_style='Caption',
|
||||||
theme_text_color='Primary',
|
# theme_text_color='Primary',
|
||||||
text="No address found!" if state.searcing_text
|
# text="No address found!" if state.searcing_text
|
||||||
else "yet no address is created by user!!!!!!!!!!!!!",
|
# else "yet no address is created by user!!!!!!!!!!!!!",
|
||||||
halign='center',
|
# halign='center',
|
||||||
size_hint_y=None,
|
# size_hint_y=None,
|
||||||
valign='top')
|
# valign='top')
|
||||||
self.ids.ml.add_widget(content)
|
self.ids.ml.add_widget(self.default_label_when_empty())
|
||||||
if not state.searcing_text and not self.is_add_created:
|
if not state.searcing_text and not self.is_add_created:
|
||||||
try:
|
try:
|
||||||
self.manager.current = 'login'
|
self.manager.current = 'login'
|
||||||
|
@ -111,15 +119,16 @@ class MyAddress(Screen):
|
||||||
meny.bind(on_press=partial(
|
meny.bind(on_press=partial(
|
||||||
self.myadd_detail, item['secondary_text'], item['text']))
|
self.myadd_detail, item['secondary_text'], item['text']))
|
||||||
if state.association == item['secondary_text'] and is_enable == 'true':
|
if state.association == item['secondary_text'] and is_enable == 'true':
|
||||||
badge_obj = BadgeText(
|
# badge_obj = BadgeText(
|
||||||
size_hint=(None, None),
|
# size_hint=(None, None),
|
||||||
size=[90 if platform == 'android' else 50, 60],
|
# size=[90 if platform == 'android' else 50, 60],
|
||||||
text='Active', halign='center',
|
# text='Active', halign='center',
|
||||||
font_style='Body1', theme_text_color='Custom',
|
# font_style='Body1', theme_text_color='Custom',
|
||||||
text_color=ThemeClsColor
|
# text_color=ThemeClsColor
|
||||||
)
|
# )
|
||||||
badge_obj.font_size = '13sp'
|
# badge_obj.font_size = '13sp'
|
||||||
meny.add_widget(badge_obj)
|
# meny.add_widget(badge_obj)
|
||||||
|
meny.add_widget(self.is_active_badge())
|
||||||
else:
|
else:
|
||||||
meny.add_widget(ToggleBtn(active=True if is_enable == 'true' else False))
|
meny.add_widget(ToggleBtn(active=True if is_enable == 'true' else False))
|
||||||
self.ids.ml.add_widget(meny)
|
self.ids.ml.add_widget(meny)
|
||||||
|
@ -142,42 +151,49 @@ class MyAddress(Screen):
|
||||||
# @staticmethod
|
# @staticmethod
|
||||||
def myadd_detail(self, fromaddress, label, *args):
|
def myadd_detail(self, fromaddress, label, *args):
|
||||||
"""Load myaddresses details"""
|
"""Load myaddresses details"""
|
||||||
|
|
||||||
if BMConfigParser().get(fromaddress, 'enabled') == 'true':
|
if BMConfigParser().get(fromaddress, 'enabled') == 'true':
|
||||||
obj = MyaddDetailPopup()
|
obj = MyaddDetailPopup()
|
||||||
self.address_label = obj.address_label = label
|
self.address_label = obj.address_label = label
|
||||||
self.text_address = obj.address = fromaddress
|
self.text_address = obj.address = fromaddress
|
||||||
width = .9 if platform == 'android' else .6
|
width = .9 if platform == 'android' else .6
|
||||||
self.myadddetail_popup = MDDialog(
|
# self.myadddetail_popup = MDDialog(
|
||||||
type="custom",
|
# type="custom",
|
||||||
size_hint=(width, .25),
|
# size_hint=(width, .25),
|
||||||
content_cls=obj,
|
# content_cls=obj,
|
||||||
)
|
# )
|
||||||
|
self.myadddetail_popup = self.myaddress_detail_popup(obj, width)
|
||||||
|
|
||||||
# self.myadddetail_popup.set_normal_height()
|
# self.myadddetail_popup.set_normal_height()
|
||||||
self.myadddetail_popup.auto_dismiss = False
|
self.myadddetail_popup.auto_dismiss = False
|
||||||
self.myadddetail_popup.open()
|
self.myadddetail_popup.open()
|
||||||
# p.set_address(fromaddress, label)
|
# p.set_address(fromaddress, label)
|
||||||
else:
|
else:
|
||||||
width = .8 if platform == 'android' else .55
|
width = .8 if platform == 'android' else .55
|
||||||
dialog_box = MDDialog(
|
# dialog_box = MDDialog(
|
||||||
text='Address is not currently active. Please click on Toggle button to active it.',
|
# text='Address is not currently active. Please click on Toggle button to active it.',
|
||||||
size_hint=(width, .25),
|
# size_hint=(width, .25),
|
||||||
buttons=[
|
# buttons=[
|
||||||
MDFlatButton(
|
# MDFlatButton(
|
||||||
text="Ok", on_release=lambda x: callback_for_menu_items("Ok")
|
# text="Ok", on_release=lambda x: callback_for_menu_items("Ok")
|
||||||
),
|
# ),
|
||||||
],
|
# ],
|
||||||
)
|
# )
|
||||||
dialog_box.open()
|
# import pdb; pdb.set_trace()
|
||||||
|
self.dialog_box = self.inactive_address_popup(width, self.callback_for_menu_items)
|
||||||
|
self.dialog_box.open()
|
||||||
|
|
||||||
def callback_for_menu_items(text_item, *arg):
|
# def callback_for_menu_items(text_item, *arg):
|
||||||
"""Callback of alert box"""
|
# """Callback of alert box"""
|
||||||
dialog_box.dismiss()
|
# import pdb; pdb.set_trace()
|
||||||
toast(text_item)
|
# dialog_box.dismiss()
|
||||||
|
# toast(text_item)
|
||||||
|
|
||||||
# @staticmethod
|
# @staticmethod
|
||||||
# def callback_for_menu_items(text_item, *arg):
|
def callback_for_menu_items(self, text_item, *arg):
|
||||||
# """Callback of alert box"""
|
"""Callback of alert box"""
|
||||||
# toast(text_item)
|
self.dialog_box.dismiss()
|
||||||
|
toast(text_item)
|
||||||
|
|
||||||
def refresh_callback(self, *args):
|
def refresh_callback(self, *args):
|
||||||
"""Method updates the state of application,
|
"""Method updates the state of application,
|
||||||
|
|
68
src/bitmessagekivy/baseclass/myaddress_widgets.py
Normal file
68
src/bitmessagekivy/baseclass/myaddress_widgets.py
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
# pylint: disable=no-member, too-many-arguments
|
||||||
|
"""
|
||||||
|
MyAddress widgets are here.
|
||||||
|
"""
|
||||||
|
from bitmessagekivy.get_platform import platform
|
||||||
|
|
||||||
|
from kivymd.uix.button import MDRaisedButton
|
||||||
|
from kivymd.uix.button import MDFlatButton
|
||||||
|
from kivymd.uix.dialog import MDDialog
|
||||||
|
from kivymd.uix.label import MDLabel
|
||||||
|
from kivymd.uix.list import (IRightBodyTouch, TwoLineAvatarIconListItem)
|
||||||
|
|
||||||
|
import state
|
||||||
|
|
||||||
|
from bitmessagekivy.baseclass.common import (
|
||||||
|
avatarImageFirstLetter, AvatarSampleWidget, ThemeClsColor,
|
||||||
|
toast
|
||||||
|
)
|
||||||
|
|
||||||
|
class BadgeText(IRightBodyTouch, MDLabel):
|
||||||
|
"""BadgeText class for kivy Ui"""
|
||||||
|
|
||||||
|
class HelperMyAddress(object):
|
||||||
|
"""Widget used in MyAddress are here"""
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def default_label_when_empty():
|
||||||
|
"""This function returns default message when no address is generated."""
|
||||||
|
content = MDLabel(
|
||||||
|
font_style='Caption',
|
||||||
|
theme_text_color='Primary',
|
||||||
|
text="No address found!" if state.searching_text
|
||||||
|
else "yet no address is created by user!!!!!!!!!!!!!", halign='center', size_hint_y=None, valign='top')
|
||||||
|
return content
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def is_active_badge():
|
||||||
|
badge_obj = BadgeText(
|
||||||
|
size_hint=(None, None),
|
||||||
|
size=[90 if platform == 'android' else 50, 60],
|
||||||
|
text='Active', halign='center',
|
||||||
|
font_style='Body1', theme_text_color='Custom',
|
||||||
|
text_color=ThemeClsColor
|
||||||
|
)
|
||||||
|
badge_obj.font_size = '13sp'
|
||||||
|
return badge_obj
|
||||||
|
|
||||||
|
def myaddress_detail_popup(self, obj, width):
|
||||||
|
show_myaddress_dialogue = MDDialog(
|
||||||
|
type="custom",
|
||||||
|
size_hint=(width, .25),
|
||||||
|
content_cls=obj,
|
||||||
|
)
|
||||||
|
return show_myaddress_dialogue
|
||||||
|
|
||||||
|
def inactive_address_popup(self, width, callback_for_menu_items):
|
||||||
|
dialog_box = MDDialog(
|
||||||
|
text='Address is not currently active. Please click on Toggle button to active it.',
|
||||||
|
size_hint=(width, .25),
|
||||||
|
buttons=[
|
||||||
|
MDFlatButton(
|
||||||
|
text="Ok", on_release=lambda x: callback_for_menu_items("Ok")
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
return dialog_box
|
Reference in New Issue
Block a user