diff --git a/src/addresses.py b/src/addresses.py index c3c61466..192c819f 100644 --- a/src/addresses.py +++ b/src/addresses.py @@ -8,6 +8,8 @@ from struct import pack, unpack from debug import logger +from bmconfigparser import BMConfigParser + ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" @@ -276,3 +278,15 @@ def addBMIfNotPresent(address): """Prepend BM- to an address if it doesn't already have it""" address = str(address).strip() return address if address[:3] == 'BM-' else 'BM-' + address + + +def disable_addresses(address): + """"To disable the Address""" + BMConfigParser().set(str(address), 'enabled', 'false') + BMConfigParser().save() + + +def enable_addresses(address): + """"To enable the Address""" + BMConfigParser().set(address, 'enabled', 'true') + BMConfigParser().save() diff --git a/src/bitmessagekivy/baseclass/addressbook.py b/src/bitmessagekivy/baseclass/addressbook.py index 0eb08462..ce89169c 100644 --- a/src/bitmessagekivy/baseclass/addressbook.py +++ b/src/bitmessagekivy/baseclass/addressbook.py @@ -1,4 +1,3 @@ -from turtle import pd from bitmessagekivy.get_platform import platform from bitmessagekivy import kivy_helper_search from helper_sql import sqlExecute @@ -14,21 +13,26 @@ from kivymd.uix.label import MDLabel from kivy.uix.screenmanager import Screen import state +import os +from debug import logger from bitmessagekivy.baseclass.common import ( - avatarImageFirstLetter, toast, + avatarImageFirstLetter, toast, empty_screen_label, ThemeClsColor, SwipeToDeleteItem ) from bitmessagekivy.baseclass.popup import AddbookDetailPopup from bitmessagekivy.baseclass.addressbook_widgets import HelperAddressBook -class AddressBook(Screen): + +class AddressBook(Screen, HelperAddressBook): """AddressBook Screen class for kivy Ui""" queryreturn = ListProperty() has_refreshed = True address_label = StringProperty() address = StringProperty() + label_str = "No contact found yet......" + no_search_res_found = "No search result found" def __init__(self, *args, **kwargs): """Getting AddressBook Details""" @@ -39,7 +43,7 @@ class AddressBook(Screen): def init_ui(self, dt=0): """Clock Schdule for method AddressBook""" self.loadAddresslist(None, 'All', '') - print(dt) + logger.debug(dt) def loadAddresslist(self, account, where="", what=""): """Clock Schdule for method AddressBook""" @@ -58,6 +62,7 @@ class AddressBook(Screen): self.set_mdList(0, 20) self.ids.scroll_y.bind(scroll_y=self.check_scroll_y) else: + """This is still exprimental, may need to make changes somewhere""" # content = MDLabel( # font_style='Caption', # theme_text_color='Primary', @@ -66,18 +71,7 @@ class AddressBook(Screen): # 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 + 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""" @@ -92,8 +86,9 @@ class AddressBook(Screen): # listItem.add_widget(AvatarSampleWidget( # source=state.imageDir + '/text_images/{}.png'.format( # avatarImageFirstLetter(item[0].strip())))) - image = state.imageDir + "/text_images/{}.png".format( - avatarImageFirstLetter(item[0].strip())) + image = os.path.join( + state.imageDir, "text_images", "{}.png".format(avatarImageFirstLetter(item[0].strip())) + ) message_row.ids.avater_img.source = image listItem.bind(on_release=partial( self.addBook_detail, item[1], item[0], message_row)) @@ -127,11 +122,10 @@ class AddressBook(Screen): if instance.state == 'closed': instance.ids.delete_msg.disabled = True if instance.open_progress == 0.0: - 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 + 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), @@ -151,10 +145,12 @@ class AddressBook(Screen): # ), # ], # ) - # # self.addbook_popup.set_normal_height() - # self.addbook_popup = HelperAddressBook.address_detail_popup(self) - # self.addbook_popup.auto_dismiss = False - # self.addbook_popup.open() + # self.addbook_popup.set_normal_height() + self.addbook_popup = self.address_detail_popup( + obj, self.send_message_to, self.update_addbook_label, + self.close_pop, width) + self.addbook_popup.auto_dismiss = False + self.addbook_popup.open() else: instance.ids.delete_msg.disabled = False @@ -165,7 +161,7 @@ class AddressBook(Screen): if self.ids.ml.children is not None: self.ids.tag_label.text = '' sqlExecute( - "DELETE FROM addressbook WHERE address = '{}';".format(address)) + "DELETE FROM addressbook WHERE address = ?", address) toast('Address Deleted') def close_pop(self, instance): @@ -183,9 +179,8 @@ class AddressBook(Screen): stored_labels.remove(label) if label and label not in stored_labels: sqlExecute( - "UPDATE addressbook SET label = '{}' WHERE" - " address = '{}';".format( - label, self.addbook_popup.content_cls.address)) + "UPDATE addressbook SET label = ? WHERE" + "address = ?", label, self.addbook_popup.content_cls.address) state.kivyapp.root.ids.sc11.ids.ml.clear_widgets() state.kivyapp.root.ids.sc11.loadAddresslist(None, 'All', '') self.addbook_popup.dismiss() @@ -194,11 +189,13 @@ class AddressBook(Screen): def send_message_to(self, instance): """Method used to fill to_address of composer autofield""" state.kivyapp.set_navbar_for_composer() - window_obj = state.kivyapp.root.ids - window_obj.sc3.children[1].ids.txt_input.text = self.address - window_obj.sc3.children[1].ids.ti.text = '' - window_obj.sc3.children[1].ids.btn.text = 'Select' - window_obj.sc3.children[1].ids.subject.text = '' - window_obj.sc3.children[1].ids.body.text = '' - window_obj.scr_mngr.current = 'create' + # import pdb; pdb.set_trace() + self.compose_message(None, self.address, None, None) + # window_obj = state.kivyapp.root.ids + # window_obj.sc3.children[1].ids.txt_input.text = self.address + # window_obj.sc3.children[1].ids.ti.text = '' + # window_obj.sc3.children[1].ids.btn.text = 'Select' + # window_obj.sc3.children[1].ids.subject.text = '' + # window_obj.sc3.children[1].ids.body.text = '' + # window_obj.scr_mngr.current = 'create' self.addbook_popup.dismiss() diff --git a/src/bitmessagekivy/baseclass/addressbook_widgets.py b/src/bitmessagekivy/baseclass/addressbook_widgets.py index 0521a90a..49b47b5a 100644 --- a/src/bitmessagekivy/baseclass/addressbook_widgets.py +++ b/src/bitmessagekivy/baseclass/addressbook_widgets.py @@ -8,41 +8,62 @@ 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( +label_str = "No contact found yet......" +no_search_res_found = "No contact found!" + + +class DefaultLabelMixin(object): + pass +""" + # @staticmethod + # def default_label_when_empty(): + # content = MDLabel( + # font_style='Caption', + # theme_text_color='Primary', + # # TODO: searcing_text(typo) need to create a kivy_state.py and add kivy related variables + # text=no_search_res_found if state.searcing_text else label_str, + # halign='center', + # size_hint_y=None, + # valign='top') + # return content +""" + +class HelperAddressBook(DefaultLabelMixin): + """Widget used in Addressbook are here""" + + @staticmethod + def address_detail_popup(obj, send_message, update_address, close_popup, width): + retval = MDDialog( type="custom", size_hint=(width, .25), content_cls=obj, buttons=[ MDRaisedButton( text="Send message to", - on_release=self.send_message_to, + on_release=send_message, ), MDRaisedButton( text="Save", - on_release=self.update_addbook_label, + on_release=update_address, ), MDRaisedButton( text="Cancel", - on_release=self.close_pop, + on_release=close_popup, ), ], ) - self.addbook_popup.auto_dismiss = False - self.addbook_popup.open() + return retval + + @staticmethod + def compose_message(from_addr=None, to_addr=None, subject=None, body=None): + window_obj = state.kivyapp.root.ids + if to_addr: + window_obj.sc3.children[1].ids.txt_input.text = to_addr + if from_addr: + window_obj.sc3.children[1].ids.txt_input.text = from_addr + window_obj.sc3.children[1].ids.ti.text = '' + window_obj.sc3.children[1].ids.btn.text = 'Select' + window_obj.sc3.children[1].ids.subject.text = '' + window_obj.sc3.children[1].ids.body.text = '' + window_obj.scr_mngr.current = 'create' diff --git a/src/bitmessagekivy/baseclass/common.py b/src/bitmessagekivy/baseclass/common.py index 70b750fd..eae8459b 100644 --- a/src/bitmessagekivy/baseclass/common.py +++ b/src/bitmessagekivy/baseclass/common.py @@ -16,7 +16,9 @@ from kivy.properties import ( NumericProperty, StringProperty ) +from kivymd.uix.label import MDLabel +import state ThemeClsColor = [0.12, 0.58, 0.95, 1] @@ -70,7 +72,7 @@ def chipTag(text): def toast(text): - """Method will display the toast message""" + """Function will display the toast message""" kivytoast.toast(text) def showLimitedCnt(total_msg): @@ -81,16 +83,14 @@ def showLimitedCnt(total_msg): def avatarImageFirstLetter(letter_string): """This function is used to the first letter for the avatar image""" try: - if letter_string[0].upper() >= 'A' and letter_string[0].upper() <= 'Z': - img_latter = letter_string[0].upper() - elif int(letter_string[0]) >= 0 and int(letter_string[0]) <= 9: - img_latter = letter_string[0] + if isinstance(letter_string, int): + return letter_string[0] + elif isinstance(letter_string, str) and letter_string[0].isalnum(): + return letter_string.title()[0] else: - img_latter = '!' - except ValueError: - img_latter = '!' - return img_latter if img_latter else '!' - + return '!' + except IndexError: + return '!' def AddTimeWidget(time): # pylint: disable=redefined-outer-name, W0201 """This method is used to create TimeWidget""" @@ -142,3 +142,27 @@ class CutsomSwipeToDeleteItem(MDCardSwipe): cla = Window.size[0] / 2 swipe_distance = NumericProperty(cla) opening_time = NumericProperty(0.5) + + +def empty_screen_label(label_str=None, no_search_res_found=None): + """Returns default text on screen when no address is there.""" + content = MDLabel( + font_style='Caption', + theme_text_color='Primary', + text=no_search_res_found if state.searcing_text else label_str, + halign='center', + size_hint_y=None, + valign='top') + return content + + +def mdlist_message_content(queryreturn, data, max_len=25, min_len=10): + for mail in 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]}) diff --git a/src/bitmessagekivy/baseclass/myaddress.py b/src/bitmessagekivy/baseclass/myaddress.py index d3b9574d..dbbceee8 100644 --- a/src/bitmessagekivy/baseclass/myaddress.py +++ b/src/bitmessagekivy/baseclass/myaddress.py @@ -32,7 +32,6 @@ from bitmessagekivy.baseclass.common import ( toast ) -from addresses import disable_addresses, enable_addresses from bitmessagekivy.baseclass.popup import MyaddDetailPopup @@ -229,7 +228,7 @@ class MyAddress(Screen, HelperMyAddress): def disable_address_ui(self, address, instance): """This method is used to disable addresses from UI""" - BMConfigParser().enable_addresses(address) + BMConfigParser().enable_address(address) instance.parent.parent.theme_text_color = 'Primary' instance.parent.parent.canvas.children[3].rgba = [0.5, 0.5, 0.5, 0.5] # try: @@ -241,7 +240,7 @@ class MyAddress(Screen, HelperMyAddress): def enable_address_ui(self, address, instance): """This method is used to enable addresses from UI""" - BMConfigParser().disable_addresses(address) + BMConfigParser().disable_address(address) instance.parent.parent.theme_text_color = 'Custom' instance.parent.parent.canvas.children[3].rgba = [0, 0, 0, 0] # try: diff --git a/src/bitmessagekivy/kivy_state.py b/src/bitmessagekivy/kivy_state.py new file mode 100644 index 00000000..f5388b77 --- /dev/null +++ b/src/bitmessagekivy/kivy_state.py @@ -0,0 +1,36 @@ +# pylint: disable=too-many-instance-attributes, too-few-public-methods + +""" +Kivy State variables are assigned here, they are separated from state.py +================================= +""" + + +class KivyStateVariables(object): + """This Class hold all the kivy state variables""" + + def __init__(self): + self.association = '' + self.navinstance = None + self.mail_id = 0 + self.myAddressObj = None + self.detailPageType = None + self.ackdata = None + self.status = None + self.screen_density = None + self.msg_counter_objs = None + self.check_sent_acc = None + self.sent_count = 0 + self.inbox_count = 0 + self.trash_count = 0 + self.draft_count = 0 + self.all_count = 0 + self.searcing_text = '' + self.search_screen = '' + self.send_draft_mail = None + self.is_allmail = False + self.in_composer = False + self.availabe_credit = 0 + self.in_sent_method = False + self.in_search_mode = False + self.imageDir = None diff --git a/src/bitmessagekivy/kv/login.kv b/src/bitmessagekivy/kv/login.kv index ffa922e1..992938dc 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.set_screen('random') + app.set_screen('random') on_press: app.root.ids.sc7.reset_address_label() diff --git a/src/bitmessagekivy/mpybit.py b/src/bitmessagekivy/mpybit.py index 054e512f..1a435689 100644 --- a/src/bitmessagekivy/mpybit.py +++ b/src/bitmessagekivy/mpybit.py @@ -61,6 +61,9 @@ from bitmessagekivy.baseclass.common import toast from qr_scanner.zbarcam import ZBarCam from pyzbar.pyzbar import ZBarSymbol +# import pdb; pdb.set_trace() +from bitmessagekivy.kivy_state import KivyStateVariables + if platform != "android": from kivy.config import Config Config.set("input", "mouse", "mouse, multitouch_on_demand") @@ -208,8 +211,11 @@ class CustomSpinner(Spinner): class NavigateApp(MDApp): """Navigation Layout of class""" # pylint: disable=too-many-public-methods,inconsistent-return-statements - # theme_cls = ThemeManager() + def __init__(self): + super(NavigateApp, self).__init__() + self.kivy_state_obj = KivyStateVariables() + previous_date = ObjectProperty() obj_1 = ObjectProperty() variable_1 = ListProperty(addr for addr in BMConfigParser().addresses() diff --git a/src/bmconfigparser.py b/src/bmconfigparser.py index a7e1b673..228fff0a 100644 --- a/src/bmconfigparser.py +++ b/src/bmconfigparser.py @@ -194,3 +194,18 @@ class BMConfigParser(configparser.ConfigParser): if value < 0 or value > 8: return False return True + + @staticmethod + 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()