From ac5ebb9204d1ad2205a686dc877d87013c05aa22 Mon Sep 17 00:00:00 2001 From: Sander van Grieken Date: Thu, 3 Aug 2023 12:14:49 +0200 Subject: [PATCH] qt: refactor please_wait layout to widget to better control UI, add in-page error view --- electrum/gui/qt/wizard/server_connect.py | 4 +++ electrum/gui/qt/wizard/wallet.py | 6 ++++ electrum/gui/qt/wizard/wizard.py | 36 ++++++++++++++++++------ 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/electrum/gui/qt/wizard/server_connect.py b/electrum/gui/qt/wizard/server_connect.py index 030f7a6ca..ab2c40b08 100644 --- a/electrum/gui/qt/wizard/server_connect.py +++ b/electrum/gui/qt/wizard/server_connect.py @@ -43,6 +43,7 @@ class WCAutoConnect(WizardComponent): choices = [_("Auto connect"), _("Select server manually")] self.clayout = ChoicesLayout(message, choices, on_clicked=self.on_updated) self.layout().addLayout(self.clayout.layout()) + self.layout().addStretch(1) self._valid = True def apply(self): @@ -65,6 +66,7 @@ class WCProxyAsk(WizardComponent): choices = [_("Yes"), _("No")] self.clayout = ChoicesLayout(message, choices) self.layout().addLayout(self.clayout.layout()) + self.layout().addStretch(1) self._valid = True def apply(self): @@ -77,6 +79,7 @@ class WCProxyConfig(WizardComponent): WizardComponent.__init__(self, parent, wizard, title=_("Proxy")) pw = ProxyWidget(self) self.layout().addWidget(pw) + self.layout().addStretch(1) def apply(self): # TODO @@ -88,6 +91,7 @@ class WCServerConfig(WizardComponent): WizardComponent.__init__(self, parent, wizard, title=_("Server")) sw = ServerWidget(self) self.layout().addWidget(sw) + self.layout().addStretch(1) def apply(self): # TODO diff --git a/electrum/gui/qt/wizard/wallet.py b/electrum/gui/qt/wizard/wallet.py index 9b20051b7..0509890fb 100644 --- a/electrum/gui/qt/wizard/wallet.py +++ b/electrum/gui/qt/wizard/wallet.py @@ -180,6 +180,7 @@ class WCWalletName(WizardComponent): widget_create_new.setLayout(vbox_create_new) vbox_create_new.setContentsMargins(0, 0, 0, 0) self.layout().addWidget(widget_create_new) + self.layout().addStretch(1) temp_storage = None # type: Optional[WalletStorage] wallet_folder = os.path.dirname(path) @@ -268,6 +269,7 @@ class WCWalletType(WizardComponent): c_titles = [x[1] for x in choices] self.clayout = ChoicesLayout(message, c_titles) self.layout().addLayout(self.clayout.layout()) + self.layout().addStretch(1) self._valid = True def apply(self): @@ -289,6 +291,7 @@ class WCKeystoreType(WizardComponent): c_titles = [x[1] for x in choices] self.clayout = ChoicesLayout(message, c_titles) self.layout().addLayout(self.clayout.layout()) + self.layout().addStretch(1) self._valid = True def apply(self): @@ -327,6 +330,7 @@ class WCCreateSeed(WizardComponent): config=self.wizard.config, ) self.layout().addLayout(self.slayout) + self.layout().addStretch(1) self.busy = False self.valid = True @@ -466,6 +470,7 @@ class WCHaveSeed(WizardComponent): self.slayout.updated.connect(self.validate) self.layout().addLayout(self.slayout) + self.layout().addStretch(1) def is_seed(self, x): if self.wizard_data['wallet_type'] == 'standard': @@ -780,6 +785,7 @@ class WCMultisig(WizardComponent): self.layout().addLayout(grid) self.layout().addSpacing(2 * char_width_in_lineedit()) self.layout().addWidget(backup_warning_label) + self.layout().addStretch(1) self.n_edit = n_edit self.m_edit = m_edit diff --git a/electrum/gui/qt/wizard/wizard.py b/electrum/gui/qt/wizard/wizard.py index 62e356611..b07c30e48 100644 --- a/electrum/gui/qt/wizard/wizard.py +++ b/electrum/gui/qt/wizard/wizard.py @@ -41,19 +41,34 @@ class QEAbstractWizard(QDialog): self.logo = QLabel() - self.please_wait_layout = QVBoxLayout() - self.please_wait_layout.addStretch(1) - self.please_wait = QLabel(_("Please wait...")) - self.please_wait.setAlignment(Qt.AlignCenter) - self.please_wait.setVisible(False) - self.please_wait_layout.addWidget(self.please_wait) - self.please_wait_layout.addStretch(1) + please_wait_layout = QVBoxLayout() + please_wait_layout.addStretch(1) + please_wait_l = QLabel(_("Please wait...")) + please_wait_l.setAlignment(Qt.AlignCenter) + please_wait_layout.addWidget(please_wait_l) + please_wait_layout.addStretch(1) + self.please_wait = QWidget() + self.please_wait.setLayout(please_wait_layout) + + error_layout = QVBoxLayout() + error_layout.addStretch(1) + error_l = QLabel(_("Error!")) + error_l.setAlignment(Qt.AlignCenter) + error_layout.addWidget(error_l) + self.error_msg = QLabel() + self.error_msg.setAlignment(Qt.AlignCenter) + error_layout.addWidget(self.error_msg) + error_layout.addStretch(1) + self.error = QWidget() + self.error.setLayout(error_layout) outer_vbox = QVBoxLayout(self) inner_vbox = QVBoxLayout() inner_vbox.addWidget(self.title) inner_vbox.addWidget(self.main_widget) - inner_vbox.addLayout(self.please_wait_layout) + inner_vbox.addWidget(self.please_wait) + inner_vbox.addWidget(self.error) + scroll_widget = QWidget() scroll_widget.setLayout(inner_vbox) scroll = QScrollArea() @@ -139,8 +154,10 @@ class QEAbstractWizard(QDialog): self.back_button.setText(_('Back') if self.can_go_back() else _('Cancel')) self.next_button.setText(_('Next') if not self.is_last(page.wizard_data) else _('Finish')) self.next_button.setEnabled(page.valid) - self.main_widget.setVisible(not page.busy) + self.main_widget.setVisible(not page.busy and not bool(page.error)) self.please_wait.setVisible(page.busy) + self.error_msg.setText(str(page.error)) + self.error.setVisible(not page.busy and bool(page.error)) icon = page.params.get('icon', icon_path('electrum.png')) if icon != self.icon_filename: self.set_icon(icon) @@ -195,6 +212,7 @@ class WizardComponent(QWidget): self.wizard_data = {} self.title = title if title is not None else 'No title' self.wizard = wizard + self.error = '' self._valid = False self._busy = False