Browse Source

Clean up install wizard a little

Also fixes #1462
283
Neil Booth 9 years ago
parent
commit
5071d75912
  1. 38
      gui/qt/__init__.py
  2. 48
      gui/qt/installwizard.py

38
gui/qt/__init__.py

@ -34,6 +34,8 @@ from electrum.plugins import run_hook
from electrum import SimpleConfig, Wallet, WalletStorage from electrum import SimpleConfig, Wallet, WalletStorage
from electrum.paymentrequest import InvoiceStore from electrum.paymentrequest import InvoiceStore
from electrum.contacts import Contacts from electrum.contacts import Contacts
from installwizard import InstallWizard
try: try:
import icons_rc import icons_rc
@ -119,31 +121,6 @@ class ElectrumGui:
for window in self.windows: for window in self.windows:
window.close() window.close()
def run_wizard(self, storage, action):
import installwizard
if storage.file_exists and action != 'new':
msg = _("The file '%s' contains an incompletely created wallet.")%storage.path + '\n'\
+ _("Do you want to complete its creation now?")
if not self.question(msg):
if self.question(_("Do you want to delete '%s'?")%storage.path):
os.remove(storage.path)
QMessageBox.information(self, _('Warning'), _('The file was removed'), _('OK'))
return
return
wizard = installwizard.InstallWizard(self.config, self.network, storage, self)
wizard.show()
if action == 'new':
action, wallet_type = wizard.restore_or_create()
else:
wallet_type = None
try:
wallet = wizard.run(action, wallet_type)
except BaseException as e:
traceback.print_exc(file=sys.stdout)
QMessageBox.information(None, _('Error'), str(e), _('OK'))
return
return wallet
def load_wallet_file(self, filename): def load_wallet_file(self, filename):
try: try:
storage = WalletStorage(filename) storage = WalletStorage(filename)
@ -166,7 +143,8 @@ class ElectrumGui:
action = wallet.get_action() action = wallet.get_action()
# run wizard # run wizard
if action is not None: if action is not None:
wallet = self.run_wizard(storage, action) wizard = InstallWizard(self.config, self.network, storage)
wallet = wizard.run(action)
# keep current wallet # keep current wallet
if not wallet: if not wallet:
return return
@ -180,7 +158,6 @@ class ElectrumGui:
return os.path.dirname(os.path.abspath(self.config.get_wallet_path())) return os.path.dirname(os.path.abspath(self.config.get_wallet_path()))
def new_wallet(self): def new_wallet(self):
import installwizard
wallet_folder = self.get_wallet_folder() wallet_folder = self.get_wallet_folder()
i = 1 i = 1
while True: while True:
@ -197,11 +174,8 @@ class ElectrumGui:
if storage.file_exists: if storage.file_exists:
QMessageBox.critical(None, "Error", _("File exists")) QMessageBox.critical(None, "Error", _("File exists"))
return return
wizard = installwizard.InstallWizard(self.config, self.network, storage, self.app) wizard = InstallWizard(self.config, self.network, storage)
action, wallet_type = wizard.restore_or_create() wallet = wizard.run('new')
if not action:
return
wallet = wizard.run(action, wallet_type)
if wallet: if wallet:
self.new_window(full_path) self.new_window(full_path)

48
gui/qt/installwizard.py

@ -64,9 +64,8 @@ class CosignWidget(QWidget):
class InstallWizard(QDialog): class InstallWizard(QDialog):
def __init__(self, config, network, storage, app): def __init__(self, config, network, storage):
QDialog.__init__(self) QDialog.__init__(self)
self.app = app
self.config = config self.config = config
self.network = network self.network = network
self.storage = storage self.storage = storage
@ -400,24 +399,6 @@ class InstallWizard(QDialog):
wallet_type = '%dof%d'%(m,n) wallet_type = '%dof%d'%(m,n)
return wallet_type return wallet_type
def question(self, msg, yes_label=_('OK'), no_label=_('Cancel'), icon=None):
vbox = QVBoxLayout()
self.set_layout(vbox)
if icon:
logo = QLabel()
logo.setPixmap(icon)
vbox.addWidget(logo)
label = QLabel(msg)
label.setWordWrap(True)
vbox.addWidget(label)
vbox.addStretch(1)
vbox.addLayout(Buttons(CancelButton(self, no_label), OkButton(self, yes_label)))
if not self.exec_():
return None
return True
def show_seed(self, seed, sid): def show_seed(self, seed, sid):
vbox = seed_dialog.show_seed_box_msg(seed, sid) vbox = seed_dialog.show_seed_box_msg(seed, sid)
vbox.addLayout(Buttons(CancelButton(self), OkButton(self, _("Next")))) vbox.addLayout(Buttons(CancelButton(self), OkButton(self, _("Next"))))
@ -432,9 +413,32 @@ class InstallWizard(QDialog):
self.set_layout( make_password_dialog(self, None, msg) ) self.set_layout( make_password_dialog(self, None, msg) )
return run_password_dialog(self, None, self)[2] return run_password_dialog(self, None, self)[2]
def run(self, action):
if self.storage.file_exists and action != 'new':
path = self.storage.path
msg = _("The file '%s' contains an incompletely created wallet.\n"
"Do you want to complete its creation now?") % path
if not question(msg):
if question(_("Do you want to delete '%s'?") % path):
os.remove(path)
QMessageBox.information(self, _('Warning'),
_('The file was removed'), _('OK'))
return
return
self.show()
if action == 'new':
action, wallet_type = self.restore_or_create()
else:
wallet_type = None
try:
wallet = self.run_wallet_type(action, wallet_type)
except BaseException as e:
traceback.print_exc(file=sys.stdout)
QMessageBox.information(None, _('Error'), str(e), _('OK'))
return
return wallet
def run(self, action, wallet_type): def run_wallet_type(self, action, wallet_type):
if action in ['create', 'restore']: if action in ['create', 'restore']:
if wallet_type == 'multisig': if wallet_type == 'multisig':
wallet_type = self.multisig_choice() wallet_type = self.multisig_choice()

Loading…
Cancel
Save