From 5744131e186c8b3b580e424f5f71ede45e028dd4 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Sat, 7 Apr 2012 15:13:18 +0200 Subject: [PATCH] callbacks --- client/electrum4a.py | 70 +++++++++++++++++++++-------------- client/electrum_text_320.png | Bin 4882 -> 4634 bytes client/gui_qt.py | 14 +++++-- client/interface.py | 39 +++++++++++-------- client/wallet.py | 3 +- 5 files changed, 77 insertions(+), 49 deletions(-) diff --git a/client/electrum4a.py b/client/electrum4a.py index f670ccb79..6ec8fe98c 100755 --- a/client/electrum4a.py +++ b/client/electrum4a.py @@ -152,19 +152,18 @@ def main_layout(): return make_layout(""" + android:textSize="6pt" + android:gravity="center_vertical|center_horizontal|left"> - @@ -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 += """ fj~O^kg@wp<}hwP zDXrVHS2ga3Y5>BqwpJEy@zd+Ll&?P4vEA)|7>k?cUK26PW^o`kXt<8g{@PpVJ^ly9m2Fv|X1Bh!s_y93CXA4g8|8Xp3Hg4*?)#%%6 zuHbhybB(?9*7T+XWvo?d(Egg!v44d@2)AMhIYFNi(F7DEc?7lf4t@|y+ZNj~`&lPF zgFYL@XU4l$TzKQ;C@LtTK8wtYN!E>)jXuh_N_*YY40NiF9bp+&gecGS2 zLFmj4y^VSaRGZ+N2^2+@a2axVTEMLQ`#!D-hi3Pq$DnyL@SN>a*pC`&hX@AJXUKlKLus{iZVD% z4AR3vv?sdEg?l~Hw|~cfipe8dz}p^(uy)h9mv+8TYl2=#u|qk2vwsF%KEP8pJWW)8k z+4@i7F=%1 zj=8AJD7aSAsq4B4T$*?Gz6%R)P^j|*gcDQ%s`evAzE6OmL_@rE-iSr6bC?w_#~7nW zaB3Oi)V67+#wtgLS5!}x(oF^8$7)D)DI9AlI=ym9S*rD7&3m3+6Kg| zI$~HqwOMJ?@r|2L(-1MM(IM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L|=4%)#eQO*ywt1Bvosx%ke{8<<_{pz= zNR?XpHvr2avEXQq^oPa8X-F`T%irY%W-i2rtUdx{v>`3DUZaP zN!hXW9s6m(_y7t%ih~`gXqFS9r<)IZ*Ts7b@0=&8WO>CL`%`PjgNE*{q0at(j2!y@ z_ukQ>y*IyTaRK77=G~#?c+&afGI^VtF|P;$D5a|BFwqdvdhGmNX@#Eg?Y|A9Ol#ctaX(4D z{rAqkDTeW*KI;_x6pW%5g@@`8ZN>MPB7@SqB9mjY1n+KD4y55z4@B5$o3?buIll?= z{y6P>?HJw-oKA(WGyjt?@?XT0|3^07V4jd!;&NJPVaBCBbqe6>?CJFUL}=Fk0n6wv A@&Et; diff --git a/client/gui_qt.py b/client/gui_qt.py index 66f61cefc..9c2dc7524 100644 --- a/client/gui_qt.py +++ b/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_() diff --git a/client/interface.py b/client/interface.py index 56ad9e612..bdba222dd 100644 --- a/client/interface.py +++ b/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() diff --git a/client/wallet.py b/client/wallet.py index d0418ebef..906b53677 100644 --- a/client/wallet.py +++ b/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