From b2fd30c338ba4e7d0f0a129f108785f48942e197 Mon Sep 17 00:00:00 2001 From: shekhar-cis Date: Thu, 10 Mar 2022 20:32:01 +0530 Subject: [PATCH] Add set_screen() to set dynamic screen, created separate helper method for widget calling for addressbook --- src/bitmessagekivy/baseclass/addressbook.py | 85 +++++++++++-------- .../baseclass/addressbook_widgets.py | 48 +++++++++++ src/bitmessagekivy/kv/common_widgets.kv | 2 +- src/bitmessagekivy/kv/credits.kv | 2 +- src/bitmessagekivy/kv/login.kv | 2 +- src/bitmessagekivy/kv/msg_composer.kv | 2 +- src/bitmessagekivy/kv/popup.kv | 2 +- src/bitmessagekivy/mpybit.py | 3 + src/bitmessagemain.py | 2 +- 9 files changed, 106 insertions(+), 42 deletions(-) create mode 100644 src/bitmessagekivy/baseclass/addressbook_widgets.py diff --git a/src/bitmessagekivy/baseclass/addressbook.py b/src/bitmessagekivy/baseclass/addressbook.py index 53ec14eb..0eb08462 100644 --- a/src/bitmessagekivy/baseclass/addressbook.py +++ b/src/bitmessagekivy/baseclass/addressbook.py @@ -20,7 +20,7 @@ from bitmessagekivy.baseclass.common import ( ThemeClsColor, SwipeToDeleteItem ) from bitmessagekivy.baseclass.popup import AddbookDetailPopup - +from bitmessagekivy.baseclass.addressbook_widgets import HelperAddressBook class AddressBook(Screen): """AddressBook Screen class for kivy Ui""" @@ -58,15 +58,26 @@ class AddressBook(Screen): self.set_mdList(0, 20) self.ids.scroll_y.bind(scroll_y=self.check_scroll_y) else: - content = MDLabel( - font_style='Caption', - theme_text_color='Primary', - text="No contact found!" if state.searcing_text - else "No contact found yet...... ", - 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 contact found!" if state.searcing_text + # else "No contact found yet...... ", + # halign='center', + # size_hint_y=None, + # valign='top') + self.ids.ml.add_widget(HelperAddressBook.default_label_while_empty()) + + # def show_default_content(self): + # content = MDLabel( + # font_style='Caption', + # theme_text_color='Primary', + # text="No contact found!" if state.searcing_text + # else "No contact found yet...... ", + # halign='center', + # size_hint_y=None, + # valign='top') + # return content def set_mdList(self, start_index, end_index): """Creating the mdList""" @@ -116,32 +127,34 @@ class AddressBook(Screen): if instance.state == 'closed': instance.ids.delete_msg.disabled = True if instance.open_progress == 0.0: - obj = AddbookDetailPopup() - self.address_label = obj.address_label = label - self.address = obj.address = address - width = .9 if platform == 'android' else .8 - self.addbook_popup = MDDialog( - type="custom", - size_hint=(width, .25), - content_cls=obj, - buttons=[ - MDRaisedButton( - text="Send message to", - on_release=self.send_message_to, - ), - MDRaisedButton( - text="Save", - on_release=self.update_addbook_label, - ), - MDRaisedButton( - text="Cancel", - on_release=self.close_pop, - ), - ], - ) - # self.addbook_popup.set_normal_height() - self.addbook_popup.auto_dismiss = False - self.addbook_popup.open() + HelperAddressBook.address_detail_popup(self, address, label, instance) + # obj = AddbookDetailPopup() + # self.address_label = obj.address_label = label + # self.address = obj.address = address + # width = .9 if platform == 'android' else .8 + # self.addbook_popup = MDDialog( + # type="custom", + # size_hint=(width, .25), + # content_cls=obj, + # buttons=[ + # MDRaisedButton( + # text="Send message to", + # on_release=self.send_message_to, + # ), + # MDRaisedButton( + # text="Save", + # on_release=self.update_addbook_label, + # ), + # MDRaisedButton( + # text="Cancel", + # on_release=self.close_pop, + # ), + # ], + # ) + # # self.addbook_popup.set_normal_height() + # self.addbook_popup = HelperAddressBook.address_detail_popup(self) + # self.addbook_popup.auto_dismiss = False + # self.addbook_popup.open() else: instance.ids.delete_msg.disabled = False diff --git a/src/bitmessagekivy/baseclass/addressbook_widgets.py b/src/bitmessagekivy/baseclass/addressbook_widgets.py new file mode 100644 index 00000000..0521a90a --- /dev/null +++ b/src/bitmessagekivy/baseclass/addressbook_widgets.py @@ -0,0 +1,48 @@ +import state + +from bitmessagekivy.get_platform import platform + +from kivymd.uix.button import MDRaisedButton +from kivymd.uix.dialog import MDDialog +from kivymd.uix.label import MDLabel + +from bitmessagekivy.baseclass.popup import AddbookDetailPopup + +class HelperAddressBook: + def default_label_while_empty(): + content = MDLabel( + font_style='Caption', + theme_text_color='Primary', + text="No contact found!" if state.searcing_text + else "No contact found yet...... ", + halign='center', + size_hint_y=None, + valign='top') + return content + + def address_detail_popup(self, address, label, instance): + obj = AddbookDetailPopup() + self.address_label = obj.address_label = label + self.address = obj.address = address + width = .9 if platform == 'android' else .8 + self.addbook_popup = MDDialog( + type="custom", + size_hint=(width, .25), + content_cls=obj, + buttons=[ + MDRaisedButton( + text="Send message to", + on_release=self.send_message_to, + ), + MDRaisedButton( + text="Save", + on_release=self.update_addbook_label, + ), + MDRaisedButton( + text="Cancel", + on_release=self.close_pop, + ), + ], + ) + self.addbook_popup.auto_dismiss = False + self.addbook_popup.open() diff --git a/src/bitmessagekivy/kv/common_widgets.kv b/src/bitmessagekivy/kv/common_widgets.kv index 792fef1e..4a734266 100644 --- a/src/bitmessagekivy/kv/common_widgets.kv +++ b/src/bitmessagekivy/kv/common_widgets.kv @@ -40,7 +40,7 @@ opposite_colors: True elevation_normal: 8 md_bg_color: [0.941, 0, 0,1] - on_press: app.root.ids.scr_mngr.current = 'create' + on_press: app.root.set_screen('create') on_press: app.clear_composer() diff --git a/src/bitmessagekivy/kv/credits.kv b/src/bitmessagekivy/kv/credits.kv index b5eb3db7..46664bb8 100644 --- a/src/bitmessagekivy/kv/credits.kv +++ b/src/bitmessagekivy/kv/credits.kv @@ -25,4 +25,4 @@ MDRaisedButton: height: dp(38) text: app.tr._("+Add more credits") - on_press: app.root.ids.scr_mngr.current = 'payment' + on_press: app.root.set_screen('payment') diff --git a/src/bitmessagekivy/kv/login.kv b/src/bitmessagekivy/kv/login.kv index 44e24c04..ffa922e1 100644 --- a/src/bitmessagekivy/kv/login.kv +++ b/src/bitmessagekivy/kv/login.kv @@ -80,7 +80,7 @@ icon: "chevron-double-right" text: app.tr._("Proceed Next") on_release: - app.root.ids.scr_mngr.current = 'random' + app.root.set_screen('random') on_press: app.root.ids.sc7.reset_address_label() diff --git a/src/bitmessagekivy/kv/msg_composer.kv b/src/bitmessagekivy/kv/msg_composer.kv index 82a2a8cb..0a9f0b5b 100644 --- a/src/bitmessagekivy/kv/msg_composer.kv +++ b/src/bitmessagekivy/kv/msg_composer.kv @@ -76,7 +76,7 @@ icon: 'qrcode-scan' pos_hint: {'center_x': 0.95, 'y': 0.6} on_release: - if root.is_camara_attached(): app.root.ids.scr_mngr.current = 'scanscreen' + if root.is_camara_attached(): app.root.set_screen('scanscreen') else: root.camera_alert() on_press: app.root.ids.sc23.get_screen('composer') diff --git a/src/bitmessagekivy/kv/popup.kv b/src/bitmessagekivy/kv/popup.kv index 217d9131..fd64ee26 100644 --- a/src/bitmessagekivy/kv/popup.kv +++ b/src/bitmessagekivy/kv/popup.kv @@ -153,7 +153,7 @@ MDRaisedButton: size_hint: 1.5, None height: dp(40) - on_press: app.root.ids.scr_mngr.current = 'showqrcode' + on_press: app.set_screen('showqrcode') on_press: app.root.ids.sc15.qrdisplay(root, root.address) MDLabel: font_style: 'H6' diff --git a/src/bitmessagekivy/mpybit.py b/src/bitmessagekivy/mpybit.py index e8adc0c8..054e512f 100644 --- a/src/bitmessagekivy/mpybit.py +++ b/src/bitmessagekivy/mpybit.py @@ -246,6 +246,9 @@ class NavigateApp(MDApp): return Builder.load_file( os.path.join(os.path.dirname(__file__), 'main.kv')) + def set_screen(self, screen_name): + self.root.ids.scr_mngr.current = screen_name + def run(self): """Running the widgets""" kivyuisignaler.release() diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index 2f609074..1ac71795 100755 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -310,7 +310,7 @@ class Main(object): asyncoreThread = BMNetworkThread() asyncoreThread.daemon = True asyncoreThread.start() - for i in range(config.safeGet('threads', 'receive')): + for i in range(config.safeGetInt('threads', 'receive')): receiveQueueThread = ReceiveQueueThread(i) receiveQueueThread.daemon = True receiveQueueThread.start()