From 08118ca1674f58860b5a5a639372c95bc012eb80 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Sat, 11 Apr 2020 15:50:12 +0200 Subject: [PATCH] qt wizard: tweak GoBack behaviour to recalc inputs to previous dialog follow-up f13f46c555b979b265c7da9b6e340b6342f9e4b0 When on dialog n user presses "Back", - previously, we went back to when dialog n-1 appeared - now, go back to just after dialog n-2 finishes This way, any calculations between when dialog n-2 finishes and dialog n-1 appears will rerun, potentially populating dialog n-1 differently. Namely if the user presses back on the confirm_seed_dialog, we want to go back to the show_seed_dialog but with a freshly generated seed. --- electrum/base_wizard.py | 3 +++ electrum/gui/qt/installwizard.py | 22 ++++++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/electrum/base_wizard.py b/electrum/base_wizard.py index ce8fcc603..9144a9ace 100644 --- a/electrum/base_wizard.py +++ b/electrum/base_wizard.py @@ -60,6 +60,9 @@ class ScriptTypeNotSupported(Exception): pass class GoBack(Exception): pass +class ReRunDialog(Exception): pass + + class ChooseHwDeviceAgain(Exception): pass diff --git a/electrum/gui/qt/installwizard.py b/electrum/gui/qt/installwizard.py index 6918ab285..b71d9f5db 100644 --- a/electrum/gui/qt/installwizard.py +++ b/electrum/gui/qt/installwizard.py @@ -19,7 +19,7 @@ from PyQt5.QtWidgets import (QWidget, QDialog, QLabel, QHBoxLayout, QMessageBox, from electrum.wallet import Wallet, Abstract_Wallet from electrum.storage import WalletStorage, StorageReadWriteError from electrum.util import UserCancelled, InvalidPassword, WalletFileException, get_new_wallet_name -from electrum.base_wizard import BaseWizard, HWD_SETUP_DECRYPT_WALLET, GoBack +from electrum.base_wizard import BaseWizard, HWD_SETUP_DECRYPT_WALLET, GoBack, ReRunDialog from electrum.i18n import _ from .seed_dialog import SeedLayout, KeysLayout @@ -97,6 +97,7 @@ def wizard_dialog(func): run_next = kwargs['run_next'] wizard = args[0] # type: InstallWizard while True: + #wizard.logger.debug(f"dialog stack. len: {len(wizard._stack)}. stack: {wizard._stack}") wizard.back_button.setText(_('Back') if wizard.can_go_back() else _('Cancel')) # current dialog try: @@ -110,11 +111,24 @@ def wizard_dialog(func): raise # next dialog try: - run_next(*out) - except GoBack: + while True: + try: + run_next(*out) + except ReRunDialog: + # restore state, and then let the loop re-run next + wizard.go_back(rerun_previous=False) + else: + break + except GoBack as e: # to go back from the next dialog, we ask the wizard to restore state wizard.go_back(rerun_previous=False) - # and we re-run the current dialog (by continuing) + # and we re-run the current dialog + if wizard.can_go_back(): + # also rerun any calculations that might have populated the inputs to the current dialog, + # by going back to just after the *previous* dialog finished + raise ReRunDialog() from e + else: + continue else: break return func_wrapper