separated kivy-state

This commit is contained in:
shekhar-cis 2022-01-13 19:24:04 +05:30
parent 4b3f45ec5f
commit 98501ec845
Signed by untrusted user: shekhar-cis
GPG Key ID: F4F00AB04E83F9A7
16 changed files with 319 additions and 361 deletions

View File

@ -13,6 +13,7 @@ from kivymd.uix.dialog import MDDialog
from kivymd.uix.label import MDLabel from kivymd.uix.label import MDLabel
from kivy.uix.screenmanager import Screen from kivy.uix.screenmanager import Screen
import kivy_state
import state import state
from bitmessagekivy.baseclass.common import ( from bitmessagekivy.baseclass.common import (
@ -43,10 +44,10 @@ class AddressBook(Screen):
def loadAddresslist(self, account, where="", what=""): def loadAddresslist(self, account, where="", what=""):
"""Clock Schdule for method AddressBook""" """Clock Schdule for method AddressBook"""
if state.searcing_text: if kivy_state.searcing_text:
self.ids.scroll_y.scroll_y = 1.0 self.ids.scroll_y.scroll_y = 1.0
where = ['label', 'address'] where = ['label', 'address']
what = state.searcing_text what = kivy_state.searcing_text
xAddress = '' xAddress = ''
self.ids.tag_label.text = '' self.ids.tag_label.text = ''
self.queryreturn = kivy_helper_search.search_sql( self.queryreturn = kivy_helper_search.search_sql(
@ -61,7 +62,7 @@ class AddressBook(Screen):
content = MDLabel( content = MDLabel(
font_style='Caption', font_style='Caption',
theme_text_color='Primary', theme_text_color='Primary',
text="No contact found!" if state.searcing_text text="No contact found!" if kivy_state.searcing_text
else "No contact found yet...... ", else "No contact found yet...... ",
halign='center', halign='center',
size_hint_y=None, size_hint_y=None,
@ -79,9 +80,9 @@ class AddressBook(Screen):
listItem.theme_text_color = "Custom" listItem.theme_text_color = "Custom"
listItem.text_color = ThemeClsColor listItem.text_color = ThemeClsColor
# listItem.add_widget(AvatarSampleWidget( # listItem.add_widget(AvatarSampleWidget(
# source=state.imageDir + '/text_images/{}.png'.format( # source=kivy_state.imageDir + '/text_images/{}.png'.format(
# avatarImageFirstLetter(item[0].strip())))) # avatarImageFirstLetter(item[0].strip()))))
image = state.imageDir + "/text_images/{}.png".format( image = kivy_state.imageDir + "/text_images/{}.png".format(
avatarImageFirstLetter(item[0].strip())) avatarImageFirstLetter(item[0].strip()))
message_row.ids.avater_img.source = image message_row.ids.avater_img.source = image
listItem.bind(on_release=partial( listItem.bind(on_release=partial(

View File

@ -9,6 +9,7 @@ from kivy.properties import (
from kivy.uix.screenmanager import Screen from kivy.uix.screenmanager import Screen
from kivymd.uix.label import MDLabel from kivymd.uix.label import MDLabel
import kivy_state
import state import state
from bitmessagekivy.baseclass.common import ( from bitmessagekivy.baseclass.common import (
@ -31,9 +32,9 @@ class Allmails(Screen):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
"""Method Parsing the address""" """Method Parsing the address"""
super(Allmails, self).__init__(*args, **kwargs) super(Allmails, self).__init__(*args, **kwargs)
if state.association == '': if kivy_state.association == '':
if state.kivyapp.variable_1: if state.kivyapp.variable_1:
state.association = state.kivyapp.variable_1[0] kivy_state.association = state.kivyapp.variable_1[0]
Clock.schedule_once(self.init_ui, 0) Clock.schedule_once(self.init_ui, 0)
def init_ui(self, dt=0): def init_ui(self, dt=0):
@ -43,16 +44,16 @@ class Allmails(Screen):
def loadMessagelist(self): def loadMessagelist(self):
"""Load Inbox, Sent anf Draft list of messages""" """Load Inbox, Sent anf Draft list of messages"""
self.account = state.association self.account = kivy_state.association
self.ids.tag_label.text = '' self.ids.tag_label.text = ''
self.allMessageQuery(0, 20) self.allMessageQuery(0, 20)
if self.all_mails: if self.all_mails:
self.ids.tag_label.text = 'All Mails' self.ids.tag_label.text = 'All Mails'
state.kivyapp.get_inbox_count() state.kivyapp.get_inbox_count()
state.kivyapp.get_sent_count() state.kivyapp.get_sent_count()
state.all_count = str( kivy_state.all_count = str(
int(state.sent_count) + int(state.inbox_count)) int(kivy_state.sent_count) + int(kivy_state.inbox_count))
self.set_AllmailCnt(state.all_count) self.set_AllmailCnt(kivy_state.all_count)
self.set_mdlist() self.set_mdlist()
# self.ids.refresh_layout.bind(scroll_y=self.check_scroll_y) # self.ids.refresh_layout.bind(scroll_y=self.check_scroll_y)
self.ids.scroll_y.bind(scroll_y=self.check_scroll_y) self.ids.scroll_y.bind(scroll_y=self.check_scroll_y)
@ -101,7 +102,7 @@ class Allmails(Screen):
listItem.secondary_text = secondary_text listItem.secondary_text = secondary_text
listItem.theme_text_color = "Custom" listItem.theme_text_color = "Custom"
listItem.text_color = ThemeClsColor listItem.text_color = ThemeClsColor
img_latter = state.imageDir + '/text_images/{}.png'.format( img_latter = kivy_state.imageDir + '/text_images/{}.png'.format(
avatarImageFirstLetter(body.strip())) avatarImageFirstLetter(body.strip()))
message_row.ids.avater_img.source = img_latter message_row.ids.avater_img.source = img_latter
listItem.bind(on_release=partial( listItem.bind(on_release=partial(
@ -117,7 +118,7 @@ class Allmails(Screen):
# listItem.text_color = ThemeClsColor # listItem.text_color = ThemeClsColor
# listItem.add_widget(AvatarSampleWidget( # listItem.add_widget(AvatarSampleWidget(
# source=state.imageDir + '/text_images/{}.png'.format( # source=kivy_state.imageDir + '/text_images/{}.png'.format(
# avatarImageFirstLetter(body.strip())))) # avatarImageFirstLetter(body.strip()))))
# listItem.bind(on_release=partial( # listItem.bind(on_release=partial(
# self.mail_detail, item[5], item[4], message_row)) # self.mail_detail, item[5], item[4], message_row))
@ -147,9 +148,9 @@ class Allmails(Screen):
if instance.state == 'closed': if instance.state == 'closed':
instance.ids.delete_msg.disabled = True instance.ids.delete_msg.disabled = True
if instance.open_progress == 0.0: if instance.open_progress == 0.0:
state.detailPageType = folder kivy_state.detailPageType = folder
state.is_allmail = True kivy_state.is_allmail = True
state.mail_id = unique_id kivy_state.mail_id = unique_id
if self.manager: if self.manager:
src_mng_obj = self.manager src_mng_obj = self.manager
else: else:
@ -178,21 +179,21 @@ class Allmails(Screen):
msg_count_objs = self.parent.parent.parent.ids.content_drawer.ids msg_count_objs = self.parent.parent.parent.ids.content_drawer.ids
nav_lay_obj = self.parent.parent.parent.ids nav_lay_obj = self.parent.parent.parent.ids
if folder == 'inbox': if folder == 'inbox':
msg_count_objs.inbox_cnt.ids.badge_txt.text = showLimitedCnt(int(state.inbox_count) - 1) msg_count_objs.inbox_cnt.ids.badge_txt.text = showLimitedCnt(int(kivy_state.inbox_count) - 1)
state.inbox_count = str(int(state.inbox_count) - 1) kivy_state.inbox_count = str(int(kivy_state.inbox_count) - 1)
nav_lay_obj.sc1.ids.ml.clear_widgets() nav_lay_obj.sc1.ids.ml.clear_widgets()
nav_lay_obj.sc1.loadMessagelist(state.association) nav_lay_obj.sc1.loadMessagelist(kivy_state.association)
else: else:
msg_count_objs.send_cnt.ids.badge_txt.text = showLimitedCnt(int(state.sent_count) - 1) msg_count_objs.send_cnt.ids.badge_txt.text = showLimitedCnt(int(kivy_state.sent_count) - 1)
state.sent_count = str(int(state.sent_count) - 1) kivy_state.sent_count = str(int(kivy_state.sent_count) - 1)
nav_lay_obj.sc4.ids.ml.clear_widgets() nav_lay_obj.sc4.ids.ml.clear_widgets()
nav_lay_obj.sc4.loadSent(state.association) nav_lay_obj.sc4.loadSent(kivy_state.association)
if folder != 'inbox': if folder != 'inbox':
msg_count_objs.allmail_cnt.ids.badge_txt.text = showLimitedCnt(int(state.all_count) - 1) msg_count_objs.allmail_cnt.ids.badge_txt.text = showLimitedCnt(int(kivy_state.all_count) - 1)
state.all_count = str(int(state.all_count) - 1) kivy_state.all_count = str(int(kivy_state.all_count) - 1)
msg_count_objs.trash_cnt.ids.badge_txt.text = showLimitedCnt(int(state.trash_count) + 1) msg_count_objs.trash_cnt.ids.badge_txt.text = showLimitedCnt(int(kivy_state.trash_count) + 1)
state.trash_count = str(int(state.trash_count) + 1) kivy_state.trash_count = str(int(kivy_state.trash_count) + 1)
if int(state.all_count) <= 0: if int(kivy_state.all_count) <= 0:
self.ids.tag_label.text = '' self.ids.tag_label.text = ''
# nav_lay_obj.sc5.clear_widgets() # nav_lay_obj.sc5.clear_widgets()
# nav_lay_obj.sc5.add_widget(Trash()) # nav_lay_obj.sc5.add_widget(Trash())

View File

@ -13,6 +13,7 @@ from kivy.properties import (
from kivy.uix.screenmanager import Screen from kivy.uix.screenmanager import Screen
from kivymd.uix.label import MDLabel from kivymd.uix.label import MDLabel
import kivy_state
import state import state
from bitmessagekivy.baseclass.common import ( from bitmessagekivy.baseclass.common import (
@ -33,9 +34,9 @@ class Draft(Screen):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
"""Method used for storing draft messages""" """Method used for storing draft messages"""
super(Draft, self).__init__(*args, **kwargs) super(Draft, self).__init__(*args, **kwargs)
if state.association == '': if kivy_state.association == '':
if state.kivyapp.variable_1: if state.kivyapp.variable_1:
state.association = state.kivyapp.variable_1[0] kivy_state.association = state.kivyapp.variable_1[0]
Clock.schedule_once(self.init_ui, 0) Clock.schedule_once(self.init_ui, 0)
def init_ui(self, dt=0): def init_ui(self, dt=0):
@ -45,20 +46,20 @@ class Draft(Screen):
def sentaccounts(self): def sentaccounts(self):
"""Load draft accounts""" """Load draft accounts"""
# self.account = state.association # self.account = kivy_state.association
self.loadDraft() self.loadDraft()
def loadDraft(self, where="", what=""): def loadDraft(self, where="", what=""):
"""Load draft list for Draft messages""" """Load draft list for Draft messages"""
self.account = state.association self.account = kivy_state.association
xAddress = 'fromaddress' xAddress = 'fromaddress'
self.ids.tag_label.text = '' self.ids.tag_label.text = ''
self.draftDataQuery(xAddress, where, what) self.draftDataQuery(xAddress, where, what)
# if state.msg_counter_objs: # if kivy_state.msg_counter_objs:
# state.msg_counter_objs.draft_cnt.children[0].children[0].text = showLimitedCnt(len(self.queryreturn)) # kivy_state.msg_counter_objs.draft_cnt.children[0].children[0].text = showLimitedCnt(len(self.queryreturn))
if self.queryreturn: if self.queryreturn:
self.ids.tag_label.text = 'Draft' self.ids.tag_label.text = 'Draft'
self.set_draftCnt(state.draft_count) self.set_draftCnt(kivy_state.draft_count)
self.set_mdList() self.set_mdList()
self.ids.scroll_y.bind(scroll_y=self.check_scroll_y) self.ids.scroll_y.bind(scroll_y=self.check_scroll_y)
else: else:
@ -104,7 +105,7 @@ class Draft(Screen):
listItem.secondary_text = item["text"] listItem.secondary_text = item["text"]
listItem.theme_text_color = "Custom" listItem.theme_text_color = "Custom"
listItem.text_color = ThemeClsColor listItem.text_color = ThemeClsColor
message_row.ids.avater_img.source = state.imageDir + '/avatar.png' message_row.ids.avater_img.source = kivy_state.imageDir + '/avatar.png'
listItem.bind(on_release=partial( listItem.bind(on_release=partial(
self.draft_detail, item['ackdata'], message_row)) self.draft_detail, item['ackdata'], message_row))
message_row.ids.time_tag.text = str(ShowTimeHistoy(item['senttime'])) message_row.ids.time_tag.text = str(ShowTimeHistoy(item['senttime']))
@ -130,8 +131,8 @@ class Draft(Screen):
if instance.state == 'closed': if instance.state == 'closed':
instance.ids.delete_msg.disabled = True instance.ids.delete_msg.disabled = True
if instance.open_progress == 0.0: if instance.open_progress == 0.0:
state.detailPageType = 'draft' kivy_state.detailPageType = 'draft'
state.mail_id = ackdata kivy_state.mail_id = ackdata
if self.manager: if self.manager:
src_mng_obj = self.manager src_mng_obj = self.manager
else: else:
@ -145,10 +146,10 @@ class Draft(Screen):
def delete_draft(self, data_index, instance, *args): def delete_draft(self, data_index, instance, *args):
"""Delete draft message permanently""" """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: if int(kivy_state.draft_count) > 0:
state.draft_count = str(int(state.draft_count) - 1) kivy_state.draft_count = str(int(kivy_state.draft_count) - 1)
self.set_draftCnt(state.draft_count) self.set_draftCnt(kivy_state.draft_count)
if int(state.draft_count) <= 0: if int(kivy_state.draft_count) <= 0:
# self.ids.identi_tag.children[0].text = '' # self.ids.identi_tag.children[0].text = ''
self.ids.tag_label.text = '' self.ids.tag_label.text = ''
self.ids.ml.remove_widget(instance.parent.parent) self.ids.ml.remove_widget(instance.parent.parent)
@ -190,9 +191,9 @@ class Draft(Screen):
'draft', 'draft',
encoding, encoding,
BMConfigParser().safeGetInt('bitmessagesettings', 'ttl')) BMConfigParser().safeGetInt('bitmessagesettings', 'ttl'))
state.msg_counter_objs = src_object.children[2].children[0].ids kivy_state.msg_counter_objs = src_object.children[2].children[0].ids
state.draft_count = str(int(state.draft_count) + 1) \ kivy_state.draft_count = str(int(kivy_state.draft_count) + 1) \
if state.association == fromAddress else state.draft_count if kivy_state.association == fromAddress else kivy_state.draft_count
src_object.ids.sc16.clear_widgets() src_object.ids.sc16.clear_widgets()
src_object.ids.sc16.add_widget(Draft()) src_object.ids.sc16.add_widget(Draft())
toast('Save draft') toast('Save draft')

View File

@ -13,6 +13,7 @@ from kivy.properties import (
from kivy.uix.screenmanager import Screen from kivy.uix.screenmanager import Screen
from kivymd.uix.label import MDLabel from kivymd.uix.label import MDLabel
import kivy_state
import state import state
from bitmessagekivy.baseclass.common import ( from bitmessagekivy.baseclass.common import (
@ -39,9 +40,9 @@ class Inbox(Screen):
@staticmethod @staticmethod
def set_defaultAddress(): def set_defaultAddress():
"""This method set's default address""" """This method set's default address"""
if state.association == "": if kivy_state.association == "":
if state.kivyapp.variable_1: if state.kivyapp.variable_1:
state.association = state.kivyapp.variable_1[0] kivy_state.association = state.kivyapp.variable_1[0]
def init_ui(self, dt=0): def init_ui(self, dt=0):
"""Clock schdule for method inbox accounts""" """Clock schdule for method inbox accounts"""
@ -50,12 +51,12 @@ class Inbox(Screen):
def loadMessagelist(self, where="", what=""): def loadMessagelist(self, where="", what=""):
"""Load Inbox list for Inbox messages""" """Load Inbox list for Inbox messages"""
self.set_defaultAddress() self.set_defaultAddress()
self.account = state.association self.account = kivy_state.association
if state.searcing_text: if kivy_state.searcing_text:
# self.children[2].children[0].children[0].scroll_y = 1.0 # self.children[2].children[0].children[0].scroll_y = 1.0
self.ids.scroll_y.scroll_y = 1.0 self.ids.scroll_y.scroll_y = 1.0
where = ["subject", "message"] where = ["subject", "message"]
what = state.searcing_text what = kivy_state.searcing_text
xAddress = "toaddress" xAddress = "toaddress"
data = [] data = []
self.ids.tag_label.text = "" self.ids.tag_label.text = ""
@ -64,7 +65,7 @@ class Inbox(Screen):
if self.queryreturn: if self.queryreturn:
self.ids.tag_label.text = "Inbox" self.ids.tag_label.text = "Inbox"
state.kivyapp.get_inbox_count() state.kivyapp.get_inbox_count()
self.set_inboxCount(state.inbox_count) self.set_inboxCount(kivy_state.inbox_count)
for mail in self.queryreturn: for mail in self.queryreturn:
# third_text = mail[3].replace('\n', ' ') # third_text = mail[3].replace('\n', ' ')
body = mail[3].decode() if isinstance(mail[3], bytes) else mail[3] body = mail[3].decode() if isinstance(mail[3], bytes) else mail[3]
@ -93,7 +94,7 @@ class Inbox(Screen):
font_style="Caption", font_style="Caption",
theme_text_color="Primary", theme_text_color="Primary",
text="No message found!" text="No message found!"
if state.searcing_text if kivy_state.searcing_text
else "yet no message for this account!!!!!!!!!!!!!", else "yet no message for this account!!!!!!!!!!!!!",
halign="center", halign="center",
size_hint_y=None, size_hint_y=None,
@ -106,9 +107,9 @@ class Inbox(Screen):
src_mng_obj = state.kivyapp.root.ids.content_drawer.ids src_mng_obj = state.kivyapp.root.ids.content_drawer.ids
src_mng_obj.inbox_cnt.ids.badge_txt.text = showLimitedCnt(int(msgCnt)) src_mng_obj.inbox_cnt.ids.badge_txt.text = showLimitedCnt(int(msgCnt))
state.kivyapp.get_sent_count() state.kivyapp.get_sent_count()
state.all_count = str( kivy_state.all_count = str(
int(state.sent_count) + int(state.inbox_count)) int(kivy_state.sent_count) + int(kivy_state.inbox_count))
src_mng_obj.allmail_cnt.ids.badge_txt.text = showLimitedCnt(int(state.all_count)) src_mng_obj.allmail_cnt.ids.badge_txt.text = showLimitedCnt(int(kivy_state.all_count))
def inboxDataQuery(self, xAddress, where, what, start_indx=0, end_indx=20): def inboxDataQuery(self, xAddress, where, what, start_indx=0, end_indx=20):
"""This method is used for retrieving inbox data""" """This method is used for retrieving inbox data"""
@ -128,7 +129,7 @@ class Inbox(Screen):
listItem.theme_text_color = "Custom" listItem.theme_text_color = "Custom"
listItem.text_color = ThemeClsColor listItem.text_color = ThemeClsColor
listItem._txt_right_pad = dp(70) listItem._txt_right_pad = dp(70)
image = state.imageDir + "/text_images/{}.png".format( image = kivy_state.imageDir + "/text_images/{}.png".format(
avatarImageFirstLetter(item["secondary_text"].strip())) avatarImageFirstLetter(item["secondary_text"].strip()))
message_row.ids.avater_img.source = image message_row.ids.avater_img.source = image
listItem.bind(on_release=partial(self.inbox_detail, item["msgid"], message_row)) listItem.bind(on_release=partial(self.inbox_detail, item["msgid"], message_row))
@ -148,9 +149,9 @@ class Inbox(Screen):
def update_inbox_screen_on_scroll(self, total_message, where="", what=""): def update_inbox_screen_on_scroll(self, total_message, where="", what=""):
"""This method is used to load more data on scroll down""" """This method is used to load more data on scroll down"""
data = [] data = []
if state.searcing_text: if kivy_state.searcing_text:
where = ["subject", "message"] where = ["subject", "message"]
what = state.searcing_text what = kivy_state.searcing_text
self.inboxDataQuery("toaddress", where, what, total_message, 5) self.inboxDataQuery("toaddress", where, what, total_message, 5)
for mail in self.queryreturn: for mail in self.queryreturn:
# third_text = mail[3].replace('\n', ' ') # third_text = mail[3].replace('\n', ' ')
@ -173,8 +174,8 @@ class Inbox(Screen):
if instance.state == 'closed': if instance.state == 'closed':
instance.ids.delete_msg.disabled = True instance.ids.delete_msg.disabled = True
if instance.open_progress == 0.0: if instance.open_progress == 0.0:
state.detailPageType = "inbox" kivy_state.detailPageType = "inbox"
state.mail_id = msg_id kivy_state.mail_id = msg_id
if self.manager: if self.manager:
src_mng_obj = self.manager src_mng_obj = self.manager
else: else:
@ -189,22 +190,22 @@ class Inbox(Screen):
"""Delete inbox mail from inbox listing""" """Delete inbox mail from inbox listing"""
sqlExecute("UPDATE inbox SET folder = 'trash' WHERE msgid = ?;", data_index) sqlExecute("UPDATE inbox SET folder = 'trash' WHERE msgid = ?;", data_index)
msg_count_objs = self.parent.parent.ids.content_drawer.ids msg_count_objs = self.parent.parent.ids.content_drawer.ids
if int(state.inbox_count) > 0: if int(kivy_state.inbox_count) > 0:
msg_count_objs.inbox_cnt.ids.badge_txt.text = showLimitedCnt( msg_count_objs.inbox_cnt.ids.badge_txt.text = showLimitedCnt(
int(state.inbox_count) - 1 int(kivy_state.inbox_count) - 1
) )
msg_count_objs.trash_cnt.ids.badge_txt.text = showLimitedCnt( msg_count_objs.trash_cnt.ids.badge_txt.text = showLimitedCnt(
int(state.trash_count) + 1 int(kivy_state.trash_count) + 1
) )
state.inbox_count = str(int(state.inbox_count) - 1) kivy_state.inbox_count = str(int(kivy_state.inbox_count) - 1)
state.trash_count = str(int(state.trash_count) + 1) kivy_state.trash_count = str(int(kivy_state.trash_count) + 1)
if int(state.all_count) > 0: if int(kivy_state.all_count) > 0:
msg_count_objs.allmail_cnt.ids.badge_txt.text = showLimitedCnt( msg_count_objs.allmail_cnt.ids.badge_txt.text = showLimitedCnt(
int(state.all_count) - 1 int(kivy_state.all_count) - 1
) )
state.all_count = str(int(state.all_count) - 1) kivy_state.all_count = str(int(kivy_state.all_count) - 1)
if int(state.inbox_count) <= 0: if int(kivy_state.inbox_count) <= 0:
# self.ids.identi_tag.children[0].text = '' # self.ids.identi_tag.children[0].text = ''
self.ids.tag_label.text = '' self.ids.tag_label.text = ''
self.ids.ml.remove_widget( self.ids.ml.remove_widget(
@ -235,10 +236,10 @@ 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 = "" kivy_state.searcing_text = ""
self.children[2].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(kivy_state.association)
self.has_refreshed = True self.has_refreshed = True
self.ids.refresh_layout.refresh_done() self.ids.refresh_layout.refresh_done()
self.tick = 0 self.tick = 0

View File

@ -7,6 +7,7 @@ from kivy.uix.boxlayout import BoxLayout
from kivymd.uix.behaviors.elevation import RectangularElevationBehavior from kivymd.uix.behaviors.elevation import RectangularElevationBehavior
from kivy.uix.screenmanager import Screen from kivy.uix.screenmanager import Screen
import kivy_state
import state import state
from bitmessagekivy.baseclass.common import toast from bitmessagekivy.baseclass.common import toast

View File

@ -19,6 +19,7 @@ from kivymd.uix.list import (
) )
from kivy.uix.screenmanager import Screen from kivy.uix.screenmanager import Screen
import kivy_state
import state import state
from bitmessagekivy.baseclass.common import ( from bitmessagekivy.baseclass.common import (
@ -96,20 +97,20 @@ class MailDetail(Screen): # pylint: disable=too-many-instance-attributes
def init_ui(self, dt=0): def init_ui(self, dt=0):
"""Clock Schdule for method MailDetail mails""" """Clock Schdule for method MailDetail mails"""
self.page_type = state.detailPageType if state.detailPageType else '' self.page_type = kivy_state.detailPageType if kivy_state.detailPageType else ''
try: try:
if state.detailPageType == 'sent' or state.detailPageType == 'draft': if kivy_state.detailPageType == 'sent' or kivy_state.detailPageType == 'draft':
data = sqlQuery( data = sqlQuery(
"select toaddress, fromaddress, subject, message, status," "select toaddress, fromaddress, subject, message, status,"
" ackdata, senttime from sent where ackdata = ?;", state.mail_id) " ackdata, senttime from sent where ackdata = ?;", kivy_state.mail_id)
state.status = self kivy_state.status = self
state.ackdata = data[0][5] kivy_state.ackdata = data[0][5]
self.assign_mail_details(data) self.assign_mail_details(data)
state.kivyapp.set_mail_detail_header() state.kivyapp.set_mail_detail_header()
elif state.detailPageType == 'inbox': elif kivy_state.detailPageType == 'inbox':
data = sqlQuery( data = sqlQuery(
"select toaddress, fromaddress, subject, message, received from inbox" "select toaddress, fromaddress, subject, message, received from inbox"
" where msgid = ?;", state.mail_id) " where msgid = ?;", kivy_state.mail_id)
self.assign_mail_details(data) self.assign_mail_details(data)
state.kivyapp.set_mail_detail_header() state.kivyapp.set_mail_detail_header()
except Exception as e: except Exception as e:
@ -127,51 +128,51 @@ class MailDetail(Screen): # pylint: disable=too-many-instance-attributes
self.message = body self.message = body
if len(data[0]) == 7: if len(data[0]) == 7:
self.status = data[0][4] self.status = data[0][4]
self.time_tag = ShowTimeHistoy(data[0][4]) if state.detailPageType == 'inbox' else ShowTimeHistoy(data[0][6]) self.time_tag = ShowTimeHistoy(data[0][4]) if kivy_state.detailPageType == 'inbox' else ShowTimeHistoy(data[0][6])
self.avatarImg = state.imageDir + '/avatar.png' if state.detailPageType == 'draft' else ( self.avatarImg = kivy_state.imageDir + '/avatar.png' if kivy_state.detailPageType == 'draft' else (
state.imageDir + '/text_images/{0}.png'.format(avatarImageFirstLetter(self.subject.strip()))) kivy_state.imageDir + '/text_images/{0}.png'.format(avatarImageFirstLetter(self.subject.strip())))
self.timeinseconds = data[0][4] if state.detailPageType == 'inbox' else data[0][6] self.timeinseconds = data[0][4] if kivy_state.detailPageType == 'inbox' else data[0][6]
def delete_mail(self): def delete_mail(self):
"""Method for mail delete""" """Method for mail delete"""
msg_count_objs = state.kivyapp.root.ids.content_drawer.ids msg_count_objs = state.kivyapp.root.ids.content_drawer.ids
state.searcing_text = '' kivy_state.searcing_text = ''
self.children[0].children[0].active = True self.children[0].children[0].active = True
if state.detailPageType == 'sent': if kivy_state.detailPageType == 'sent':
state.kivyapp.root.ids.sc4.ids.sent_search.ids.search_field.text = '' state.kivyapp.root.ids.sc4.ids.sent_search.ids.search_field.text = ''
sqlExecute( sqlExecute(
"UPDATE sent SET folder = 'trash' WHERE" "UPDATE sent SET folder = 'trash' WHERE"
" ackdata = ?;", state.mail_id) " ackdata = ?;", kivy_state.mail_id)
msg_count_objs.send_cnt.ids.badge_txt.text = str(int(state.sent_count) - 1) msg_count_objs.send_cnt.ids.badge_txt.text = str(int(kivy_state.sent_count) - 1)
state.sent_count = str(int(state.sent_count) - 1) kivy_state.sent_count = str(int(kivy_state.sent_count) - 1)
self.parent.screens[2].ids.ml.clear_widgets() self.parent.screens[2].ids.ml.clear_widgets()
self.parent.screens[2].loadSent(state.association) self.parent.screens[2].loadSent(kivy_state.association)
elif state.detailPageType == 'inbox': elif kivy_state.detailPageType == 'inbox':
state.kivyapp.root.ids.sc1.ids.inbox_search.ids.search_field.text = '' state.kivyapp.root.ids.sc1.ids.inbox_search.ids.search_field.text = ''
sqlExecute( sqlExecute(
"UPDATE inbox SET folder = 'trash' WHERE" "UPDATE inbox SET folder = 'trash' WHERE"
" msgid = ?;", state.mail_id) " msgid = ?;", kivy_state.mail_id)
msg_count_objs.inbox_cnt.ids.badge_txt.text = str( msg_count_objs.inbox_cnt.ids.badge_txt.text = str(
int(state.inbox_count) - 1) int(kivy_state.inbox_count) - 1)
state.inbox_count = str(int(state.inbox_count) - 1) kivy_state.inbox_count = str(int(kivy_state.inbox_count) - 1)
self.parent.screens[0].ids.ml.clear_widgets() self.parent.screens[0].ids.ml.clear_widgets()
self.parent.screens[0].loadMessagelist(state.association) self.parent.screens[0].loadMessagelist(kivy_state.association)
elif state.detailPageType == 'draft': elif kivy_state.detailPageType == 'draft':
sqlExecute("DELETE FROM sent WHERE ackdata = ?;", state.mail_id) sqlExecute("DELETE FROM sent WHERE ackdata = ?;", kivy_state.mail_id)
msg_count_objs.draft_cnt.ids.badge_txt.text = str( msg_count_objs.draft_cnt.ids.badge_txt.text = str(
int(state.draft_count) - 1) int(kivy_state.draft_count) - 1)
state.draft_count = str(int(state.draft_count) - 1) kivy_state.draft_count = str(int(kivy_state.draft_count) - 1)
self.parent.screens[13].clear_widgets() self.parent.screens[13].clear_widgets()
self.parent.screens[13].add_widget(Factory.Draft()) self.parent.screens[13].add_widget(Factory.Draft())
if state.detailPageType != 'draft': if kivy_state.detailPageType != 'draft':
msg_count_objs.trash_cnt.ids.badge_txt.text = str( msg_count_objs.trash_cnt.ids.badge_txt.text = str(
int(state.trash_count) + 1) int(kivy_state.trash_count) + 1)
msg_count_objs.allmail_cnt.ids.badge_txt.text = str( msg_count_objs.allmail_cnt.ids.badge_txt.text = str(
int(state.all_count) - 1) int(kivy_state.all_count) - 1)
state.trash_count = str(int(state.trash_count) + 1) kivy_state.trash_count = str(int(kivy_state.trash_count) + 1)
state.all_count = str(int(state.all_count) - 1) if int(state.all_count) else '0' kivy_state.all_count = str(int(kivy_state.all_count) - 1) if int(kivy_state.all_count) else '0'
self.parent.screens[3].clear_widgets() self.parent.screens[3].clear_widgets()
self.parent.screens[3].add_widget(Factory.Trash()) self.parent.screens[3].add_widget(Factory.Trash())
self.parent.screens[14].clear_widgets() self.parent.screens[14].clear_widgets()
@ -180,20 +181,20 @@ class MailDetail(Screen): # pylint: disable=too-many-instance-attributes
def callback_for_delete(self, dt=0): def callback_for_delete(self, dt=0):
"""Delete method from allmails""" """Delete method from allmails"""
if state.detailPageType: if kivy_state.detailPageType:
self.children[0].children[0].active = False self.children[0].children[0].active = False
state.kivyapp.set_common_header() state.kivyapp.set_common_header()
self.parent.current = 'allmails' \ self.parent.current = 'allmails' \
if state.is_allmail else state.detailPageType if kivy_state.is_allmail else kivy_state.detailPageType
state.detailPageType = '' kivy_state.detailPageType = ''
toast('Deleted') toast('Deleted')
def inbox_reply(self): def inbox_reply(self):
"""Reply inbox messages""" """Reply inbox messages"""
state.in_composer = True kivy_state.in_composer = True
data = sqlQuery( data = sqlQuery(
"select toaddress, fromaddress, subject, message, received from inbox where" "select toaddress, fromaddress, subject, message, received from inbox where"
" msgid = ?;", state.mail_id) " msgid = ?;", kivy_state.mail_id)
composer_obj = self.parent.screens[1].children[1].ids composer_obj = self.parent.screens[1].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]
@ -214,10 +215,10 @@ class MailDetail(Screen): # pylint: disable=too-many-instance-attributes
def write_msg(self, navApp): def write_msg(self, navApp):
"""Write on draft mail""" """Write on draft mail"""
state.send_draft_mail = state.mail_id kivy_state.send_draft_mail = kivy_state.mail_id
data = sqlQuery( data = sqlQuery(
"select toaddress, fromaddress, subject, message from sent where" "select toaddress, fromaddress, subject, message from sent where"
" ackdata = ?;", state.mail_id) " ackdata = ?;", kivy_state.mail_id)
composer_ids = ( composer_ids = (
self.parent.parent.ids.sc3.children[1].ids) self.parent.parent.ids.sc3.children[1].ids)
composer_ids.ti.text = data[0][1] composer_ids.ti.text = data[0][1]

View File

@ -26,6 +26,7 @@ from kivy.uix.textinput import TextInput
from kivymd.uix.behaviors.hover_behavior import HoverBehavior from kivymd.uix.behaviors.hover_behavior import HoverBehavior
from kivymd.uix.boxlayout import MDBoxLayout from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.theming import ThemableBehavior from kivymd.theming import ThemableBehavior
import kivy_state
import state import state
import queues import queues
@ -94,7 +95,7 @@ class DropDownWidget(BoxLayout):
) )
if status == "success": if status == "success":
navApp.root.ids.sc3.children[0].active = True navApp.root.ids.sc3.children[0].active = True
if state.detailPageType == "draft" and state.send_draft_mail: if kivy_state.detailPageType == "draft" and kivy_state.send_draft_mail:
sqlExecute( sqlExecute(
"UPDATE sent SET toaddress = ?" "UPDATE sent SET toaddress = ?"
", fromaddress = ? , subject = ?" ", fromaddress = ? , subject = ?"
@ -107,11 +108,11 @@ class DropDownWidget(BoxLayout):
message, message,
int(time.time()), int(time.time()),
int(time.time()), int(time.time()),
state.send_draft_mail) kivy_state.send_draft_mail)
self.parent.parent.screens[13].clear_widgets() self.parent.parent.screens[13].clear_widgets()
self.parent.parent.screens[13].add_widget(Factory.Draft()) self.parent.parent.screens[13].add_widget(Factory.Draft())
# state.detailPageType = '' # kivy_state.detailPageType = ''
# state.send_draft_mail = None # kivy_state.send_draft_mail = None
else: else:
# toAddress = addBMIfNotPresent(toAddress) # toAddress = addBMIfNotPresent(toAddress)
if (addressVersionNumber > 4) or ( if (addressVersionNumber > 4) or (
@ -145,24 +146,24 @@ class DropDownWidget(BoxLayout):
3, #encoding 3, #encoding
BMConfigParser().safeGetInt( BMConfigParser().safeGetInt(
'bitmessagesettings', 'ttl')) 'bitmessagesettings', 'ttl'))
state.check_sent_acc = fromAddress kivy_state.check_sent_acc = fromAddress
# state.msg_counter_objs = self.parent.parent.parent.parent\ # kivy_state.msg_counter_objs = self.parent.parent.parent.parent\
# .parent.parent.children[2].children[0].ids # .parent.parent.children[2].children[0].ids
if state.detailPageType == 'draft' \ if kivy_state.detailPageType == 'draft' \
and state.send_draft_mail: and kivy_state.send_draft_mail:
state.draft_count = str(int(state.draft_count) - 1) kivy_state.draft_count = str(int(kivy_state.draft_count) - 1)
# state.msg_counter_objs.draft_cnt.badge_text = ( # kivy_state.msg_counter_objs.draft_cnt.badge_text = (
# state.draft_count) # kivy_state.draft_count)
state.detailPageType = '' kivy_state.detailPageType = ''
state.send_draft_mail = None kivy_state.send_draft_mail = None
self.parent.parent.parent.ids.sc4.update_sent_messagelist() self.parent.parent.parent.ids.sc4.update_sent_messagelist()
allmailCnt_obj = state.kivyapp.root.ids.content_drawer.ids.allmail_cnt allmailCnt_obj = state.kivyapp.root.ids.content_drawer.ids.allmail_cnt
allmailCnt_obj.ids.badge_txt.text = showLimitedCnt(int(state.all_count) + 1) allmailCnt_obj.ids.badge_txt.text = showLimitedCnt(int(kivy_state.all_count) + 1)
state.all_count = str(int(state.all_count) + 1) kivy_state.all_count = str(int(kivy_state.all_count) + 1)
Clock.schedule_once(self.callback_for_msgsend, 3) Clock.schedule_once(self.callback_for_msgsend, 3)
queues.workerQueue.put(('sendmessage', addBMIfNotPresent(toAddress))) queues.workerQueue.put(('sendmessage', addBMIfNotPresent(toAddress)))
print("sqlExecute successfully #######################") print("sqlExecute successfully #######################")
state.in_composer = True kivy_state.in_composer = True
return return
else: else:
msg = 'Enter a valid recipients address' msg = 'Enter a valid recipients address'
@ -176,7 +177,7 @@ class DropDownWidget(BoxLayout):
def callback_for_msgsend(dt=0): # pylint: disable=unused-argument def callback_for_msgsend(dt=0): # pylint: disable=unused-argument
"""Callback method for messagesend""" """Callback method for messagesend"""
state.kivyapp.root.ids.sc3.children[0].active = False state.kivyapp.root.ids.sc3.children[0].active = False
state.in_sent_method = True kivy_state.in_sent_method = True
state.kivyapp.back_press() state.kivyapp.back_press()
toast("sent") toast("sent")

View File

@ -17,6 +17,7 @@ from kivymd.uix.list import (
from kivymd.uix.selectioncontrol import MDSwitch from kivymd.uix.selectioncontrol import MDSwitch
from kivy.uix.screenmanager import Screen from kivy.uix.screenmanager import Screen
import kivy_state
import state import state
from bitmessagekivy.baseclass.common import ( from bitmessagekivy.baseclass.common import (
@ -57,7 +58,7 @@ class MyAddress(Screen):
# pylint: disable=unnecessary-lambda, deprecated-lambda # pylint: disable=unnecessary-lambda, deprecated-lambda
# self.addresses_list = state.kivyapp.variable_1 # self.addresses_list = state.kivyapp.variable_1
self.addresses_list = BMConfigParser().addresses() self.addresses_list = BMConfigParser().addresses()
if state.searcing_text: if kivy_state.searcing_text:
self.ids.refresh_layout.scroll_y = 1.0 self.ids.refresh_layout.scroll_y = 1.0
filtered_list = [ filtered_list = [
x for x in BMConfigParser().addresses() x for x in BMConfigParser().addresses()
@ -75,13 +76,13 @@ class MyAddress(Screen):
content = MDLabel( content = MDLabel(
font_style='Caption', font_style='Caption',
theme_text_color='Primary', theme_text_color='Primary',
text="No address found!" if state.searcing_text text="No address found!" if kivy_state.searcing_text
else "yet no address is created by user!!!!!!!!!!!!!", else "yet no address is created by user!!!!!!!!!!!!!",
halign='center', halign='center',
size_hint_y=None, size_hint_y=None,
valign='top') valign='top')
self.ids.ml.add_widget(content) self.ids.ml.add_widget(content)
if not state.searcing_text and not self.is_add_created: if not kivy_state.searcing_text and not self.is_add_created:
try: try:
self.manager.current = 'login' self.manager.current = 'login'
except Exception: except Exception:
@ -106,11 +107,11 @@ class MyAddress(Screen):
except Exception: except Exception:
pass pass
meny.add_widget(AvatarSampleWidget( meny.add_widget(AvatarSampleWidget(
source=state.imageDir + '/text_images/{}.png'.format( source=kivy_state.imageDir + '/text_images/{}.png'.format(
avatarImageFirstLetter(item['text'].strip())))) avatarImageFirstLetter(item['text'].strip()))))
meny.bind(on_press=partial( meny.bind(on_press=partial(
self.myadd_detail, item['secondary_text'], item['text'])) self.myadd_detail, item['secondary_text'], item['text']))
if state.association == item['secondary_text'] and is_enable == 'true': if kivy_state.association == item['secondary_text'] and is_enable == 'true':
badge_obj = BadgeText( badge_obj = BadgeText(
size_hint=(None, None), size_hint=(None, None),
size=[90 if platform == 'android' else 50, 60], size=[90 if platform == 'android' else 50, 60],
@ -184,7 +185,7 @@ class MyAddress(Screen):
While the spinner remains on the screen""" While the spinner remains on the screen"""
def refresh_callback(interval): def refresh_callback(interval):
"""Method used for loading the myaddress screen data""" """Method used for loading the myaddress screen data"""
state.searcing_text = '' kivy_state.searcing_text = ''
# state.kivyapp.root.ids.sc10.children[2].active = False # state.kivyapp.root.ids.sc10.children[2].active = False
self.ids.search_bar.ids.search_field.text = '' self.ids.search_bar.ids.search_field.text = ''
self.has_refreshed = True self.has_refreshed = True
@ -203,7 +204,7 @@ class MyAddress(Screen):
BMConfigParser().get(address, 'label').lower(), BMConfigParser().get(address, 'label').lower(),
address.lower() address.lower()
] ]
if (state.searcing_text).lower() in x if (kivy_state.searcing_text).lower() in x
]: ]:
return True return True
return False return False

View File

@ -1,3 +1,4 @@
import kivy_state
import state import state
from kivy.clock import Clock from kivy.clock import Clock

View File

@ -15,6 +15,7 @@ from kivymd.uix.list import (
from bitmessagekivy.baseclass.common import toast from bitmessagekivy.baseclass.common import toast
# import queues # import queues
import kivy_state
import state import state
@ -24,7 +25,7 @@ class Payment(Screen):
def get_free_credits(self, instance): def get_free_credits(self, instance):
"""Get the available credits""" """Get the available credits"""
# pylint: disable=no-self-use # pylint: disable=no-self-use
state.availabe_credit = instance.parent.children[1].text kivy_state.availabe_credit = instance.parent.children[1].text
existing_credits = state.kivyapp.root.ids.sc18.ids.cred.text existing_credits = state.kivyapp.root.ids.sc18.ids.cred.text
if float(existing_credits.split()[1]) > 0: if float(existing_credits.split()[1]) > 0:
toast( toast(
@ -33,7 +34,7 @@ class Payment(Screen):
else: else:
toast('Coins added to your account!') toast('Coins added to your account!')
state.kivyapp.root.ids.sc18.ids.cred.text = '{0}'.format( state.kivyapp.root.ids.sc18.ids.cred.text = '{0}'.format(
state.availabe_credit) kivy_state.availabe_credit)
@staticmethod @staticmethod
def create_hidden_payment_address(): def create_hidden_payment_address():

View File

@ -8,6 +8,7 @@ from kivy.properties import StringProperty
from kivy.uix.boxlayout import BoxLayout from kivy.uix.boxlayout import BoxLayout
from kivy.uix.popup import Popup from kivy.uix.popup import Popup
import kivy_state
import state import state
from addresses import decodeAddress from addresses import decodeAddress
from datetime import datetime from datetime import datetime

View File

@ -1,3 +1,4 @@
import kivy_state
import state import state
from bitmessagekivy.baseclass.common import toast from bitmessagekivy.baseclass.common import toast
from kivy.uix.screenmanager import Screen from kivy.uix.screenmanager import Screen

View File

@ -10,6 +10,7 @@ from kivy.properties import StringProperty, ListProperty
from kivy.uix.screenmanager import Screen from kivy.uix.screenmanager import Screen
from kivymd.uix.label import MDLabel from kivymd.uix.label import MDLabel
import kivy_state
import state import state
from bitmessagekivy.baseclass.common import ( from bitmessagekivy.baseclass.common import (
@ -29,9 +30,9 @@ class Sent(Screen):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
"""Association with the screen""" """Association with the screen"""
super(Sent, self).__init__(*args, **kwargs) super(Sent, self).__init__(*args, **kwargs)
if state.association == '': if kivy_state.association == '':
if state.kivyapp.variable_1: if state.kivyapp.variable_1:
state.association = state.kivyapp.variable_1[0] kivy_state.association = state.kivyapp.variable_1[0]
Clock.schedule_once(self.init_ui, 0) Clock.schedule_once(self.init_ui, 0)
def init_ui(self, dt=0): def init_ui(self, dt=0):
@ -41,18 +42,18 @@ class Sent(Screen):
def loadSent(self, where="", what=""): def loadSent(self, where="", what=""):
"""Load Sent list for Sent messages""" """Load Sent list for Sent messages"""
self.account = state.association self.account = kivy_state.association
if state.searcing_text: if kivy_state.searcing_text:
self.ids.scroll_y.scroll_y = 1.0 self.ids.scroll_y.scroll_y = 1.0
where = ['subject', 'message'] where = ['subject', 'message']
what = state.searcing_text what = kivy_state.searcing_text
xAddress = 'fromaddress' xAddress = 'fromaddress'
data = [] data = []
self.ids.tag_label.text = '' self.ids.tag_label.text = ''
self.sentDataQuery(xAddress, where, what) self.sentDataQuery(xAddress, where, what)
if self.queryreturn: if self.queryreturn:
self.ids.tag_label.text = 'Sent' self.ids.tag_label.text = 'Sent'
self.set_sentCount(state.sent_count) self.set_sentCount(kivy_state.sent_count)
for mail in self.queryreturn: for mail in self.queryreturn:
data.append({ data.append({
'text': mail[1].strip(), 'text': mail[1].strip(),
@ -68,7 +69,7 @@ class Sent(Screen):
content = MDLabel( content = MDLabel(
font_style='Caption', font_style='Caption',
theme_text_color='Primary', theme_text_color='Primary',
text="No message found!" if state.searcing_text text="No message found!" if kivy_state.searcing_text
else "yet no message for this account!!!!!!!!!!!!!", else "yet no message for this account!!!!!!!!!!!!!",
halign='center', halign='center',
size_hint_y=None, size_hint_y=None,
@ -98,7 +99,7 @@ class Sent(Screen):
listItem.secondary_text = item["secondary_text"] listItem.secondary_text = item["secondary_text"]
listItem.theme_text_color = "Custom" listItem.theme_text_color = "Custom"
listItem.text_color = ThemeClsColor listItem.text_color = ThemeClsColor
image = state.imageDir + '/text_images/{}.png'.format( image = kivy_state.imageDir + '/text_images/{}.png'.format(
avatarImageFirstLetter(item['secondary_text'].strip())) avatarImageFirstLetter(item['secondary_text'].strip()))
message_row.ids.avater_img.source = image message_row.ids.avater_img.source = image
listItem.bind(on_release=partial(self.sent_detail, item['ackdata'], message_row)) listItem.bind(on_release=partial(self.sent_detail, item['ackdata'], message_row))
@ -111,25 +112,25 @@ class Sent(Screen):
def update_sent_messagelist(self): def update_sent_messagelist(self):
"""This method is used to update screen when new mail is sent""" """This method is used to update screen when new mail is sent"""
self.account = state.association self.account = kivy_state.association
if len(self.ids.ml.children) < 3: if len(self.ids.ml.children) < 3:
self.ids.ml.clear_widgets() self.ids.ml.clear_widgets()
self.loadSent() self.loadSent()
if state.association == state.check_sent_acc: if kivy_state.association == kivy_state.check_sent_acc:
total_sent = int(state.sent_count) + 1 total_sent = int(kivy_state.sent_count) + 1
state.sent_count = str(int(state.sent_count) + 1) kivy_state.sent_count = str(int(kivy_state.sent_count) + 1)
self.set_sentCount(total_sent) self.set_sentCount(total_sent)
else: else:
total_sent = int(state.sent_count) total_sent = int(kivy_state.sent_count)
else: else:
data = [] data = []
self.sentDataQuery('fromaddress', '', '', 0, 1) self.sentDataQuery('fromaddress', '', '', 0, 1)
if state.association == state.check_sent_acc: if kivy_state.association == kivy_state.check_sent_acc:
total_sent = int(state.sent_count) + 1 total_sent = int(kivy_state.sent_count) + 1
state.sent_count = str(int(state.sent_count) + 1) kivy_state.sent_count = str(int(kivy_state.sent_count) + 1)
self.set_sentCount(total_sent) self.set_sentCount(total_sent)
else: else:
total_sent = int(state.sent_count) total_sent = int(kivy_state.sent_count)
for mail in self.queryreturn: for mail in self.queryreturn:
data.append({ data.append({
'text': mail[1].strip(), 'text': mail[1].strip(),
@ -138,11 +139,11 @@ class Sent(Screen):
'\t', '').replace(' ', ''), '\t', '').replace(' ', ''),
'ackdata': mail[5], 'senttime': mail[6]}) 'ackdata': mail[5], 'senttime': mail[6]})
self.set_mdlist(data, total_sent - 1) self.set_mdlist(data, total_sent - 1)
if state.msg_counter_objs and state.association == ( if kivy_state.msg_counter_objs and kivy_state.association == (
state.check_sent_acc): kivy_state.check_sent_acc):
state.all_count = str(int(state.all_count) + 1) kivy_state.all_count = str(int(kivy_state.all_count) + 1)
state.msg_counter_objs.allmail_cnt.badge_text = state.all_count kivy_state.msg_counter_objs.allmail_cnt.badge_text = kivy_state.all_count
state.check_sent_acc = None kivy_state.check_sent_acc = None
def check_scroll_y(self, instance, somethingelse): def check_scroll_y(self, instance, somethingelse):
"""Load data on scroll down""" """Load data on scroll down"""
@ -153,9 +154,9 @@ class Sent(Screen):
def update_sent_screen_on_scroll(self, total_sent_msg, where="", what=""): def update_sent_screen_on_scroll(self, total_sent_msg, where="", what=""):
"""This method is used to load more data on scroll down""" """This method is used to load more data on scroll down"""
if state.searcing_text: if kivy_state.searcing_text:
where = ['subject', 'message'] where = ['subject', 'message']
what = state.searcing_text what = kivy_state.searcing_text
self.sentDataQuery('fromaddress', where, what, total_sent_msg, 5) self.sentDataQuery('fromaddress', where, what, total_sent_msg, 5)
data = [] data = []
for mail in self.queryreturn: for mail in self.queryreturn:
@ -172,7 +173,7 @@ class Sent(Screen):
"""Set the total no. of sent message count""" """Set the total no. of sent message count"""
src_mng_obj = state.kivyapp.root.ids.content_drawer.ids.send_cnt src_mng_obj = state.kivyapp.root.ids.content_drawer.ids.send_cnt
state.kivyapp.root.ids.content_drawer.ids.send_cnt.ids.badge_txt.text state.kivyapp.root.ids.content_drawer.ids.send_cnt.ids.badge_txt.text
if state.association: if kivy_state.association:
src_mng_obj.ids.badge_txt.text = showLimitedCnt(int(total_sent)) src_mng_obj.ids.badge_txt.text = showLimitedCnt(int(total_sent))
else: else:
src_mng_obj.ids.badge_txt.text = '0' src_mng_obj.ids.badge_txt.text = '0'
@ -182,8 +183,8 @@ class Sent(Screen):
if instance.state == 'closed': if instance.state == 'closed':
instance.ids.delete_msg.disabled = True instance.ids.delete_msg.disabled = True
if instance.open_progress == 0.0: if instance.open_progress == 0.0:
state.detailPageType = 'sent' kivy_state.detailPageType = 'sent'
state.mail_id = ackdata kivy_state.mail_id = ackdata
if self.manager: if self.manager:
src_mng_obj = self.manager src_mng_obj = self.manager
else: else:
@ -197,14 +198,14 @@ class Sent(Screen):
def delete(self, data_index, instance, *args): def delete(self, data_index, instance, *args):
"""Delete sent mail from sent mail listing""" """Delete sent mail from sent mail listing"""
msg_count_objs = self.parent.parent.ids.content_drawer.ids msg_count_objs = self.parent.parent.ids.content_drawer.ids
if int(state.sent_count) > 0: if int(kivy_state.sent_count) > 0:
msg_count_objs.send_cnt.ids.badge_txt.text = showLimitedCnt(int(state.sent_count) - 1) msg_count_objs.send_cnt.ids.badge_txt.text = showLimitedCnt(int(kivy_state.sent_count) - 1)
msg_count_objs.trash_cnt.ids.badge_txt.text = showLimitedCnt(int(state.trash_count) + 1) msg_count_objs.trash_cnt.ids.badge_txt.text = showLimitedCnt(int(kivy_state.trash_count) + 1)
msg_count_objs.allmail_cnt.ids.badge_txt.text = showLimitedCnt(int(state.all_count) - 1) msg_count_objs.allmail_cnt.ids.badge_txt.text = showLimitedCnt(int(kivy_state.all_count) - 1)
state.sent_count = str(int(state.sent_count) - 1) kivy_state.sent_count = str(int(kivy_state.sent_count) - 1)
state.trash_count = str(int(state.trash_count) + 1) kivy_state.trash_count = str(int(kivy_state.trash_count) + 1)
state.all_count = str(int(state.all_count) - 1) kivy_state.all_count = str(int(kivy_state.all_count) - 1)
if int(state.sent_count) <= 0: if int(kivy_state.sent_count) <= 0:
self.ids.tag_label.text = '' self.ids.tag_label.text = ''
sqlExecute( sqlExecute(
"UPDATE sent SET folder = 'trash'" "UPDATE sent SET folder = 'trash'"

View File

@ -12,6 +12,7 @@ from kivymd.uix.dialog import MDDialog
from kivymd.uix.label import MDLabel from kivymd.uix.label import MDLabel
from kivy.uix.screenmanager import Screen from kivy.uix.screenmanager import Screen
import kivy_state
import state import state
from bitmessagekivy.baseclass.common import ( from bitmessagekivy.baseclass.common import (
@ -36,17 +37,17 @@ class Trash(Screen):
def init_ui(self, dt=0): def init_ui(self, dt=0):
"""Clock Schdule for method trash screen""" """Clock Schdule for method trash screen"""
if state.association == '': if kivy_state.association == '':
if state.kivyapp.variable_1: if state.kivyapp.variable_1:
state.association = state.kivyapp.variable_1[0] kivy_state.association = state.kivyapp.variable_1[0]
self.ids.tag_label.text = '' self.ids.tag_label.text = ''
self.trashDataQuery(0, 20) self.trashDataQuery(0, 20)
if len(self.trash_messages): if len(self.trash_messages):
self.ids.ml.clear_widgets() self.ids.ml.clear_widgets()
self.ids.tag_label.text = 'Trash' self.ids.tag_label.text = 'Trash'
# src_mng_obj = state.kivyapp.root.children[2].children[0].ids # src_mng_obj = state.kivyapp.root.children[2].children[0].ids
# src_mng_obj.trash_cnt.badge_text = state.trash_count # src_mng_obj.trash_cnt.badge_text = kivy_state.trash_count
self.set_TrashCnt(state.trash_count) self.set_TrashCnt(kivy_state.trash_count)
self.set_mdList() self.set_mdList()
self.ids.scroll_y.bind(scroll_y=self.check_scroll_y) self.ids.scroll_y.bind(scroll_y=self.check_scroll_y)
else: else:
@ -72,7 +73,7 @@ class Trash(Screen):
" DATE(received) As actionTime, received as msgtime FROM inbox" " DATE(received) As actionTime, received as msgtime FROM inbox"
" WHERE folder = 'trash' and toaddress = '{0}'" " WHERE folder = 'trash' and toaddress = '{0}'"
" ORDER BY actionTime DESC limit {1}, {2}".format( " ORDER BY actionTime DESC limit {1}, {2}".format(
state.association, start_indx, end_indx)) kivy_state.association, start_indx, end_indx))
def set_TrashCnt(self, Count): # pylint: disable=no-self-use def set_TrashCnt(self, Count): # pylint: disable=no-self-use
"""This method is used to set trash message count""" """This method is used to set trash message count"""
@ -94,7 +95,7 @@ class Trash(Screen):
subject) >= 50 else (subject + ',' + body)[0:50] + '........').replace('\t', '').replace(' ', '') subject) >= 50 else (subject + ',' + body)[0:50] + '........').replace('\t', '').replace(' ', '')
listItem.theme_text_color = "Custom" listItem.theme_text_color = "Custom"
listItem.text_color = ThemeClsColor listItem.text_color = ThemeClsColor
img_latter = state.imageDir + '/text_images/{}.png'.format( img_latter = kivy_state.imageDir + '/text_images/{}.png'.format(
avatarImageFirstLetter(subject[0].strip())) avatarImageFirstLetter(subject[0].strip()))
message_row.ids.avater_img.source = img_latter message_row.ids.avater_img.source = img_latter
message_row.ids.time_tag.text = str(ShowTimeHistoy(item[7])) message_row.ids.time_tag.text = str(ShowTimeHistoy(item[7]))
@ -175,9 +176,9 @@ class Trash(Screen):
elif self.table_name == 'sent': elif self.table_name == 'sent':
sqlExecute( sqlExecute(
"DELETE FROM sent WHERE ackdata = ?;", self.delete_index) "DELETE FROM sent WHERE ackdata = ?;", self.delete_index)
if int(state.trash_count) > 0: if int(kivy_state.trash_count) > 0:
# msg_count_objs.trash_cnt.badge_text = str( # msg_count_objs.trash_cnt.badge_text = str(
# int(state.trash_count) - 1) # int(kivy_state.trash_count) - 1)
self.set_TrashCnt(int(state.trash_count) - 1) self.set_TrashCnt(int(kivy_state.trash_count) - 1)
state.trash_count = str(int(state.trash_count) - 1) kivy_state.trash_count = str(int(kivy_state.trash_count) - 1)
Clock.schedule_once(self.callback_for_screen_load, 1) Clock.schedule_once(self.callback_for_screen_load, 1)

View File

@ -47,6 +47,7 @@ from kivy.uix.screenmanager import RiseInTransition, SlideTransition, FallOutTra
import queues import queues
from semaphores import kivyuisignaler from semaphores import kivyuisignaler
import kivy_state
import state import state
from kivymd.uix.bottomsheet import MDCustomBottomSheet from kivymd.uix.bottomsheet import MDCustomBottomSheet
@ -215,16 +216,16 @@ class NavigateApp(MDApp):
variable_1 = ListProperty(addr for addr in BMConfigParser().addresses() variable_1 = ListProperty(addr for addr in BMConfigParser().addresses()
if BMConfigParser().get(str(addr), 'enabled') == 'true') if BMConfigParser().get(str(addr), 'enabled') == 'true')
nav_drawer = ObjectProperty() nav_drawer = ObjectProperty()
state.screen_density = Window.size kivy_state.screen_density = Window.size
window_size = state.screen_density window_size = kivy_state.screen_density
app_platform = platform app_platform = platform
title = "PyBitmessage" title = "PyBitmessage"
imgstatus = False imgstatus = False
count = 0 count = 0
manager_open = False manager_open = False
file_manager = None file_manager = None
state.imageDir = os.path.join('./images', 'kivy') kivy_state.imageDir = os.path.join('./images', 'kivy')
image_path = state.imageDir image_path = kivy_state.imageDir
tr = Lang("en") # for changing in franch replace en with fr tr = Lang("en") # for changing in franch replace en with fr
def build(self): def build(self):
@ -267,7 +268,7 @@ class NavigateApp(MDApp):
def getCurrentAccountData(self, text): def getCurrentAccountData(self, text):
"""Get Current Address Account Data""" """Get Current Address Account Data"""
if text != '': if text != '':
if os.path.exists(state.imageDir + '/default_identicon/{}.png'.format(text)): if os.path.exists(kivy_state.imageDir + '/default_identicon/{}.png'.format(text)):
self.load_selected_Image(text) self.load_selected_Image(text)
else: else:
self.set_identicon(text) self.set_identicon(text)
@ -277,8 +278,8 @@ class NavigateApp(MDApp):
BMConfigParser().get(text, 'label'), text) BMConfigParser().get(text, 'label'), text)
self.root_window.children[1].ids.toolbar.title = address_label self.root_window.children[1].ids.toolbar.title = address_label
state.association = text kivy_state.association = text
state.searcing_text = '' kivy_state.searcing_text = ''
LoadingPopup().open() LoadingPopup().open()
self.set_message_count() self.set_message_count()
for nav_obj in self.root.ids.content_drawer.children[ for nav_obj in self.root.ids.content_drawer.children[
@ -297,11 +298,11 @@ class NavigateApp(MDApp):
def setCurrentAccountData(self, dt=0): def setCurrentAccountData(self, dt=0):
"""This method set the current accout data on all the screens""" """This method set the current accout data on all the screens"""
self.root.ids.sc1.ids.ml.clear_widgets() self.root.ids.sc1.ids.ml.clear_widgets()
self.root.ids.sc1.loadMessagelist(state.association) self.root.ids.sc1.loadMessagelist(kivy_state.association)
self.root.ids.sc4.ids.ml.clear_widgets() self.root.ids.sc4.ids.ml.clear_widgets()
self.root.ids.sc4.children[2].children[2].ids.search_field.text = '' self.root.ids.sc4.children[2].children[2].ids.search_field.text = ''
self.root.ids.sc4.loadSent(state.association) self.root.ids.sc4.loadSent(kivy_state.association)
self.root.ids.sc16.clear_widgets() self.root.ids.sc16.clear_widgets()
self.root.ids.sc16.add_widget(Draft()) self.root.ids.sc16.add_widget(Draft())
@ -320,8 +321,8 @@ class NavigateApp(MDApp):
@staticmethod @staticmethod
def getCurrentAccount(): def getCurrentAccount():
"""It uses to get current account label""" """It uses to get current account label"""
if state.association: if kivy_state.association:
return state.association return kivy_state.association
return "Bitmessage Login" return "Bitmessage Login"
# @staticmethod # @staticmethod
@ -394,7 +395,7 @@ class NavigateApp(MDApp):
folder="addressbook")] folder="addressbook")]
if label and address and address not in stored_address \ if label and address and address not in stored_address \
and label not in stored_labels and pupup_obj.valid: and label not in stored_labels and pupup_obj.valid:
# state.navinstance = self.parent.children[1] # kivy_state.navinstance = self.parent.children[1]
queues.UISignalQueue.put(('rerenderAddressBook', '')) queues.UISignalQueue.put(('rerenderAddressBook', ''))
self.add_popup.dismiss() self.add_popup.dismiss()
sqlExecute("INSERT INTO addressbook VALUES(?,?)", label, address) sqlExecute("INSERT INTO addressbook VALUES(?,?)", label, address)
@ -415,24 +416,24 @@ class NavigateApp(MDApp):
def getDefaultAccData(self, instance): def getDefaultAccData(self, instance):
"""Getting Default Account Data""" """Getting Default Account Data"""
if self.variable_1: if self.variable_1:
state.association = first_addr = self.variable_1[0] kivy_state.association = first_addr = self.variable_1[0]
# if BMConfigParser().get(str(first_addr), 'enabled') == 'true': # if BMConfigParser().get(str(first_addr), 'enabled') == 'true':
# img = identiconGeneration.generate(first_addr) # img = identiconGeneration.generate(first_addr)
# print('line...........................................426') # print('line...........................................426')
# self.createFolder(state.imageDir + '/default_identicon/') # self.createFolder(kivy_state.imageDir + '/default_identicon/')
# if platform == 'android': # if platform == 'android':
# # android_path = os.path.expanduser # # android_path = os.path.expanduser
# # ("~/user/0/org.test.bitapp/files/app/") # # ("~/user/0/org.test.bitapp/files/app/")
# if not os.path.exists(state.imageDir + '/default_identicon/{}.png'.format( # if not os.path.exists(kivy_state.imageDir + '/default_identicon/{}.png'.format(
# BMConfigParser().addresses()[0])): # BMConfigParser().addresses()[0])):
# android_path = os.path.join( # android_path = os.path.join(
# os.environ['ANDROID_PRIVATE'] + '/app/') # os.environ['ANDROID_PRIVATE'] + '/app/')
# img.texture.save('{1}/images/kivy/default_identicon/{0}.png'.format( # img.texture.save('{1}/images/kivy/default_identicon/{0}.png'.format(
# BMConfigParser().addresses()[0], android_path)) # BMConfigParser().addresses()[0], android_path))
# else: # else:
# if not os.path.exists(state.imageDir + '/default_identicon/{}.png'.format( # if not os.path.exists(kivy_state.imageDir + '/default_identicon/{}.png'.format(
# BMConfigParser().addresses()[0])): # BMConfigParser().addresses()[0])):
# img.texture.save(state.imageDir + '/default_identicon/{}.png'.format( # img.texture.save(kivy_state.imageDir + '/default_identicon/{}.png'.format(
# BMConfigParser().addresses()[0])) # BMConfigParser().addresses()[0]))
# instance.parent.parent.parent.parent.parent.ids.top_box.children[0].texture = ( # instance.parent.parent.parent.parent.parent.ids.top_box.children[0].texture = (
# img.texture) # img.texture)
@ -445,14 +446,14 @@ class NavigateApp(MDApp):
first_addr = self.variable_1[0] first_addr = self.variable_1[0]
if BMConfigParser().get(str(first_addr), 'enabled') == 'true': if BMConfigParser().get(str(first_addr), 'enabled') == 'true':
if os.path.exists( if os.path.exists(
state.imageDir + '/default_identicon/{}.png'.format(first_addr)): kivy_state.imageDir + '/default_identicon/{}.png'.format(first_addr)):
return state.imageDir + '/default_identicon/{}.png'.format( return kivy_state.imageDir + '/default_identicon/{}.png'.format(
first_addr) first_addr)
else: else:
img = identiconGeneration.generate(first_addr) img = identiconGeneration.generate(first_addr)
instance.texture = img.texture instance.texture = img.texture
return return
return state.imageDir + '/drawer_logo1.png' return kivy_state.imageDir + '/drawer_logo1.png'
@staticmethod @staticmethod
def addressexist(): def addressexist():
@ -462,18 +463,18 @@ class NavigateApp(MDApp):
return False return False
def on_key(self, window, key, *args): def on_key(self, window, key, *args):
# pylint: disable=inconsistent-return-statements, too-many-branches # pylint: disable=inconsistent-return-kivy_statements, too-many-branches
"""Method is used for going on previous screen""" """Method is used for going on previous screen"""
if key == 27: if key == 27:
if state.in_search_mode and self.root.ids.scr_mngr.current not in [ if kivy_state.in_search_mode and self.root.ids.scr_mngr.current not in [
"mailDetail", "create"]: "mailDetail", "create"]:
self.closeSearchScreen() self.closeSearchScreen()
elif self.root.ids.scr_mngr.current == "mailDetail": elif self.root.ids.scr_mngr.current == "mailDetail":
self.root.ids.scr_mngr.current = 'sent'\ self.root.ids.scr_mngr.current = 'sent'\
if state.detailPageType == 'sent' else 'inbox' \ if kivy_state.detailPageType == 'sent' else 'inbox' \
if state.detailPageType == 'inbox' else 'draft' if kivy_state.detailPageType == 'inbox' else 'draft'
self.back_press() self.back_press()
if state.in_search_mode and state.searcing_text: if kivy_state.in_search_mode and kivy_state.searcing_text:
toolbar_obj = self.root.ids.toolbar toolbar_obj = self.root.ids.toolbar
toolbar_obj.left_action_items = [ toolbar_obj.left_action_items = [
['arrow-left', lambda x: self.closeSearchScreen()]] ['arrow-left', lambda x: self.closeSearchScreen()]]
@ -482,7 +483,7 @@ class NavigateApp(MDApp):
elif self.root.ids.scr_mngr.current == "create": elif self.root.ids.scr_mngr.current == "create":
self.save_draft() self.save_draft()
self.set_common_header() self.set_common_header()
state.in_composer = False kivy_state.in_composer = False
self.root.ids.scr_mngr.current = 'inbox' self.root.ids.scr_mngr.current = 'inbox'
elif self.root.ids.scr_mngr.current == "showqrcode": elif self.root.ids.scr_mngr.current == "showqrcode":
self.set_common_header() self.set_common_header()
@ -493,10 +494,10 @@ class NavigateApp(MDApp):
self.set_common_header() self.set_common_header()
self.root.ids.scr_mngr.current = 'payment' self.root.ids.scr_mngr.current = 'payment'
elif self.root.ids.scr_mngr.current == 'chroom': elif self.root.ids.scr_mngr.current == 'chroom':
if state.association: if kivy_state.association:
address_label = self.current_address_label( address_label = self.current_address_label(
BMConfigParser().get( BMConfigParser().get(
state.association, 'label'), state.association) kivy_state.association, 'label'), kivy_state.association)
self.root.ids.toolbar.title = address_label self.root.ids.toolbar.title = address_label
self.set_common_header() self.set_common_header()
self.root.ids.scr_mngr.transition = FallOutTransition() self.root.ids.scr_mngr.transition = FallOutTransition()
@ -508,39 +509,39 @@ class NavigateApp(MDApp):
self.root.ids.scr_mngr.transition.direction = 'right' self.root.ids.scr_mngr.transition.direction = 'right'
self.root.ids.scr_mngr.transition.bind(on_complete=self.reset) self.root.ids.scr_mngr.transition.bind(on_complete=self.reset)
return True return True
elif key == 13 and state.searcing_text and not state.in_composer: elif key == 13 and kivy_state.searcing_text and not kivy_state.in_composer:
if state.search_screen == 'inbox': if kivy_state.search_screen == 'inbox':
self.root.ids.sc1.children[1].active = True self.root.ids.sc1.children[1].active = True
Clock.schedule_once(self.search_callback, 0.5) Clock.schedule_once(self.search_callback, 0.5)
elif state.search_screen == 'addressbook': elif kivy_state.search_screen == 'addressbook':
self.root.ids.sc11.children[1].active = True self.root.ids.sc11.children[1].active = True
Clock.schedule_once(self.search_callback, 0.5) Clock.schedule_once(self.search_callback, 0.5)
elif state.search_screen == 'myaddress': elif kivy_state.search_screen == 'myaddress':
self.loadMyAddressScreen(True) self.loadMyAddressScreen(True)
Clock.schedule_once(self.search_callback, 0.5) Clock.schedule_once(self.search_callback, 0.5)
elif state.search_screen == 'sent': elif kivy_state.search_screen == 'sent':
self.root.ids.sc4.children[1].active = True self.root.ids.sc4.children[1].active = True
Clock.schedule_once(self.search_callback, 0.5) Clock.schedule_once(self.search_callback, 0.5)
def search_callback(self, dt=0): def search_callback(self, dt=0):
"""Show data after loader is loaded""" """Show data after loader is loaded"""
if state.search_screen == 'inbox': if kivy_state.search_screen == 'inbox':
self.root.ids.sc1.ids.ml.clear_widgets() self.root.ids.sc1.ids.ml.clear_widgets()
self.root.ids.sc1.loadMessagelist(state.association) self.root.ids.sc1.loadMessagelist(kivy_state.association)
self.root.ids.sc1.children[1].active = False self.root.ids.sc1.children[1].active = False
elif state.search_screen == 'addressbook': elif kivy_state.search_screen == 'addressbook':
self.root.ids.sc11.ids.ml.clear_widgets() self.root.ids.sc11.ids.ml.clear_widgets()
self.root.ids.sc11.loadAddresslist(None, 'All', '') self.root.ids.sc11.loadAddresslist(None, 'All', '')
self.root.ids.sc11.children[1].active = False self.root.ids.sc11.children[1].active = False
elif state.search_screen == 'myaddress': elif kivy_state.search_screen == 'myaddress':
self.root.ids.sc10.ids.ml.clear_widgets() self.root.ids.sc10.ids.ml.clear_widgets()
self.root.ids.sc10.init_ui() self.root.ids.sc10.init_ui()
self.loadMyAddressScreen(False) self.loadMyAddressScreen(False)
else: else:
self.root.ids.sc4.ids.ml.clear_widgets() self.root.ids.sc4.ids.ml.clear_widgets()
self.root.ids.sc4.loadSent(state.association) self.root.ids.sc4.loadSent(kivy_state.association)
self.root.ids.sc4.children[1].active = False self.root.ids.sc4.children[1].active = False
self.root.ids.scr_mngr.current = state.search_screen self.root.ids.scr_mngr.current = kivy_state.search_screen
def loadMyAddressScreen(self, action): def loadMyAddressScreen(self, action):
"""loadMyAddressScreen method spin the loader""" """loadMyAddressScreen method spin the loader"""
@ -554,8 +555,8 @@ class NavigateApp(MDApp):
composer_objs = self.root composer_objs = self.root
from_addr = str(self.root.ids.sc3.children[1].ids.ti.text) 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) # to_addr = str(self.root.ids.sc3.children[1].ids.txt_input.text)
if from_addr and state.detailPageType != 'draft' \ if from_addr and kivy_state.detailPageType != 'draft' \
and not state.in_sent_method: and not kivy_state.in_sent_method:
Draft().draft_msg(composer_objs) Draft().draft_msg(composer_objs)
return return
@ -568,8 +569,8 @@ class NavigateApp(MDApp):
def status_dispatching(data): def status_dispatching(data):
"""Dispatching Status acknowledgment""" """Dispatching Status acknowledgment"""
ackData, message = data ackData, message = data
if state.ackdata == ackData: if kivy_state.ackdata == ackData:
state.status.status = message kivy_state.status.status = message
def clear_composer(self): def clear_composer(self):
"""If slow down, the new composer edit screen""" """If slow down, the new composer edit screen"""
@ -580,8 +581,8 @@ class NavigateApp(MDApp):
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 kivy_state.in_composer = True
state.in_sent_method = False kivy_state.in_sent_method = False
def set_navbar_for_composer(self): def set_navbar_for_composer(self):
"""Clearing toolbar data when composer open""" """Clearing toolbar data when composer open"""
@ -614,7 +615,7 @@ class NavigateApp(MDApp):
if self.root.ids.scr_mngr.current == 'create': if self.root.ids.scr_mngr.current == 'create':
self.save_draft() self.save_draft()
if self.root.ids.scr_mngr.current == \ if self.root.ids.scr_mngr.current == \
'mailDetail' and state.in_search_mode: 'mailDetail' and kivy_state.in_search_mode:
toolbar_obj = self.root.ids.toolbar toolbar_obj = self.root.ids.toolbar
toolbar_obj.left_action_items = [ toolbar_obj.left_action_items = [
['arrow-left', lambda x: self.closeSearchScreen()]] ['arrow-left', lambda x: self.closeSearchScreen()]]
@ -622,16 +623,16 @@ class NavigateApp(MDApp):
self.root.ids.toolbar.title = '' self.root.ids.toolbar.title = ''
else: else:
self.set_common_header() self.set_common_header()
if self.root.ids.scr_mngr.current == 'chroom' and state.association: if self.root.ids.scr_mngr.current == 'chroom' and kivy_state.association:
self.root.ids.scr_mngr.transition = FallOutTransition() self.root.ids.scr_mngr.transition = FallOutTransition()
address_label = self.current_address_label( address_label = self.current_address_label(
BMConfigParser().get( BMConfigParser().get(
state.association, 'label'), state.association) kivy_state.association, 'label'), kivy_state.association)
self.root.ids.toolbar.title = address_label self.root.ids.toolbar.title = address_label
self.root.ids.scr_mngr.current = 'inbox' \ self.root.ids.scr_mngr.current = 'inbox' \
if state.in_composer else 'allmails'\ if kivy_state.in_composer else 'allmails'\
if state.is_allmail else state.detailPageType\ if kivy_state.is_allmail else kivy_state.detailPageType\
if state.detailPageType else 'myaddress'\ if kivy_state.detailPageType else 'myaddress'\
if self.root.ids.scr_mngr.current == 'showqrcode' else 'payment'\ if self.root.ids.scr_mngr.current == 'showqrcode' else 'payment'\
if self.root.ids.scr_mngr.current == 'pay-options' else 'chlist'\ if self.root.ids.scr_mngr.current == 'pay-options' else 'chlist'\
if self.root.ids.scr_mngr.current == 'chroom' else 'inbox' if self.root.ids.scr_mngr.current == 'chroom' else 'inbox'
@ -639,24 +640,24 @@ class NavigateApp(MDApp):
self.root.ids.scr_mngr.transition = SlideTransition() self.root.ids.scr_mngr.transition = SlideTransition()
self.root.ids.scr_mngr.transition.direction = 'right' self.root.ids.scr_mngr.transition.direction = 'right'
self.root.ids.scr_mngr.transition.bind(on_complete=self.reset) self.root.ids.scr_mngr.transition.bind(on_complete=self.reset)
if state.is_allmail or state.detailPageType == 'draft': if kivy_state.is_allmail or kivy_state.detailPageType == 'draft':
state.is_allmail = False kivy_state.is_allmail = False
state.detailPageType = '' kivy_state.detailPageType = ''
state.in_composer = False kivy_state.in_composer = False
@staticmethod @staticmethod
def get_inbox_count(): def get_inbox_count():
"""Getting inbox count""" """Getting inbox count"""
state.inbox_count = str(sqlQuery( kivy_state.inbox_count = str(sqlQuery(
"SELECT COUNT(*) FROM inbox WHERE toaddress = '{}' and" "SELECT COUNT(*) FROM inbox WHERE toaddress = '{}' and"
" folder = 'inbox' ;".format(state.association))[0][0]) " folder = 'inbox' ;".format(kivy_state.association))[0][0])
@staticmethod @staticmethod
def get_sent_count(): def get_sent_count():
"""Getting sent count""" """Getting sent count"""
state.sent_count = str(sqlQuery( kivy_state.sent_count = str(sqlQuery(
"SELECT COUNT(*) FROM sent WHERE fromaddress = '{}' and" "SELECT COUNT(*) FROM sent WHERE fromaddress = '{}' and"
" folder = 'sent' ;".format(state.association))[0][0]) " folder = 'sent' ;".format(kivy_state.association))[0][0])
def set_message_count(self): def set_message_count(self):
"""Setting message count""" """Setting message count"""
@ -669,21 +670,21 @@ class NavigateApp(MDApp):
# self.root_window.children[2].children[2].children[0].ids) # self.root_window.children[2].children[2].children[0].ids)
self.get_inbox_count() self.get_inbox_count()
self.get_sent_count() self.get_sent_count()
state.trash_count = str(sqlQuery( kivy_state.trash_count = str(sqlQuery(
"SELECT (SELECT count(*) FROM sent" "SELECT (SELECT count(*) FROM sent"
" where fromaddress = '{0}' and folder = 'trash' )" " where fromaddress = '{0}' and folder = 'trash' )"
"+(SELECT count(*) FROM inbox where toaddress = '{0}' and" "+(SELECT count(*) FROM inbox where toaddress = '{0}' and"
" folder = 'trash') AS SumCount".format(state.association))[0][0]) " folder = 'trash') AS SumCount".format(kivy_state.association))[0][0])
state.draft_count = str(sqlQuery( kivy_state.draft_count = str(sqlQuery(
"SELECT COUNT(*) FROM sent WHERE fromaddress = '{}' and" "SELECT COUNT(*) FROM sent WHERE fromaddress = '{}' and"
" folder = 'draft' ;".format(state.association))[0][0]) " folder = 'draft' ;".format(kivy_state.association))[0][0])
state.all_count = str(int(state.sent_count) + int(state.inbox_count)) kivy_state.all_count = str(int(kivy_state.sent_count) + int(kivy_state.inbox_count))
if msg_counter_objs: if msg_counter_objs:
msg_counter_objs.send_cnt.badge_text = state.sent_count msg_counter_objs.send_cnt.badge_text = kivy_state.sent_count
msg_counter_objs.inbox_cnt.badge_text = state.inbox_count msg_counter_objs.inbox_cnt.badge_text = kivy_state.inbox_count
msg_counter_objs.trash_cnt.badge_text = state.trash_count msg_counter_objs.trash_cnt.badge_text = kivy_state.trash_count
msg_counter_objs.draft_cnt.badge_text = state.draft_count msg_counter_objs.draft_cnt.badge_text = kivy_state.draft_count
msg_counter_objs.allmail_cnt.badge_text = state.all_count msg_counter_objs.allmail_cnt.badge_text = kivy_state.all_count
def on_start(self): def on_start(self):
"""Setting message count""" """Setting message count"""
@ -719,33 +720,33 @@ class NavigateApp(MDApp):
def searchQuery(self, instance): def searchQuery(self, instance):
"""Showing searched mails""" """Showing searched mails"""
state.search_screen = self.root.ids.scr_mngr.current kivy_state.search_screen = self.root.ids.scr_mngr.current
state.searcing_text = str(instance.text).strip() kivy_state.searcing_text = str(instance.text).strip()
if instance.focus and state.searcing_text: if instance.focus and kivy_state.searcing_text:
toolbar_obj = self.root.ids.toolbar toolbar_obj = self.root.ids.toolbar
toolbar_obj.left_action_items = [ toolbar_obj.left_action_items = [
['arrow-left', lambda x: self.closeSearchScreen()]] ['arrow-left', lambda x: self.closeSearchScreen()]]
toolbar_obj.right_action_items = [] toolbar_obj.right_action_items = []
self.root.ids.toolbar.title = '' self.root.ids.toolbar.title = ''
state.in_search_mode = True kivy_state.in_search_mode = True
def closeSearchScreen(self): def closeSearchScreen(self):
"""Function for close search screen""" """Function for close search screen"""
self.set_common_header() self.set_common_header()
if state.association: if kivy_state.association:
address_label = self.current_address_label( address_label = self.current_address_label(
BMConfigParser().get( BMConfigParser().get(
state.association, 'label'), state.association) kivy_state.association, 'label'), kivy_state.association)
self.root.ids.toolbar.title = address_label self.root.ids.toolbar.title = address_label
state.searcing_text = '' kivy_state.searcing_text = ''
self.refreshScreen() self.refreshScreen()
state.in_search_mode = False kivy_state.in_search_mode = False
def refreshScreen(self): def refreshScreen(self):
"""Method show search button only on inbox or sent screen""" """Method show search button only on inbox or sent screen"""
# pylint: disable=unused-variable # pylint: disable=unused-variable
state.searcing_text = '' kivy_state.searcing_text = ''
if state.search_screen == 'inbox': if kivy_state.search_screen == 'inbox':
self.root.ids.sc1.ids.inbox_search.ids.search_field.text = '' self.root.ids.sc1.ids.inbox_search.ids.search_field.text = ''
# try: # try:
# self.root.ids.sc1.children[ # self.root.ids.sc1.children[
@ -755,14 +756,14 @@ class NavigateApp(MDApp):
# 2].children[2].ids.search_field.text = '' # 2].children[2].ids.search_field.text = ''
self.root.ids.sc1.children[1].active = True self.root.ids.sc1.children[1].active = True
Clock.schedule_once(self.search_callback, 0.5) Clock.schedule_once(self.search_callback, 0.5)
elif state.search_screen == 'addressbook': elif kivy_state.search_screen == 'addressbook':
self.root.ids.sc11.ids.address_search.ids.search_field.text = '' self.root.ids.sc11.ids.address_search.ids.search_field.text = ''
# self.root.ids.sc11.children[ # self.root.ids.sc11.children[
# 2].children[2].ids.search_field.text = '' # 2].children[2].ids.search_field.text = ''
self.root.ids.sc11.children[ self.root.ids.sc11.children[
1].active = True 1].active = True
Clock.schedule_once(self.search_callback, 0.5) Clock.schedule_once(self.search_callback, 0.5)
elif state.search_screen == 'myaddress': elif kivy_state.search_screen == 'myaddress':
self.root.ids.sc10.ids.search_bar.ids.search_field.text = '' self.root.ids.sc10.ids.search_bar.ids.search_field.text = ''
# try: # try:
# self.root.ids.sc10.children[ # self.root.ids.sc10.children[
@ -789,10 +790,10 @@ class NavigateApp(MDApp):
def set_mail_detail_header(self): def set_mail_detail_header(self):
"""Setting the details of the page""" """Setting the details of the page"""
if state.association and state.in_search_mode: if kivy_state.association and kivy_state.in_search_mode:
address_label = self.current_address_label( address_label = self.current_address_label(
BMConfigParser().get( BMConfigParser().get(
state.association, 'label'), state.association) kivy_state.association, 'label'), kivy_state.association)
self.root.ids.toolbar.title = address_label self.root.ids.toolbar.title = address_label
toolbar_obj = self.root.ids.toolbar toolbar_obj = self.root.ids.toolbar
toolbar_obj.left_action_items = [ toolbar_obj.left_action_items = [
@ -800,13 +801,13 @@ class NavigateApp(MDApp):
delete_btn = ['delete-forever', delete_btn = ['delete-forever',
lambda x: self.root.ids.sc14.delete_mail()] lambda x: self.root.ids.sc14.delete_mail()]
dynamic_list = [] dynamic_list = []
if state.detailPageType == 'inbox': if kivy_state.detailPageType == 'inbox':
dynamic_list = [ dynamic_list = [
['reply', lambda x: self.root.ids.sc14.inbox_reply()], ['reply', lambda x: self.root.ids.sc14.inbox_reply()],
delete_btn] delete_btn]
elif state.detailPageType == 'sent': elif kivy_state.detailPageType == 'sent':
dynamic_list = [delete_btn] dynamic_list = [delete_btn]
elif state.detailPageType == 'draft': elif kivy_state.detailPageType == 'draft':
dynamic_list = [ dynamic_list = [
['pencil', lambda x: self.root.ids.sc14.write_msg(self)], ['pencil', lambda x: self.root.ids.sc14.write_msg(self)],
delete_btn] delete_btn]
@ -835,7 +836,7 @@ class NavigateApp(MDApp):
"""This method is rotating loader for few seconds""" """This method is rotating loader for few seconds"""
if instance.text == 'Inbox': if instance.text == 'Inbox':
self.root.ids.sc1.ids.ml.clear_widgets() self.root.ids.sc1.ids.ml.clear_widgets()
self.root.ids.sc1.loadMessagelist(state.association) self.root.ids.sc1.loadMessagelist(kivy_state.association)
self.root.ids.sc1.children[1].active = False self.root.ids.sc1.children[1].active = False
elif instance.text == 'All Mails': elif instance.text == 'All Mails':
self.root.ids.sc17.clear_widgets() self.root.ids.sc17.clear_widgets()
@ -894,12 +895,12 @@ class NavigateApp(MDApp):
if not os.path.exists(android_path + '/default_identicon/'): if not os.path.exists(android_path + '/default_identicon/'):
os.makedirs(android_path + '/default_identicon/') os.makedirs(android_path + '/default_identicon/')
newImg.save('{1}/default_identicon/{0}.png'.format( newImg.save('{1}/default_identicon/{0}.png'.format(
state.association, android_path)) kivy_state.association, android_path))
else: else:
if not os.path.exists(state.imageDir + '/default_identicon/'): if not os.path.exists(kivy_state.imageDir + '/default_identicon/'):
os.makedirs(state.imageDir + '/default_identicon/') os.makedirs(kivy_state.imageDir + '/default_identicon/')
newImg.save(state.imageDir + '/default_identicon/{0}.png'.format(state.association)) newImg.save(kivy_state.imageDir + '/default_identicon/{0}.png'.format(kivy_state.association))
self.load_selected_Image(state.association) self.load_selected_Image(kivy_state.association)
toast('Image changed') toast('Image changed')
except Exception: except Exception:
toast('Exit') toast('Exit')
@ -915,7 +916,7 @@ class NavigateApp(MDApp):
top_box_obj = self.root.ids.content_drawer.ids.top_box.children[0] top_box_obj = self.root.ids.content_drawer.ids.top_box.children[0]
# spinner_img_obj = self.root.ids.content_drawer.ids.btn.children[1] # spinner_img_obj = self.root.ids.content_drawer.ids.btn.children[1]
# spinner_img_obj.source = top_box_obj.source ='./images/default_identicon/{0}.png'.format(curerentAddr) # spinner_img_obj.source = top_box_obj.source ='./images/default_identicon/{0}.png'.format(curerentAddr)
top_box_obj.source = state.imageDir + '/default_identicon/{0}.png'.format(curerentAddr) top_box_obj.source = kivy_state.imageDir + '/default_identicon/{0}.png'.format(curerentAddr)
self.root.ids.content_drawer.ids.reset_image.opacity = 1 self.root.ids.content_drawer.ids.reset_image.opacity = 1
self.root.ids.content_drawer.ids.reset_image.disabled = False self.root.ids.content_drawer.ids.reset_image.disabled = False
top_box_obj.reload() top_box_obj.reload()
@ -923,8 +924,8 @@ class NavigateApp(MDApp):
def rest_default_avatar_img(self): def rest_default_avatar_img(self):
"""set default avatar generated image""" """set default avatar generated image"""
self.set_identicon(state.association) self.set_identicon(kivy_state.association)
img_path = state.imageDir + '/default_identicon/{}.png'.format(state.association) img_path = kivy_state.imageDir + '/default_identicon/{}.png'.format(kivy_state.association)
try: try:
if os.path.exists(img_path): if os.path.exists(img_path):
os.remove(img_path) os.remove(img_path)

View File

@ -1,30 +1,41 @@
""" """
src/state.py Global runtime variables.
=================================
""" """
import collections
neededPubkeys = {} neededPubkeys = {}
streamsInWhichIAmParticipating = [] streamsInWhichIAmParticipating = []
# For UPnP
extPort = None extPort = None
# for Tor hidden service """For UPnP"""
socksIP = None socksIP = None
# Network protocols availability, initialised below """for Tor hidden service"""
networkProtocolAvailability = None
appdata = '' # holds the location of the application data storage directory appdata = ''
# Set to 1 by the doCleanShutdown function. """holds the location of the application data storage directory"""
# Used to tell the proof of work worker threads to exit.
shutdown = 0 shutdown = 0
"""
Set to 1 by the `.shutdown.doCleanShutdown` function.
Used to tell the threads to exit.
"""
# Component control flags - set on startup, do not change during runtime # Component control flags - set on startup, do not change during runtime
# The defaults are for standalone GUI (default operating mode) # The defaults are for standalone GUI (default operating mode)
enableNetwork = True # enable network threads enableNetwork = True
enableObjProc = True # enable object processing threads """enable network threads"""
enableAPI = True # enable API (if configured) enableObjProc = True
enableGUI = True # enable GUI (QT or ncurses) """enable object processing thread"""
enableSTDIO = False # enable STDIO threads enableAPI = True
"""enable API (if configured)"""
enableGUI = True
"""enable GUI (QT or ncurses)"""
enableSTDIO = False
"""enable STDIO threads"""
enableKivy = False
"""enable kivy app and test cases"""
curses = False curses = False
sqlReady = False # set to true by sqlTread when ready for processing
maximumNumberOfHalfOpenConnections = 0 maximumNumberOfHalfOpenConnections = 0
maximumLengthOfTimeToBotherResendingMessages = 0 maximumLengthOfTimeToBotherResendingMessages = 0
@ -33,84 +44,18 @@ invThread = None
addrThread = None addrThread = None
downloadThread = None downloadThread = None
uploadThread = None uploadThread = None
ownAddresses = {} ownAddresses = {}
# If the trustedpeer option is specified in keys.dat then this will
# contain a Peer which will be connected to instead of using the
# addresses advertised by other peers. The client will only connect to
# this peer and the timing attack mitigation will be disabled in order
# to download data faster. The expected use case is where the user has
# a fast connection to a trusted server where they run a BitMessage
# daemon permanently. If they then run a second instance of the client
# on a local machine periodically when they want to check for messages
# it will sync with the network a lot faster without compromising
# security.
trustedPeer = None
discoveredPeers = {} discoveredPeers = {}
Peer = collections.namedtuple('Peer', ['host', 'port'])
def resetNetworkProtocolAvailability():
"""This method helps to reset the availability of network protocol"""
# pylint: disable=global-statement
global networkProtocolAvailability
networkProtocolAvailability = {'IPv4': None, 'IPv6': None, 'onion': None}
resetNetworkProtocolAvailability()
dandelion = 0 dandelion = 0
testmode = False
kivy = False kivy = False
association = ''
kivyapp = None kivyapp = None
navinstance = None testmode = False
mail_id = 0
myAddressObj = None
detailPageType = None
ackdata = None
status = None
screen_density = None
msg_counter_objs = None
check_sent_acc = None
sent_count = 0
inbox_count = 0
trash_count = 0
draft_count = 0
all_count = 0
searcing_text = ''
search_screen = ''
send_draft_mail = None
is_allmail = False
in_composer = False
availabe_credit = 0
in_sent_method = False
in_search_mode = False
clientHasReceivedIncomingConnections = False clientHasReceivedIncomingConnections = False
"""used by API command clientStatus""" """used by API command clientStatus"""
@ -129,5 +74,3 @@ ackdataForWhichImWatching = {}
thisapp = None thisapp = None
"""Singleton instance""" """Singleton instance"""
imageDir = None