Merge branch 'Kivy-UI-Enhancement' into kivy-exprimental-draft

This commit is contained in:
shekhar-cis 2022-05-09 15:08:47 +05:30
commit cce69bd307
Signed by untrusted user: shekhar-cis
GPG Key ID: F4F00AB04E83F9A7
5 changed files with 169 additions and 65 deletions

View File

@ -1,8 +1,16 @@
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
"""
import os
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
@ -23,8 +31,11 @@ from bitmessagekivy.baseclass.common import (
avatarImageFirstLetter, AvatarSampleWidget, ThemeClsColor, avatarImageFirstLetter, AvatarSampleWidget, ThemeClsColor,
toast toast
) )
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 +45,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 +83,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'
@ -106,20 +117,23 @@ class MyAddress(Screen):
except Exception: except Exception:
pass pass
meny.add_widget(AvatarSampleWidget( meny.add_widget(AvatarSampleWidget(
source=state.imageDir + '/text_images/{}.png'.format( source=os.path.join(
avatarImageFirstLetter(item['text'].strip())))) state.imageDir, 'text_images/{}.png'.format(avatarImageFirstLetter(item["text"].strip())))
))
# source=os.path.join(state.imageDir + '/text_images/{}.jpg'.format(avatarImageFirstLetter(item['text'].strip())))
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 +156,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,
@ -198,20 +219,16 @@ class MyAddress(Screen):
@staticmethod @staticmethod
def filter_address(address): def filter_address(address):
"""Method will filter the my address list data""" """Method will filter the my address list data"""
if [ # import pdb; pdb.set_trace()
x for x in [ searched_text = state.searcing_text.lower()
BMConfigParser().get(address, 'label').lower(), if BMConfigParser().search_addresses(address, searched_text):
address.lower()
]
if (state.searcing_text).lower() in x
]:
return True return True
return False return False
# if [x for x in [BMConfigParser().get(address, 'label').lower(), address.lower()] if (state.searcing_text).lower() in x]:
def disableAddress(self, address, instance): def disable_address_ui(self, address, instance):
"""This method is use for disabling address""" """This method is used to disable addresses from UI"""
BMConfigParser().set(str(address), 'enabled', 'false') BMConfigParser().enable_address(address)
BMConfigParser().save()
instance.parent.parent.theme_text_color = 'Primary' instance.parent.parent.theme_text_color = 'Primary'
instance.parent.parent.canvas.children[3].rgba = [0.5, 0.5, 0.5, 0.5] instance.parent.parent.canvas.children[3].rgba = [0.5, 0.5, 0.5, 0.5]
# try: # try:
@ -221,10 +238,9 @@ class MyAddress(Screen):
toast('Address disabled') toast('Address disabled')
Clock.schedule_once(self.address_permision_callback, 0) Clock.schedule_once(self.address_permision_callback, 0)
def enableAddress(self, address, instance): def enable_address_ui(self, address, instance):
"""This method is use for enabling address""" """This method is used to enable addresses from UI"""
BMConfigParser().set(address, 'enabled', 'true') BMConfigParser().disable_address(address)
BMConfigParser().save()
instance.parent.parent.theme_text_color = 'Custom' instance.parent.parent.theme_text_color = 'Custom'
instance.parent.parent.canvas.children[3].rgba = [0, 0, 0, 0] instance.parent.parent.canvas.children[3].rgba = [0, 0, 0, 0]
# try: # try:
@ -246,6 +262,6 @@ class MyAddress(Screen):
"""This method is used for enable or disable address""" """This method is used for enable or disable address"""
addr = instance.parent.parent.secondary_text addr = instance.parent.parent.secondary_text
if instance.active: if instance.active:
self.enableAddress(addr, instance) self.enable_address_ui(addr, instance)
else: else:
self.disableAddress(addr, instance) self.disable_address_ui(addr, instance)

View File

@ -0,0 +1,78 @@
# pylint: disable=too-many-arguments, no-name-in-module, import-error
# pylint: disable=too-few-public-methods, no-member
"""
MyAddress widgets are here.
"""
from kivymd.uix.button import MDFlatButton
from kivymd.uix.dialog import MDDialog
from kivymd.uix.label import MDLabel
from kivymd.uix.list import IRightBodyTouch
import state
from bitmessagekivy.get_platform import platform
from bitmessagekivy.baseclass.common import ThemeClsColor
class BadgeText(IRightBodyTouch, MDLabel):
"""BadgeText class for kivy UI"""
# pylint: disable=no-init, old-style-class
class DefaultLabelMixin:
"""Widget used in MyAddress are here"""
@staticmethod
def default_label_when_empty():
"""This function returns default message when no address is generated."""
empty_search_label = "No address found!"
no_address_found = "yet no address is created by user!!!!!!!!!!!!!"
content = MDLabel(
font_style='Caption',
theme_text_color='Primary',
text=empty_search_label if state.searching_text # FIXME: Need to replace state with kivy_state
else no_address_found, halign='center', size_hint_y=None, valign='top')
return content
class HelperMyAddress(DefaultLabelMixin):
"""Widget used in MyAddress are here"""
@staticmethod
def is_active_badge():
"""This function show the 'active' label of active Address."""
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, font_size='13sp'
)
return badge_obj
@staticmethod
def myaddress_detail_popup(obj, width):
"""This method show the details of address as popup opens."""
show_myaddress_dialogue = MDDialog(
type="custom",
size_hint=(width, .25),
content_cls=obj,
)
return show_myaddress_dialogue
@staticmethod
def inactive_address_popup(width, callback_for_menu_items):
"""This method shows the warning popup if the address is inactive"""
dialog_text = 'Address is not currently active. Please click on Toggle button to active it.'
dialog_box = MDDialog(
text=dialog_text,
size_hint=(width, .25),
buttons=[
MDFlatButton(
text="Ok", on_release=lambda x: callback_for_menu_items("Ok")
),
],
)
return dialog_box

View File

@ -34,3 +34,4 @@ class KivyStateVariables(object):
self.in_sent_method = False self.in_sent_method = False
self.in_search_mode = False self.in_search_mode = False
self.imageDir = None self.imageDir = None
self.sqlReady = False # set to true by sqlTread when ready for processing

View File

@ -211,7 +211,6 @@ class CustomSpinner(Spinner):
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
kivyy = KivyStateVariables()
# theme_cls = ThemeManager() # theme_cls = ThemeManager()
def __init__(self): def __init__(self):
super(NavigateApp, self).__init__() super(NavigateApp, self).__init__()

View File

@ -199,3 +199,13 @@ class BMConfigParser(configparser.ConfigParser):
def search_addresses(address, searched_text): def search_addresses(address, searched_text):
return [x for x in [BMConfigParser().get(address, 'label').lower(), address.lower()] return [x for x in [BMConfigParser().get(address, 'label').lower(), address.lower()]
if searched_text in x] if searched_text in x]
def disable_address(self, address):
""""To disable the Address"""
self.set(str(address), 'enabled', 'false')
self.save()
def enable_address(self, address):
""""To enable the Address"""
self.set(address, 'enabled', 'true')
self.save()