callbacks
This commit is contained in:
@@ -152,19 +152,18 @@ def main_layout():
|
|||||||
return make_layout("""
|
return make_layout("""
|
||||||
<TextView android:id="@+id/balanceTextView"
|
<TextView android:id="@+id/balanceTextView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="70"
|
||||||
android:text=""
|
android:text=""
|
||||||
|
android:textColor="#ffffffff"
|
||||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||||
android:gravity="left"
|
|
||||||
android:textColor="0xffffffff"
|
|
||||||
android:padding="10"
|
android:padding="10"
|
||||||
android:textSize="18" >
|
android:textSize="6pt"
|
||||||
|
android:gravity="center_vertical|center_horizontal|left">
|
||||||
</TextView>
|
</TextView>
|
||||||
|
|
||||||
|
|
||||||
<TextView android:id="@+id/historyTextView"
|
<TextView android:id="@+id/historyTextView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="70"
|
android:layout_height="wrap_content"
|
||||||
android:text="Recent transactions"
|
android:text="Recent transactions"
|
||||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||||
android:gravity="center_vertical|center_horizontal|center">
|
android:gravity="center_vertical|center_horizontal|center">
|
||||||
@@ -346,7 +345,7 @@ def get_history_layout(n):
|
|||||||
values = get_history_values(n)
|
values = get_history_values(n)
|
||||||
for v in values:
|
for v in values:
|
||||||
a,b,c,d = v
|
a,b,c,d = v
|
||||||
color = "0xff00ff00" if a == 'v' else "0xffff0000"
|
color = "#ff00ff00" if a == 'v' else "#ffff0000"
|
||||||
rows += """
|
rows += """
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TextView
|
<TextView
|
||||||
@@ -391,9 +390,9 @@ def set_history_layout(n):
|
|||||||
droid.fullSetProperty("hl_%d_col1"%i,"text", a)
|
droid.fullSetProperty("hl_%d_col1"%i,"text", a)
|
||||||
|
|
||||||
if a == 'v':
|
if a == 'v':
|
||||||
droid.fullSetProperty("hl_%d_col1"%i, "textColor","0xff00ff00")
|
droid.fullSetProperty("hl_%d_col1"%i, "textColor","#ff00ff00")
|
||||||
else:
|
else:
|
||||||
droid.fullSetProperty("hl_%d_col1"%i, "textColor","0xffff0000")
|
droid.fullSetProperty("hl_%d_col1"%i, "textColor","#ffff0000")
|
||||||
|
|
||||||
droid.fullSetProperty("hl_%d_col2"%i,"text", b)
|
droid.fullSetProperty("hl_%d_col2"%i,"text", b)
|
||||||
droid.fullSetProperty("hl_%d_col3"%i,"text", c)
|
droid.fullSetProperty("hl_%d_col3"%i,"text", c)
|
||||||
@@ -402,8 +401,10 @@ def set_history_layout(n):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
def update_layout():
|
|
||||||
|
|
||||||
|
status_text = ''
|
||||||
|
def update_layout():
|
||||||
|
global status_text
|
||||||
if not wallet.interface.is_connected:
|
if not wallet.interface.is_connected:
|
||||||
text = "Not connected..."
|
text = "Not connected..."
|
||||||
elif wallet.blocks == 0:
|
elif wallet.blocks == 0:
|
||||||
@@ -415,15 +416,16 @@ def update_layout():
|
|||||||
text = "Balance:"+format_satoshis(c)
|
text = "Balance:"+format_satoshis(c)
|
||||||
if u : text += ' [' + format_satoshis(u,True).strip() + ']'
|
if u : text += ' [' + format_satoshis(u,True).strip() + ']'
|
||||||
|
|
||||||
droid.fullSetProperty("balanceTextView", "text", text)
|
|
||||||
|
|
||||||
if wallet.was_updated and wallet.up_to_date:
|
# vibrate if status changed
|
||||||
global first_time_update
|
if text != status_text:
|
||||||
if not first_time_update:
|
if status_text and wallet.interface.is_connected and wallet.up_to_date:
|
||||||
droid.vibrate()
|
droid.vibrate()
|
||||||
else:
|
status_text = text
|
||||||
first_time_update = False
|
|
||||||
wallet.was_updated = False
|
droid.fullSetProperty("balanceTextView", "text", status_text)
|
||||||
|
|
||||||
|
if wallet.up_to_date:
|
||||||
set_history_layout(15)
|
set_history_layout(15)
|
||||||
|
|
||||||
|
|
||||||
@@ -513,18 +515,34 @@ def make_new_contact():
|
|||||||
modal_dialog('Invalid address', address)
|
modal_dialog('Invalid address', address)
|
||||||
|
|
||||||
|
|
||||||
|
do_refresh = False
|
||||||
|
|
||||||
|
def update_callback():
|
||||||
|
global do_refresh
|
||||||
|
print "gui callback", wallet.interface.is_connected, wallet.up_to_date
|
||||||
|
do_refresh = True
|
||||||
|
droid.eventPost("refresh",'z')
|
||||||
|
|
||||||
def main_loop():
|
def main_loop():
|
||||||
|
global do_refresh
|
||||||
|
|
||||||
update_layout()
|
update_layout()
|
||||||
out = None
|
out = None
|
||||||
quitting = False
|
quitting = False
|
||||||
while out is None:
|
while out is None:
|
||||||
|
|
||||||
event = droid.eventWait(1000).result # wait for 1 second
|
event = droid.eventWait(1000).result
|
||||||
if not event:
|
if event is None:
|
||||||
update_layout()
|
if do_refresh:
|
||||||
|
update_layout()
|
||||||
|
do_refresh = False
|
||||||
continue
|
continue
|
||||||
|
|
||||||
print "got event in main loop", event
|
print "got event in main loop", repr(event)
|
||||||
|
if event == 'OK': continue
|
||||||
|
if event is None: continue
|
||||||
|
#if event["name"]=="refresh":
|
||||||
|
|
||||||
|
|
||||||
# request 2 taps before we exit
|
# request 2 taps before we exit
|
||||||
if event["name"]=="key":
|
if event["name"]=="key":
|
||||||
@@ -578,15 +596,13 @@ def payto_loop():
|
|||||||
recipient = droid.fullQueryDetail("recipient").result.get('text')
|
recipient = droid.fullQueryDetail("recipient").result.get('text')
|
||||||
label = droid.fullQueryDetail("label").result.get('text')
|
label = droid.fullQueryDetail("label").result.get('text')
|
||||||
amount = droid.fullQueryDetail('amount').result.get('text')
|
amount = droid.fullQueryDetail('amount').result.get('text')
|
||||||
fee = '0.001'
|
|
||||||
try:
|
try:
|
||||||
amount = int( 100000000 * Decimal(amount) )
|
amount = int( 100000000 * Decimal(amount) )
|
||||||
except:
|
except:
|
||||||
modal_dialog('Error','invalid amount')
|
modal_dialog('Error','invalid amount')
|
||||||
continue
|
continue
|
||||||
|
|
||||||
fee = int( 100000000 * Decimal(fee) )
|
result = pay_to(recipient, amount, wallet.fee, label)
|
||||||
result = pay_to(recipient, amount, fee, label)
|
|
||||||
if result:
|
if result:
|
||||||
out = 'main'
|
out = 'main'
|
||||||
|
|
||||||
@@ -771,14 +787,12 @@ def settings_loop():
|
|||||||
|
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
menu_commands = ["send", "receive", "settings", "contacts", "main"]
|
menu_commands = ["send", "receive", "settings", "contacts", "main"]
|
||||||
|
|
||||||
|
|
||||||
first_time_update = True
|
|
||||||
droid = android.Android()
|
droid = android.Android()
|
||||||
wallet = Wallet()
|
wallet = Wallet(update_callback)
|
||||||
|
|
||||||
wallet.set_path("/sdcard/electrum.dat")
|
wallet.set_path("/sdcard/electrum.dat")
|
||||||
wallet.read()
|
wallet.read()
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 4.5 KiB |
@@ -144,6 +144,8 @@ class ElectrumWindow(QMainWindow):
|
|||||||
def __init__(self, wallet):
|
def __init__(self, wallet):
|
||||||
QMainWindow.__init__(self)
|
QMainWindow.__init__(self)
|
||||||
self.wallet = wallet
|
self.wallet = wallet
|
||||||
|
self.wallet.gui_callback = self.update_callback
|
||||||
|
|
||||||
self.funds_error = False
|
self.funds_error = False
|
||||||
|
|
||||||
self.tabs = tabs = QTabWidget(self)
|
self.tabs = tabs = QTabWidget(self)
|
||||||
@@ -164,11 +166,11 @@ class ElectrumWindow(QMainWindow):
|
|||||||
QShortcut(QKeySequence("Ctrl+Q"), self, self.close)
|
QShortcut(QKeySequence("Ctrl+Q"), self, self.close)
|
||||||
QShortcut(QKeySequence("Ctrl+PgUp"), self, lambda: tabs.setCurrentIndex( (tabs.currentIndex() - 1 )%tabs.count() ))
|
QShortcut(QKeySequence("Ctrl+PgUp"), self, lambda: tabs.setCurrentIndex( (tabs.currentIndex() - 1 )%tabs.count() ))
|
||||||
QShortcut(QKeySequence("Ctrl+PgDown"), self, lambda: tabs.setCurrentIndex( (tabs.currentIndex() + 1 )%tabs.count() ))
|
QShortcut(QKeySequence("Ctrl+PgDown"), self, lambda: tabs.setCurrentIndex( (tabs.currentIndex() + 1 )%tabs.count() ))
|
||||||
|
|
||||||
|
self.connect(self, QtCore.SIGNAL('updatesignal'), self.update_wallet)
|
||||||
|
|
||||||
|
|
||||||
def connect_slots(self, sender):
|
def connect_slots(self, sender):
|
||||||
self.connect(sender, QtCore.SIGNAL('timersignal'), self.update_wallet)
|
|
||||||
self.connect(sender, QtCore.SIGNAL('timersignal'), self.check_recipient)
|
self.connect(sender, QtCore.SIGNAL('timersignal'), self.check_recipient)
|
||||||
self.previous_payto_e=''
|
self.previous_payto_e=''
|
||||||
|
|
||||||
@@ -189,6 +191,9 @@ class ElectrumWindow(QMainWindow):
|
|||||||
self.payto_e.setText(s)
|
self.payto_e.setText(s)
|
||||||
|
|
||||||
|
|
||||||
|
def update_callback(self):
|
||||||
|
self.emit(QtCore.SIGNAL('updatesignal'))
|
||||||
|
|
||||||
def update_wallet(self):
|
def update_wallet(self):
|
||||||
if self.wallet.interface.is_connected:
|
if self.wallet.interface.is_connected:
|
||||||
if self.wallet.blocks == -1:
|
if self.wallet.blocks == -1:
|
||||||
@@ -215,8 +220,7 @@ class ElectrumWindow(QMainWindow):
|
|||||||
self.statusBar().showMessage(text)
|
self.statusBar().showMessage(text)
|
||||||
self.status_button.setIcon( icon )
|
self.status_button.setIcon( icon )
|
||||||
|
|
||||||
if self.wallet.was_updated and self.wallet.up_to_date:
|
if self.wallet.up_to_date:
|
||||||
self.wallet.was_updated = False
|
|
||||||
self.textbox.setText( self.wallet.banner )
|
self.textbox.setText( self.wallet.banner )
|
||||||
self.update_history_tab()
|
self.update_history_tab()
|
||||||
self.update_receive_tab()
|
self.update_receive_tab()
|
||||||
@@ -1059,4 +1063,6 @@ class ElectrumGui():
|
|||||||
if url: w.set_url(url)
|
if url: w.set_url(url)
|
||||||
w.app = self.app
|
w.app = self.app
|
||||||
w.connect_slots(s)
|
w.connect_slots(s)
|
||||||
|
w.update_wallet()
|
||||||
|
|
||||||
self.app.exec_()
|
self.app.exec_()
|
||||||
|
|||||||
@@ -316,6 +316,7 @@ class TcpStratumInterface(Interface):
|
|||||||
traceback.print_exc(file=sys.stdout)
|
traceback.print_exc(file=sys.stdout)
|
||||||
|
|
||||||
self.is_connected = False
|
self.is_connected = False
|
||||||
|
print "poking"
|
||||||
self.poke()
|
self.poke()
|
||||||
|
|
||||||
def send(self, messages):
|
def send(self, messages):
|
||||||
@@ -448,27 +449,33 @@ class WalletSynchronizer(threading.Thread):
|
|||||||
def run(self):
|
def run(self):
|
||||||
import socket, time
|
import socket, time
|
||||||
while True:
|
while True:
|
||||||
try:
|
while self.interface.is_connected:
|
||||||
while self.interface.is_connected:
|
new_addresses = self.wallet.synchronize()
|
||||||
new_addresses = self.wallet.synchronize()
|
if new_addresses:
|
||||||
if new_addresses:
|
self.interface.subscribe(new_addresses)
|
||||||
self.interface.subscribe(new_addresses)
|
for addr in new_addresses:
|
||||||
for addr in new_addresses:
|
with self.wallet.lock:
|
||||||
with self.wallet.lock:
|
self.wallet.addresses_waiting_for_status.append(addr)
|
||||||
self.wallet.addresses_waiting_for_status.append(addr)
|
|
||||||
|
|
||||||
if self.wallet.is_up_to_date():
|
if self.wallet.is_up_to_date():
|
||||||
|
if not self.wallet.up_to_date:
|
||||||
self.wallet.up_to_date = True
|
self.wallet.up_to_date = True
|
||||||
|
self.wallet.was_updated = True
|
||||||
self.wallet.up_to_date_event.set()
|
self.wallet.up_to_date_event.set()
|
||||||
else:
|
else:
|
||||||
|
if self.wallet.up_to_date:
|
||||||
self.wallet.up_to_date = False
|
self.wallet.up_to_date = False
|
||||||
|
self.wallet.was_updated = True
|
||||||
|
|
||||||
response = self.interface.responses.get()#True,100000000000) # workaround so that it can be keyboard interrupted
|
if self.wallet.was_updated:
|
||||||
self.handle_response(response)
|
self.wallet.gui_callback()
|
||||||
except socket.error:
|
self.wallet.was_updated = False
|
||||||
print "socket error"
|
|
||||||
wallet.interface.is_connected = False
|
|
||||||
|
|
||||||
|
response = self.interface.responses.get()
|
||||||
|
self.handle_response(response)
|
||||||
|
|
||||||
|
print "disconnected, gui callback"
|
||||||
|
self.wallet.gui_callback()
|
||||||
if self.loop:
|
if self.loop:
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
self.start_interface()
|
self.start_interface()
|
||||||
|
|||||||
@@ -242,10 +242,11 @@ from interface import DEFAULT_SERVERS
|
|||||||
|
|
||||||
|
|
||||||
class Wallet:
|
class Wallet:
|
||||||
def __init__(self):
|
def __init__(self, gui_callback = lambda: None):
|
||||||
|
|
||||||
self.electrum_version = ELECTRUM_VERSION
|
self.electrum_version = ELECTRUM_VERSION
|
||||||
self.seed_version = SEED_VERSION
|
self.seed_version = SEED_VERSION
|
||||||
|
self.gui_callback = gui_callback
|
||||||
|
|
||||||
self.gap_limit = 5 # configuration
|
self.gap_limit = 5 # configuration
|
||||||
self.fee = 100000
|
self.fee = 100000
|
||||||
|
|||||||
Reference in New Issue
Block a user