diff --git a/client/electrum4a.py b/client/electrum4a.py index f37d30331..c980615ec 100755 --- a/client/electrum4a.py +++ b/client/electrum4a.py @@ -36,10 +36,20 @@ wallet.read() +def select_from_contacts(): + title = 'Contacts:' + droid.dialogCreateAlert(title) + droid.dialogSetItems(wallet.addressbook) + droid.dialogShow() + response = droid.dialogGetResponse() + result = response.result.get('item') + droid.dialogDismiss() + if result is not None: + addr = wallet.addressbook[result] + return addr - -def show_addresses(): +def select_from_addresses(): droid.dialogCreateAlert("Addresses:") l = [] for i in range(len(wallet.addresses)): @@ -48,17 +58,19 @@ def show_addresses(): droid.dialogSetItems(l) droid.dialogShow() - response = droid.dialogGetResponse().result + response = droid.dialogGetResponse() + result = response.result.get('item') droid.dialogDismiss() + if result is not None: + addr = wallet.addresses[result] + return addr - # show qr code - print response title = """ - - - - -"""%title - + """) @@ -362,19 +387,6 @@ def update_layout(): -def recipient_dialog(): - title = 'Pay to:' - message = ('Select recipient') - droid.dialogCreateAlert(title, message) - droid.dialogSetItems(wallet.addressbook) - droid.dialogShow() - response = droid.dialogGetResponse() - result = response.result.get('item') - droid.dialogDismiss() - if result is not None: - addr = wallet.addressbook[result] - return addr - def pay_to(recipient, amount, fee, label): @@ -456,7 +468,8 @@ else: def add_menu(): - droid.addOptionsMenuItem("Settings","settings",None,"") + droid.addOptionsMenuItem("Network","settings",None,"") + droid.addOptionsMenuItem("New contact","newcontact",None,"") droid.addOptionsMenuItem("Quit","quit",None,"") add_menu() @@ -481,12 +494,45 @@ def main_loop(): if id=="buttonSend": out = 'payto' + if id=="buttonContacts": + global contact_addr + contact_addr = select_from_contacts() + if contact_addr: + out = 'contacts' + elif id=="buttonReceive": - show_addresses() + global receive_addr + receive_addr = select_from_addresses() + if receive_addr: + out = 'receive' elif event["name"]=="settings": out = 'settings' + elif event["name"]=="newcontact": + code = droid.scanBarcode() + r = code.result + if r: + address = r['extras']['SCAN_RESULT'] + if address: + if wallet.is_valid(address): + droid.dialogCreateAlert('Add to contacts?', address) + droid.dialogSetPositiveButtonText('OK') + droid.dialogSetNegativeButtonText('Cancel') + droid.dialogShow() + response = droid.dialogGetResponse().result + droid.dialogDismiss() + print response + if response.get('which') == 'positive': + wallet.addressbook.append(address) + wallet.save() + else: + droid.dialogCreateAlert('Invalid address', address) + droid.dialogSetPositiveButtonText('OK') + droid.dialogShow() + response = droid.dialogGetResponse().result + droid.dialogDismiss() + elif event["name"]=="key": if event["data"]["key"] == '4': out = 'quit' @@ -494,11 +540,6 @@ def main_loop(): elif event["name"]=="quit": out = 'quit' - # print droid.fullSetProperty("background","backgroundColor","0xff7f0000") - # elif event["name"]=="screen": - # if event["data"]=="destroy": - # out = 'exit' - return out def payto_loop(): @@ -530,7 +571,7 @@ def payto_loop(): out = 'main' elif id=="buttonContacts": - addr = recipient_dialog() + addr = select_from_contacts() droid.fullSetProperty("recipient","text",addr) elif id=="buttonQR": @@ -561,13 +602,17 @@ def payto_loop(): return out -def history_loop(): - layout = get_history_layout(15) - droid.fullShow(layout) +receive_addr = '' +contact_addr = '' + + +def receive_loop(): + droid.fullShow(receive_layout) + droid.fullSetProperty("receiveTextView","text", receive_addr) out = None while out is None: event = droid.eventWait().result - print "got event in history loop", event + print "got event", event if event["name"] == "click": if event["data"]["text"] == "OK": @@ -577,12 +622,27 @@ def history_loop(): if event["data"]["key"] == '4': out = 'main' - #elif event["name"]=="screen": - # if event["data"]=="destroy": - # out = 'main' + return out + +def contacts_loop(): + droid.fullShow(contacts_layout) + droid.fullSetProperty("contactTextView","text", contact_addr) + out = None + while out is None: + event = droid.eventWait().result + print "got event", event + if event["name"] == "click": + + if event["data"]["text"] == "OK": + out = 'main' + + elif event["name"]=="key": + if event["data"]["key"] == '4': + out = 'main' return out + def server_dialog(plist): droid.dialogCreateAlert("servers") droid.dialogSetItems( plist.keys() ) @@ -593,6 +653,7 @@ def server_dialog(plist): response = plist.keys()[i] return response + def protocol_dialog(plist): options=["TCP","HTTP","native"] droid.dialogCreateAlert("Protocol") @@ -661,10 +722,12 @@ while True: s = main_loop() elif s == 'payto': s = payto_loop() + elif s == 'receive': + s = receive_loop() + elif s == 'contacts': + s = contacts_loop() elif s == 'settings': s = settings_loop() - elif s == 'history': - s = history_loop() elif s == 'contacts': s = contacts_loop() else: