From 70fa0622c60c651a5918fa6da745da2bc5f1e201 Mon Sep 17 00:00:00 2001 From: shekhar-cis Date: Wed, 30 Mar 2022 14:53:43 +0530 Subject: [PATCH 1/6] Add draft_widgets --- src/bitmessagekivy/baseclass/draft.py | 24 ++++++++------- src/bitmessagekivy/baseclass/draft_widgets.py | 30 +++++++++++++++++++ 2 files changed, 43 insertions(+), 11 deletions(-) create mode 100644 src/bitmessagekivy/baseclass/draft_widgets.py diff --git a/src/bitmessagekivy/baseclass/draft.py b/src/bitmessagekivy/baseclass/draft.py index cf31599e..2b22b108 100644 --- a/src/bitmessagekivy/baseclass/draft.py +++ b/src/bitmessagekivy/baseclass/draft.py @@ -1,5 +1,6 @@ import time +import os from bitmessagekivy import kivy_helper_search from bmconfigparser import BMConfigParser from helper_sql import sqlExecute @@ -20,9 +21,10 @@ from bitmessagekivy.baseclass.common import ( SwipeToDeleteItem, ShowTimeHistoy ) from bitmessagekivy.baseclass.maildetail import MailDetail +from bitmessagekivy.baseclass.draft_widgets import HelperDraft -class Draft(Screen): +class Draft(Screen, HelperDraft): """Draft screen class for kivy Ui""" data = ListProperty() @@ -63,14 +65,14 @@ class Draft(Screen): self.ids.scroll_y.bind(scroll_y=self.check_scroll_y) else: self.set_draftCnt('0') - content = MDLabel( - font_style='Caption', - theme_text_color='Primary', - text="yet no message for this account!!!!!!!!!!!!!", - halign='center', - size_hint_y=None, - valign='top') - self.ids.ml.add_widget(content) + # content = MDLabel( + # font_style='Caption', + # theme_text_color='Primary', + # text="yet no message for this account!!!!!!!!!!!!!", + # halign='center', + # size_hint_y=None, + # valign='top') + self.ids.ml.add_widget(self.default_label_when_empty()) def draftDataQuery(self, xAddress, where, what, start_indx=0, end_indx=20): """This methosd is for retrieving draft messages""" @@ -104,7 +106,7 @@ class Draft(Screen): listItem.secondary_text = item["text"] listItem.theme_text_color = "Custom" listItem.text_color = ThemeClsColor - message_row.ids.avater_img.source = state.imageDir + '/avatar.png' + message_row.ids.avater_img.source = os.path.join(state.imageDir, 'avatar.png') listItem.bind(on_release=partial( self.draft_detail, item['ackdata'], message_row)) message_row.ids.time_tag.text = str(ShowTimeHistoy(item['senttime'])) @@ -144,7 +146,7 @@ class Draft(Screen): def delete_draft(self, data_index, instance, *args): """Delete draft message permanently""" - sqlExecute("DELETE FROM sent WHERE ackdata = ?;", data_index) + sqlExecute("DELETE FROM sent WHERE ackdata = ?", data_index) if int(state.draft_count) > 0: state.draft_count = str(int(state.draft_count) - 1) self.set_draftCnt(state.draft_count) diff --git a/src/bitmessagekivy/baseclass/draft_widgets.py b/src/bitmessagekivy/baseclass/draft_widgets.py new file mode 100644 index 00000000..42d1782e --- /dev/null +++ b/src/bitmessagekivy/baseclass/draft_widgets.py @@ -0,0 +1,30 @@ +# pylint: disable=no-member, too-many-arguments +""" +Draft screen widgets are here. +""" + + +from kivymd.uix.button import MDRaisedButton +from kivymd.uix.dialog import MDDialog +from kivymd.uix.label import MDLabel + +import state + + +class HelperDraft(object): + """Widget used in Draft screen are here""" + def __init__(self): + pass + + @staticmethod + def default_label_when_empty(): + """This function returns default message while no address is there.""" + empty_screen_msg = "yet no message for this account!!!!!!!!!!!!!" + content = MDLabel( + font_style='Caption', + theme_text_color='Primary', + text=empty_screen_msg, + halign='center', + size_hint_y=None, + valign='top') + return content From f2d36181261af76193a30029ecb5504193fe768d Mon Sep 17 00:00:00 2001 From: shekhar-cis Date: Fri, 1 Apr 2022 13:12:57 +0530 Subject: [PATCH 2/6] Set Draft Count staticmethod --- src/bitmessagekivy/baseclass/draft.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/bitmessagekivy/baseclass/draft.py b/src/bitmessagekivy/baseclass/draft.py index 2b22b108..8443461d 100644 --- a/src/bitmessagekivy/baseclass/draft.py +++ b/src/bitmessagekivy/baseclass/draft.py @@ -80,7 +80,8 @@ class Draft(Screen, HelperDraft): xAddress, self.account, "draft", where, what, False, start_indx, end_indx) - def set_draftCnt(self, Count): # pylint: disable=no-self-use + @staticmethod + def set_draftCnt(Count): """This method set the count of draft mails""" draftCnt_obj = state.kivyapp.root.ids.content_drawer.ids.draft_cnt draftCnt_obj.ids.badge_txt.text = showLimitedCnt(int(Count)) From 3369379ebabcb2607f26166ca8edd80ac3b93786 Mon Sep 17 00:00:00 2001 From: shekhar-cis Date: Mon, 18 Apr 2022 20:54:31 +0530 Subject: [PATCH 3/6] Fixed code quality --- src/bitmessagekivy/baseclass/draft.py | 33 +++++++++++++++++++-------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/bitmessagekivy/baseclass/draft.py b/src/bitmessagekivy/baseclass/draft.py index 8443461d..fdbc1852 100644 --- a/src/bitmessagekivy/baseclass/draft.py +++ b/src/bitmessagekivy/baseclass/draft.py @@ -1,21 +1,27 @@ -import time +# pylint: disable=unused-argument, import-error, too-many-arguments +# pylint: disable=unnecessary-comprehension, no-member + +""" +draft.py +============== + +Draft screen + +""" -import os -from bitmessagekivy import kivy_helper_search -from bmconfigparser import BMConfigParser -from helper_sql import sqlExecute from functools import partial -from addresses import decodeAddress +import time +import os + + from kivy.clock import Clock from kivy.properties import ( ListProperty, StringProperty ) from kivy.uix.screenmanager import Screen -from kivymd.uix.label import MDLabel - -import state +from bitmessagekivy import kivy_helper_search from bitmessagekivy.baseclass.common import ( showLimitedCnt, toast, ThemeClsColor, SwipeToDeleteItem, ShowTimeHistoy @@ -23,6 +29,12 @@ from bitmessagekivy.baseclass.common import ( from bitmessagekivy.baseclass.maildetail import MailDetail from bitmessagekivy.baseclass.draft_widgets import HelperDraft +from bmconfigparser import BMConfigParser +from addresses import decodeAddress + +import state +from helper_sql import sqlExecute + class Draft(Screen, HelperDraft): """Draft screen class for kivy Ui""" @@ -56,8 +68,9 @@ class Draft(Screen, HelperDraft): xAddress = 'fromaddress' self.ids.tag_label.text = '' self.draftDataQuery(xAddress, where, what) + # state.msg_counter_objs.draft_cnt.children[0].children[0].text = showLimitedCnt(len(self.queryreturn)) # if state.msg_counter_objs: - # state.msg_counter_objs.draft_cnt.children[0].children[0].text = showLimitedCnt(len(self.queryreturn)) + if self.queryreturn: self.ids.tag_label.text = 'Draft' self.set_draftCnt(state.draft_count) From 293e171a478df7e4be9a1bfb70c1cb7c5ec99b21 Mon Sep 17 00:00:00 2001 From: shekhar-cis Date: Thu, 21 Apr 2022 19:54:33 +0530 Subject: [PATCH 4/6] Added delete() in helper_sent, common method for empty screen in common.py and called in draft.py --- src/bitmessagekivy/baseclass/common.py | 14 +++++++++++ src/bitmessagekivy/baseclass/draft.py | 9 +++---- src/bitmessagekivy/baseclass/draft_widgets.py | 24 +++++++++---------- src/helper_sent.py | 3 +++ 4 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/bitmessagekivy/baseclass/common.py b/src/bitmessagekivy/baseclass/common.py index 70b750fd..48417bed 100644 --- a/src/bitmessagekivy/baseclass/common.py +++ b/src/bitmessagekivy/baseclass/common.py @@ -17,6 +17,7 @@ from kivy.properties import ( StringProperty ) +from kivymd.uix.label import MDLabel ThemeClsColor = [0.12, 0.58, 0.95, 1] @@ -142,3 +143,16 @@ class CutsomSwipeToDeleteItem(MDCardSwipe): cla = Window.size[0] / 2 swipe_distance = NumericProperty(cla) opening_time = NumericProperty(0.5) + + +def empty_screen_label(label_str): + """This function returns default message while no address is there.""" + # empty_screen_msg = "yet no message for this account!!!!!!!!!!!!!" + content = MDLabel( + font_style='Caption', + theme_text_color='Primary', + text=label_str, + halign='center', + size_hint_y=None, + valign='top') + return content diff --git a/src/bitmessagekivy/baseclass/draft.py b/src/bitmessagekivy/baseclass/draft.py index fdbc1852..3ddbcd04 100644 --- a/src/bitmessagekivy/baseclass/draft.py +++ b/src/bitmessagekivy/baseclass/draft.py @@ -24,7 +24,7 @@ from kivy.uix.screenmanager import Screen from bitmessagekivy import kivy_helper_search from bitmessagekivy.baseclass.common import ( showLimitedCnt, toast, ThemeClsColor, - SwipeToDeleteItem, ShowTimeHistoy + SwipeToDeleteItem, ShowTimeHistoy, empty_screen_label ) from bitmessagekivy.baseclass.maildetail import MailDetail from bitmessagekivy.baseclass.draft_widgets import HelperDraft @@ -34,7 +34,7 @@ from addresses import decodeAddress import state from helper_sql import sqlExecute - +import helper_sent class Draft(Screen, HelperDraft): """Draft screen class for kivy Ui""" @@ -85,7 +85,8 @@ class Draft(Screen, HelperDraft): # halign='center', # size_hint_y=None, # valign='top') - self.ids.ml.add_widget(self.default_label_when_empty()) + label_str = "yet no message for this account!!!!!!!!!!!!!2" + self.ids.ml.add_widget(empty_screen_label(label_str)) def draftDataQuery(self, xAddress, where, what, start_indx=0, end_indx=20): """This methosd is for retrieving draft messages""" @@ -160,7 +161,7 @@ class Draft(Screen, HelperDraft): def delete_draft(self, data_index, instance, *args): """Delete draft message permanently""" - sqlExecute("DELETE FROM sent WHERE ackdata = ?", data_index) + helper_sent.delete(data_index) if int(state.draft_count) > 0: state.draft_count = str(int(state.draft_count) - 1) self.set_draftCnt(state.draft_count) diff --git a/src/bitmessagekivy/baseclass/draft_widgets.py b/src/bitmessagekivy/baseclass/draft_widgets.py index 42d1782e..a22981cd 100644 --- a/src/bitmessagekivy/baseclass/draft_widgets.py +++ b/src/bitmessagekivy/baseclass/draft_widgets.py @@ -16,15 +16,15 @@ class HelperDraft(object): def __init__(self): pass - @staticmethod - def default_label_when_empty(): - """This function returns default message while no address is there.""" - empty_screen_msg = "yet no message for this account!!!!!!!!!!!!!" - content = MDLabel( - font_style='Caption', - theme_text_color='Primary', - text=empty_screen_msg, - halign='center', - size_hint_y=None, - valign='top') - return content + # @staticmethod + # def default_label_when_empty(): + # """This function returns default message while no address is there.""" + # empty_screen_msg = "yet no message for this account!!!!!!!!!!!!!" + # content = MDLabel( + # font_style='Caption', + # theme_text_color='Primary', + # text=empty_screen_msg, + # halign='center', + # size_hint_y=None, + # valign='top') + # return content diff --git a/src/helper_sent.py b/src/helper_sent.py index 47fc5bb4..e684f2eb 100644 --- a/src/helper_sent.py +++ b/src/helper_sent.py @@ -7,3 +7,6 @@ from helper_sql import sqlExecute def insert(t): """Perform an insert into the `sent` table""" sqlExecute('''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)''', *t) + +def delete(data_index): + sqlExecute("DELETE FROM sent WHERE ackdata = ?", data_index) \ No newline at end of file From 9ea8e4e900e6b5782d39814497903fb6ae125718 Mon Sep 17 00:00:00 2001 From: shekhar-cis Date: Fri, 29 Apr 2022 20:29:16 +0530 Subject: [PATCH 5/6] Create a function to feed data in MDList message --- src/bitmessagekivy/baseclass/draft.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/bitmessagekivy/baseclass/draft.py b/src/bitmessagekivy/baseclass/draft.py index 3ddbcd04..fd565150 100644 --- a/src/bitmessagekivy/baseclass/draft.py +++ b/src/bitmessagekivy/baseclass/draft.py @@ -23,7 +23,7 @@ from kivy.uix.screenmanager import Screen from bitmessagekivy import kivy_helper_search from bitmessagekivy.baseclass.common import ( - showLimitedCnt, toast, ThemeClsColor, + showLimitedCnt, toast, ThemeClsColor, mdlist_message_content, SwipeToDeleteItem, ShowTimeHistoy, empty_screen_label ) from bitmessagekivy.baseclass.maildetail import MailDetail @@ -43,6 +43,7 @@ class Draft(Screen, HelperDraft): account = StringProperty() queryreturn = ListProperty() has_refreshed = True + label_str = "yet no message for this account!!!!!!!!!!!!!" def __init__(self, *args, **kwargs): """Method used for storing draft messages""" @@ -85,8 +86,7 @@ class Draft(Screen, HelperDraft): # halign='center', # size_hint_y=None, # valign='top') - label_str = "yet no message for this account!!!!!!!!!!!!!2" - self.ids.ml.add_widget(empty_screen_label(label_str)) + self.ids.ml.add_widget(empty_screen_label(self.label_str)) def draftDataQuery(self, xAddress, where, what, start_indx=0, end_indx=20): """This methosd is for retrieving draft messages""" @@ -104,15 +104,7 @@ class Draft(Screen, HelperDraft): """This method is used to create mdlist""" data = [] total_draft_msg = len(self.ids.ml.children) - for mail in self.queryreturn: - third_text = mail[3].replace('\n', ' ') - data.append({ - 'text': mail[1].strip(), - 'secondary_text': mail[2][:10] + '...........' if len( - mail[2]) > 10 else mail[2] + '\n' + " " + ( - third_text[:25] + '...!') if len( - third_text) > 25 else third_text, - 'ackdata': mail[5], 'senttime': mail[6]}) + mdlist_message_content(self.queryreturn,data=data) for item in data: message_row = SwipeToDeleteItem( text='Draft', From 38196a49b2f8eefd9c8a26f9322eaeb29a2c62cb Mon Sep 17 00:00:00 2001 From: shekhar-cis Date: Tue, 10 May 2022 15:49:05 +0530 Subject: [PATCH 6/6] Fixed kivy variable, fixed draft msg count --- src/bitmessagekivy/baseclass/draft.py | 33 +++++++++++++++------------ 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/bitmessagekivy/baseclass/draft.py b/src/bitmessagekivy/baseclass/draft.py index fd565150..c1108907 100644 --- a/src/bitmessagekivy/baseclass/draft.py +++ b/src/bitmessagekivy/baseclass/draft.py @@ -26,6 +26,8 @@ from bitmessagekivy.baseclass.common import ( showLimitedCnt, toast, ThemeClsColor, mdlist_message_content, SwipeToDeleteItem, ShowTimeHistoy, empty_screen_label ) +from kivy.app import App + from bitmessagekivy.baseclass.maildetail import MailDetail from bitmessagekivy.baseclass.draft_widgets import HelperDraft @@ -48,9 +50,11 @@ class Draft(Screen, HelperDraft): def __init__(self, *args, **kwargs): """Method used for storing draft messages""" super(Draft, self).__init__(*args, **kwargs) - if state.association == '': + self.kivy_running_app = App.get_running_app() + self.kivy_state = self.kivy_running_app.kivy_state_obj + if self.kivy_state.association == '': if state.kivyapp.variable_1: - state.association = state.kivyapp.variable_1[0] + self.kivy_state.association = state.kivyapp.variable_1[0] Clock.schedule_once(self.init_ui, 0) def init_ui(self, dt=0): @@ -65,16 +69,16 @@ class Draft(Screen, HelperDraft): def loadDraft(self, where="", what=""): """Load draft list for Draft messages""" - self.account = state.association + self.account = self.kivy_state.association xAddress = 'fromaddress' self.ids.tag_label.text = '' self.draftDataQuery(xAddress, where, what) - # state.msg_counter_objs.draft_cnt.children[0].children[0].text = showLimitedCnt(len(self.queryreturn)) + # state.msg_counter_objs.draft_cnt.children[0].children[0].text = showLimitedCnt(len(self.queryreturn)) # if state.msg_counter_objs: if self.queryreturn: self.ids.tag_label.text = 'Draft' - self.set_draftCnt(state.draft_count) + self.set_draftCnt(self.kivy_state.draft_count) self.set_mdList() self.ids.scroll_y.bind(scroll_y=self.check_scroll_y) else: @@ -139,8 +143,8 @@ class Draft(Screen, HelperDraft): if instance.state == 'closed': instance.ids.delete_msg.disabled = True if instance.open_progress == 0.0: - state.detailPageType = 'draft' - state.mail_id = ackdata + self.kivy_state.detailPageType = 'draft' + self.kivy_state.mail_id = ackdata if self.manager: src_mng_obj = self.manager else: @@ -154,10 +158,10 @@ class Draft(Screen, HelperDraft): def delete_draft(self, data_index, instance, *args): """Delete draft message permanently""" helper_sent.delete(data_index) - if int(state.draft_count) > 0: - state.draft_count = str(int(state.draft_count) - 1) - self.set_draftCnt(state.draft_count) - if int(state.draft_count) <= 0: + if int(self.kivy_state.draft_count) > 0: + self.kivy_state.draft_count = str(int(self.kivy_state.draft_count) - 1) + self.set_draftCnt(self.kivy_state.draft_count) + if int(self.kivy_state.draft_count) <= 0: # self.ids.identi_tag.children[0].text = '' self.ids.tag_label.text = '' self.ids.ml.remove_widget(instance.parent.parent) @@ -199,9 +203,10 @@ class Draft(Screen, HelperDraft): 'draft', encoding, BMConfigParser().safeGetInt('bitmessagesettings', 'ttl')) - state.msg_counter_objs = src_object.children[2].children[0].ids - state.draft_count = str(int(state.draft_count) + 1) \ - if state.association == fromAddress else state.draft_count + + # state.msg_counter_objs = src_object.children[2].children[0].ids + Draft().kivy_state.draft_count = str(int(Draft().kivy_state.draft_count) + 1) \ + if state.association == fromAddress else Draft().kivy_state.draft_count src_object.ids.sc16.clear_widgets() src_object.ids.sc16.add_widget(Draft()) toast('Save draft')