Browse Source

allow multiple callbacks for a given name

283
thomasv 12 years ago
parent
commit
0b76e16d04
  1. 6
      electrum
  2. 2
      lib/gui_lite.py
  3. 12
      lib/interface.py
  4. 13
      lib/wallet.py

6
electrum

@ -185,15 +185,13 @@ if __name__ == '__main__':
sys.exit("Error: Unknown GUI: " + pref_gui ) sys.exit("Error: Unknown GUI: " + pref_gui )
interface = Interface(config, True) interface = Interface(config, True)
interface.start()
wallet.interface = interface wallet.interface = interface
gui = gui.ElectrumGui(wallet, config) gui = gui.ElectrumGui(wallet, config)
interface.register_callback('peers', gui.server_list_changed) interface.register_callback('peers', gui.server_list_changed)
# need to wait until interface is connected..
interface.start()
WalletSynchronizer(wallet, config).start() WalletSynchronizer(wallet, config).start()
WalletVerifier(wallet, config).start() WalletVerifier(wallet, config).start()
try: try:
found = config.wallet_file_exists found = config.wallet_file_exists

2
lib/gui_lite.py

@ -801,6 +801,8 @@ class MiniDriver(QObject):
self.window = window self.window = window
self.wallet.interface.register_callback('updated',self.update_callback) 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 self.state = None

12
lib/interface.py

@ -49,15 +49,15 @@ class Interface(threading.Thread):
def register_callback(self, event, callback): def register_callback(self, event, callback):
with self.lock: 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): def trigger_callback(self, event):
with self.lock: with self.lock:
callback = self.callbacks.get(event) callbacks = self.callbacks.get(event,[])[:]
if callback: if callbacks:
callback() [callback() for callback in callbacks]
def init_server(self, host, port, proxy=None, use_ssl=True): def init_server(self, host, port, proxy=None, use_ssl=True):
self.host = host self.host = host

13
lib/wallet.py

@ -844,9 +844,6 @@ class WalletSynchronizer(threading.Thread):
self.wallet.up_to_date = False self.wallet.up_to_date = False
self.wallet.was_updated = True 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): def subscribe_to_addresses(self, addresses):
@ -868,6 +865,10 @@ class WalletSynchronizer(threading.Thread):
# 1. send new requests # 1. send new requests
self.synchronize_wallet() self.synchronize_wallet()
if self.wallet.was_updated:
self.interface.trigger_callback('updated')
self.wallet.was_updated = False
# 2. get a response # 2. get a response
r = self.interface.get_response('synchronizer') r = self.interface.get_response('synchronizer')
if not r: continue if not r: continue
@ -918,11 +919,15 @@ class WalletSynchronizer(threading.Thread):
elif method == 'server.banner': elif method == 'server.banner':
self.wallet.banner = result self.wallet.banner = result
self.interface.trigger_callback('updated') self.wallet.was_updated = True
else: else:
print_error("Error: Unknown message:" + method + ", " + repr(params) + ", " + repr(result) ) 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') encode = lambda x: x[::-1].encode('hex')
decode = lambda x: x.decode('hex')[::-1] decode = lambda x: x.decode('hex')[::-1]

Loading…
Cancel
Save