instantiate wizard only if needed

This commit is contained in:
ThomasV 2016-01-13 11:27:17 +01:00
parent 0219687d41
commit 632905dfbe
3 changed files with 58 additions and 50 deletions

View File

@ -143,6 +143,9 @@ class ElectrumGui:
run_hook('on_new_window', w)
return w
def get_wizard(self):
return InstallWizard(self.config, self.app, self.plugins)
def start_new_window(self, path, uri):
'''Raises the window for the wallet if it is open. Otherwise
opens the wallet and creates a new window for it.'''
@ -151,8 +154,7 @@ class ElectrumGui:
w.bring_to_top()
break
else:
wizard = InstallWizard(self.config, self.app, self.plugins)
wallet = self.daemon.load_wallet(path, wizard)
wallet = self.daemon.load_wallet(path, self.get_wizard)
if not wallet:
return
w = self.create_window_for_wallet(wallet)

View File

@ -120,12 +120,12 @@ class Daemon(DaemonThread):
response = "Error: Electrum is running in daemon mode. Please stop the daemon first."
return response
def load_wallet(self, path, wizard=None):
def load_wallet(self, path, get_wizard):
if path in self.wallets:
wallet = self.wallets[path]
else:
if wizard:
wallet = wizard.open_wallet(self.network, path)
if get_wizard:
wallet = self.open_wallet_with_wizard(self.network, path, get_wizard)
else:
storage = WalletStorage(path)
wallet = Wallet(storage)
@ -134,6 +134,57 @@ class Daemon(DaemonThread):
self.wallets[path] = wallet
return wallet
def open_wallet_with_wizard(self, network, filename, get_wizard):
'''Instantiate wizard only if needed'''
storage = WalletStorage(filename)
need_sync = False
is_restore = False
self.wizard = None
def wizard():
if self.wizard is None:
self.wizard = get_wizard()
return self.wizard
if storage.file_exists:
wallet = Wallet(storage)
#self.update_wallet_format(wallet)
else:
cr, wallet = wizard().create_or_restore(storage)
if not wallet:
return
need_sync = True
is_restore = (cr == 'restore')
while True:
action = wallet.get_action()
if not action:
break
need_sync = True
wizard().run_wallet_action(wallet, action)
# Save the wallet after each action
wallet.storage.write()
if network:
# Show network dialog if config does not exist
if self.config.get('server') is None:
wizard().choose_server(network)
else:
wizard().show_warning(_('You are offline'))
if need_sync:
wizard().create_addresses(wallet)
# start wallet threads
if network:
wallet.start_threads(network)
if is_restore:
wizard().show_restore(wallet, network)
return wallet
def run_cmdline(self, config_options):
config = SimpleConfig(config_options)
cmdname = config.get('cmd')

View File

@ -119,51 +119,6 @@ class WizardBase(PrintError):
"""Show restore result"""
pass
def open_wallet(self, network, filename):
'''The main entry point of the wizard. Open a wallet from the given
filename. If the file doesn't exist launch the GUI-specific
install wizard proper.'''
storage = WalletStorage(filename)
need_sync = False
is_restore = False
if storage.file_exists:
wallet = Wallet(storage)
self.update_wallet_format(wallet)
else:
cr, wallet = self.create_or_restore(storage)
if not wallet:
return
need_sync = True
is_restore = (cr == 'restore')
while True:
action = wallet.get_action()
if not action:
break
need_sync = True
self.run_wallet_action(wallet, action)
# Save the wallet after each action
wallet.storage.write()
if network:
# Show network dialog if config does not exist
if self.config.get('server') is None:
self.choose_server(network)
else:
self.show_warning(_('You are offline'))
if need_sync:
self.create_addresses(wallet)
# start wallet threads
if network:
wallet.start_threads(network)
if is_restore:
self.show_restore(wallet, network)
return wallet
def run_wallet_action(self, wallet, action):