tallow multiple callbacks for a given name - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 0b76e16d04dd28fbda32b2855dfe8cb9b8a4953a DIR parent 82531131ee6c0d588a3425ac16714f08d6399f45 HTML Author: thomasv <thomasv@gitorious> Date: Mon, 22 Oct 2012 13:43:58 +0200 allow multiple callbacks for a given name Diffstat: M electrum | 6 ++---- M lib/gui_lite.py | 2 ++ M lib/interface.py | 12 ++++++------ M lib/wallet.py | 13 +++++++++---- 4 files changed, 19 insertions(+), 14 deletions(-) --- DIR diff --git a/electrum b/electrum t@@ -185,15 +185,13 @@ if __name__ == '__main__': sys.exit("Error: Unknown GUI: " + pref_gui ) interface = Interface(config, True) - interface.start() wallet.interface = interface - gui = gui.ElectrumGui(wallet, config) interface.register_callback('peers', gui.server_list_changed) - # need to wait until interface is connected.. + + interface.start() WalletSynchronizer(wallet, config).start() WalletVerifier(wallet, config).start() - try: found = config.wallet_file_exists DIR diff --git a/lib/gui_lite.py b/lib/gui_lite.py t@@ -801,6 +801,8 @@ class MiniDriver(QObject): self.window = window self.wallet.interface.register_callback('updated',self.update_callback) + self.wallet.interface.register_callback('connected', self.update_callback) + self.wallet.interface.register_callback('disconnected', self.update_callback) self.state = None DIR diff --git a/lib/interface.py b/lib/interface.py t@@ -49,15 +49,15 @@ class Interface(threading.Thread): def register_callback(self, event, callback): with self.lock: - self.callbacks[event] = callback + if not self.callbacks.get(event): + self.callbacks[event] = [] + self.callbacks[event].append(callback) def trigger_callback(self, event): with self.lock: - callback = self.callbacks.get(event) - if callback: - callback() - - + callbacks = self.callbacks.get(event,[])[:] + if callbacks: + [callback() for callback in callbacks] def init_server(self, host, port, proxy=None, use_ssl=True): self.host = host DIR diff --git a/lib/wallet.py b/lib/wallet.py t@@ -844,9 +844,6 @@ class WalletSynchronizer(threading.Thread): self.wallet.up_to_date = False self.wallet.was_updated = True - if self.wallet.was_updated: - self.interface.trigger_callback('updated') - self.wallet.was_updated = False def subscribe_to_addresses(self, addresses): t@@ -868,6 +865,10 @@ class WalletSynchronizer(threading.Thread): # 1. send new requests self.synchronize_wallet() + if self.wallet.was_updated: + self.interface.trigger_callback('updated') + self.wallet.was_updated = False + # 2. get a response r = self.interface.get_response('synchronizer') if not r: continue t@@ -918,11 +919,15 @@ class WalletSynchronizer(threading.Thread): elif method == 'server.banner': self.wallet.banner = result - self.interface.trigger_callback('updated') + self.wallet.was_updated = True else: print_error("Error: Unknown message:" + method + ", " + repr(params) + ", " + repr(result) ) + if self.wallet.was_updated: + self.interface.trigger_callback('updated') + self.wallet.was_updated = False + encode = lambda x: x[::-1].encode('hex') decode = lambda x: x.decode('hex')[::-1]