This commit is contained in:
ThomasV 2017-06-29 18:23:10 +02:00
parent 064b59c65e
commit 2a53e85e8d
1 changed files with 51 additions and 42 deletions

View File

@ -147,63 +147,73 @@ class InstallWizard(QDialog, MessageBoxMixin, BaseWizard):
def run_and_get_wallet(self): def run_and_get_wallet(self):
def on_filename(): vbox = QVBoxLayout()
hbox = QHBoxLayout()
hbox.addWidget(QLabel(_('Wallet') + ':'))
self.name_e = QLineEdit()
hbox.addWidget(self.name_e)
button = QPushButton(_('Choose...'))
hbox.addWidget(button)
vbox.addLayout(hbox)
self.msg_label = QLabel('')
vbox.addWidget(self.msg_label)
hbox2 = QHBoxLayout()
self.pw_e = QLineEdit('', self)
self.pw_e.setFixedWidth(150)
self.pw_e.setEchoMode(2)
self.pw_label = QLabel(_('Password') + ':')
hbox2.addWidget(self.pw_label)
hbox2.addWidget(self.pw_e)
hbox2.addStretch()
vbox.addLayout(hbox2)
self.set_layout(vbox, title=_('Electrum wallet'))
def on_choose():
wallet_folder = os.path.dirname(self.storage.path) wallet_folder = os.path.dirname(self.storage.path)
path = unicode(QFileDialog.getOpenFileName(self, "Select your wallet file", wallet_folder)) path = unicode(QFileDialog.getOpenFileName(self, "Select your wallet file", wallet_folder))
if path: if path:
self.name_e.setText(path) self.name_e.setText(path)
self.storage = WalletStorage(path)
update_layout()
def update_layout():
name = os.path.basename(self.storage.path)
vbox = QVBoxLayout()
hbox = QHBoxLayout()
hbox.addWidget(QLabel(_('Wallet') + ':'))
self.name_e = QLineEdit(text=name)
hbox.addWidget(self.name_e)
button = QPushButton(_('Choose...'))
button.clicked.connect(on_filename)
hbox.addWidget(button)
vbox.addLayout(hbox)
self.pw_e = None
if not self.storage.file_exists(): def on_filename(path):
msg = _("This file does not exist.") + '\n' \ try:
+ _("Press 'Next' to create this wallet, or chose another file.") self.storage = WalletStorage(unicode(path))
vbox.addWidget(QLabel(msg)) except IOError:
self.storage = None
elif self.storage.file_exists() and self.storage.is_encrypted(): if self.storage:
msg = _("This file is encrypted.") + '\n' + _('Enter your password or choose another file.') if not self.storage.file_exists():
vbox.addWidget(QLabel(msg)) msg =_("This file does not exist.") + '\n' \
hbox2 = QHBoxLayout() + _("Press 'Next' to create this wallet, or choose another file.")
self.pw_e = QLineEdit('', self) pw = False
self.pw_e.setFixedWidth(150) elif self.storage.file_exists() and self.storage.is_encrypted():
self.pw_e.setEchoMode(2) msg = _("This file is encrypted.") + '\n' + _('Enter your password or choose another file.')
hbox2.addWidget(QLabel(_('Password') + ':')) pw = True
hbox2.addWidget(self.pw_e) else:
hbox2.addStretch() msg = _("Press 'Next' to open this wallet.")
vbox.addLayout(hbox2) pw = False
else: else:
msg = _("Press 'Next' to open this wallet.") msg = _('Cannot read file')
vbox.addWidget(QLabel(msg)) pw = False
self.msg_label.setText(msg)
self.set_layout(vbox, title=_('Electrum wallet')) if pw:
if self.pw_e: self.pw_label.show()
self.pw_e.show() self.pw_e.show()
self.pw_e.setFocus() self.pw_e.setFocus()
else:
self.pw_label.hide()
self.pw_e.hide()
button.clicked.connect(on_choose)
self.name_e.textChanged.connect(on_filename)
self.name_e.setText(os.path.basename(self.storage.path))
while True: while True:
update_layout()
if self.storage.file_exists() and not self.storage.is_encrypted(): if self.storage.file_exists() and not self.storage.is_encrypted():
break break
if not self.loop.exec_(): if not self.loop.exec_():
return return
if not self.storage.file_exists(): if not self.storage.file_exists():
break break
if self.storage.file_exists() and self.storage.is_encrypted(): if self.storage.file_exists() and self.storage.is_encrypted():
password = unicode(self.pw_e.text()) password = unicode(self.pw_e.text())
try: try:
@ -217,7 +227,6 @@ class InstallWizard(QDialog, MessageBoxMixin, BaseWizard):
QMessageBox.information(None, _('Error'), str(e), _('OK')) QMessageBox.information(None, _('Error'), str(e), _('OK'))
return return
path = self.storage.path path = self.storage.path
if self.storage.requires_split(): if self.storage.requires_split():
self.hide() self.hide()