Browse Source

call load_wallet and close_wallet for each plugin

master
ThomasV 11 years ago
parent
commit
dda4a0fcb3
  1. 9
      gui/qt/main_window.py
  2. 25
      lib/plugins.py
  3. 2
      plugins/trezor.py

9
gui/qt/main_window.py

@ -203,6 +203,7 @@ class ElectrumWindow(QMainWindow):
def close_wallet(self): def close_wallet(self):
self.wallet.stop_threads() self.wallet.stop_threads()
self.hide()
run_hook('close_wallet') run_hook('close_wallet')
def load_wallet(self, wallet): def load_wallet(self, wallet):
@ -210,13 +211,17 @@ class ElectrumWindow(QMainWindow):
self.wallet = wallet self.wallet = wallet
self.update_wallet_format() self.update_wallet_format()
# address used to create a dummy transaction and estimate transaction fee # address used to create a dummy transaction and estimate transaction fee
self.dummy_address = self.wallet.addresses(False)[0] a = self.wallet.addresses(False)
self.dummy_address = a[0] if a else None
self.invoices = self.wallet.storage.get('invoices', {}) self.invoices = self.wallet.storage.get('invoices', {})
self.accounts_expanded = self.wallet.storage.get('accounts_expanded',{}) self.accounts_expanded = self.wallet.storage.get('accounts_expanded',{})
self.current_account = self.wallet.storage.get("current_account", None) self.current_account = self.wallet.storage.get("current_account", None)
title = 'Electrum ' + self.wallet.electrum_version + ' - ' + os.path.basename(self.wallet.storage.path) title = 'Electrum ' + self.wallet.electrum_version + ' - ' + os.path.basename(self.wallet.storage.path)
if self.wallet.is_watching_only(): title += ' [%s]' % (_('watching only')) if self.wallet.is_watching_only(): title += ' [%s]' % (_('watching only'))
self.setWindowTitle( title ) self.setWindowTitle( title )
self.update_history_tab()
self.show()
self.update_wallet() self.update_wallet()
# Once GUI has been initialized check if we want to announce something since the callback has been called before the GUI was initialized # Once GUI has been initialized check if we want to announce something since the callback has been called before the GUI was initialized
self.notify_transactions() self.notify_transactions()
@ -308,6 +313,8 @@ class ElectrumWindow(QMainWindow):
QMessageBox.critical(None, "Error", _("File exists")) QMessageBox.critical(None, "Error", _("File exists"))
return return
if self.wallet:
self.close_wallet()
wizard = installwizard.InstallWizard(self.config, self.network, storage) wizard = installwizard.InstallWizard(self.config, self.network, storage)
wallet = wizard.run('new') wallet = wizard.run('new')
if wallet: if wallet:

25
lib/plugins.py

@ -45,16 +45,17 @@ def run_hook(name, *args):
for p, f in f_list: for p, f in f_list:
if name == 'load_wallet': if name == 'load_wallet':
p.wallet = args[0] p.wallet = args[0]
if not p.is_enabled(): if p.is_enabled():
continue try:
try: r = f(*args)
r = f(*args) except Exception:
except Exception: print_error("Plugin error")
print_error("Plugin error") traceback.print_exc(file=sys.stdout)
traceback.print_exc(file=sys.stdout) r = False
r = False if r:
if r: results.append(r)
results.append(r) if name == 'close_wallet':
p.wallet = None
if results: if results:
assert len(results) == 1, results assert len(results) == 1, results
@ -92,8 +93,12 @@ class BasePlugin:
def init_qt(self, gui): pass def init_qt(self, gui): pass
@hook
def load_wallet(self, wallet): pass def load_wallet(self, wallet): pass
@hook
def close_wallet(self): pass
#def init(self): pass #def init(self): pass
def close(self): pass def close(self): pass

2
plugins/trezor.py

@ -93,7 +93,7 @@ class Plugin(BasePlugin):
@hook @hook
def close_wallet(self): def close_wallet(self):
print_error("trezor: clear session") print_error("trezor: clear session")
if self.wallet.client: if self.wallet and self.wallet.client:
self.wallet.client.clear_session() self.wallet.client.clear_session()
@hook @hook

Loading…
Cancel
Save