From 3ac14edea10b067903bffc6d0aaf5530172b03f1 Mon Sep 17 00:00:00 2001 From: surbhi Date: Fri, 20 Sep 2024 06:51:15 +0530 Subject: [PATCH 1/7] code-quality: Update code quality kivy/baseclass/maildetail --- src/bitmessagekivy/baseclass/maildetail.py | 212 +++++++++++---------- 1 file changed, 107 insertions(+), 105 deletions(-) diff --git a/src/bitmessagekivy/baseclass/maildetail.py b/src/bitmessagekivy/baseclass/maildetail.py index 11fb6c794..b8702af44 100644 --- a/src/bitmessagekivy/baseclass/maildetail.py +++ b/src/bitmessagekivy/baseclass/maildetail.py @@ -2,28 +2,23 @@ # pylint: disable=unnecessary-comprehension, no-member, no-name-in-module, too-few-public-methods """ -Maildetail screen for inbox, sent, draft and trash. +MailDetail screen for inbox, sent, draft, and trash. """ import os from datetime import datetime +import logging from kivy.core.clipboard import Clipboard from kivy.clock import Clock -from kivy.properties import ( - StringProperty, - NumericProperty -) +from kivy.properties import StringProperty, NumericProperty from kivy.uix.screenmanager import Screen from kivy.factory import Factory from kivy.app import App from kivymd.uix.button import MDFlatButton, MDIconButton from kivymd.uix.dialog import MDDialog -from kivymd.uix.list import ( - OneLineListItem, - IRightBodyTouch -) +from kivymd.uix.list import OneLineListItem, IRightBodyTouch from pybitmessage.bitmessagekivy.baseclass.common import ( toast, avatar_image_first_letter, show_time_history, kivy_state_variables @@ -34,45 +29,41 @@ class OneLineListTitle(OneLineListItem): - """OneLineListTitle class for kivy Ui""" + """OneLineListTitle class for Kivy UI.""" __events__ = ('on_long_press', ) long_press_time = NumericProperty(1) def on_state(self, instance, value): - """On state""" + """Handle state change for long press.""" if value == 'down': - lpt = self.long_press_time - self._clockev = Clock.schedule_once(self._do_long_press, lpt) + self._clock_event = Clock.schedule_once(self._do_long_press, self.long_press_time) else: - self._clockev.cancel() + self._clock_event.cancel() def _do_long_press(self, dt): - """Do long press""" + """Trigger the long press event.""" self.dispatch('on_long_press') - def on_long_press(self, *largs): - """On long press""" - self.copymessageTitle(self.text) + def on_long_press(self, *args): + """Handle long press and display message title.""" + self.copy_message_title(self.text) - def copymessageTitle(self, title_text): - """this method is for displaying dialog box""" + def copy_message_title(self, title_text): + """Display dialog box with options to copy the message title.""" self.title_text = title_text - width = .8 if platform == 'android' else .55 + width = 0.8 if platform == 'android' else 0.55 self.dialog_box = MDDialog( text=title_text, - size_hint=(width, .25), + size_hint=(width, 0.25), buttons=[ - MDFlatButton( - text="Copy", on_release=self.callback_for_copy_title - ), - MDFlatButton( - text="Cancel", on_release=self.callback_for_copy_title, - ), - ],) + MDFlatButton(text="Copy", on_release=self.copy_title_callback), + MDFlatButton(text="Cancel", on_release=self.copy_title_callback), + ], + ) self.dialog_box.open() - def callback_for_copy_title(self, instance): - """Callback of alert box""" + def copy_title_callback(self, instance): + """Handle dialog box button callback.""" if instance.text == 'Copy': Clipboard.copy(self.title_text) self.dialog_box.dismiss() @@ -80,11 +71,10 @@ def callback_for_copy_title(self, instance): class IconRightSampleWidget(IRightBodyTouch, MDIconButton): - """IconRightSampleWidget class for kivy Ui""" - + """IconRightSampleWidget class for Kivy UI.""" class MailDetail(Screen): # pylint: disable=too-many-instance-attributes - """MailDetail Screen class for kivy Ui""" + """MailDetail Screen class for Kivy UI.""" to_addr = StringProperty() from_addr = StringProperty() @@ -97,98 +87,111 @@ class MailDetail(Screen): # pylint: disable=too-many-instance-attributes no_subject = '(no subject)' def __init__(self, *args, **kwargs): - """Mail Details method""" - super(MailDetail, self).__init__(*args, **kwargs) + """Initialize MailDetail screen.""" + super().__init__(*args, **kwargs) self.kivy_state = kivy_state_variables() Clock.schedule_once(self.init_ui, 0) def init_ui(self, dt=0): - """Clock Schdule for method MailDetail mails""" - self.page_type = self.kivy_state.detail_page_type if self.kivy_state.detail_page_type else '' + """Initialize UI elements based on page type.""" + self.page_type = self.kivy_state.detail_page_type or '' try: - if self.kivy_state.detail_page_type in ('sent', 'draft'): + if self.page_type in ('sent', 'draft'): App.get_running_app().set_mail_detail_header() - elif self.kivy_state.detail_page_type == 'inbox': + elif self.page_type == 'inbox': data = sqlQuery( - "select toaddress, fromaddress, subject, message, received from inbox" - " where msgid = ?", self.kivy_state.mail_id) + "SELECT toaddress, fromaddress, subject, message, received FROM inbox " + "WHERE msgid = ?", self.kivy_state.mail_id + ) self.assign_mail_details(data) App.get_running_app().set_mail_detail_header() - except Exception as e: # pylint: disable=unused-variable - print('Something wents wrong!!') + except Exception: + print('Something went wrong!') def assign_mail_details(self, data): - """Assigning mail details""" + """Assign mail details from query result.""" subject = data[0][2].decode() if isinstance(data[0][2], bytes) else data[0][2] - body = data[0][3].decode() if isinstance(data[0][2], bytes) else data[0][3] + body = data[0][3].decode() if isinstance(data[0][3], bytes) else data[0][3] self.to_addr = data[0][0] if len(data[0][0]) > 4 else ' ' self.from_addr = data[0][1] - self.subject = subject.capitalize( - ) if subject.capitalize() else self.no_subject + self.subject = subject.capitalize() or self.no_subject self.message = body if len(data[0]) == 7: self.status = data[0][4] - self.time_tag = show_time_history(data[0][4]) if self.kivy_state.detail_page_type == 'inbox' \ - else show_time_history(data[0][6]) - self.avatarImg = os.path.join(self.kivy_state.imageDir, 'draft-icon.png') \ - if self.kivy_state.detail_page_type == 'draft' \ - else (os.path.join(self.kivy_state.imageDir, 'text_images', '{0}.png'.format(avatar_image_first_letter( - self.subject.strip())))) - self.timeinseconds = data[0][4] if self.kivy_state.detail_page_type == 'inbox' else data[0][6] + self.time_tag = show_time_history(data[0][4]) if self.page_type == 'inbox' else show_time_history(data[0][6]) + self.avatarImg = ( + os.path.join(self.kivy_state.image_dir, 'draft-icon.png') + if self.page_type == 'draft' + else os.path.join(self.kivy_state.image_dir, 'text_images', f'{avatar_image_first_letter(self.subject.strip())}.png') + ) + self.timeinseconds = data[0][4] if self.page_type == 'inbox' else data[0][6] def delete_mail(self): - """Method for mail delete""" + """Delete the current mail and update UI.""" msg_count_objs = App.get_running_app().root.ids.content_drawer.ids self.kivy_state.searching_text = '' self.children[0].children[0].active = True - if self.kivy_state.detail_page_type == 'sent': - App.get_running_app().root.ids.id_sent.ids.sent_search.ids.search_field.text = '' - msg_count_objs.send_cnt.ids.badge_txt.text = str(int(self.kivy_state.sent_count) - 1) - self.kivy_state.sent_count = str(int(self.kivy_state.sent_count) - 1) - self.parent.screens[2].ids.ml.clear_widgets() - self.parent.screens[2].loadSent(self.kivy_state.selected_address) - elif self.kivy_state.detail_page_type == 'inbox': - App.get_running_app().root.ids.id_inbox.ids.inbox_search.ids.search_field.text = '' - msg_count_objs.inbox_cnt.ids.badge_txt.text = str( - int(self.kivy_state.inbox_count) - 1) - self.kivy_state.inbox_count = str(int(self.kivy_state.inbox_count) - 1) - self.parent.screens[0].ids.ml.clear_widgets() - self.parent.screens[0].loadMessagelist(self.kivy_state.selected_address) - - elif self.kivy_state.detail_page_type == 'draft': - msg_count_objs.draft_cnt.ids.badge_txt.text = str( - int(self.kivy_state.draft_count) - 1) - self.kivy_state.draft_count = str(int(self.kivy_state.draft_count) - 1) - self.parent.screens[13].clear_widgets() - self.parent.screens[13].add_widget(Factory.Draft()) - - if self.kivy_state.detail_page_type != 'draft': - msg_count_objs.trash_cnt.ids.badge_txt.text = str( - int(self.kivy_state.trash_count) + 1) - msg_count_objs.allmail_cnt.ids.badge_txt.text = str( - int(self.kivy_state.all_count) - 1) - self.kivy_state.trash_count = str(int(self.kivy_state.trash_count) + 1) - self.kivy_state.all_count = str(int(self.kivy_state.all_count) - 1) if \ - int(self.kivy_state.all_count) else '0' - self.parent.screens[3].clear_widgets() - self.parent.screens[3].add_widget(Factory.Trash()) - self.parent.screens[14].clear_widgets() - self.parent.screens[14].add_widget(Factory.AllMails()) + + if self.page_type == 'sent': + self._update_sent_mail(msg_count_objs) + elif self.page_type == 'inbox': + self._update_inbox_mail(msg_count_objs) + elif self.page_type == 'draft': + self._update_draft_mail(msg_count_objs) + + if self.page_type != 'draft': + self._update_mail_counts(msg_count_objs) + Clock.schedule_once(self.callback_for_delete, 4) + + #created separate function for more readablity and maintanence + + def _update_sent_mail(self, msg_count_objs): + """Update UI for sent mail.""" + App.get_running_app().root.ids.id_sent.ids.sent_search.ids.search_field.text = '' + msg_count_objs.send_cnt.ids.badge_txt.text = str(int(self.kivy_state.sent_count) - 1) + self.kivy_state.sent_count = str(int(self.kivy_state.sent_count) - 1) + self.parent.screens[2].ids.ml.clear_widgets() + self.parent.screens[2].loadSent(self.kivy_state.selected_address) + + def _update_inbox_mail(self, msg_count_objs): + """Update UI for inbox mail.""" + App.get_running_app().root.ids.id_inbox.ids.inbox_search.ids.search_field.text = '' + msg_count_objs.inbox_cnt.ids.badge_txt.text = str(int(self.kivy_state.inbox_count) - 1) + self.kivy_state.inbox_count = str(int(self.kivy_state.inbox_count) - 1) + self.parent.screens[0].ids.ml.clear_widgets() + self.parent.screens[0].loadMessagelist(self.kivy_state.selected_address) + + def _update_draft_mail(self, msg_count_objs): + """Update UI for draft mail.""" + msg_count_objs.draft_cnt.ids.badge_txt.text = str(int(self.kivy_state.draft_count) - 1) + self.kivy_state.draft_count = str(int(self.kivy_state.draft_count) - 1) + self.parent.screens[13].clear_widgets() + self.parent.screens[13].add_widget(Factory.Draft()) + + def _update_mail_counts(self, msg_count_objs): + """Update mail counts and refresh relevant screens.""" + msg_count_objs.trash_cnt.ids.badge_txt.text = str(int(self.kivy_state.trash_count) + 1) + msg_count_objs.allmail_cnt.ids.badge_txt.text = str(int(self.kivy_state.all_count) - 1) + self.kivy_state.trash_count = str(int(self.kivy_state.trash_count) + 1) + self.kivy_state.all_count = str(int(self.kivy_state.all_count) - 1) if int(self.kivy_state.all_count) else '0' + self.parent.screens[3].clear_widgets() + self.parent.screens[3].add_widget(Factory.Trash()) + self.parent.screens[14].clear_widgets() + self.parent.screens[14].add_widget(Factory.AllMails()) def callback_for_delete(self, dt=0): - """Delete method from allmails""" - if self.kivy_state.detail_page_type: + """Handle post-deletion operations.""" + if self.page_type: self.children[0].children[0].active = False App.get_running_app().set_common_header() - self.parent.current = 'allmails' \ - if self.kivy_state.is_allmail else self.kivy_state.detail_page_type + self.parent.current = 'allmails' if self.kivy_state.is_allmail else self.page_type self.kivy_state.detail_page_type = '' toast('Deleted') def get_message_details_to_reply(self, data): - """Getting message details and fill into fields when reply""" + """Prepare message details for reply.""" sender_address = ' wrote:--------------\n' message_time = '\n\n --------------On ' composer_obj = self.parent.screens[1].children[1].ids @@ -201,12 +204,13 @@ def get_message_details_to_reply(self, data): time_tag = time_obj.strftime("%d %b %Y, %I:%M %p") sender_name = data[0][1] composer_obj.body.text = ( - message_time + time_tag + ', ' + sender_name + sender_address + data[0][3]) + message_time + time_tag + ', ' + sender_name + sender_address + data[0][3] + ) composer_obj.body.focus = True composer_obj.body.cursor = (0, 0) def inbox_reply(self): - """Reply inbox messages""" + """Prepare for replying to an inbox message.""" self.kivy_state.in_composer = True App.get_running_app().root.ids.id_create.children[1].ids.rv.data = '' App.get_running_app().root.ids.sc3.children[1].ids.rv.data = '' @@ -214,9 +218,8 @@ def inbox_reply(self): App.get_running_app().set_navbar_for_composer() def get_message_details_for_draft_reply(self, data): - """Getting and setting message details fill into fields when draft reply""" - composer_ids = ( - self.parent.parent.ids.id_create.children[1].ids) + """Prepare message details for a draft reply.""" + composer_ids = self.parent.parent.ids.id_create.children[1].ids composer_ids.ti.text = data[0][1] composer_ids.btn.text = data[0][1] composer_ids.txt_input.text = data[0][0] @@ -224,19 +227,18 @@ def get_message_details_for_draft_reply(self, data): composer_ids.body.text = data[0][3] def write_msg(self, navApp): - """Write on draft mail""" + """Switch to draft mail composition.""" self.kivy_state.send_draft_mail = self.kivy_state.mail_id self.parent.current = 'create' navApp.set_navbar_for_composer() def detailedPopup(self): - """Detailed popup""" + """Show detailed sender information popup.""" obj = SenderDetailPopup() obj.open() - arg = (self.to_addr, self.from_addr, self.timeinseconds) - obj.assignDetail(*arg) + obj.assignDetail(self.to_addr, self.from_addr, self.timeinseconds) @staticmethod - def callback_for_menu_items(text_item, *arg): - """Callback of alert box""" + def callback_for_menu_items(text_item, *args): + """Handle menu item callback.""" toast(text_item) From 2092d53fa51f442ea2c2074626ce80afceda3bf3 Mon Sep 17 00:00:00 2001 From: surbhi Date: Tue, 22 Oct 2024 10:21:54 +0530 Subject: [PATCH 2/7] Supress f-string flake8 error --- src/bitmessagekivy/baseclass/maildetail.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bitmessagekivy/baseclass/maildetail.py b/src/bitmessagekivy/baseclass/maildetail.py index b8702af44..2dbdcca4f 100644 --- a/src/bitmessagekivy/baseclass/maildetail.py +++ b/src/bitmessagekivy/baseclass/maildetail.py @@ -123,7 +123,7 @@ def assign_mail_details(self, data): self.avatarImg = ( os.path.join(self.kivy_state.image_dir, 'draft-icon.png') if self.page_type == 'draft' - else os.path.join(self.kivy_state.image_dir, 'text_images', f'{avatar_image_first_letter(self.subject.strip())}.png') + else os.path.join(self.kivy_state.image_dir, 'text_images', f'{avatar_image_first_letter(self.subject.strip())}.png') # noqa: E999 ) self.timeinseconds = data[0][4] if self.page_type == 'inbox' else data[0][6] From 3a2cc275922844eb5ed8266c0f0c564ac7d96365 Mon Sep 17 00:00:00 2001 From: surbhi Date: Thu, 13 Feb 2025 18:41:26 +0000 Subject: [PATCH 3/7] refactor quality & lint fixes --- src/bitmessagekivy/baseclass/maildetail.py | 34 ++++++++++++++-------- src/bitmessagekivy/kv/maildetail.kv | 20 ++----------- 2 files changed, 24 insertions(+), 30 deletions(-) diff --git a/src/bitmessagekivy/baseclass/maildetail.py b/src/bitmessagekivy/baseclass/maildetail.py index 2dbdcca4f..59a4cf598 100644 --- a/src/bitmessagekivy/baseclass/maildetail.py +++ b/src/bitmessagekivy/baseclass/maildetail.py @@ -1,5 +1,6 @@ # pylint: disable=unused-argument, consider-using-f-string, import-error, attribute-defined-outside-init # pylint: disable=unnecessary-comprehension, no-member, no-name-in-module, too-few-public-methods +# pylint: disable=broad-except """ MailDetail screen for inbox, sent, draft, and trash. @@ -7,7 +8,6 @@ import os from datetime import datetime -import logging from kivy.core.clipboard import Clipboard from kivy.clock import Clock @@ -73,6 +73,7 @@ def copy_title_callback(self, instance): class IconRightSampleWidget(IRightBodyTouch, MDIconButton): """IconRightSampleWidget class for Kivy UI.""" + class MailDetail(Screen): # pylint: disable=too-many-instance-attributes """MailDetail Screen class for Kivy UI.""" @@ -83,7 +84,7 @@ class MailDetail(Screen): # pylint: disable=too-many-instance-attributes status = StringProperty() page_type = StringProperty() time_tag = StringProperty() - avatarImg = StringProperty() + avatar_image = StringProperty() no_subject = '(no subject)' def __init__(self, *args, **kwargs): @@ -119,11 +120,17 @@ def assign_mail_details(self, data): self.message = body if len(data[0]) == 7: self.status = data[0][4] - self.time_tag = show_time_history(data[0][4]) if self.page_type == 'inbox' else show_time_history(data[0][6]) - self.avatarImg = ( + self.time_tag = ( + show_time_history(data[0][4]) if self.page_type == 'inbox' + else show_time_history(data[0][6]) + ) + self.avatar_image = ( os.path.join(self.kivy_state.image_dir, 'draft-icon.png') if self.page_type == 'draft' - else os.path.join(self.kivy_state.image_dir, 'text_images', f'{avatar_image_first_letter(self.subject.strip())}.png') # noqa: E999 + else os.path.join( + self.kivy_state.image_dir, 'text_images', + f'{avatar_image_first_letter(self.subject.strip())}.png' + ) ) self.timeinseconds = data[0][4] if self.page_type == 'inbox' else data[0][6] @@ -144,8 +151,6 @@ def delete_mail(self): self._update_mail_counts(msg_count_objs) Clock.schedule_once(self.callback_for_delete, 4) - - #created separate function for more readablity and maintanence def _update_sent_mail(self, msg_count_objs): """Update UI for sent mail.""" @@ -175,7 +180,11 @@ def _update_mail_counts(self, msg_count_objs): msg_count_objs.trash_cnt.ids.badge_txt.text = str(int(self.kivy_state.trash_count) + 1) msg_count_objs.allmail_cnt.ids.badge_txt.text = str(int(self.kivy_state.all_count) - 1) self.kivy_state.trash_count = str(int(self.kivy_state.trash_count) + 1) - self.kivy_state.all_count = str(int(self.kivy_state.all_count) - 1) if int(self.kivy_state.all_count) else '0' + self.kivy_state.all_count = ( + str(int(self.kivy_state.all_count) - 1) + if int(self.kivy_state.all_count) + else '0' + ) self.parent.screens[3].clear_widgets() self.parent.screens[3].add_widget(Factory.Trash()) self.parent.screens[14].clear_widgets() @@ -199,7 +208,8 @@ def get_message_details_to_reply(self, data): composer_obj.composer_dropdown.text = data[0][0] composer_obj.txt_input.text = data[0][1] split_subject = data[0][2].split('Re:', 1) - composer_obj.subject.text = 'Re: ' + (split_subject[1] if len(split_subject) > 1 else split_subject[0]) + subject_text = split_subject[1] if len(split_subject) > 1 else split_subject[0] + composer_obj.subject.text = 'Re: ' + subject_text time_obj = datetime.fromtimestamp(int(data[0][4])) time_tag = time_obj.strftime("%d %b %Y, %I:%M %p") sender_name = data[0][1] @@ -226,13 +236,13 @@ def get_message_details_for_draft_reply(self, data): composer_ids.subject.text = data[0][2] if data[0][2] != self.no_subject else '' composer_ids.body.text = data[0][3] - def write_msg(self, navApp): + def write_msg(self, nav_app): """Switch to draft mail composition.""" self.kivy_state.send_draft_mail = self.kivy_state.mail_id self.parent.current = 'create' - navApp.set_navbar_for_composer() + nav_app.set_navbar_for_composer() - def detailedPopup(self): + def detailed_popup(self): """Show detailed sender information popup.""" obj = SenderDetailPopup() obj.open() diff --git a/src/bitmessagekivy/kv/maildetail.kv b/src/bitmessagekivy/kv/maildetail.kv index e98b86610..cd6e9654e 100644 --- a/src/bitmessagekivy/kv/maildetail.kv +++ b/src/bitmessagekivy/kv/maildetail.kv @@ -8,15 +8,6 @@ # height: dp(bod.height) + self.minimum_height height: self.minimum_height padding: dp(10) - # MDLabel: - # size_hint_y: None - # id: subj - # text: root.subject - # theme_text_color: 'Primary' - # halign: 'left' - # font_style: 'H5' - # height: dp(40) - # on_touch_down: root.allclick(self) OneLineListTitle: id: subj text: app.tr._(root.subject) @@ -30,7 +21,7 @@ text: app.tr._(root.from_addr) secondary_text: app.tr._('to ' + root.to_addr) divider: None - on_press: root.detailedPopup() + on_press: root.detailed_popup() BadgeText: size_hint:(None, None) size:[120, 140] if app.app_platform == 'android' else [64, 80] @@ -49,20 +40,13 @@ radius: [8] height: self.parent.height/4 AvatarSampleWidget: - source: root.avatarImg + source: root.avatar_image MDLabel: text: root.status disabled: True font_style: 'Body2' halign:'left' padding_x: 20 - # MDLabel: - # id: bod - # font_style: 'Subtitle2' - # theme_text_color: 'Primary' - # text: root.message - # halign: 'left' - # height: self.texture_size[1] MyMDTextField: id: bod size_hint_y: None From 6b481fc3242fcc196e5844775f5088754aecb58e Mon Sep 17 00:00:00 2001 From: surbhi Date: Mon, 17 Feb 2025 17:02:02 +0530 Subject: [PATCH 4/7] refactor maildetail.py: replace magic numbers with constants --- src/bitmessagekivy/baseclass/maildetail.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/bitmessagekivy/baseclass/maildetail.py b/src/bitmessagekivy/baseclass/maildetail.py index 59a4cf598..0fe662a0d 100644 --- a/src/bitmessagekivy/baseclass/maildetail.py +++ b/src/bitmessagekivy/baseclass/maildetail.py @@ -3,7 +3,7 @@ # pylint: disable=broad-except """ -MailDetail screen for inbox, sent, draft, and trash. +MailDetail screen for inbox, sent, draft and trash. """ import os @@ -27,11 +27,18 @@ from pybitmessage.bitmessagekivy.get_platform import platform from pybitmessage.helper_sql import sqlQuery +# Define constants for magic numbers +ANDROID_WIDTH = 0.8 +OTHER_WIDTH = 0.55 +DIALOG_HEIGHT = 0.25 +LONG_PRESS_DURATION = 1 +DELETE_DELAY = 4 + class OneLineListTitle(OneLineListItem): """OneLineListTitle class for Kivy UI.""" __events__ = ('on_long_press', ) - long_press_time = NumericProperty(1) + long_press_time = NumericProperty(LONG_PRESS_DURATION) def on_state(self, instance, value): """Handle state change for long press.""" @@ -51,10 +58,10 @@ def on_long_press(self, *args): def copy_message_title(self, title_text): """Display dialog box with options to copy the message title.""" self.title_text = title_text - width = 0.8 if platform == 'android' else 0.55 + width = ANDROID_WIDTH if platform == 'android' else OTHER_WIDTH self.dialog_box = MDDialog( text=title_text, - size_hint=(width, 0.25), + size_hint=(width, DIALOG_HEIGHT), buttons=[ MDFlatButton(text="Copy", on_release=self.copy_title_callback), MDFlatButton(text="Cancel", on_release=self.copy_title_callback), @@ -89,7 +96,7 @@ class MailDetail(Screen): # pylint: disable=too-many-instance-attributes def __init__(self, *args, **kwargs): """Initialize MailDetail screen.""" - super().__init__(*args, **kwargs) + super().__init__(*args, **kwargs) # pylint: disable=missing-super-argument self.kivy_state = kivy_state_variables() Clock.schedule_once(self.init_ui, 0) @@ -150,7 +157,7 @@ def delete_mail(self): if self.page_type != 'draft': self._update_mail_counts(msg_count_objs) - Clock.schedule_once(self.callback_for_delete, 4) + Clock.schedule_once(self.callback_for_delete, DELETE_DELAY) def _update_sent_mail(self, msg_count_objs): """Update UI for sent mail.""" From 8c7f7005bdc5849fac58da4b8402a46e8a1ba49b Mon Sep 17 00:00:00 2001 From: surbhi Date: Thu, 27 Feb 2025 16:20:12 +0000 Subject: [PATCH 5/7] improve quality --- src/bitmessagekivy/baseclass/common.py | 6 ++++++ src/bitmessagekivy/baseclass/maildetail.py | 25 ++++++++-------------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/bitmessagekivy/baseclass/common.py b/src/bitmessagekivy/baseclass/common.py index 2cf4d76b2..147c213d6 100644 --- a/src/bitmessagekivy/baseclass/common.py +++ b/src/bitmessagekivy/baseclass/common.py @@ -43,6 +43,12 @@ }, } +DIALOG_WIDTH_ANDROID = 0.8 +DIALOG_WIDTH_OTHER = 0.55 +DIALOG_HEIGHT = 0.25 +LONG_PRESS_DURATION = 1 +DELETE_DELAY = 4 + def load_image_path(): """Return the path of kivy images""" diff --git a/src/bitmessagekivy/baseclass/maildetail.py b/src/bitmessagekivy/baseclass/maildetail.py index 0fe662a0d..d002b68e7 100644 --- a/src/bitmessagekivy/baseclass/maildetail.py +++ b/src/bitmessagekivy/baseclass/maildetail.py @@ -9,31 +9,24 @@ import os from datetime import datetime -from kivy.core.clipboard import Clipboard +from kivy.app import App from kivy.clock import Clock -from kivy.properties import StringProperty, NumericProperty -from kivy.uix.screenmanager import Screen +from kivy.core.clipboard import Clipboard from kivy.factory import Factory -from kivy.app import App - +from kivy.properties import NumericProperty, StringProperty +from kivy.uix.screenmanager import Screen from kivymd.uix.button import MDFlatButton, MDIconButton from kivymd.uix.dialog import MDDialog -from kivymd.uix.list import OneLineListItem, IRightBodyTouch +from kivymd.uix.list import IRightBodyTouch, OneLineListItem from pybitmessage.bitmessagekivy.baseclass.common import ( - toast, avatar_image_first_letter, show_time_history, kivy_state_variables -) + avatar_image_first_letter, kivy_state_variables, show_time_history, toast, + DIALOG_WIDTH_ANDROID, DIALOG_WIDTH_OTHER, DIALOG_HEIGHT, LONG_PRESS_DURATION, + DELETE_DELAY) from pybitmessage.bitmessagekivy.baseclass.popup import SenderDetailPopup from pybitmessage.bitmessagekivy.get_platform import platform from pybitmessage.helper_sql import sqlQuery -# Define constants for magic numbers -ANDROID_WIDTH = 0.8 -OTHER_WIDTH = 0.55 -DIALOG_HEIGHT = 0.25 -LONG_PRESS_DURATION = 1 -DELETE_DELAY = 4 - class OneLineListTitle(OneLineListItem): """OneLineListTitle class for Kivy UI.""" @@ -58,7 +51,7 @@ def on_long_press(self, *args): def copy_message_title(self, title_text): """Display dialog box with options to copy the message title.""" self.title_text = title_text - width = ANDROID_WIDTH if platform == 'android' else OTHER_WIDTH + width = DIALOG_WIDTH_ANDROID if platform == 'android' else DIALOG_WIDTH_OTHER self.dialog_box = MDDialog( text=title_text, size_hint=(width, DIALOG_HEIGHT), From 153ee6c2148aedc6f8dc934a1d977cd1c9c7fde3 Mon Sep 17 00:00:00 2001 From: surbhi Date: Fri, 28 Feb 2025 10:10:09 +0000 Subject: [PATCH 6/7] improve magic numbers --- src/bitmessagekivy/baseclass/common.py | 20 +++++++++++++++ src/bitmessagekivy/baseclass/maildetail.py | 4 ++- src/bitmessagekivy/kv/maildetail.kv | 30 +++++++++++++--------- 3 files changed, 41 insertions(+), 13 deletions(-) diff --git a/src/bitmessagekivy/baseclass/common.py b/src/bitmessagekivy/baseclass/common.py index 147c213d6..cd89bebdd 100644 --- a/src/bitmessagekivy/baseclass/common.py +++ b/src/bitmessagekivy/baseclass/common.py @@ -43,6 +43,26 @@ }, } + +class ChipProperties: + """ChipProperties class for kivy UI""" + CENTER_X_ANDROID = 0.91 + CENTER_X_OTHER = 0.94 + CENTER_Y = 0.3 + HEIGHT_DP = 18 + RADIUS = [8] + TEXT_COLOR = (1, 1, 1, 1) + SIZE_HINT_ANDROID = (0.16, None) + SIZE_HINT_OTHER = (0.08, None) + + +class BadgeProperties: + """BadgeProperties class for kivy UI""" + SIZE_ANDROID = [120, 140] + SIZE_OTHER = [64, 80] + FONT_SIZE = "11sp" + + DIALOG_WIDTH_ANDROID = 0.8 DIALOG_WIDTH_OTHER = 0.55 DIALOG_HEIGHT = 0.25 diff --git a/src/bitmessagekivy/baseclass/maildetail.py b/src/bitmessagekivy/baseclass/maildetail.py index d002b68e7..20471e34f 100644 --- a/src/bitmessagekivy/baseclass/maildetail.py +++ b/src/bitmessagekivy/baseclass/maildetail.py @@ -22,7 +22,7 @@ from pybitmessage.bitmessagekivy.baseclass.common import ( avatar_image_first_letter, kivy_state_variables, show_time_history, toast, DIALOG_WIDTH_ANDROID, DIALOG_WIDTH_OTHER, DIALOG_HEIGHT, LONG_PRESS_DURATION, - DELETE_DELAY) + DELETE_DELAY, ChipProperties, BadgeProperties) from pybitmessage.bitmessagekivy.baseclass.popup import SenderDetailPopup from pybitmessage.bitmessagekivy.get_platform import platform from pybitmessage.helper_sql import sqlQuery @@ -86,6 +86,8 @@ class MailDetail(Screen): # pylint: disable=too-many-instance-attributes time_tag = StringProperty() avatar_image = StringProperty() no_subject = '(no subject)' + chipProperties = ChipProperties() + badgeProperties = BadgeProperties() def __init__(self, *args, **kwargs): """Initialize MailDetail screen.""" diff --git a/src/bitmessagekivy/kv/maildetail.kv b/src/bitmessagekivy/kv/maildetail.kv index cd6e9654e..636f8ac9b 100644 --- a/src/bitmessagekivy/kv/maildetail.kv +++ b/src/bitmessagekivy/kv/maildetail.kv @@ -1,3 +1,6 @@ +#:set color_transparent (0,0,0,0) # transparent black +#:set color_black (0,0,0,1) # black + : name: 'mailDetail' ScrollView: @@ -15,7 +18,7 @@ font_style: 'H5' theme_text_color: 'Primary' _no_ripple_effect: True - long_press_time: 1 + long_press_time: self.long_press_time TwoLineAvatarIconListItem: id: subaft text: app.tr._(root.from_addr) @@ -24,20 +27,23 @@ on_press: root.detailed_popup() BadgeText: size_hint:(None, None) - size:[120, 140] if app.app_platform == 'android' else [64, 80] + size: root.badgeProperties.SIZE_ANDROID if app.app_platform == 'android' else root.badgeProperties.SIZE_OTHER text: app.tr._(root.time_tag) halign:'center' font_style:'Caption' pos_hint: {'center_y': .8} _txt_right_pad: dp(70) - font_size: '11sp' + font_size: root.badgeProperties.FONT_SIZE MDChip: - size_hint: (.16 if app.app_platform == 'android' else .08 , None) + size_hint: root.chipProperties.SIZE_HINT_ANDROID if app.app_platform == 'android' else root.chipProperties.SIZE_HINT_OTHER text: app.tr._(root.page_type) icon: '' - text_color: (1,1,1,1) - pos_hint: {'center_x': .91 if app.app_platform == 'android' else .95, 'center_y': .3} - radius: [8] + text_color: root.chipProperties.TEXT_COLOR + pos_hint: { + 'center_x': root.chipProperties.CENTER_X_ANDROID if app.app_platform == 'android' else root.chipProperties.CENTER_X_OTHER, + 'center_y': root.chipProperties.CENTER_Y + } + radius: root.chipProperties.RADIUS height: self.parent.height/4 AvatarSampleWidget: source: root.avatar_image @@ -54,18 +60,18 @@ text: root.message multiline: True readonly: True - line_color_normal: [0,0,0,0] - _current_line_color: [0,0,0,0] - line_color_focus: [0,0,0,0] + line_color_normal: color_transparent + _current_line_color: color_transparent + line_color_focus: color_transparent markup: True font_size: '15sp' canvas.before: Color: - rgba: (0,0,0,1) + rgba: color_black Loader: : canvas.before: Color: - rgba: (0,0,0,1) + rgba: color_black From a565dc8974728154d1dc5d9bb3fece08b5a67024 Mon Sep 17 00:00:00 2001 From: surbhi Date: Thu, 6 Mar 2025 04:24:51 +0000 Subject: [PATCH 7/7] improve error msg --- src/bitmessagekivy/baseclass/maildetail.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bitmessagekivy/baseclass/maildetail.py b/src/bitmessagekivy/baseclass/maildetail.py index 20471e34f..22de4a423 100644 --- a/src/bitmessagekivy/baseclass/maildetail.py +++ b/src/bitmessagekivy/baseclass/maildetail.py @@ -109,7 +109,7 @@ def init_ui(self, dt=0): self.assign_mail_details(data) App.get_running_app().set_mail_detail_header() except Exception: - print('Something went wrong!') + print("Error during MailDetail initalization") def assign_mail_details(self, data): """Assign mail details from query result."""