tBring the network dialog into the new framework - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 9390a97e9ee272c21c1f04bdda26625db1beb7ba DIR parent 4c9b224d4c08f8c3fd140bddc1bff53f7e6c4e8e HTML Author: Neil Booth <kyuupichan@gmail.com> Date: Wed, 13 Jan 2016 20:34:42 +0900 Bring the network dialog into the new framework Diffstat: M gui/qt/installwizard.py | 65 ++++++++++++++----------------- M gui/qt/network_dialog.py | 34 ++++++++++++++++++------------- M lib/wizard.py | 10 ++++++++-- 3 files changed, 58 insertions(+), 51 deletions(-) --- DIR diff --git a/gui/qt/installwizard.py b/gui/qt/installwizard.py t@@ -8,7 +8,7 @@ import electrum from electrum.i18n import _ from seed_dialog import SeedDisplayLayout, SeedWarningLayout, SeedInputLayout -from network_dialog import NetworkDialog +from network_dialog import NetworkChoiceLayout from util import * from password_dialog import PasswordLayout, PW_NEW, PW_PASSPHRASE t@@ -110,12 +110,17 @@ class InstallWizard(WindowModalDialog, WizardBase): self.show() self.raise_() + def finished(self): + '''Ensure the dialog is closed.''' + self.accept() + self.refresh_gui() + def set_icon(self, filename): prior_filename, self.icon_filename = self.icon_filename, filename self.logo.setPixmap(QPixmap(filename).scaledToWidth(70)) return prior_filename - def set_main_layout(self, layout, title=None): + def set_main_layout(self, layout, title=None, raise_on_cancel=True): self.title.setText(title or "") self.title.setVisible(bool(title)) # Get rid of any prior layout t@@ -127,7 +132,8 @@ class InstallWizard(WindowModalDialog, WizardBase): self.next_button.setEnabled(True) self.main_widget.setVisible(True) self.please_wait.setVisible(False) - if not self.loop.exec_(): + result = self.loop.exec_() + if not result and raise_on_cancel: raise UserCancelled self.title.setVisible(False) self.cancel_button.setEnabled(False) t@@ -135,6 +141,7 @@ class InstallWizard(WindowModalDialog, WizardBase): self.main_widget.setVisible(False) self.please_wait.setVisible(True) self.refresh_gui() + return result def refresh_gui(self): # For some reason, to refresh the GUI this needs to be called twice t@@ -204,9 +211,6 @@ class InstallWizard(WindowModalDialog, WizardBase): the password or None for no password.""" return self.pw_layout(msg or MSG_ENTER_PASSWORD, PW_NEW) - def choose_server(self, network): - self.network_dialog(network) - def show_restore(self, wallet, network): if network: def task(): t@@ -295,35 +299,26 @@ class InstallWizard(WindowModalDialog, WizardBase): self.set_main_layout(vbox) return get_texts() - def network_dialog(self, network): - grid = QGridLayout() - grid.setSpacing(5) - label = QLabel(_("Electrum communicates with remote servers to get information about your transactions and addresses. The servers all fulfil the same purpose only differing in hardware. In most cases you simply want to let Electrum pick one at random if you have a preference though feel free to select a server manually.") + "\n\n" \ - + _("How do you want to connect to a server:")+" ") - label.setWordWrap(True) - grid.addWidget(label, 0, 0) - gb = QGroupBox() - b1 = QRadioButton(gb) - b1.setText(_("Auto connect")) - b1.setChecked(True) - b2 = QRadioButton(gb) - b2.setText(_("Select server manually")) - grid.addWidget(b1,1,0) - grid.addWidget(b2,2,0) - vbox = QVBoxLayout() - vbox.addLayout(grid) - vbox.addStretch(1) - vbox.addLayout(Buttons(CancelButton(self), OkButton(self, _('Next')))) - - self.set_layout(vbox) - if not self.exec_(): - return - - if b2.isChecked(): - NetworkDialog(network, self.config, None).do_exec() - else: - self.config.set_key('auto_connect', True, True) - network.auto_connect = True + def choose_server(self, network): + title = _("Electrum communicates with remote servers to get " + "information about your transactions and addresses. The " + "servers all fulfil the same purpose only differing in " + "hardware. In most cases you simply want to let Electrum " + "pick one at random. However if you prefer feel free to " + "select a server manually.") + choices = [_("Auto connect"), _("Select server manually")] + choices_title = _("How do you want to connect to a server? ") + clayout = ChoicesLayout(choices_title, choices) + self.set_main_layout(clayout.layout(), title) + + auto_connect = True + if clayout.selected_index() == 1: + nlayout = NetworkChoiceLayout(network, self.config, wizard=True) + if self.set_main_layout(nlayout.layout(), raise_on_cancel=False): + nlayout.accept() + auto_connect = False + self.config.set_key('auto_connect', auto_connect, True) + network.auto_connect = auto_connect def query_choice(self, msg, choices): clayout = ChoicesLayout(msg, choices) DIR diff --git a/gui/qt/network_dialog.py b/gui/qt/network_dialog.py t@@ -32,7 +32,20 @@ class NetworkDialog(WindowModalDialog): def __init__(self, network, config, parent): WindowModalDialog.__init__(self, parent, _('Network')) self.setMinimumSize(375, 20) + self.nlayout = NetworkChoiceLayout(network, config) + vbox = QVBoxLayout(self) + vbox.addLayout(nlayout.layout()) + vbox.addLayout(Buttons(CancelButton(self), OkButton(self))) + + def do_exec(self): + result = self.exec_() + if result: + self.nlayout.accept() + return result + +class NetworkChoiceLayout(object): + def __init__(self, network, config, wizard=False): self.network = network self.config = config self.protocol = None t@@ -42,7 +55,7 @@ class NetworkDialog(WindowModalDialog): if not proxy_config: proxy_config = { "mode":"none", "host":"localhost", "port":"9050"} - if parent: + if not wizard: n = len(network.get_interfaces()) if n: status = _("Blockchain") + ": " + "%d "%(network.get_local_height()) + _("blocks") + ".\n" + _("Getting block headers from %d nodes.")%n t@@ -56,7 +69,6 @@ class NetworkDialog(WindowModalDialog): status = _("Please choose a server.") + "\n" + _("Select 'Cancel' if you are offline.") vbox = QVBoxLayout() - vbox.setSpacing(30) hbox = QHBoxLayout() l = QLabel() l.setPixmap(QPixmap(":icons/network.png")) t@@ -69,6 +81,7 @@ class NetworkDialog(WindowModalDialog): + _("This blockchain is used to verify the transactions sent by the address server.") hbox.addWidget(HelpButton(msg)) vbox.addLayout(hbox) + vbox.addSpacing(15) # grid layout grid = QGridLayout() t@@ -101,7 +114,7 @@ class NetworkDialog(WindowModalDialog): self.autoconnect_cb.setToolTip(msg) label = _('Active Servers') if network.is_connected() else _('Default Servers') - self.servers_list_widget = QTreeWidget(parent) + self.servers_list_widget = QTreeWidget() self.servers_list_widget.setHeaderLabels( [ label, _('Limit') ] ) self.servers_list_widget.setMaximumHeight(150) self.servers_list_widget.setColumnWidth(0, 240) t@@ -155,11 +168,10 @@ class NetworkDialog(WindowModalDialog): grid.addWidget(self.proxy_mode, 4, 1) grid.addWidget(self.proxy_host, 4, 2) grid.addWidget(self.proxy_port, 4, 3) + self.layout_ = vbox - # buttons - vbox.addLayout(Buttons(CancelButton(self), OkButton(self))) - self.setLayout(vbox) - + def layout(self): + return self.layout_ def init_servers_list(self): self.servers_list_widget.clear() t@@ -211,12 +223,7 @@ class NetworkDialog(WindowModalDialog): self.server_port.setText( port ) self.ssl_cb.setChecked(protocol=='s') - - def do_exec(self): - - if not self.exec_(): - return - + def accept(self): host = str(self.server_host.text()) port = str(self.server_port.text()) protocol = 's' if self.ssl_cb.isChecked() else 't' t@@ -236,4 +243,3 @@ class NetworkDialog(WindowModalDialog): auto_connect = self.autoconnect_cb.isChecked() self.network.set_parameters(host, port, protocol, proxy, auto_connect) - return True DIR diff --git a/lib/wizard.py b/lib/wizard.py t@@ -119,6 +119,10 @@ class WizardBase(PrintError): """Show restore result""" pass + def finished(self): + """Called when the wizard is done.""" + pass + @classmethod def open_wallet(self, network, filename, config, create_wizard): '''The main entry point of the wizard. Open a wallet from the given t@@ -156,7 +160,7 @@ class WizardBase(PrintError): if network: # Show network dialog if config does not exist - if config.get('server') is None: + if config.get('auto_connect') is None: wizard().choose_server(network) else: wizard().show_warning(_('You are offline')) t@@ -171,7 +175,9 @@ class WizardBase(PrintError): if is_restore: wizard().show_restore(wallet, network) - self.my_wizard = None + if self.my_wizard: + self.my_wizard.finished() + self.my_wizard = None return wallet