From 216f2e09003d87d79534d13da7b132fb0c7e24a3 Mon Sep 17 00:00:00 2001 From: shekhar-cis Date: Thu, 24 Mar 2022 15:29:24 +0530 Subject: [PATCH 1/7] Add myaddress_widget --- src/bitmessagekivy/baseclass/myaddress.py | 106 ++++++++++-------- .../baseclass/myaddress_widgets.py | 68 +++++++++++ 2 files changed, 129 insertions(+), 45 deletions(-) create mode 100644 src/bitmessagekivy/baseclass/myaddress_widgets.py diff --git a/src/bitmessagekivy/baseclass/myaddress.py b/src/bitmessagekivy/baseclass/myaddress.py index 2e84e871..a68269e3 100644 --- a/src/bitmessagekivy/baseclass/myaddress.py +++ b/src/bitmessagekivy/baseclass/myaddress.py @@ -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 bitmessagekivy.get_platform import platform from bmconfigparser import BMConfigParser from kivy.clock import Clock -# from kivy.metrics import dp from kivy.properties import ( ListProperty, StringProperty @@ -25,6 +32,7 @@ from bitmessagekivy.baseclass.common import ( ) from bitmessagekivy.baseclass.popup import MyaddDetailPopup +from bitmessagekivy.baseclass.myaddress_widgets import HelperMyAddress class ToggleBtn(IRightBodyTouch, MDSwitch): """ToggleBtn class for kivy Ui""" @@ -34,11 +42,11 @@ class CustomTwoLineAvatarIconListItem(TwoLineAvatarIconListItem): """CustomTwoLineAvatarIconListItem class for kivy Ui""" -class BadgeText(IRightBodyTouch, MDLabel): - """BadgeText class for kivy Ui""" +# class BadgeText(IRightBodyTouch, MDLabel): +# """BadgeText class for kivy Ui""" -class MyAddress(Screen): +class MyAddress(Screen, HelperMyAddress): """MyAddress screen class for kivy Ui""" address_label = StringProperty() @@ -72,15 +80,15 @@ class MyAddress(Screen): self.set_mdList(0, 15) self.ids.refresh_layout.bind(scroll_y=self.check_scroll_y) else: - content = MDLabel( - font_style='Caption', - theme_text_color='Primary', - text="No address found!" if state.searcing_text - else "yet no address is created by user!!!!!!!!!!!!!", - halign='center', - size_hint_y=None, - valign='top') - self.ids.ml.add_widget(content) + # content = MDLabel( + # font_style='Caption', + # theme_text_color='Primary', + # text="No address found!" if state.searcing_text + # else "yet no address is created by user!!!!!!!!!!!!!", + # halign='center', + # size_hint_y=None, + # valign='top') + self.ids.ml.add_widget(self.default_label_when_empty()) if not state.searcing_text and not self.is_add_created: try: self.manager.current = 'login' @@ -111,15 +119,16 @@ class MyAddress(Screen): meny.bind(on_press=partial( self.myadd_detail, item['secondary_text'], item['text'])) if state.association == item['secondary_text'] and is_enable == 'true': - 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' - meny.add_widget(badge_obj) + # 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' + # meny.add_widget(badge_obj) + meny.add_widget(self.is_active_badge()) else: meny.add_widget(ToggleBtn(active=True if is_enable == 'true' else False)) self.ids.ml.add_widget(meny) @@ -142,42 +151,49 @@ class MyAddress(Screen): # @staticmethod def myadd_detail(self, fromaddress, label, *args): """Load myaddresses details""" + if BMConfigParser().get(fromaddress, 'enabled') == 'true': obj = MyaddDetailPopup() self.address_label = obj.address_label = label self.text_address = obj.address = fromaddress width = .9 if platform == 'android' else .6 - self.myadddetail_popup = MDDialog( - type="custom", - size_hint=(width, .25), - content_cls=obj, - ) + # self.myadddetail_popup = MDDialog( + # type="custom", + # size_hint=(width, .25), + # content_cls=obj, + # ) + self.myadddetail_popup = self.myaddress_detail_popup(obj, width) + # self.myadddetail_popup.set_normal_height() self.myadddetail_popup.auto_dismiss = False self.myadddetail_popup.open() # p.set_address(fromaddress, label) else: width = .8 if platform == 'android' else .55 - 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") - ), - ], - ) - dialog_box.open() + # 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") + # ), + # ], + # ) + # 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): - """Callback of alert box""" - dialog_box.dismiss() - toast(text_item) + # def callback_for_menu_items(text_item, *arg): + # """Callback of alert box""" + # import pdb; pdb.set_trace() + # dialog_box.dismiss() + # toast(text_item) # @staticmethod - # def callback_for_menu_items(text_item, *arg): - # """Callback of alert box""" - # toast(text_item) + def callback_for_menu_items(self, text_item, *arg): + """Callback of alert box""" + self.dialog_box.dismiss() + toast(text_item) def refresh_callback(self, *args): """Method updates the state of application, diff --git a/src/bitmessagekivy/baseclass/myaddress_widgets.py b/src/bitmessagekivy/baseclass/myaddress_widgets.py new file mode 100644 index 00000000..4c67ef35 --- /dev/null +++ b/src/bitmessagekivy/baseclass/myaddress_widgets.py @@ -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 From b553b9c3bb735a82890688b63d02e6f118b514bc Mon Sep 17 00:00:00 2001 From: shekhar-cis Date: Thu, 24 Mar 2022 19:07:41 +0530 Subject: [PATCH 2/7] add Static method --- src/bitmessagekivy/baseclass/myaddress_widgets.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/bitmessagekivy/baseclass/myaddress_widgets.py b/src/bitmessagekivy/baseclass/myaddress_widgets.py index 4c67ef35..1ef8cd0d 100644 --- a/src/bitmessagekivy/baseclass/myaddress_widgets.py +++ b/src/bitmessagekivy/baseclass/myaddress_widgets.py @@ -42,12 +42,12 @@ class HelperMyAddress(object): size=[90 if platform == 'android' else 50, 60], text='Active', halign='center', font_style='Body1', theme_text_color='Custom', - text_color=ThemeClsColor + text_color=ThemeClsColor, font_size = '13sp' ) - badge_obj.font_size = '13sp' return badge_obj - def myaddress_detail_popup(self, obj, width): + @staticmethod + def myaddress_detail_popup(obj, width): show_myaddress_dialogue = MDDialog( type="custom", size_hint=(width, .25), @@ -55,7 +55,8 @@ class HelperMyAddress(object): ) return show_myaddress_dialogue - def inactive_address_popup(self, width, callback_for_menu_items): + @staticmethod + def inactive_address_popup(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), From 309a3d0bcc85e0cd3fa288d13475c365aa509e5d Mon Sep 17 00:00:00 2001 From: shekhar-cis Date: Fri, 25 Mar 2022 15:35:35 +0530 Subject: [PATCH 3/7] Add f string instead of format() --- src/bitmessagekivy/baseclass/myaddress.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/bitmessagekivy/baseclass/myaddress.py b/src/bitmessagekivy/baseclass/myaddress.py index a68269e3..a003a10c 100644 --- a/src/bitmessagekivy/baseclass/myaddress.py +++ b/src/bitmessagekivy/baseclass/myaddress.py @@ -6,6 +6,7 @@ myaddress.py All generated addresses are managed in MyAddress """ +import os from functools import partial from bitmessagekivy.get_platform import platform from bmconfigparser import BMConfigParser @@ -114,8 +115,10 @@ class MyAddress(Screen, HelperMyAddress): except Exception: pass meny.add_widget(AvatarSampleWidget( - source=state.imageDir + '/text_images/{}.png'.format( - avatarImageFirstLetter(item['text'].strip())))) + source=os.path.join( + 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( self.myadd_detail, item['secondary_text'], item['text'])) if state.association == item['secondary_text'] and is_enable == 'true': From c3a39229a02f7b69f82e517045429f985d3d73bb Mon Sep 17 00:00:00 2001 From: shekhar-cis Date: Mon, 4 Apr 2022 17:49:30 +0530 Subject: [PATCH 4/7] Add mixin label class --- .../baseclass/myaddress_widgets.py | 38 +++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/src/bitmessagekivy/baseclass/myaddress_widgets.py b/src/bitmessagekivy/baseclass/myaddress_widgets.py index 1ef8cd0d..d4bd70f4 100644 --- a/src/bitmessagekivy/baseclass/myaddress_widgets.py +++ b/src/bitmessagekivy/baseclass/myaddress_widgets.py @@ -1,53 +1,60 @@ -# pylint: disable=no-member, too-many-arguments +# pylint: disable=too-many-arguments, no-name-in-module, import-error +# pylint: disable=too-few-public-methods, no-member + """ 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) +from kivymd.uix.list import IRightBodyTouch import state -from bitmessagekivy.baseclass.common import ( - avatarImageFirstLetter, AvatarSampleWidget, ThemeClsColor, - toast -) +from bitmessagekivy.get_platform import platform +from bitmessagekivy.baseclass.common import ThemeClsColor + class BadgeText(IRightBodyTouch, MDLabel): - """BadgeText class for kivy Ui""" + """BadgeText class for kivy UI""" -class HelperMyAddress(object): + +# pylint: disable=no-init, old-style-class +class DefaultLabelMixin: """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.""" + 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="No address found!" if state.searching_text - else "yet no address is created by user!!!!!!!!!!!!!", halign='center', size_hint_y=None, valign='top') + 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' + 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), @@ -57,6 +64,7 @@ class HelperMyAddress(object): @staticmethod def inactive_address_popup(width, callback_for_menu_items): + """This method shows the warning popup if the address is inactive""" dialog_box = MDDialog( text='Address is not currently active. Please click on Toggle button to active it.', size_hint=(width, .25), From 25d58c2a0cff9772e0c9df15f291bdf4b39c5806 Mon Sep 17 00:00:00 2001 From: shekhar-cis Date: Thu, 5 May 2022 15:33:24 +0530 Subject: [PATCH 5/7] Add enable/disable method in bmconfigparser & initialize kivy state variable inside NavigateApp --- src/bitmessagekivy/mpybit.py | 1 - src/bmconfigparser.py | 10 ++++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/bitmessagekivy/mpybit.py b/src/bitmessagekivy/mpybit.py index 25c5384e..1a435689 100644 --- a/src/bitmessagekivy/mpybit.py +++ b/src/bitmessagekivy/mpybit.py @@ -211,7 +211,6 @@ class CustomSpinner(Spinner): class NavigateApp(MDApp): """Navigation Layout of class""" # pylint: disable=too-many-public-methods,inconsistent-return-statements - kivyy = KivyStateVariables() # theme_cls = ThemeManager() def __init__(self): super(NavigateApp, self).__init__() diff --git a/src/bmconfigparser.py b/src/bmconfigparser.py index 30a6be4b..228fff0a 100644 --- a/src/bmconfigparser.py +++ b/src/bmconfigparser.py @@ -199,3 +199,13 @@ class BMConfigParser(configparser.ConfigParser): def search_addresses(address, searched_text): return [x for x in [BMConfigParser().get(address, 'label').lower(), address.lower()] 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() From b01764a5a9f141c050957f3416fc706a8fba92c0 Mon Sep 17 00:00:00 2001 From: shekhar-cis Date: Wed, 4 May 2022 19:25:30 +0530 Subject: [PATCH 6/7] Add address enable/disable function to addresses --- src/bitmessagekivy/baseclass/myaddress.py | 32 +++++++++---------- .../baseclass/myaddress_widgets.py | 3 +- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/bitmessagekivy/baseclass/myaddress.py b/src/bitmessagekivy/baseclass/myaddress.py index a003a10c..d3b9574d 100644 --- a/src/bitmessagekivy/baseclass/myaddress.py +++ b/src/bitmessagekivy/baseclass/myaddress.py @@ -31,6 +31,9 @@ from bitmessagekivy.baseclass.common import ( avatarImageFirstLetter, AvatarSampleWidget, ThemeClsColor, toast ) + +from addresses import disable_addresses, enable_addresses + from bitmessagekivy.baseclass.popup import MyaddDetailPopup from bitmessagekivy.baseclass.myaddress_widgets import HelperMyAddress @@ -217,20 +220,16 @@ class MyAddress(Screen, HelperMyAddress): @staticmethod def filter_address(address): """Method will filter the my address list data""" - if [ - x for x in [ - BMConfigParser().get(address, 'label').lower(), - address.lower() - ] - if (state.searcing_text).lower() in x - ]: + # import pdb; pdb.set_trace() + searched_text = state.searcing_text.lower() + if BMConfigParser().search_addresses(address, searched_text): return True 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): - """This method is use for disabling address""" - BMConfigParser().set(str(address), 'enabled', 'false') - BMConfigParser().save() + def disable_address_ui(self, address, instance): + """This method is used to disable addresses from UI""" + BMConfigParser().enable_addresses(address) instance.parent.parent.theme_text_color = 'Primary' instance.parent.parent.canvas.children[3].rgba = [0.5, 0.5, 0.5, 0.5] # try: @@ -240,10 +239,9 @@ class MyAddress(Screen, HelperMyAddress): toast('Address disabled') Clock.schedule_once(self.address_permision_callback, 0) - def enableAddress(self, address, instance): - """This method is use for enabling address""" - BMConfigParser().set(address, 'enabled', 'true') - BMConfigParser().save() + def enable_address_ui(self, address, instance): + """This method is used to enable addresses from UI""" + BMConfigParser().disable_addresses(address) instance.parent.parent.theme_text_color = 'Custom' instance.parent.parent.canvas.children[3].rgba = [0, 0, 0, 0] # try: @@ -265,6 +263,6 @@ class MyAddress(Screen, HelperMyAddress): """This method is used for enable or disable address""" addr = instance.parent.parent.secondary_text if instance.active: - self.enableAddress(addr, instance) + self.enable_address_ui(addr, instance) else: - self.disableAddress(addr, instance) + self.disable_address_ui(addr, instance) diff --git a/src/bitmessagekivy/baseclass/myaddress_widgets.py b/src/bitmessagekivy/baseclass/myaddress_widgets.py index d4bd70f4..94202cd5 100644 --- a/src/bitmessagekivy/baseclass/myaddress_widgets.py +++ b/src/bitmessagekivy/baseclass/myaddress_widgets.py @@ -65,8 +65,9 @@ class HelperMyAddress(DefaultLabelMixin): @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='Address is not currently active. Please click on Toggle button to active it.', + text=dialog_text, size_hint=(width, .25), buttons=[ MDFlatButton( From aa93bdcfdec448d247f64fb0a11f5908a1e0018c Mon Sep 17 00:00:00 2001 From: shekhar-cis Date: Mon, 9 May 2022 15:08:24 +0530 Subject: [PATCH 7/7] add sqlready var in kivy_state --- src/bitmessagekivy/kivy_state.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bitmessagekivy/kivy_state.py b/src/bitmessagekivy/kivy_state.py index f5388b77..0c8bc4c5 100644 --- a/src/bitmessagekivy/kivy_state.py +++ b/src/bitmessagekivy/kivy_state.py @@ -34,3 +34,4 @@ class KivyStateVariables(object): self.in_sent_method = False self.in_search_mode = False self.imageDir = None + self.sqlReady = False # set to true by sqlTread when ready for processing