Merge branch 'UiChanges' of https://github.com/cis-navjot-g/PyBitmessage into codequalitykivy

This commit is contained in:
lakshyacis 2019-08-21 18:44:21 +05:30
commit ad3d9f1db1
No known key found for this signature in database
GPG Key ID: D2C539C8EC63E9EB
3 changed files with 123 additions and 64 deletions

View File

@ -304,7 +304,7 @@ NavigationLayout:
BoxLayout: BoxLayout:
orientation: 'vertical' orientation: 'vertical'
size_hint_y: None size_hint_y: None
height: dp(600) height: dp(500)
padding: dp(32) padding: dp(32)
spacing: 15 spacing: 15
BoxLayout: BoxLayout:
@ -326,7 +326,7 @@ NavigationLayout:
background_color: app.theme_cls.primary_dark background_color: app.theme_cls.primary_dark
id: btn id: btn
values: app.variable_1 values: app.variable_1
on_text: ti.text = self.text if self.text != 'Select' else '' on_text: root.auto_fill_fromaddr() if self.text != 'Select' else ''
option_cls: Factory.get("MySpinnerOption") option_cls: Factory.get("MySpinnerOption")
background_color: color_button if self.state == 'normal' else color_button_pressed background_color: color_button if self.state == 'normal' else color_button_pressed
background_down: 'atlas://data/images/defaulttheme/spinner' background_down: 'atlas://data/images/defaulttheme/spinner'
@ -344,7 +344,7 @@ NavigationLayout:
id: txt_input id: txt_input
size_hint_y: None size_hint_y: None
font_size: '13sp' font_size: '13sp'
height: 100 height: 70
hint_text: 'type or search recipients address starting with BM-' hint_text: 'type or search recipients address starting with BM-'
RV: RV:
id: rv id: rv
@ -525,7 +525,7 @@ NavigationLayout:
MDRaisedButton: MDRaisedButton:
size_hint: .5, None size_hint: .5, None
height: dp(40) height: dp(40)
on_release: root.generateaddress() on_release: root.generateaddress(app)
opposite_colors: True opposite_colors: True
MDLabel: MDLabel:
font_style: 'Title' font_style: 'Title'
@ -828,10 +828,10 @@ NavigationLayout:
MDRaisedButton: MDRaisedButton:
size_hint: 1, None size_hint: 1, None
height: dp(40) height: dp(40)
on_press: root.inbox_reply() if root.page_type == 'inbox' else root.copy_sent_mail() on_press: root.inbox_reply() if root.page_type == 'inbox' else root.copy_sent_mail() if root.page_type == 'sent' else root.write_msg()
MDLabel: MDLabel:
font_style: 'Title' font_style: 'Title'
text: 'Reply' if root.page_type == 'inbox' else 'Copy' text: 'Reply' if root.page_type == 'inbox' else 'Copy' if root.page_type == 'sent' else 'Write'
font_size: '13sp' font_size: '13sp'
color: (1,1,1,1) color: (1,1,1,1)
halign: 'center' halign: 'center'

View File

@ -480,44 +480,54 @@ class DropDownWidget(BoxLayout):
status, addressVersionNumber, streamNumber, ripe = \ status, addressVersionNumber, streamNumber, ripe = \
decodeAddress(toAddress) decodeAddress(toAddress)
if status == 'success': if status == 'success':
from addresses import addBMIfNotPresent if state.detailPageType == 'draft' and state.send_draft_mail:
toAddress = addBMIfNotPresent(toAddress) sqlExecute(
statusIconColor = 'red' "UPDATE sent SET toaddress = '{0}', fromaddress ='{1}' , subject = '{2}', message = '{3}', folder = 'sent' \
if addressVersionNumber > 4 or addressVersionNumber <= 1: WHERE lastactiontime = '{4}';".format(toAddress, fromAddress, subject, message, state.send_draft_mail))
print "addressVersionNumber > 4 \ self.parent.parent.screens[15].clear_widgets()
or addressVersionNumber <= 1" self.parent.parent.screens[15].add_widget(Draft())
if streamNumber > 1 or streamNumber == 0: state.detailPageType = 'draft'
print "streamNumber > 1 or streamNumber == 0" else:
if statusIconColor == 'red': from addresses import addBMIfNotPresent
print "shared.statusIconColor == 'red'" toAddress = addBMIfNotPresent(toAddress)
stealthLevel = BMConfigParser().safeGetInt( statusIconColor = 'red'
'bitmessagesettings', 'ackstealthlevel') if addressVersionNumber > 4 or addressVersionNumber <= 1:
from helper_ackPayload import genAckPayload print "addressVersionNumber > 4 \
ackdata = genAckPayload(streamNumber, stealthLevel) or addressVersionNumber <= 1"
t = () if streamNumber > 1 or streamNumber == 0:
sqlExecute( print "streamNumber > 1 or streamNumber == 0"
'''INSERT INTO sent VALUES if statusIconColor == 'red':
(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)''', print "shared.statusIconColor == 'red'"
'', stealthLevel = BMConfigParser().safeGetInt(
toAddress, 'bitmessagesettings', 'ackstealthlevel')
ripe, from helper_ackPayload import genAckPayload
fromAddress, ackdata = genAckPayload(streamNumber, stealthLevel)
subject, t = ()
message, sqlExecute(
ackdata, '''INSERT INTO sent VALUES
int(time.time()), (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)''',
int(time.time()), '',
0, toAddress,
'msgqueued', ripe,
0, fromAddress,
'sent', subject,
encoding, message,
BMConfigParser().getint('bitmessagesettings', 'ttl')) ackdata,
int(time.time()),
int(time.time()),
0,
'msgqueued',
0,
'sent',
encoding,
BMConfigParser().getint('bitmessagesettings', 'ttl'))
state.check_sent_acc = fromAddress state.check_sent_acc = fromAddress
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[0].children[2].children[0].ids
self.parent.parent.screens[3].clear_widgets() self.parent.parent.screens[3].clear_widgets()
self.parent.parent.screens[3].add_widget(Sent()) self.parent.parent.screens[3].add_widget(Sent())
self.parent.parent.screens[16].clear_widgets()
self.parent.parent.screens[16].add_widget(Allmails())
toLabel = '' toLabel = ''
queues.workerQueue.put(('sendmessage', toAddress)) queues.workerQueue.put(('sendmessage', toAddress))
print "sqlExecute successfully #######################" print "sqlExecute successfully #######################"
@ -572,6 +582,10 @@ class DropDownWidget(BoxLayout):
self.ids.subject.text = '' self.ids.subject.text = ''
self.ids.body.text = '' self.ids.body.text = ''
def auto_fill_fromaddr(self):
self.ids.ti.text = self.ids.btn.text
self.ids.ti.focus = True
class MyTextInput(TextInput): class MyTextInput(TextInput):
"""Takes the text input in the field.""" """Takes the text input in the field."""
@ -674,7 +688,7 @@ class Random(Screen):
is_active = BooleanProperty(False) is_active = BooleanProperty(False)
checked = StringProperty("") checked = StringProperty("")
def generateaddress(self): def generateaddress(self, navApp):
"""Method for Address Generator.""" """Method for Address Generator."""
streamNumberForAddress = 1 streamNumberForAddress = 1
label = self.ids.label.text label = self.ids.label.text
@ -694,6 +708,7 @@ class Random(Screen):
self.parent.parent.parent.parent.ids.toolbar.disabled = False self.parent.parent.parent.parent.ids.toolbar.disabled = False
self.parent.parent.parent.parent.ids.sc10.clear_widgets() self.parent.parent.parent.parent.ids.sc10.clear_widgets()
self.parent.parent.parent.parent.ids.sc10.add_widget(MyAddress()) self.parent.parent.parent.parent.ids.sc10.add_widget(MyAddress())
navApp.add_search_bar()
toast('New address created') toast('New address created')
@ -998,10 +1013,12 @@ class NavigateApp(App):
self.root.ids.sc4.clear_widgets() self.root.ids.sc4.clear_widgets()
self.root.ids.sc5.clear_widgets() self.root.ids.sc5.clear_widgets()
self.root.ids.sc16.clear_widgets() self.root.ids.sc16.clear_widgets()
self.root.ids.sc17.clear_widgets()
self.root.ids.sc1.add_widget(Inbox()) self.root.ids.sc1.add_widget(Inbox())
self.root.ids.sc4.add_widget(Sent()) self.root.ids.sc4.add_widget(Sent())
self.root.ids.sc5.add_widget(Trash()) self.root.ids.sc5.add_widget(Trash())
self.root.ids.sc16.add_widget(Draft()) self.root.ids.sc16.add_widget(Draft())
self.root.ids.sc17.add_widget(Allmails())
self.root.ids.scr_mngr.current = 'inbox' self.root.ids.scr_mngr.current = 'inbox'
msg_counter_objs = \ msg_counter_objs = \
@ -1022,12 +1039,14 @@ class NavigateApp(App):
sqlQuery( 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(state.association))[0][0])
state.all_count = str(int(state.sent_count) + int(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 = state.sent_count
msg_counter_objs.inbox_cnt.badge_text = state.inbox_count msg_counter_objs.inbox_cnt.badge_text = state.inbox_count
msg_counter_objs.trash_cnt.badge_text = state.trash_count msg_counter_objs.trash_cnt.badge_text = state.trash_count
msg_counter_objs.draft_cnt.badge_text = state.draft_count msg_counter_objs.draft_cnt.badge_text = state.draft_count
msg_counter_objs.allmail_cnt.badge_text = state.all_count
@staticmethod @staticmethod
def getCurrentAccount(): def getCurrentAccount():
@ -1061,18 +1080,18 @@ class NavigateApp(App):
if key == 27: if key == 27:
if self.root.ids.scr_mngr.current == "mailDetail": if self.root.ids.scr_mngr.current == "mailDetail":
self.root.ids.scr_mngr.current = \ self.root.ids.scr_mngr.current = \
'sent' if state.detailPageType == 'sent' else 'inbox' 'sent' if state.detailPageType == 'sent' else 'inbox' if state.detailPageType == 'inbox' else 'draft'
self.add_search_bar() if state.detailPageType in ['sent', 'inbox']:
self.add_search_bar()
elif self.root.ids.scr_mngr.current == "create": elif self.root.ids.scr_mngr.current == "create":
composer_objs = self.root composer_objs = self.root
from_addr = str(self.root.children[1].children[0].children[ from_addr = str(self.root.ids.sc3.children[0].ids.ti.text)
0].children[0].children[0].ids.ti.text) to_addr = str(self.root.ids.sc3.children[0].ids.txt_input.text)
to_addr = str(self.root.children[1].children[0].children[ if from_addr and to_addr and state.detailPageType != 'draft':
0].children[0].children[0].ids.txt_input.text)
if from_addr and to_addr:
Draft().draft_msg(composer_objs) Draft().draft_msg(composer_objs)
self.root.ids.scr_mngr.current = 'inbox' self.root.ids.scr_mngr.current = 'inbox'
self.add_search_bar() self.add_search_bar()
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":
@ -1081,13 +1100,13 @@ class NavigateApp(App):
self.root.ids.scr_mngr.current = 'inbox' self.root.ids.scr_mngr.current = 'inbox'
self.add_search_bar() self.add_search_bar()
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.restart) self.root.ids.scr_mngr.transition.bind(on_complete=self.reset)
return True return True
def restart(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'
self.root.ids.scr_mngr.transition.unbind(on_complete=self.restart) self.root.ids.scr_mngr.transition.unbind(on_complete=self.reset)
@staticmethod @staticmethod
def status_dispatching(data): def status_dispatching(data):
@ -1098,6 +1117,9 @@ class NavigateApp(App):
def clear_composer(self): def clear_composer(self):
"""If slow down the nwe will make new composer edit screen.""" """If slow down the nwe will make new composer edit screen."""
self.root.ids.toolbar.left_action_items = [['arrow-left', lambda x: self.back_press()]]
self.root.ids.myButton.opacity = 0
self.root.ids.myButton.disabled = True
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[0].ids
composer_obj.ti.text = '' composer_obj.ti.text = ''
@ -1105,6 +1127,16 @@ class NavigateApp(App):
composer_obj.txt_input.text = '' composer_obj.txt_input.text = ''
composer_obj.subject.text = '' composer_obj.subject.text = ''
def back_press(self):
"""This method is used for going back from composer to previous page"""
self.root.ids.myButton.opacity = 1
self.root.ids.myButton.disabled = False
self.root.ids.toolbar.left_action_items = [['menu', lambda x: self.root.toggle_nav_drawer()]]
self.root.ids.scr_mngr.current = 'inbox'
self.root.ids.scr_mngr.transition.direction = 'right'
self.root.ids.scr_mngr.transition.bind(on_complete=self.reset)
self.add_search_bar()
@staticmethod @staticmethod
def on_stop(): def on_stop():
"""On stop methos is used for stoping the runing script.""" """On stop methos is used for stoping the runing script."""
@ -1145,9 +1177,9 @@ class NavigateApp(App):
return state.draft_count return state.draft_count
elif text == 'All Mails': elif text == 'All Mails':
state.all_count = str(sqlQuery( state.all_count = str(sqlQuery(
"SELECT (SELECT count(*) FROM sent where fromaddress = '{0}'\ "SELECT (SELECT count(*) FROM sent where fromaddress = '{0}' and \
and folder != 'trash' )+(SELECT count(*) FROM inbox where \ folder = 'sent' )+(SELECT count(*) FROM inbox where \
toaddress = '{0}' and folder != 'trash') AS SumCount".format( toaddress = '{0}' and folder != 'trash') AS SumCount".format(
state.association))[0][0]) state.association))[0][0])
return state.all_count return state.all_count
@ -1225,12 +1257,13 @@ class GrashofPopup(Popup):
"""Method is used for Saving Contacts.""" """Method is used for Saving Contacts."""
my_addresses = \ my_addresses = \
self.parent.children[1].children[2].children[0].ids.btn.values self.parent.children[1].children[2].children[0].ids.btn.values
entered_text = str(self.ids.label.text) entered_text = str(self.ids.address.text)
if entered_text in my_addresses: if entered_text in my_addresses:
self.ids.label.focus = True self.ids.address.focus = False
self.ids.label.helper_text = 'Please Enter corrent address' self.ids.address.helper_text = 'Please Enter corrent address'
elif entered_text == '': elif entered_text == '':
self.ids.label.focus = True self.ids.label.focus = True
# self.ids.address.focus = True
self.ids.label.helper_text = 'This field is required' self.ids.label.helper_text = 'This field is required'
label = self.ids.label.text label = self.ids.label.text
@ -1335,7 +1368,7 @@ class MailDetail(Screen):
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 = state.detailPageType if state.detailPageType else ''
if state.detailPageType == 'sent': if state.detailPageType == 'sent' or state.detailPageType == 'draft':
data = sqlQuery( data = sqlQuery(
"select toaddress, fromaddress, subject, message, status, \ "select toaddress, fromaddress, subject, message, status, \
ackdata from sent where lastactiontime = {};".format( ackdata from sent where lastactiontime = {};".format(
@ -1353,7 +1386,7 @@ class MailDetail(Screen):
"""Assigning mail details.""" """Assigning mail details."""
self.to_addr = data[0][0] self.to_addr = data[0][0]
self.from_addr = data[0][1] self.from_addr = data[0][1]
self.subject = data[0][2].upper() self.subject = data[0][2].upper() if data[0][2].upper() else '(no subject)'
self.message = data[0][3] self.message = data[0][3]
if len(data[0]) == 6: if len(data[0]) == 6:
self.status = data[0][4] self.status = data[0][4]
@ -1405,6 +1438,17 @@ class MailDetail(Screen):
"""Method used for copying sent mail to the composer.""" """Method used for copying sent mail to the composer."""
pass pass
def write_msg(self):
"""This method is used to write on draft mail."""
state.send_draft_mail = state.sentMailTime
composer_ids = self.parent.parent.parent.parent.parent.ids.sc3.children[0].ids
composer_ids.ti.text = self.from_addr
composer_ids.btn.text = self.from_addr
composer_ids.txt_input.text = self.to_addr
composer_ids.subject.text = '' if self.subject == '(no subject)' else self.subject.lower()
composer_ids.body.text = self.message
self.parent.parent.current = 'create'
class MyaddDetailPopup(Popup): class MyaddDetailPopup(Popup):
"""MyaddDetailPopup pop is used for showing my address detail.""" """MyaddDetailPopup pop is used for showing my address detail."""
@ -1537,9 +1581,9 @@ class Draft(Screen):
xAddress, account, "draft", where, what, False) xAddress, account, "draft", where, what, False)
if state.msg_counter_objs: if state.msg_counter_objs:
state.msg_counter_objs.draft_cnt.badge_text = str(len(queryreturn)) state.msg_counter_objs.draft_cnt.badge_text = str(len(queryreturn))
state.all_count = str(int(state.all_count) + 1) # state.all_count = str(int(state.all_count) + 1)
state.msg_counter_objs.allmail_cnt.badge_text = state.all_count # state.msg_counter_objs.allmail_cnt.badge_text = state.all_count
state.msg_counter_objs = None # state.msg_counter_objs = None
if queryreturn: if queryreturn:
for mail in queryreturn: for mail in queryreturn:
@ -1559,6 +1603,8 @@ class Draft(Screen):
text_color=NavigateApp().theme_cls.primary_color) text_color=NavigateApp().theme_cls.primary_color)
meny.add_widget(AvatarSampleWidget( meny.add_widget(AvatarSampleWidget(
source='./images/avatar.png')) source='./images/avatar.png'))
meny.bind(on_press=partial(
self.draft_detail, item['lastactiontime']))
carousel = Carousel(direction='right') carousel = Carousel(direction='right')
if platform == 'android': if platform == 'android':
carousel.height = 150 carousel.height = 150
@ -1588,6 +1634,17 @@ class Draft(Screen):
valign='top') valign='top')
self.ids.ml.add_widget(content) self.ids.ml.add_widget(content)
def draft_detail(self, lastsenttime, *args):
state.detailPageType = 'draft'
state.sentMailTime = lastsenttime
if self.manager:
src_mng_obj = self.manager
else:
src_mng_obj = self.parent.parent
src_mng_obj.screens[13].clear_widgets()
src_mng_obj.screens[13].add_widget(MailDetail())
src_mng_obj.current = 'mailDetail'
def delete_draft(self, data_index, instance, *args): def delete_draft(self, data_index, instance, *args):
"""Method used to delete draft message permanently.""" """Method used to delete draft message permanently."""
sqlExecute("DELETE FROM sent WHERE lastactiontime = '{}';".format( sqlExecute("DELETE FROM sent WHERE lastactiontime = '{}';".format(
@ -1712,8 +1769,8 @@ class Allmails(Screen):
inbox WHERE folder = 'inbox' and toaddress = '{}';".format( inbox WHERE folder = 'inbox' and toaddress = '{}';".format(
account)) account))
sent_and_draft = sqlQuery( sent_and_draft = sqlQuery(
"SELECT toaddress, fromaddress, subject, message, folder from\ "SELECT toaddress, fromaddress, subject, message, folder from sent \
sent WHERE folder != 'trash' and fromaddress = '{}';".format( WHERE folder = 'sent' and fromaddress = '{}';".format(
account)) account))
all_mails = inbox + sent_and_draft all_mails = inbox + sent_and_draft

View File

@ -103,3 +103,5 @@ all_count = 0
searcing_text = '' searcing_text = ''
search_screen = '' search_screen = ''
send_draft_mail = None