Browse Source

qt: initial open existing wallet from wizard,

set window title for wizard dialogs,
catch RuntimeError for WizardComponent.updated signal, widget might be gone
master
Sander van Grieken 2 years ago
parent
commit
83c2eb46bb
  1. 2
      electrum/gui/qt/wizard/server_connect.py
  2. 53
      electrum/gui/qt/wizard/wallet.py
  3. 3
      electrum/gui/qt/wizard/wizard.py
  4. 3
      electrum/wizard.py

2
electrum/gui/qt/wizard/server_connect.py

@ -19,6 +19,8 @@ class QEServerConnectWizard(ServerConnectWizard, QEAbstractWizard):
ServerConnectWizard.__init__(self, daemon) ServerConnectWizard.__init__(self, daemon)
QEAbstractWizard.__init__(self, config, app) QEAbstractWizard.__init__(self, config, app)
self.setWindowTitle(_('Network and server configuration'))
# attach view names # attach view names
self.navmap_merge({ self.navmap_merge({
'autoconnect': { 'gui': WCAutoConnect }, 'autoconnect': { 'gui': WCAutoConnect },

53
electrum/gui/qt/wizard/wallet.py

@ -53,6 +53,8 @@ class QENewWalletWizard(NewWalletWizard, QEAbstractWizard):
NewWalletWizard.__init__(self, daemon, plugins) NewWalletWizard.__init__(self, daemon, plugins)
QEAbstractWizard.__init__(self, config, app) QEAbstractWizard.__init__(self, config, app)
self.setWindowTitle(_('Create/Restore wallet'))
self._path = path self._path = path
# attach gui classes to views # attach gui classes to views
@ -77,7 +79,19 @@ class QENewWalletWizard(NewWalletWizard, QEAbstractWizard):
'wallet_password_hardware': { 'gui': WCWalletPasswordHardware } 'wallet_password_hardware': { 'gui': WCWalletPasswordHardware }
}) })
# modify default flow, insert seed extension entry/confirm as separate views # add open existing wallet from wizard, incl hw unlock
self.navmap_merge({
'wallet_name': {
'next': lambda d: 'hw_unlock' if d['wallet_needs_hw_unlock'] else 'wallet_type',
'last': lambda d: d['wallet_exists'] and not d['wallet_needs_hw_unlock']
},
'hw_unlock': {
'last': True,
'gui': WCChooseHWDevice
}
})
# insert seed extension entry/confirm as separate views
self.navmap_merge({ self.navmap_merge({
'create_seed': { 'create_seed': {
'next': lambda d: 'create_ext' if self.wants_ext(d) else 'confirm_seed' 'next': lambda d: 'create_ext' if self.wants_ext(d) else 'confirm_seed'
@ -164,6 +178,10 @@ class WCWalletName(WizardComponent):
if os.path.isdir(path): if os.path.isdir(path):
raise Exception("wallet path cannot point to a directory") raise Exception("wallet path cannot point to a directory")
self.wallet_exists = False
self.wallet_is_open = False
self.wallet_needs_hw_unlock = False
hbox = QHBoxLayout() hbox = QHBoxLayout()
hbox.addWidget(QLabel(_('Wallet') + ':')) hbox.addWidget(QLabel(_('Wallet') + ':'))
self.name_e = QLineEdit() self.name_e = QLineEdit()
@ -175,11 +193,11 @@ class WCWalletName(WizardComponent):
msg_label = WWLabel('') msg_label = WWLabel('')
self.layout().addWidget(msg_label) self.layout().addWidget(msg_label)
hbox2 = QHBoxLayout() hbox2 = QHBoxLayout()
pw_e = PasswordLineEdit('', self) self.pw_e = PasswordLineEdit('', self)
pw_e.setFixedWidth(17 * char_width_in_lineedit()) self.pw_e.setFixedWidth(17 * char_width_in_lineedit())
pw_label = QLabel(_('Password') + ':') pw_label = QLabel(_('Password') + ':')
hbox2.addWidget(pw_label) hbox2.addWidget(pw_label)
hbox2.addWidget(pw_e) hbox2.addWidget(self.pw_e)
hbox2.addStretch() hbox2.addStretch()
self.layout().addLayout(hbox2) self.layout().addLayout(hbox2)
@ -208,15 +226,19 @@ class WCWalletName(WizardComponent):
nonlocal temp_storage nonlocal temp_storage
temp_storage = None temp_storage = None
msg = None msg = None
self.wallet_exists = False
self.wallet_is_open = False
self.wallet_needs_hw_unlock = False
if filename: if filename:
path = os.path.join(wallet_folder, filename) path = os.path.join(wallet_folder, filename)
# wallet_from_memory = get_wallet_from_daemon(path)
wallet_from_memory = self.wizard._daemon.get_wallet(path) wallet_from_memory = self.wizard._daemon.get_wallet(path)
try: try:
if wallet_from_memory: if wallet_from_memory:
temp_storage = wallet_from_memory.storage # type: Optional[WalletStorage] temp_storage = wallet_from_memory.storage # type: Optional[WalletStorage]
self.wallet_is_open = True
else: else:
temp_storage = WalletStorage(path) temp_storage = WalletStorage(path)
self.wallet_exists = temp_storage.file_exists()
except (StorageReadWriteError, WalletFileException) as e: except (StorageReadWriteError, WalletFileException) as e:
msg = _('Cannot read file') + f'\n{repr(e)}' msg = _('Cannot read file') + f'\n{repr(e)}'
except Exception as e: except Exception as e:
@ -224,12 +246,11 @@ class WCWalletName(WizardComponent):
msg = _('Cannot read file') + f'\n{repr(e)}' msg = _('Cannot read file') + f'\n{repr(e)}'
else: else:
msg = "" msg = ""
# self.next_button.setEnabled(temp_storage is not None)
self.valid = temp_storage is not None self.valid = temp_storage is not None
user_needs_to_enter_password = False user_needs_to_enter_password = False
if temp_storage: if temp_storage:
if not temp_storage.file_exists(): if not temp_storage.file_exists():
msg =_("This file does not exist.") + '\n' \ msg = _("This file does not exist.") + '\n' \
+ _("Press 'Next' to create this wallet, or choose another file.") + _("Press 'Next' to create this wallet, or choose another file.")
elif not wallet_from_memory: elif not wallet_from_memory:
if temp_storage.is_encrypted_with_user_pw(): if temp_storage.is_encrypted_with_user_pw():
@ -239,6 +260,7 @@ class WCWalletName(WizardComponent):
elif temp_storage.is_encrypted_with_hw_device(): elif temp_storage.is_encrypted_with_hw_device():
msg = _("This file is encrypted using a hardware device.") + '\n' \ msg = _("This file is encrypted using a hardware device.") + '\n' \
+ _("Press 'Next' to choose device to decrypt.") + _("Press 'Next' to choose device to decrypt.")
self.wallet_needs_hw_unlock = True
else: else:
msg = _("Press 'Next' to open this wallet.") msg = _("Press 'Next' to open this wallet.")
else: else:
@ -250,11 +272,11 @@ class WCWalletName(WizardComponent):
widget_create_new.setVisible(bool(temp_storage and temp_storage.file_exists())) widget_create_new.setVisible(bool(temp_storage and temp_storage.file_exists()))
if user_needs_to_enter_password: if user_needs_to_enter_password:
pw_label.show() pw_label.show()
pw_e.show() self.pw_e.show()
pw_e.setFocus()
else: else:
pw_label.hide() pw_label.hide()
pw_e.hide() self.pw_e.hide()
self.on_updated()
button.clicked.connect(on_choose) button.clicked.connect(on_choose)
button_create_new.clicked.connect( button_create_new.clicked.connect(
@ -263,7 +285,17 @@ class WCWalletName(WizardComponent):
self.name_e.setText(os.path.basename(path)) self.name_e.setText(os.path.basename(path))
def apply(self): def apply(self):
if self.wallet_exists:
# use full path
path = self.wizard._path
wallet_folder = os.path.dirname(path)
self.wizard_data['wallet_name'] = os.path.join(wallet_folder, self.name_e.text())
else:
self.wizard_data['wallet_name'] = self.name_e.text() self.wizard_data['wallet_name'] = self.name_e.text()
self.wizard_data['wallet_exists'] = self.wallet_exists
self.wizard_data['wallet_is_open'] = self.wallet_is_open
self.wizard_data['wallet_open_password'] = self.pw_e.text()
self.wizard_data['wallet_needs_hw_unlock'] = self.wallet_needs_hw_unlock
class WCWalletType(WizardComponent): class WCWalletType(WizardComponent):
@ -1103,4 +1135,3 @@ class WCWalletPasswordHardware(WizardComponent):
# client.handler = self.plugin.create_handler(self.wizard) # client.handler = self.plugin.create_handler(self.wizard)
self.wizard_data['password'] = client.get_password_for_storage_encryption() self.wizard_data['password'] = client.get_password_for_storage_encryption()

3
electrum/gui/qt/wizard/wizard.py

@ -264,4 +264,7 @@ class WizardComponent(QWidget):
@pyqtSlot() @pyqtSlot()
def on_updated(self, *args): def on_updated(self, *args):
try:
self.updated.emit(self) self.updated.emit(self)
except RuntimeError:
pass

3
electrum/wizard.py

@ -182,6 +182,9 @@ class AbstractWizard:
return result return result
return sanitize(_stack_item) return sanitize(_stack_item)
def get_wizard_data(self):
return copy.deepcopy(self._current.wizard_data)
class NewWalletWizard(AbstractWizard): class NewWalletWizard(AbstractWizard):

Loading…
Cancel
Save