From 8d5ff9abba14ec6847dd63e4e419fe94df93a543 Mon Sep 17 00:00:00 2001 From: surbhi Date: Tue, 24 Jul 2018 18:12:53 +0530 Subject: [PATCH] Added changes for create new message feature for send button and cancel button --- src/bitmessagekivy/main.kv | 11 ++++- src/bitmessagekivy/mpybit.py | 83 ++++++++++++++++++++++++++++++++---- 2 files changed, 84 insertions(+), 10 deletions(-) diff --git a/src/bitmessagekivy/main.kv b/src/bitmessagekivy/main.kv index 99869f40..ed8ad339 100644 --- a/src/bitmessagekivy/main.kv +++ b/src/bitmessagekivy/main.kv @@ -175,12 +175,19 @@ BoxLayout: size_hint: 1,2 Button: - text: 'SEND' + text: 'send' size_hint_y: 0.1 - size_hint_x: 0.3 + size_hint_x: 0.2 height: '32dp' pos_hint: {'x': .5, 'y': 0.1} on_press: root.send() + Button: + text: 'cancel' + size_hint_y: 0.1 + size_hint_x: 0.2 + height: '32dp' + pos_hint: {'x': .72, 'y': 0.1} + on_press: root.cancel() : name: 'newidentity' diff --git a/src/bitmessagekivy/mpybit.py b/src/bitmessagekivy/mpybit.py index b9f3f6d2..c621d6d0 100644 --- a/src/bitmessagekivy/mpybit.py +++ b/src/bitmessagekivy/mpybit.py @@ -1,5 +1,7 @@ import os +import time import shutdown +import queues from kivy.app import App from kivy.lang import Builder from kivy.uix.screenmanager import Screen @@ -7,13 +9,16 @@ from kivy.properties import ObjectProperty, StringProperty from kivymd.theming import ThemeManager from kivy.uix.widget import Widget from kivy.uix.boxlayout import BoxLayout +from kivy.properties import BooleanProperty from kivymd.toolbar import Toolbar from navigationdrawer import NavigationDrawer from kivy.uix.label import Label from kivy.uix.textinput import TextInput from kivy.clock import Clock from bmconfigparser import BMConfigParser -from kivy.properties import BooleanProperty +from helper_ackPayload import genAckPayload +from addresses import decodeAddress, addBMIfNotPresent +from helper_sql import sqlExecute statusIconColor = 'red' @@ -22,12 +27,13 @@ class NavigateApp(App, TextInput): nav_drawer = ObjectProperty() def build(self): - main_widget = Builder.load_file(os.path.join(os.path.dirname(__file__), 'main.kv')) + main_widget = Builder.load_file( + os.path.join(os.path.dirname(__file__), 'main.kv')) self.nav_drawer = Navigator() return main_widget def say_exit(self): - print ("**************************EXITING FROM APPLICATION*****************************") + print("**************************EXITING FROM APPLICATION*****************************") App.get_running_app().stop() shutdown.doCleanShutdown() @@ -44,7 +50,8 @@ class Inbox(Screen): val_z = 0 my_box1 = BoxLayout(orientation='vertical') for i in range(1, 5): - my_box1.add_widget(Label(text="I am in inbox", size_hint = (.3,.1), pos_hint = {'x': val_z,'top': val_y},color = (0,0,0,1), background_color = (0,0,0,0))) + my_box1.add_widget(Label(text="I am in inbox", size_hint=(.3, .1), pos_hint={ + 'x': val_z, 'top': val_y}, color=(0, 0, 0, 1), background_color=(0, 0, 0, 0))) val_y += .1 self.add_widget(my_box1) @@ -56,7 +63,8 @@ class Sent(Screen): val_z = 0 my_box1 = BoxLayout(orientation='vertical') for i in range(1, 5): - my_box1.add_widget(Label(text="I am in sent", size_hint = (.3,.1), pos_hint = {'x': val_z,'top': val_y},color = (0,0,0,1), background_color = (0,0,0,0))) + my_box1.add_widget(Label(text="I am in sent", size_hint=(.3, .1), pos_hint={ + 'x': val_z, 'top': val_y}, color=(0, 0, 0, 1), background_color=(0, 0, 0, 0))) val_y += .1 self.add_widget(my_box1) @@ -68,7 +76,8 @@ class Trash(Screen): val_z = 0 my_box1 = BoxLayout(orientation='vertical') for i in range(1, 5): - my_box1.add_widget(Label(text="I am in trash", size_hint = (.3,.1), pos_hint = {'x': val_z,'top': val_y},color = (0,0,0,1), background_color = (0,0,0,0))) + my_box1.add_widget(Label(text="I am in trash", size_hint=(.3, .1), pos_hint={ + 'x': val_z, 'top': val_y}, color=(0, 0, 0, 1), background_color=(0, 0, 0, 0))) val_y += .1 self.add_widget(my_box1) @@ -95,11 +104,69 @@ class Create(Screen, Widget): return BMConfigParser().addresses() def send(self): - pass + # toAddress = self.ids.recipent.text + fromAddress = self.ids.spinner_id.text + # For now we are using static address i.e we are not using recipent field value. + toAddress = "BM-2cWyUfBdY2FbgyuCb7abFZ49JYxSzUhNFe" + message = self.ids.message.text + subject = self.ids.subject.text + encoding = 3 + print("message: ", self.ids.message.text) + sendMessageToPeople = True + if sendMessageToPeople: + if toAddress != '': + status, addressVersionNumber, streamNumber, ripe = decodeAddress( + toAddress) + if status == 'success': + toAddress = addBMIfNotPresent(toAddress) + + if addressVersionNumber > 4 or addressVersionNumber <= 1: + print("addressVersionNumber > 4 or addressVersionNumber <= 1") + if streamNumber > 1 or streamNumber == 0: + print("streamNumber > 1 or streamNumber == 0") + if statusIconColor == 'red': + print("shared.statusIconColor == 'red'") + stealthLevel = BMConfigParser().safeGetInt( + 'bitmessagesettings', 'ackstealthlevel') + ackdata = genAckPayload(streamNumber, stealthLevel) + t = () + sqlExecute( + '''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)''', + '', + toAddress, + ripe, + fromAddress, + subject, + message, + ackdata, + int(time.time()), + int(time.time()), + 0, + 'msgqueued', + 0, + 'sent', + encoding, + BMConfigParser().getint('bitmessagesettings', 'ttl')) + toLabel = '' + queues.workerQueue.put(('sendmessage', toAddress)) + print("sqlExecute successfully ##### ##################") + self.ids.message.text = '' + self.ids.spinner_id.text = '' + self.ids.subject.text = '' + self.ids.recipent.text = '' + return None class NewIdentity(Screen): is_active = BooleanProperty(False) + if __name__ == '__main__': - NavigateApp().run() \ No newline at end of file + NavigateApp().run()