Merge pull request #55 from navjotcis/newwork

worked on fixing kivy app crashing issues
This commit is contained in:
navjotcis 2019-11-08 17:40:58 +05:30 committed by GitHub
commit dda19ad876
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 138 additions and 103 deletions

View File

@ -58,7 +58,7 @@ def search_sql(xAddress="toaddress", account=None, folder="inbox", where=None, w
sqlStatementParts.append("read = 0") sqlStatementParts.append("read = 0")
if sqlStatementParts: if sqlStatementParts:
sqlStatementBase += "WHERE " + " AND ".join(sqlStatementParts) sqlStatementBase += "WHERE " + " AND ".join(sqlStatementParts)
if folder == "sent": if folder == "sent" or folder == "draft":
sqlStatementBase += " ORDER BY lastactiontime DESC" sqlStatementBase += " ORDER BY lastactiontime DESC"
elif folder == "inbox": elif folder == "inbox":
sqlStatementBase += " ORDER BY received DESC" sqlStatementBase += " ORDER BY received DESC"

View File

@ -134,62 +134,64 @@ NavigationLayout:
ContentNavigationDrawer: ContentNavigationDrawer:
id: nav_drawer id: nav_drawer
BoxLayout: FloatLayout:
id: box_layout id: float_box
orientation: 'vertical' BoxLayout:
Toolbar: id: box_layout
id: toolbar orientation: 'vertical'
title: app.current_address_label() Toolbar:
opacity: 1 if app.addressexist() else 0 id: toolbar
disabled: False if app.addressexist() else True title: app.current_address_label()
md_bg_color: app.theme_cls.primary_color opacity: 1 if app.addressexist() else 0
background_palette: 'Primary' disabled: False if app.addressexist() else True
background_hue: '500' md_bg_color: app.theme_cls.primary_color
left_action_items: [['menu', lambda x: app.root.toggle_nav_drawer()]] background_palette: 'Primary'
right_action_items: [['account-plus', lambda x: app.addingtoaddressbook()]] background_hue: '500'
left_action_items: [['menu', lambda x: app.root.toggle_nav_drawer()]]
right_action_items: [['account-plus', lambda x: app.addingtoaddressbook()]]
ScreenManager: ScreenManager:
id: scr_mngr id: scr_mngr
Inbox: Inbox:
id:sc1 id:sc1
Page: Page:
id:sc2 id:sc2
Create: Create:
id:sc3 id:sc3
Sent: Sent:
id:sc4 id:sc4
Trash: Trash:
id:sc5 id:sc5
Login: Login:
id:sc6 id:sc6
Random: Random:
id:sc7 id:sc7
Spam: Spam:
id:sc8 id:sc8
Setting: Setting:
id:sc9 id:sc9
MyAddress: MyAddress:
id:sc10 id:sc10
AddressBook: AddressBook:
id:sc11 id:sc11
Payment: Payment:
id:sc12 id:sc12
NetworkStat: NetworkStat:
id:sc13 id:sc13
MailDetail: MailDetail:
id:sc14 id:sc14
ShowQRCode: ShowQRCode:
id:sc15 id:sc15
Draft: Draft:
id:sc16 id:sc16
Allmails: Allmails:
id:sc17 id:sc17
Credits: Credits:
id:sc18 id:sc18
Starred: Starred:
id:sc19 id:sc19
Archieve: Archieve:
id:sc20 id:sc20
<Inbox>: <Inbox>:
name: 'inbox' name: 'inbox'
@ -201,7 +203,7 @@ NavigationLayout:
MDScrollViewRefreshLayout: MDScrollViewRefreshLayout:
id: refresh_layout id: refresh_layout
refresh_callback: root.refresh_callback refresh_callback: root.refresh_callback
root_layout: root root_layout: root.set_root_layout()
MDList: MDList:
id: ml id: ml
Loader: Loader:
@ -266,7 +268,7 @@ NavigationLayout:
MDScrollViewRefreshLayout: MDScrollViewRefreshLayout:
id: refresh_layout id: refresh_layout
refresh_callback: root.refresh_callback refresh_callback: root.refresh_callback
root_layout: root root_layout: root.set_root_layout()
MDList: MDList:
id: ml id: ml
ComposerButton: ComposerButton:
@ -285,6 +287,7 @@ NavigationLayout:
<Create>: <Create>:
name: 'create' name: 'create'
Loader:
<Credits>: <Credits>:
name: 'credits' name: 'credits'
@ -607,7 +610,7 @@ NavigationLayout:
MDScrollViewRefreshLayout: MDScrollViewRefreshLayout:
id: refresh_layout id: refresh_layout
refresh_callback: root.refresh_callback refresh_callback: root.refresh_callback
root_layout: root root_layout: root.set_root_layout()
MDList: MDList:
id: ml id: ml
Loader: Loader:

View File

@ -231,7 +231,7 @@ class Inbox(Screen):
def refresh_callback(interval): def refresh_callback(interval):
"""Method used for loading the inbox screen data.""" """Method used for loading the inbox screen data."""
state.searcing_text = '' state.searcing_text = ''
self.children[3].children[1].ids.search_field.text = '' self.children[2].children[1].ids.search_field.text = ''
self.ids.ml.clear_widgets() self.ids.ml.clear_widgets()
self.loadMessagelist(state.association) self.loadMessagelist(state.association)
self.ids.refresh_layout.refresh_done() self.ids.refresh_layout.refresh_done()
@ -239,6 +239,9 @@ class Inbox(Screen):
Clock.schedule_once(refresh_callback, 1) Clock.schedule_once(refresh_callback, 1)
def set_root_layout(self):
return self.parent.parent.parent
class MyAddress(Screen): class MyAddress(Screen):
"""MyAddress Screen uses screen to show widgets of screens.""" """MyAddress Screen uses screen to show widgets of screens."""
@ -305,7 +308,7 @@ class MyAddress(Screen):
"""Method used for loading the myaddress screen data.""" """Method used for loading the myaddress screen data."""
state.searcing_text = '' state.searcing_text = ''
state.kivyapp.root.ids.sc10.children[2].active = False state.kivyapp.root.ids.sc10.children[2].active = False
self.children[3].children[1].ids.search_field.text = '' self.children[2].children[1].ids.search_field.text = ''
self.ids.ml.clear_widgets() self.ids.ml.clear_widgets()
self.init_ui() self.init_ui()
self.ids.refresh_layout.refresh_done() self.ids.refresh_layout.refresh_done()
@ -322,6 +325,9 @@ class MyAddress(Screen):
return True return True
return False return False
def set_root_layout(self):
return self.manager.parent.parent
class AddressBook(Screen): class AddressBook(Screen):
"""AddressBook Screen uses screen to show widgets of screens.""" """AddressBook Screen uses screen to show widgets of screens."""
@ -466,10 +472,10 @@ class DropDownWidget(BoxLayout):
sendMessageToPeople = True sendMessageToPeople = True
if sendMessageToPeople: if sendMessageToPeople:
if toAddress != '' and subject and message: if toAddress != '' and subject and message:
# navApp.root.ids.sc1.children[1].active = True
from addresses import decodeAddress from addresses import decodeAddress
status, addressVersionNumber, streamNumber, ripe = decodeAddress(toAddress) status, addressVersionNumber, streamNumber, ripe = decodeAddress(toAddress)
if status == 'success': if status == 'success':
navApp.root.ids.sc3.children[0].active = True
if state.detailPageType == 'draft' and state.send_draft_mail: if state.detailPageType == 'draft' and state.send_draft_mail:
sqlExecute( sqlExecute(
"UPDATE sent SET toaddress = ?" "UPDATE sent SET toaddress = ?"
@ -521,22 +527,23 @@ class DropDownWidget(BoxLayout):
BMConfigParser().getint( BMConfigParser().getint(
'bitmessagesettings', 'ttl')) 'bitmessagesettings', 'ttl'))
state.check_sent_acc = fromAddress state.check_sent_acc = fromAddress
# state.msg_counter_objs = self.parent.parent.parent.parent\
# .parent.parent.children[0].children[2].children[0].ids
state.msg_counter_objs = self.parent.parent.parent.parent\ state.msg_counter_objs = self.parent.parent.parent.parent\
.parent.parent.children[0].children[2].children[0].ids .parent.parent.children[2].children[0].ids
self.parent.parent.screens[0].ids.ml.clear_widgets()
self.parent.parent.screens[0].loadMessagelist(state.association)
self.parent.parent.screens[3].ids.ml.clear_widgets() self.parent.parent.screens[3].ids.ml.clear_widgets()
self.parent.parent.screens[3].loadSent(state.association) self.parent.parent.screens[3].loadSent(state.association)
self.parent.parent.screens[16].clear_widgets() self.parent.parent.screens[16].clear_widgets()
self.parent.parent.screens[16].add_widget(Allmails()) self.parent.parent.screens[16].add_widget(Allmails())
toast('sending...')
Clock.schedule_once(self.callback_for_msgsend, 6)
toLabel = '' toLabel = ''
queues.workerQueue.put(('sendmessage', toAddress)) queues.workerQueue.put(('sendmessage', toAddress))
print "sqlExecute successfully #######################" print "sqlExecute successfully #######################"
self.parent.parent.current = 'inbox'
# navApp.root.ids.sc1.children[1].active = False
state.in_composer = True state.in_composer = True
navApp.back_press() return
toast('send')
return None
else: else:
msg = 'Enter a valid recipients address' msg = 'Enter a valid recipients address'
elif not toAddress: elif not toAddress:
@ -545,6 +552,12 @@ class DropDownWidget(BoxLayout):
msg = 'Please fill the form' msg = 'Please fill the form'
self.address_error_message(msg) self.address_error_message(msg)
def callback_for_msgsend(self, dt=0):
state.kivyapp.root.ids.sc3.children[0].active = False
state.in_sent_method = True
state.kivyapp.back_press()
toast('sent')
# pylint: disable=attribute-defined-outside-init # pylint: disable=attribute-defined-outside-init
def address_error_message(self, msg): def address_error_message(self, msg):
"""Show Error Message.""" """Show Error Message."""
@ -703,16 +716,16 @@ class Random(Screen):
nonceTrialsPerByte, nonceTrialsPerByte,
payloadLengthExtraBytes)) payloadLengthExtraBytes))
self.ids.label.text = '' self.ids.label.text = ''
self.parent.parent.parent.parent.ids.toolbar.opacity = 1 self.parent.parent.children[1].opacity = 1
self.parent.parent.parent.parent.ids.toolbar.disabled = False self.parent.parent.children[1].disabled = False
self.parent.parent.parent.parent.ids.sc10.ids.ml.clear_widgets() state.kivyapp.root.ids.sc10.children[1].active = True
self.parent.parent.parent.parent.ids.sc10.children[1].active = True
self.manager.current = 'myaddress' self.manager.current = 'myaddress'
Clock.schedule_once(self.address_created_callback, 10) Clock.schedule_once(self.address_created_callback, 6)
def address_created_callback(self, dt=0): def address_created_callback(self, dt=0):
"""New address created""" """New address created"""
state.kivyapp.root.ids.sc10.children[1].active = False state.kivyapp.root.ids.sc10.children[1].active = False
state.kivyapp.root.ids.sc10.ids.ml.clear_widgets()
state.kivyapp.root.ids.sc10.init_ui() state.kivyapp.root.ids.sc10.init_ui()
self.manager.current = 'myaddress' self.manager.current = 'myaddress'
toast('New address created') toast('New address created')
@ -1138,13 +1151,10 @@ class NavigateApp(App):
if state.detailPageType == 'inbox' else 'draft' if state.detailPageType == 'inbox' else 'draft'
self.back_press() self.back_press()
elif self.root.ids.scr_mngr.current == "create": elif self.root.ids.scr_mngr.current == "create":
composer_objs = self.root self.save_draft()
from_addr = str(self.root.ids.sc3.children[0].ids.ti.text) self.set_common_header()
to_addr = str(self.root.ids.sc3.children[0].ids.txt_input.text) state.in_composer = False
if from_addr and to_addr and state.detailPageType != 'draft':
Draft().draft_msg(composer_objs)
self.root.ids.scr_mngr.current = 'inbox' self.root.ids.scr_mngr.current = 'inbox'
self.back_press()
elif self.root.ids.scr_mngr.current == "showqrcode": elif self.root.ids.scr_mngr.current == "showqrcode":
self.root.ids.scr_mngr.current = 'myaddress' self.root.ids.scr_mngr.current = 'myaddress'
elif self.root.ids.scr_mngr.current == "random": elif self.root.ids.scr_mngr.current == "random":
@ -1169,6 +1179,14 @@ class NavigateApp(App):
self.root.ids.sc4.loadSent(state.association) self.root.ids.sc4.loadSent(state.association)
self.root.ids.scr_mngr.current = state.search_screen self.root.ids.scr_mngr.current = state.search_screen
def save_draft(self):
composer_objs = self.root
from_addr = str(self.root.ids.sc3.children[1].ids.ti.text)
to_addr = str(self.root.ids.sc3.children[1].ids.txt_input.text)
if from_addr and to_addr and state.detailPageType != 'draft' and not state.in_sent_method:
Draft().draft_msg(composer_objs)
return
def reset(self, *args): def reset(self, *args):
"""Method used to set transition direction.""" """Method used to set transition direction."""
self.root.ids.scr_mngr.transition.direction = 'left' self.root.ids.scr_mngr.transition.direction = 'left'
@ -1185,26 +1203,32 @@ class NavigateApp(App):
"""If slow down the nwe will make new composer edit screen.""" """If slow down the nwe will make new composer edit screen."""
self.set_navbar_for_composer() self.set_navbar_for_composer()
# self.root.ids.search_bar.clear_widgets() # self.root.ids.search_bar.clear_widgets()
composer_obj = self.root.ids.sc3.children[0].ids composer_obj = self.root.ids.sc3.children[1].ids
composer_obj.ti.text = '' composer_obj.ti.text = ''
composer_obj.btn.text = 'Select' composer_obj.btn.text = 'Select'
composer_obj.txt_input.text = '' composer_obj.txt_input.text = ''
composer_obj.subject.text = '' composer_obj.subject.text = ''
composer_obj.body.text = '' composer_obj.body.text = ''
state.in_composer = True state.in_composer = True
state.in_sent_method = False
def set_navbar_for_composer(self): def set_navbar_for_composer(self):
"""This method is used for clearing toolbar data when composer open""" """This method is used for clearing toolbar data when composer open"""
self.root.ids.toolbar.left_action_items = [ self.root.ids.toolbar.left_action_items = [
['arrow-left', lambda x: self.back_press()]] ['arrow-left', lambda x: self.back_press()]]
self.root.ids.toolbar.right_action_items = [ self.root.ids.toolbar.right_action_items = [
['refresh', lambda x: self.root.ids.sc3.children[0].reset_composer()], ['refresh', lambda x: self.root.ids.sc3.children[1].reset_composer()],
['send', lambda x: self.root.ids.sc3.children[0].send(self)]] ['send', lambda x: self.root.ids.sc3.children[1].send(self)]]
def set_common_header(self):
self.root.ids.toolbar.right_action_items = [['account-plus', lambda x: self.addingtoaddressbook()]]
self.root.ids.toolbar.left_action_items = [['menu', lambda x: self.root.toggle_nav_drawer()]]
return
def back_press(self): def back_press(self):
"""Method used for going back from composer to previous page.""" """Method used for going back from composer to previous page."""
self.root.ids.toolbar.right_action_items = [['account-plus', lambda x: self.addingtoaddressbook()]] self.save_draft()
self.root.ids.toolbar.left_action_items = [['menu', lambda x: self.root.toggle_nav_drawer()]] self.set_common_header()
self.root.ids.scr_mngr.current = 'inbox' \ self.root.ids.scr_mngr.current = 'inbox' \
if state.in_composer else 'allmails'\ if state.in_composer else 'allmails'\
if state.is_allmail else state.detailPageType\ if state.is_allmail else state.detailPageType\
@ -1265,8 +1289,7 @@ class NavigateApp(App):
def closeSearchScreen(self): def closeSearchScreen(self):
"""Function for close search screen""" """Function for close search screen"""
self.root.ids.toolbar.right_action_items = [['account-plus', lambda x: self.addingtoaddressbook()]] self.set_common_header()
self.root.ids.toolbar.left_action_items = [['menu', lambda x: self.root.toggle_nav_drawer()]]
address_label = self.current_address_label( address_label = self.current_address_label(
BMConfigParser().get(state.association, 'label'), state.association) BMConfigParser().get(state.association, 'label'), state.association)
self.root.ids.toolbar.title = address_label self.root.ids.toolbar.title = address_label
@ -1538,13 +1561,13 @@ class MailDetail(Screen):
data = sqlQuery( data = sqlQuery(
"select toaddress, fromaddress, subject, message from inbox where" "select toaddress, fromaddress, subject, message from inbox where"
" msgid = ?;", str(state.mail_id)) " msgid = ?;", str(state.mail_id))
composer_obj = self.parent.screens[2].children[0].ids composer_obj = self.parent.screens[2].children[1].ids
composer_obj.ti.text = data[0][0] composer_obj.ti.text = data[0][0]
composer_obj.btn.text = data[0][0] composer_obj.btn.text = data[0][0]
composer_obj.txt_input.text = data[0][1] composer_obj.txt_input.text = data[0][1]
composer_obj.subject.text = data[0][2] composer_obj.subject.text = data[0][2]
composer_obj.body.text = '' composer_obj.body.text = ''
state.kivyapp.root.ids.sc3.children[0].ids.rv.data = '' state.kivyapp.root.ids.sc3.children[1].ids.rv.data = ''
self.parent.current = 'create' self.parent.current = 'create'
state.kivyapp.set_navbar_for_composer() state.kivyapp.set_navbar_for_composer()
@ -1555,11 +1578,11 @@ class MailDetail(Screen):
def write_msg(self, navApp): def write_msg(self, navApp):
"""Method used to write on draft mail.""" """Method used to write on draft mail."""
state.send_draft_mail = state.mail_id state.send_draft_mail = state.mail_id
composer_ids = self.parent.parent.parent.parent.ids.sc3.children[0].ids composer_ids = self.parent.parent.parent.parent.parent.ids.sc3.children[1].ids
composer_ids.ti.text = state.write_msg['from_addr'] composer_ids.ti.text = state.write_msg['from_addr']
composer_ids.btn.text = state.write_msg['from_addr'] composer_ids.btn.text = state.write_msg['from_addr']
composer_ids.txt_input.text = state.write_msg['to_addr'] composer_ids.txt_input.text = state.write_msg['to_addr']
composer_ids.subject.text = state.write_msg['subject'] composer_ids.subject.text = state.write_msg['subject'] if state.write_msg['subject'] != '(no subject)' else ''
composer_ids.body.text = state.write_msg['message'] composer_ids.body.text = state.write_msg['message']
self.parent.current = 'create' self.parent.current = 'create'
navApp.set_navbar_for_composer() navApp.set_navbar_for_composer()
@ -1593,12 +1616,13 @@ class MyaddDetailPopup(Popup):
def send_message_from(self): def send_message_from(self):
"""Method used to fill from address of composer autofield.""" """Method used to fill from address of composer autofield."""
state.kivyapp.set_navbar_for_composer()
window_obj = self.parent.children[1].ids window_obj = self.parent.children[1].ids
window_obj.sc3.children[0].ids.ti.text = self.address window_obj.sc3.children[1].ids.ti.text = self.address
window_obj.sc3.children[0].ids.btn.text = self.address window_obj.sc3.children[1].ids.btn.text = self.address
window_obj.sc3.children[0].ids.txt_input.text = '' window_obj.sc3.children[1].ids.txt_input.text = ''
window_obj.sc3.children[0].ids.subject.text = '' window_obj.sc3.children[1].ids.subject.text = ''
window_obj.sc3.children[0].ids.body.text = '' window_obj.sc3.children[1].ids.body.text = ''
window_obj.scr_mngr.current = 'create' window_obj.scr_mngr.current = 'create'
self.dismiss() self.dismiss()
@ -1637,12 +1661,13 @@ class AddbookDetailPopup(Popup):
def send_message_to(self): def send_message_to(self):
"""Method used to fill to_address of composer autofield.""" """Method used to fill to_address of composer autofield."""
state.kivyapp.set_navbar_for_composer()
window_obj = self.parent.children[1].ids window_obj = self.parent.children[1].ids
window_obj.sc3.children[0].ids.txt_input.text = self.address window_obj.sc3.children[1].ids.txt_input.text = self.address
window_obj.sc3.children[0].ids.ti.text = '' window_obj.sc3.children[1].ids.ti.text = ''
window_obj.sc3.children[0].ids.btn.text = 'Select' window_obj.sc3.children[1].ids.btn.text = 'Select'
window_obj.sc3.children[0].ids.subject.text = '' window_obj.sc3.children[1].ids.subject.text = ''
window_obj.sc3.children[0].ids.body.text = '' window_obj.sc3.children[1].ids.body.text = ''
window_obj.scr_mngr.current = 'create' window_obj.scr_mngr.current = 'create'
self.dismiss() self.dismiss()
@ -1776,8 +1801,7 @@ class Draft(Screen):
def draft_msg(src_object): def draft_msg(src_object):
"""Method used for saving draft mails.""" """Method used for saving draft mails."""
# pylint: disable=too-many-locals # pylint: disable=too-many-locals
composer_object = src_object.children[1].children[0].children[ composer_object = state.kivyapp.root.ids.sc3.children[1].ids
0].children[0].children[0].ids
fromAddress = str(composer_object.ti.text) fromAddress = str(composer_object.ti.text)
toAddress = str(composer_object.txt_input.text) toAddress = str(composer_object.txt_input.text)
subject = str(composer_object.subject.text) subject = str(composer_object.subject.text)
@ -1974,6 +1998,12 @@ class Allmails(Screen):
self.tick = 0 self.tick = 0
Clock.schedule_once(refresh_callback, 1) Clock.schedule_once(refresh_callback, 1)
def set_root_layout(self):
try:
return self.manager.parent.parent
except Exception as e:
return state.kivyapp.root.ids.float_box
def avatarImageFirstLetter(letter_string): def avatarImageFirstLetter(letter_string):
"""This method is used to the first letter for the avatar image""" """This method is used to the first letter for the avatar image"""

View File

@ -106,3 +106,5 @@ in_composer = False
write_msg = {} write_msg = {}
availabe_credit = 0 availabe_credit = 0
in_sent_method = False