Browse Source

updates for the old android GUI

master
ThomasV 11 years ago
parent
commit
80284d5516
  1. 18
      contrib/make_android
  2. 21
      contrib/make_download
  3. 7
      electrum
  4. 70
      gui/android.py
  5. 8
      lib/util.py

18
contrib/make_android

@ -7,19 +7,20 @@ if __name__ == '__main__':
os.chdir(os.path.dirname(os.path.realpath(__file__))) os.chdir(os.path.dirname(os.path.realpath(__file__)))
os.chdir('..') os.chdir('..')
imp.load_module('electrum', *imp.find_module('../lib')) v = imp.load_source('version', 'lib/version.py')
from electrum.version import ELECTRUM_VERSION as version version = v.ELECTRUM_VERSION
if not ( os.path.exists('packages')): if not ( os.path.exists('packages')):
print "The packages directory is missing." print "The packages directory is missing."
sys.exit() sys.exit()
os.system('rm -rf dist/e4a-%s'%version) os.system('rm -rf dist/e4a-%s'%version)
os.mkdir('dist/e4a-%s'%version) os.mkdir('dist/e4a-%s'%version)
shutil.copyfile("electrum",'dist/e4a-%s/e4a.py'%version) shutil.copyfile("electrum",'dist/e4a-%s/e4a.py'%version)
shutil.copytree("packages",'dist/e4a-%s/packages'%version) shutil.copytree("packages",'dist/e4a-%s/packages'%version, ignore=shutil.ignore_patterns('*.pyc'))
shutil.copytree("lib",'dist/e4a-%s/lib'%version) shutil.copytree("lib",'dist/e4a-%s/lib'%version, ignore=shutil.ignore_patterns('*.pyc'))
# dns is not used by android app
os.system('rm -rf dist/e4a-%s/packages/dns')
os.mkdir('dist/e4a-%s/gui'%version) os.mkdir('dist/e4a-%s/gui'%version)
for n in ['android.py']: for n in ['android.py']:
shutil.copy("gui/%s"%n,'dist/e4a-%s/gui'%version) shutil.copy("gui/%s"%n,'dist/e4a-%s/gui'%version)
@ -27,13 +28,12 @@ if __name__ == '__main__':
os.chdir("dist") os.chdir("dist")
# create the zip file # create the zip file
os.system( "zip -r e4a-%s.zip e4a-%s"%(version, version) ) os.system( "zip -qr e4a-%s.zip e4a-%s"%(version, version) )
os.system( "rm -rf e4a-%s"%(version) ) os.system( "rm -rf e4a-%s"%(version) )
# change filename because some 3G carriers do not allow users to download a zip file... # change filename because some 3G carriers do not allow users to download a zip file...
e4a_name = "e4a-%s.zip"%version e4a_name = "e4a-%s.zip"%version
e4a_name2 = e4a_name.replace(".","") e4a_name2 = e4a_name.replace(".","")
os.system( "mv %s %s"%(e4a_name, e4a_name2) ) os.system("mv %s %s"%(e4a_name, e4a_name2))
print "dist/%s "%e4a_name2 print "dist/%s"%e4a_name2

21
contrib/make_download

@ -3,9 +3,10 @@ import sys
import hashlib import hashlib
import os import os
from versions import version, version_win, version_mac, template_path, dl_path from versions import version, version_win, version_mac
from versions import download_template, download_page
with open(template_path) as f: with open(download_template) as f:
string = f.read() string = f.read()
_tgz = "Electrum-%s.tar.gz" % version _tgz = "Electrum-%s.tar.gz" % version
@ -38,6 +39,20 @@ string = string.replace("##md5_win##", md5_win)
string = string.replace("##md5_win_setup##", md5_win_setup) string = string.replace("##md5_win_setup##", md5_win_setup)
string = string.replace("##md5_win_portable##", md5_win_portable) string = string.replace("##md5_win_portable##", md5_win_portable)
with open(dl_path,'w') as f: with open(download_page,'w') as f:
f.write(string) f.write(string)
# android
from versions import android_template, android_page
with open(android_template) as f:
string = f.read()
e4a_name = "e4a-%s.zip"%version
e4a_zipname = e4a_name.replace(".","")
string = string.replace("##VERSION##",version)
string = string.replace("##ZIPNAME##",e4a_zipname)
with open(android_page,'w') as f:
f.write(string)

7
electrum

@ -27,12 +27,13 @@ import sys
import time import time
import traceback import traceback
script_dir = os.path.dirname(os.path.realpath(__file__))
is_bundle = getattr(sys, 'frozen', False) is_bundle = getattr(sys, 'frozen', False)
is_local = not is_bundle and os.path.dirname(os.path.realpath(__file__)) == os.getcwd() is_local = not is_bundle and script_dir == os.getcwd()
is_android = 'ANDROID_DATA' in os.environ is_android = 'ANDROID_DATA' in os.environ
if is_local: if is_local or is_android:
sys.path.insert(0, 'packages') sys.path.insert(0, os.path.join(script_dir, 'packages'))
elif is_bundle and sys.platform=='darwin': elif is_bundle and sys.platform=='darwin':
sys.path.insert(0, os.getcwd() + "/lib/python2.7/packages") sys.path.insert(0, os.getcwd() + "/lib/python2.7/packages")

70
gui/android.py

@ -22,7 +22,7 @@
from __future__ import absolute_import from __future__ import absolute_import
import android import android
from electrum import SimpleConfig, Wallet, WalletStorage, format_satoshis, mnemonic_encode, mnemonic_decode from electrum import SimpleConfig, Wallet, WalletStorage, format_satoshis
from electrum.bitcoin import is_valid from electrum.bitcoin import is_valid
from electrum import util from electrum import util
from decimal import Decimal from decimal import Decimal
@ -98,7 +98,6 @@ def select_from_contacts():
return 'newcontact' return 'newcontact'
result = response.get('item') result = response.get('item')
print result
if result is not None: if result is not None:
addr = wallet.addressbook[result] addr = wallet.addressbook[result]
return addr return addr
@ -124,9 +123,7 @@ def select_from_addresses():
def protocol_name(p): def protocol_name(p):
if p == 't': return 'TCP' if p == 't': return 'TCP'
if p == 'h': return 'HTTP'
if p == 's': return 'SSL' if p == 's': return 'SSL'
if p == 'g': return 'HTTPS'
def protocol_dialog(host, protocol, z): def protocol_dialog(host, protocol, z):
@ -134,7 +131,7 @@ def protocol_dialog(host, protocol, z):
if z: if z:
protocols = z.keys() protocols = z.keys()
else: else:
protocols = 'thsg' protocols = 'ts'
l = [] l = []
current = protocols.index(protocol) current = protocols.index(protocol)
for p in protocols: for p in protocols:
@ -147,8 +144,10 @@ def protocol_dialog(host, protocol, z):
selected_item = droid.dialogGetSelectedItems().result selected_item = droid.dialogGetSelectedItems().result
droid.dialogDismiss() droid.dialogDismiss()
if not response: return if not response:
if not selected_item: return return
if not selected_item:
return
if response.get('which') == 'positive': if response.get('which') == 'positive':
return protocols[selected_item[0]] return protocols[selected_item[0]]
@ -211,7 +210,8 @@ def make_layout(s, scrollable = False):
def main_layout(): def main_layout():
return make_layout(""" h = get_history_layout(15)
l = make_layout("""
<TextView android:id="@+id/balanceTextView" <TextView android:id="@+id/balanceTextView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:text="" android:text=""
@ -229,8 +229,8 @@ def main_layout():
android:textAppearance="?android:attr/textAppearanceLarge" android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_vertical|center_horizontal|center"> android:gravity="center_vertical|center_horizontal|center">
</TextView> </TextView>
%s """%h,True)
%s """%get_history_layout(15),True) return l
@ -350,7 +350,7 @@ def get_history_values(n):
conf_str = 'v' if conf else 'o' conf_str = 'v' if conf else 'o'
label, is_default_label = wallet.get_label(tx_hash) label, is_default_label = wallet.get_label(tx_hash)
values.append((conf_str, ' ' + time_str, ' ' + format_satoshis(value,True), ' ' + label )) values.append((conf_str, ' ' + time_str, ' ' + format_satoshis(value,True), ' ' ))
return values return values
@ -616,15 +616,18 @@ def payto_loop():
code = droid.scanBarcode() code = droid.scanBarcode()
r = code.result r = code.result
if r: if r:
data = r['extras']['SCAN_RESULT'] data = str(r['extras']['SCAN_RESULT'])
if data: if data:
if re.match('^bitcoin:', data): if re.match('^bitcoin:', data):
payto, amount, label, _, _ = util.parse_URI(data) payto, amount, label, _, _ = util.parse_URI(data)
droid.fullSetProperty("recipient", "text",payto) amount = str(amount/100000000)
droid.fullSetProperty("recipient", "text", payto)
droid.fullSetProperty("amount", "text", amount) droid.fullSetProperty("amount", "text", amount)
droid.fullSetProperty("label", "text", label) droid.fullSetProperty("label", "text", label)
else: elif bitcoin.is_address(data):
droid.fullSetProperty("recipient", "text", data) droid.fullSetProperty("recipient", "text", data)
else:
modal_dialog('Error','cannot parse QR code\n'+data)
elif event["name"] in menu_commands: elif event["name"] in menu_commands:
@ -717,13 +720,12 @@ def show_seed():
password = None password = None
try: try:
seed = wallet.get_seed(password) seed = wallet.get_mnemonic(password)
except Exception: except Exception:
modal_dialog('error','incorrect password') modal_dialog('error','incorrect password')
return return
modal_dialog('Your seed is',seed) modal_dialog('Your seed is', seed)
modal_dialog('Mnemonic code:', ' '.join(mnemonic_encode(seed)) )
def change_password_dialog(): def change_password_dialog():
if wallet.use_encryption: if wallet.use_encryption:
@ -733,7 +735,7 @@ def change_password_dialog():
password = None password = None
try: try:
wallet.get_seed(password) wallet.check_password(password)
except Exception: except Exception:
modal_dialog('error','incorrect password') modal_dialog('error','incorrect password')
return return
@ -760,8 +762,8 @@ def settings_loop():
def set_listview(): def set_listview():
host, port, p = network.default_server.split(':') host, port, p, proxy_config, auto_connect = network.get_parameters()
fee = str( Decimal( wallet.fee)/100000000 ) fee = str( Decimal( wallet.fee_per_kb)/100000000 )
is_encrypted = 'yes' if wallet.use_encryption else 'no' is_encrypted = 'yes' if wallet.use_encryption else 'no'
protocol = protocol_name(p) protocol = protocol_name(p)
droid.fullShow(settings_layout) droid.fullShow(settings_layout)
@ -783,7 +785,7 @@ def settings_loop():
if name == "itemclick": if name == "itemclick":
pos = event["data"]["position"] pos = event["data"]["position"]
host, port, protocol = network.default_server.split(':') host, port, protocol, proxy_config, auto_connect = network.get_parameters()
network_changed = False network_changed = False
if pos == "0": #server if pos == "0": #server
@ -796,6 +798,7 @@ def settings_loop():
elif pos == "1": #protocol elif pos == "1": #protocol
if host in servers: if host in servers:
protocol = protocol_dialog(host, protocol, servers[host]) protocol = protocol_dialog(host, protocol, servers[host])
if protocol:
z = servers[host] z = servers[host]
port = z[protocol] port = z[protocol]
network_changed = True network_changed = True
@ -807,7 +810,8 @@ def settings_loop():
network_changed = True network_changed = True
elif pos == "3": #fee elif pos == "3": #fee
fee = modal_input('Transaction fee', 'The fee will be this amount multiplied by the number of inputs in your transaction. ', str( Decimal( wallet.fee)/100000000 ), "numberDecimal") fee = modal_input('Transaction fee', 'The fee will be this amount multiplied by the number of inputs in your transaction. ',
str(Decimal(wallet.fee_per_kb)/100000000 ), "numberDecimal")
if fee: if fee:
try: try:
fee = int( 100000000 * Decimal(fee) ) fee = int( 100000000 * Decimal(fee) )
@ -861,17 +865,15 @@ def add_menu(s):
#droid.addOptionsMenuItem("Delete","deletecontact",None,"") #droid.addOptionsMenuItem("Delete","deletecontact",None,"")
def make_bitmap(addr): def make_bitmap(data):
# fixme: this is highly inefficient # fixme: this is highly inefficient
droid.dialogCreateSpinnerProgress("please wait") droid.dialogCreateSpinnerProgress("please wait")
droid.dialogShow() droid.dialogShow()
try: try:
import pyqrnative, bmp import qrcode
qr = pyqrnative.QRCode(4, pyqrnative.QRErrorCorrectLevel.L) from electrum import bmp
qr.addData(addr) qr = qrcode.QRCode()
qr.make() qr.add_data(data)
k = qr.getModuleCount()
assert k == 33
bmp.save_qrcode(qr,"/sdcard/sl4a/qrcode.bmp") bmp.save_qrcode(qr,"/sdcard/sl4a/qrcode.bmp")
finally: finally:
droid.dialogDismiss() droid.dialogDismiss()
@ -975,7 +977,7 @@ class ElectrumGui:
def seed_dialog(self): def seed_dialog(self):
if modal_question("Enter your seed","Input method",'QR Code', 'mnemonic'): if modal_question("Enter your seed", "Input method", 'QR Code', 'mnemonic'):
code = droid.scanBarcode() code = droid.scanBarcode()
r = code.result r = code.result
if r: if r:
@ -984,11 +986,6 @@ class ElectrumGui:
return return
else: else:
m = modal_input('Mnemonic','please enter your code') m = modal_input('Mnemonic','please enter your code')
try:
seed = mnemonic_decode(m.split(' '))
except Exception:
modal_dialog('error: could not decode this seed')
return
return str(seed) return str(seed)
@ -998,8 +995,7 @@ class ElectrumGui:
def show_seed(self): def show_seed(self):
modal_dialog('Your seed is:', wallet.seed) modal_dialog('Your seed is:', wallet.get_mnemonic(None))
modal_dialog('Mnemonic code:', ' '.join(mnemonic_encode(wallet.seed)) )
def password_dialog(self): def password_dialog(self):

8
lib/util.py

@ -151,8 +151,12 @@ def parse_URI(uri):
assert u.scheme == 'bitcoin' assert u.scheme == 'bitcoin'
address = u.path address = u.path
valid_address = bitcoin.is_address(address)
# python for android fails to parse query
if address.find('?') > 0:
address, query = u.path.split('?')
pq = urlparse.parse_qs(query)
else:
pq = urlparse.parse_qs(u.query) pq = urlparse.parse_qs(u.query)
for k, v in pq.items(): for k, v in pq.items():
@ -178,7 +182,7 @@ def parse_URI(uri):
if request_url != '': if request_url != '':
return address, amount, label, message, request_url return address, amount, label, message, request_url
assert valid_address assert bitcoin.is_address(address)
return address, amount, label, message, request_url return address, amount, label, message, request_url

Loading…
Cancel
Save