do not expose network to wizard. update message in issue #1972

This commit is contained in:
ThomasV 2016-10-14 14:05:24 +02:00
parent bab15a245b
commit 7ea91dde2e
6 changed files with 34 additions and 29 deletions

View File

@ -410,6 +410,7 @@ class ElectrumWindow(App):
def on_wizard_complete(self, instance, wallet): def on_wizard_complete(self, instance, wallet):
if wallet: if wallet:
wallet.start_threads(self.daemon.network)
self.daemon.add_wallet(wallet) self.daemon.add_wallet(wallet)
self.load_wallet(wallet) self.load_wallet(wallet)
self.on_resume() self.on_resume()
@ -425,7 +426,7 @@ class ElectrumWindow(App):
self.on_resume() self.on_resume()
else: else:
Logger.debug('Electrum: Wallet not found. Launching install wizard') Logger.debug('Electrum: Wallet not found. Launching install wizard')
wizard = Factory.InstallWizard(self.electrum_config, self.network, path) wizard = Factory.InstallWizard(self.electrum_config, path)
wizard.bind(on_wizard_complete=self.on_wizard_complete) wizard.bind(on_wizard_complete=self.on_wizard_complete)
action = wizard.storage.get_action() action = wizard.storage.get_action()
wizard.run(action) wizard.run(action)

View File

@ -759,7 +759,6 @@ class InstallWizard(BaseWizard, Widget):
t.start() t.start()
def terminate(self, **kwargs): def terminate(self, **kwargs):
self.wallet.start_threads(self.network)
self.dispatch('on_wizard_complete', self.wallet) self.dispatch('on_wizard_complete', self.wallet)
def choice_dialog(self, **kwargs): def choice_dialog(self, **kwargs):

View File

@ -161,12 +161,11 @@ class ElectrumGui:
else: else:
wallet = self.daemon.load_wallet(path) wallet = self.daemon.load_wallet(path)
if not wallet: if not wallet:
wizard = InstallWizard(self.config, self.app, self.plugins, self.daemon.network, path) wizard = InstallWizard(self.config, self.app, self.plugins, path)
wallet = wizard.run_and_get_wallet() wallet = wizard.run_and_get_wallet()
if not wallet: if not wallet:
return return
#if wallet.get_action(): wallet.start_threads(self.daemon.network)
# return
self.daemon.add_wallet(wallet) self.daemon.add_wallet(wallet)
w = self.create_window_for_wallet(wallet) w = self.create_window_for_wallet(wallet)
if uri: if uri:
@ -181,23 +180,31 @@ class ElectrumGui:
self.config.save_last_wallet(window.wallet) self.config.save_last_wallet(window.wallet)
run_hook('on_close_window', window) run_hook('on_close_window', window)
def init_network(self):
# Show network dialog if config does not exist
if self.daemon.network:
if self.config.get('auto_connect') is None:
wizard = InstallWizard(self.config, self.app, self.plugins, None)
wizard.init_network(self.daemon.network)
wizard.terminate()
def main(self): def main(self):
try:
self.init_network()
except:
traceback.print_exc(file=sys.stdout)
return
self.timer.start() self.timer.start()
self.config.open_last_wallet() self.config.open_last_wallet()
path = self.config.get_wallet_path() path = self.config.get_wallet_path()
if not self.start_new_window(path, self.config.get('url')): if not self.start_new_window(path, self.config.get('url')):
return return
signal.signal(signal.SIGINT, lambda *args: self.app.quit()) signal.signal(signal.SIGINT, lambda *args: self.app.quit())
# main loop # main loop
self.app.exec_() self.app.exec_()
# Shut down the timer cleanly # Shut down the timer cleanly
self.timer.stop() self.timer.stop()
# clipboard persistence. see http://www.mail-archive.com/pyqt@riverbankcomputing.com/msg17328.html # clipboard persistence. see http://www.mail-archive.com/pyqt@riverbankcomputing.com/msg17328.html
event = QtCore.QEvent(QtCore.QEvent.Clipboard) event = QtCore.QEvent(QtCore.QEvent.Clipboard)
self.app.sendEvent(self.app.clipboard(), event) self.app.sendEvent(self.app.clipboard(), event)
self.tray.hide() self.tray.hide()

View File

@ -95,9 +95,9 @@ def wizard_dialog(func):
# WindowModalDialog must come first as it overrides show_error # WindowModalDialog must come first as it overrides show_error
class InstallWizard(QDialog, MessageBoxMixin, BaseWizard): class InstallWizard(QDialog, MessageBoxMixin, BaseWizard):
def __init__(self, config, app, plugins, network, storage): def __init__(self, config, app, plugins, storage):
BaseWizard.__init__(self, config, network, storage) BaseWizard.__init__(self, config, storage)
QDialog.__init__(self, None) QDialog.__init__(self, None)
self.setWindowTitle('Electrum - ' + _('Install Wizard')) self.setWindowTitle('Electrum - ' + _('Install Wizard'))
@ -146,10 +146,6 @@ class InstallWizard(QDialog, MessageBoxMixin, BaseWizard):
self.refresh_gui() # Need for QT on MacOSX. Lame. self.refresh_gui() # Need for QT on MacOSX. Lame.
def run_and_get_wallet(self): def run_and_get_wallet(self):
# Show network dialog if config does not exist
if self.network:
if self.config.get('auto_connect') is None:
self.choose_server(self.network)
path = self.storage.path path = self.storage.path
if self.storage.requires_split(): if self.storage.requires_split():
@ -337,7 +333,6 @@ class InstallWizard(QDialog, MessageBoxMixin, BaseWizard):
self.run(action) self.run(action)
def terminate(self): def terminate(self):
self.wallet.start_threads(self.network)
self.emit(QtCore.SIGNAL('accept')) self.emit(QtCore.SIGNAL('accept'))
def waiting_dialog(self, task, msg): def waiting_dialog(self, task, msg):
@ -391,25 +386,29 @@ class InstallWizard(QDialog, MessageBoxMixin, BaseWizard):
self.set_main_layout(vbox, _('Master Public Key')) self.set_main_layout(vbox, _('Master Public Key'))
return None return None
def choose_server(self, network): def init_network(self, network):
title = _("Electrum communicates with remote servers to get " message = _("Electrum communicates with remote servers to get "
"information about your transactions and addresses. The " "information about your transactions and addresses. The "
"servers all fulfil the same purpose only differing in " "servers all fulfil the same purpose only differing in "
"hardware. In most cases you simply want to let Electrum " "hardware. In most cases you simply want to let Electrum "
"pick one at random. However if you prefer feel free to " "pick one at random. However if you prefer feel free to "
"select a server manually.") "select a server manually.")
choices = [_("Auto connect"), _("Select server manually")] choices = [_("Auto connect"), _("Select server manually")]
choices_title = _("How do you want to connect to a server? ") title = _("How do you want to connect to a server? ")
clayout = ChoicesLayout(choices_title, choices) clayout = ChoicesLayout(message, choices)
self.set_main_layout(clayout.layout(), title) self.set_main_layout(clayout.layout(), title)
auto_connect = True r = clayout.selected_index()
if clayout.selected_index() == 1: if r == 0:
auto_connect = True
elif r == 1:
auto_connect = True
nlayout = NetworkChoiceLayout(network, self.config, wizard=True) nlayout = NetworkChoiceLayout(network, self.config, wizard=True)
if self.set_main_layout(nlayout.layout(), raise_on_cancel=False): if self.set_main_layout(nlayout.layout()):
nlayout.accept()
auto_connect = False auto_connect = False
self.config.set_key('auto_connect', auto_connect, True) else:
auto_connect = True
network.auto_connect = auto_connect network.auto_connect = auto_connect
self.config.set_key('auto_connect', auto_connect, True)
@wizard_dialog @wizard_dialog
def multisig_dialog(self, run_next): def multisig_dialog(self, run_next):

View File

@ -73,7 +73,7 @@ class NetworkChoiceLayout(object):
else: else:
status += "\n" + _("Disconnected from server") status += "\n" + _("Disconnected from server")
else: else:
status = _("Please choose a server.") + "\n" + _("Select 'Cancel' if you are offline.") status = _("Please choose a server.") + "\n" + _("Press 'Next' if you are offline.")
vbox = QVBoxLayout() vbox = QVBoxLayout()
hbox = QHBoxLayout() hbox = QHBoxLayout()

View File

@ -32,10 +32,9 @@ from plugins import run_hook
class BaseWizard(object): class BaseWizard(object):
def __init__(self, config, network, path): def __init__(self, config, path):
super(BaseWizard, self).__init__() super(BaseWizard, self).__init__()
self.config = config self.config = config
self.network = network
self.storage = WalletStorage(path) self.storage = WalletStorage(path)
self.wallet = None self.wallet = None
self.stack = [] self.stack = []