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,16 +185,14 @@ 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
if not found:

2
lib/gui_lite.py

@ -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

12
lib/interface.py

@ -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

13
lib/wallet.py

@ -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):
@ -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
@ -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]

Loading…
Cancel
Save