Browse Source

callbacks

283
ThomasV 13 years ago
parent
commit
5744131e18
  1. 70
      client/electrum4a.py
  2. BIN
      client/electrum_text_320.png
  3. 14
      client/gui_qt.py
  4. 39
      client/interface.py
  5. 3
      client/wallet.py

70
client/electrum4a.py

@ -152,19 +152,18 @@ def main_layout():
return make_layout("""
<TextView android:id="@+id/balanceTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="70"
android:text=""
android:textColor="#ffffffff"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="left"
android:textColor="0xffffffff"
android:padding="10"
android:textSize="18" >
android:textSize="6pt"
android:gravity="center_vertical|center_horizontal|left">
</TextView>
<TextView android:id="@+id/historyTextView"
android:layout_width="match_parent"
android:layout_height="70"
android:layout_height="wrap_content"
android:text="Recent transactions"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_vertical|center_horizontal|center">
@ -346,7 +345,7 @@ def get_history_layout(n):
values = get_history_values(n)
for v in values:
a,b,c,d = v
color = "0xff00ff00" if a == 'v' else "0xffff0000"
color = "#ff00ff00" if a == 'v' else "#ffff0000"
rows += """
<TableRow>
<TextView
@ -391,9 +390,9 @@ def set_history_layout(n):
droid.fullSetProperty("hl_%d_col1"%i,"text", a)
if a == 'v':
droid.fullSetProperty("hl_%d_col1"%i, "textColor","0xff00ff00")
droid.fullSetProperty("hl_%d_col1"%i, "textColor","#ff00ff00")
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_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:
text = "Not connected..."
elif wallet.blocks == 0:
@ -415,15 +416,16 @@ def update_layout():
text = "Balance:"+format_satoshis(c)
if u : text += ' [' + format_satoshis(u,True).strip() + ']'
droid.fullSetProperty("balanceTextView", "text", text)
if wallet.was_updated and wallet.up_to_date:
global first_time_update
if not first_time_update:
# vibrate if status changed
if text != status_text:
if status_text and wallet.interface.is_connected and wallet.up_to_date:
droid.vibrate()
else:
first_time_update = False
wallet.was_updated = False
status_text = text
droid.fullSetProperty("balanceTextView", "text", status_text)
if wallet.up_to_date:
set_history_layout(15)
@ -513,18 +515,34 @@ def make_new_contact():
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():
global do_refresh
update_layout()
out = None
quitting = False
while out is None:
event = droid.eventWait(1000).result # wait for 1 second
if not event:
update_layout()
event = droid.eventWait(1000).result
if event is None:
if do_refresh:
update_layout()
do_refresh = False
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
if event["name"]=="key":
@ -578,15 +596,13 @@ def payto_loop():
recipient = droid.fullQueryDetail("recipient").result.get('text')
label = droid.fullQueryDetail("label").result.get('text')
amount = droid.fullQueryDetail('amount').result.get('text')
fee = '0.001'
try:
amount = int( 100000000 * Decimal(amount) )
except:
modal_dialog('Error','invalid amount')
continue
fee = int( 100000000 * Decimal(fee) )
result = pay_to(recipient, amount, fee, label)
result = pay_to(recipient, amount, wallet.fee, label)
if result:
out = 'main'
@ -771,14 +787,12 @@ def settings_loop():
return out
menu_commands = ["send", "receive", "settings", "contacts", "main"]
first_time_update = True
menu_commands = ["send", "receive", "settings", "contacts", "main"]
droid = android.Android()
wallet = Wallet()
wallet = Wallet(update_callback)
wallet.set_path("/sdcard/electrum.dat")
wallet.read()

BIN
client/electrum_text_320.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 4.5 KiB

14
client/gui_qt.py

@ -144,6 +144,8 @@ class ElectrumWindow(QMainWindow):
def __init__(self, wallet):
QMainWindow.__init__(self)
self.wallet = wallet
self.wallet.gui_callback = self.update_callback
self.funds_error = False
self.tabs = tabs = QTabWidget(self)
@ -164,11 +166,11 @@ class ElectrumWindow(QMainWindow):
QShortcut(QKeySequence("Ctrl+Q"), self, self.close)
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() ))
self.connect(self, QtCore.SIGNAL('updatesignal'), self.update_wallet)
def connect_slots(self, sender):
self.connect(sender, QtCore.SIGNAL('timersignal'), self.update_wallet)
self.connect(sender, QtCore.SIGNAL('timersignal'), self.check_recipient)
self.previous_payto_e=''
@ -189,6 +191,9 @@ class ElectrumWindow(QMainWindow):
self.payto_e.setText(s)
def update_callback(self):
self.emit(QtCore.SIGNAL('updatesignal'))
def update_wallet(self):
if self.wallet.interface.is_connected:
if self.wallet.blocks == -1:
@ -215,8 +220,7 @@ class ElectrumWindow(QMainWindow):
self.statusBar().showMessage(text)
self.status_button.setIcon( icon )
if self.wallet.was_updated and self.wallet.up_to_date:
self.wallet.was_updated = False
if self.wallet.up_to_date:
self.textbox.setText( self.wallet.banner )
self.update_history_tab()
self.update_receive_tab()
@ -1059,4 +1063,6 @@ class ElectrumGui():
if url: w.set_url(url)
w.app = self.app
w.connect_slots(s)
w.update_wallet()
self.app.exec_()

39
client/interface.py

@ -316,6 +316,7 @@ class TcpStratumInterface(Interface):
traceback.print_exc(file=sys.stdout)
self.is_connected = False
print "poking"
self.poke()
def send(self, messages):
@ -448,27 +449,33 @@ class WalletSynchronizer(threading.Thread):
def run(self):
import socket, time
while True:
try:
while self.interface.is_connected:
new_addresses = self.wallet.synchronize()
if new_addresses:
self.interface.subscribe(new_addresses)
for addr in new_addresses:
with self.wallet.lock:
self.wallet.addresses_waiting_for_status.append(addr)
if self.wallet.is_up_to_date():
while self.interface.is_connected:
new_addresses = self.wallet.synchronize()
if new_addresses:
self.interface.subscribe(new_addresses)
for addr in new_addresses:
with self.wallet.lock:
self.wallet.addresses_waiting_for_status.append(addr)
if self.wallet.is_up_to_date():
if not self.wallet.up_to_date:
self.wallet.up_to_date = True
self.wallet.was_updated = True
self.wallet.up_to_date_event.set()
else:
else:
if self.wallet.up_to_date:
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
self.handle_response(response)
except socket.error:
print "socket error"
wallet.interface.is_connected = False
if self.wallet.was_updated:
self.wallet.gui_callback()
self.wallet.was_updated = False
response = self.interface.responses.get()
self.handle_response(response)
print "disconnected, gui callback"
self.wallet.gui_callback()
if self.loop:
time.sleep(5)
self.start_interface()

3
client/wallet.py

@ -242,10 +242,11 @@ from interface import DEFAULT_SERVERS
class Wallet:
def __init__(self):
def __init__(self, gui_callback = lambda: None):
self.electrum_version = ELECTRUM_VERSION
self.seed_version = SEED_VERSION
self.gui_callback = gui_callback
self.gap_limit = 5 # configuration
self.fee = 100000

Loading…
Cancel
Save