From b0fe7d7a04cb65337854d8ba04bde3e2c5d3c087 Mon Sep 17 00:00:00 2001 From: surbhi Date: Sat, 24 Aug 2024 21:02:26 +0530 Subject: [PATCH 1/6] code-quality: Update code quality kivy/baseclass/addressbook_widget --- .../baseclass/addressbook_widgets.py | 80 +++++++++++-------- 1 file changed, 46 insertions(+), 34 deletions(-) diff --git a/src/bitmessagekivy/baseclass/addressbook_widgets.py b/src/bitmessagekivy/baseclass/addressbook_widgets.py index 3654dfa3..bd46f51d 100644 --- a/src/bitmessagekivy/baseclass/addressbook_widgets.py +++ b/src/bitmessagekivy/baseclass/addressbook_widgets.py @@ -1,50 +1,62 @@ # pylint: disable=no-member, too-many-arguments, too-few-public-methods -""" -Addressbook widgets are here. -""" + +"""Addressbook widgets are here.""" from kivy.app import App from kivymd.uix.button import MDRaisedButton from kivymd.uix.dialog import MDDialog -class HelperAddressBook(object): - """Widget used in Addressbook are here""" +class HelperAddressBook: + """Widget utilities for Addressbook.""" @staticmethod def address_detail_popup(obj, send_message, update_address, close_popup, width): - """This function shows the address's details and opens the popup.""" - show_dialogue = MDDialog( + """ + Shows address details in a popup with clear actions. + + Args: + obj: The widget containing the address details to display. + send_message: The function to call when the "Send message" button is pressed. + update_address: The function to call when the "Save" button is pressed. + close_popup: The function to call when the "Cancel" button is pressed or the popup is closed. + width: The desired width of the popup as a proportion of the screen. + """ + + buttons = [ + MDRaisedButton(text="Send message", on_release=send_message), + MDRaisedButton(text="Update Address", on_release=update_address), + MDRaisedButton(text="Cancel", on_release=close_popup), + ] + + return MDDialog( type="custom", - size_hint=(width, .25), + size_hint=(width, 0.25), content_cls=obj, - buttons=[ - MDRaisedButton( - text="Send message to", - on_release=send_message, - ), - MDRaisedButton( - text="Save", - on_release=update_address, - ), - MDRaisedButton( - text="Cancel", - on_release=close_popup, - ), - ], + buttons=buttons, ) - return show_dialogue @staticmethod def compose_message(from_addr=None, to_addr=None): - """This UI independent method for message sending to reciever""" - window_obj = App.get_runnint_app().root.ids - if to_addr: - window_obj.id_create.children[1].ids.txt_input.text = to_addr - if from_addr: - window_obj.id_create.children[1].ids.txt_input.text = from_addr - window_obj.id_create.children[1].ids.ti.text = '' - window_obj.id_create.children[1].ids.composer_dropdown.text = 'Select' - window_obj.id_create.children[1].ids.subject.text = '' - window_obj.id_create.children[1].ids.body.text = '' - window_obj.scr_mngr.current = 'create' + """ + Composes a new message (UI-independent). + + Args: + from_addr (str, optional): The address to set in the "From" field. Defaults to None. + to_addr (str, optional): The address to set in the "To" field. Defaults to None. + """ + + app = App.get_running_app() + + ids = app.root.ids + create_screen = ids.id_create.children[1].ids + + # Reset fields + create_screen.txt_input.text = to_addr if to_addr else from_addr + create_screen.ti.text = "" + create_screen.composer_dropdown.text = "Select" + create_screen.subject.text = "" + create_screen.body.text = "" + + # Navigate to create screen + ids.scr_mngr.current = "create" -- 2.45.1 From edf8d62ea06722188730de37f0b6644e97353cef Mon Sep 17 00:00:00 2001 From: surbhi Date: Thu, 29 Aug 2024 08:16:22 +0530 Subject: [PATCH 2/6] code-quality: Update code quality kivy/baseclass/addressbook --- src/bitmessagekivy/baseclass/addressbook.py | 67 ++++++++++----------- 1 file changed, 31 insertions(+), 36 deletions(-) diff --git a/src/bitmessagekivy/baseclass/addressbook.py b/src/bitmessagekivy/baseclass/addressbook.py index f18a0142..d33d0f98 100644 --- a/src/bitmessagekivy/baseclass/addressbook.py +++ b/src/bitmessagekivy/baseclass/addressbook.py @@ -13,10 +13,7 @@ import os import logging from functools import partial -from kivy.properties import ( - ListProperty, - StringProperty -) +from kivy.properties import ListProperty, StringProperty from kivy.uix.screenmanager import Screen from kivy.app import App @@ -34,7 +31,7 @@ logger = logging.getLogger('default') class AddressBook(Screen, HelperAddressBook): - """AddressBook Screen class for kivy Ui""" + """AddressBook Screen class for kivy UI""" queryreturn = ListProperty() has_refreshed = True @@ -45,21 +42,23 @@ class AddressBook(Screen, HelperAddressBook): def __init__(self, *args, **kwargs): """Getting AddressBook Details""" - super(AddressBook, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) self.addbook_popup = None self.kivy_state = kivy_state_variables() def loadAddresslist(self, account, where="", what=""): - """Clock Schdule for method AddressBook""" + """Load address list with optional search filters""" if self.kivy_state.searching_text: self.ids.scroll_y.scroll_y = 1.0 where = ['label', 'address'] what = self.kivy_state.searching_text + xAddress = '' self.ids.tag_label.text = '' - self.queryreturn = kivy_helper_search.search_sql( - xAddress, account, "addressbook", where, what, False) - self.queryreturn = [obj for obj in reversed(self.queryreturn)] + self.queryreturn = list(reversed( + kivy_helper_search.search_sql(xAddress, account, "addressbook", where, what, False) + )) + if self.queryreturn: self.ids.tag_label.text = 'Address Book' self.has_refreshed = True @@ -69,53 +68,47 @@ class AddressBook(Screen, HelperAddressBook): self.ids.ml.add_widget(empty_screen_label(self.label_str, self.no_search_res_found)) def set_mdList(self, start_index, end_index): - """Creating the mdList""" + """Create the mdList""" for item in self.queryreturn[start_index:end_index]: - message_row = SwipeToDeleteItem( - text=item[0], - ) + message_row = SwipeToDeleteItem(text=item[0]) listItem = message_row.ids.content listItem.secondary_text = item[1] listItem.theme_text_color = "Custom" listItem.text_color = ThemeClsColor image = os.path.join( - self.kivy_state.imageDir, "text_images", "{}.png".format(avatar_image_first_letter(item[0].strip())) + self.kivy_state.imageDir, "text_images", f"{avatar_image_first_letter(item[0].strip())}.png" ) message_row.ids.avater_img.source = image - listItem.bind(on_release=partial( - self.addBook_detail, item[1], item[0], message_row)) + listItem.bind(on_release=partial(self.addBook_detail, item[1], item[0], message_row)) message_row.ids.delete_msg.bind(on_press=partial(self.delete_address, item[1])) self.ids.ml.add_widget(message_row) - def check_scroll_y(self, instance, somethingelse): - """Load data on scroll""" + def check_scroll_y(self, instance, _): + """Load more data on scroll down""" if self.ids.scroll_y.scroll_y <= -0.0 and self.has_refreshed: self.ids.scroll_y.scroll_y = 0.06 exist_addresses = len(self.ids.ml.children) if exist_addresses != len(self.queryreturn): self.update_addressBook_on_scroll(exist_addresses) - self.has_refreshed = ( - True if exist_addresses != len(self.queryreturn) else False - ) + self.has_refreshed = exist_addresses != len(self.queryreturn) def update_addressBook_on_scroll(self, exist_addresses): - """Load more data on scroll down""" + """Load more data on scroll""" self.set_mdList(exist_addresses, exist_addresses + 5) @staticmethod def refreshs(*args): """Refresh the Widget""" - # @staticmethod def addBook_detail(self, address, label, instance, *args): - """Addressbook details""" + """Display Addressbook details""" if instance.state == 'closed': instance.ids.delete_msg.disabled = True if instance.open_progress == 0.0: obj = SavedAddressDetailPopup() self.address_label = obj.address_label = label self.address = obj.address = address - width = .9 if platform == 'android' else .8 + width = 0.9 if platform == 'android' else 0.8 self.addbook_popup = self.address_detail_popup( obj, self.send_message_to, self.update_addbook_label, self.close_pop, width) @@ -125,40 +118,42 @@ class AddressBook(Screen, HelperAddressBook): instance.ids.delete_msg.disabled = False def delete_address(self, address, instance, *args): - """Delete inbox mail from inbox listing""" + """Delete address from the address book""" self.ids.ml.remove_widget(instance.parent.parent) - # if len(self.ids.ml.children) == 0: - if self.ids.ml.children is not None: + if self.ids.ml.children: self.ids.tag_label.text = '' - sqlExecute( - "DELETE FROM addressbook WHERE address = ?", address) + sqlExecute("DELETE FROM addressbook WHERE address = ?", address) toast('Address Deleted') def close_pop(self, instance): - """Pop is Canceled""" + """Cancel and close the popup""" self.addbook_popup.dismiss() toast('Canceled') def update_addbook_label(self, instance): - """Updating the label of address book address""" + """Update the label of the address book""" address_list = kivy_helper_search.search_sql(folder="addressbook") stored_labels = [labels[0] for labels in address_list] add_dict = dict(address_list) label = str(self.addbook_popup.content_cls.ids.add_label.text) + if label in stored_labels and self.address == add_dict[label]: stored_labels.remove(label) + if label and label not in stored_labels: sqlExecute(""" UPDATE addressbook SET label = ? WHERE address = ?""", label, self.addbook_popup.content_cls.address) - App.get_running_app().root.ids.id_addressbook.ids.ml.clear_widgets() - App.get_running_app().root.ids.id_addressbook.loadAddresslist(None, 'All', '') + + app = App.get_running_app() + app.root.ids.id_addressbook.ids.ml.clear_widgets() + app.root.ids.id_addressbook.loadAddresslist(None, 'All', '') self.addbook_popup.dismiss() toast('Saved') def send_message_to(self, instance): - """Method used to fill to_address of composer autofield""" + """Fill the to_address of the composer autofield""" App.get_running_app().set_navbar_for_composer() self.compose_message(None, self.address) self.addbook_popup.dismiss() -- 2.45.1 From 110286ff5e7412ce902cf85d384bdd4e3d017916 Mon Sep 17 00:00:00 2001 From: surbhi Date: Fri, 30 Aug 2024 11:10:35 +0530 Subject: [PATCH 3/6] fix image_dir typo --- src/bitmessagekivy/baseclass/addressbook.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bitmessagekivy/baseclass/addressbook.py b/src/bitmessagekivy/baseclass/addressbook.py index d33d0f98..1f3568f7 100644 --- a/src/bitmessagekivy/baseclass/addressbook.py +++ b/src/bitmessagekivy/baseclass/addressbook.py @@ -76,7 +76,7 @@ class AddressBook(Screen, HelperAddressBook): listItem.theme_text_color = "Custom" listItem.text_color = ThemeClsColor image = os.path.join( - self.kivy_state.imageDir, "text_images", f"{avatar_image_first_letter(item[0].strip())}.png" + self.kivy_state.image_dir, "text_images", f"{avatar_image_first_letter(item[0].strip())}.png" ) message_row.ids.avater_img.source = image listItem.bind(on_release=partial(self.addBook_detail, item[1], item[0], message_row)) -- 2.45.1 From 7419e4172b0262c8ca95686dd2314d7c023e3a49 Mon Sep 17 00:00:00 2001 From: surbhi Date: Fri, 11 Oct 2024 19:21:17 +0530 Subject: [PATCH 4/6] supress pylint super complaint --- src/bitmessagekivy/baseclass/addressbook.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bitmessagekivy/baseclass/addressbook.py b/src/bitmessagekivy/baseclass/addressbook.py index 1f3568f7..4a9e8ec0 100644 --- a/src/bitmessagekivy/baseclass/addressbook.py +++ b/src/bitmessagekivy/baseclass/addressbook.py @@ -42,7 +42,7 @@ class AddressBook(Screen, HelperAddressBook): def __init__(self, *args, **kwargs): """Getting AddressBook Details""" - super().__init__(*args, **kwargs) + super().__init__(*args, **kwargs) # pylint: disable=missing-super-argument self.addbook_popup = None self.kivy_state = kivy_state_variables() -- 2.45.1 From 4640b7082a6cbfbd01fea493aceceff32e15aa08 Mon Sep 17 00:00:00 2001 From: surbhi Date: Tue, 22 Oct 2024 10:04:17 +0530 Subject: [PATCH 5/6] Supress f-string flake8 error --- src/bitmessagekivy/baseclass/addressbook.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bitmessagekivy/baseclass/addressbook.py b/src/bitmessagekivy/baseclass/addressbook.py index 4a9e8ec0..d734fdb3 100644 --- a/src/bitmessagekivy/baseclass/addressbook.py +++ b/src/bitmessagekivy/baseclass/addressbook.py @@ -76,7 +76,7 @@ class AddressBook(Screen, HelperAddressBook): listItem.theme_text_color = "Custom" listItem.text_color = ThemeClsColor image = os.path.join( - self.kivy_state.image_dir, "text_images", f"{avatar_image_first_letter(item[0].strip())}.png" + self.kivy_state.image_dir, "text_images", f"{avatar_image_first_letter(item[0].strip())}.png" # noqa: E999 ) message_row.ids.avater_img.source = image listItem.bind(on_release=partial(self.addBook_detail, item[1], item[0], message_row)) -- 2.45.1 From 6c42e43e60ae5e5c7e03c455a98a04955f70d25f Mon Sep 17 00:00:00 2001 From: surbhi Date: Sun, 19 Jan 2025 20:15:56 +0530 Subject: [PATCH 6/6] Fixed lint errors --- src/bitmessagekivy/baseclass/addressbook.py | 5 +++-- src/bitmessagekivy/baseclass/addressbook_widgets.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/bitmessagekivy/baseclass/addressbook.py b/src/bitmessagekivy/baseclass/addressbook.py index d734fdb3..31da62ae 100644 --- a/src/bitmessagekivy/baseclass/addressbook.py +++ b/src/bitmessagekivy/baseclass/addressbook.py @@ -52,7 +52,7 @@ class AddressBook(Screen, HelperAddressBook): self.ids.scroll_y.scroll_y = 1.0 where = ['label', 'address'] what = self.kivy_state.searching_text - + xAddress = '' self.ids.tag_label.text = '' self.queryreturn = list(reversed( @@ -76,7 +76,8 @@ class AddressBook(Screen, HelperAddressBook): listItem.theme_text_color = "Custom" listItem.text_color = ThemeClsColor image = os.path.join( - self.kivy_state.image_dir, "text_images", f"{avatar_image_first_letter(item[0].strip())}.png" # noqa: E999 + self.kivy_state.image_dir, "text_images", + f"{avatar_image_first_letter(item[0].strip())}.png" # noqa: E999 ) message_row.ids.avater_img.source = image listItem.bind(on_release=partial(self.addBook_detail, item[1], item[0], message_row)) diff --git a/src/bitmessagekivy/baseclass/addressbook_widgets.py b/src/bitmessagekivy/baseclass/addressbook_widgets.py index bd46f51d..1c28932c 100644 --- a/src/bitmessagekivy/baseclass/addressbook_widgets.py +++ b/src/bitmessagekivy/baseclass/addressbook_widgets.py @@ -7,7 +7,7 @@ from kivymd.uix.button import MDRaisedButton from kivymd.uix.dialog import MDDialog -class HelperAddressBook: +class HelperAddressBook(): """Widget utilities for Addressbook.""" @staticmethod -- 2.45.1