mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-09-01 01:35:20 +00:00
start wizard from main_window. fixes #1250
This commit is contained in:
parent
85c0dda1a9
commit
aedfbd3855
3 changed files with 55 additions and 72 deletions
|
@ -142,30 +142,6 @@ class ElectrumGui:
|
||||||
def set_url(self, uri):
|
def set_url(self, uri):
|
||||||
self.current_window.pay_to_URI(uri)
|
self.current_window.pay_to_URI(uri)
|
||||||
|
|
||||||
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 util.question(msg):
|
|
||||||
if util.question(_("Do you want to delete '%s'?")%storage.path):
|
|
||||||
os.remove(storage.path)
|
|
||||||
QMessageBox.information(None, _('Warning'), _('The file was removed'), _('OK'))
|
|
||||||
return
|
|
||||||
return
|
|
||||||
wizard = installwizard.InstallWizard(self.config, self.network, storage, self.app)
|
|
||||||
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 main(self, url):
|
def main(self, url):
|
||||||
|
|
||||||
|
@ -173,29 +149,6 @@ class ElectrumGui:
|
||||||
if last_wallet is not None and self.config.get('wallet_path') is None:
|
if last_wallet is not None and self.config.get('wallet_path') is None:
|
||||||
if os.path.exists(last_wallet):
|
if os.path.exists(last_wallet):
|
||||||
self.config.cmdline_options['default_wallet_path'] = last_wallet
|
self.config.cmdline_options['default_wallet_path'] = last_wallet
|
||||||
try:
|
|
||||||
storage = WalletStorage(self.config.get_wallet_path())
|
|
||||||
except BaseException as e:
|
|
||||||
QMessageBox.warning(None, _('Warning'), str(e), _('OK'))
|
|
||||||
self.config.set_key('gui_last_wallet', None)
|
|
||||||
return
|
|
||||||
|
|
||||||
if storage.file_exists:
|
|
||||||
try:
|
|
||||||
wallet = Wallet(storage)
|
|
||||||
except BaseException as e:
|
|
||||||
QMessageBox.warning(None, _('Warning'), str(e), _('OK'))
|
|
||||||
return
|
|
||||||
action = wallet.get_action()
|
|
||||||
else:
|
|
||||||
action = 'new'
|
|
||||||
|
|
||||||
if action is not None:
|
|
||||||
wallet = self.run_wizard(storage, action)
|
|
||||||
if not wallet:
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
wallet.start_threads(self.network)
|
|
||||||
|
|
||||||
# init tray
|
# init tray
|
||||||
self.dark_icon = self.config.get("dark_icon", False)
|
self.dark_icon = self.config.get("dark_icon", False)
|
||||||
|
@ -209,15 +162,16 @@ class ElectrumGui:
|
||||||
# main window
|
# main window
|
||||||
self.main_window = w = ElectrumWindow(self.config, self.network, self)
|
self.main_window = w = ElectrumWindow(self.config, self.network, self)
|
||||||
self.current_window = self.main_window
|
self.current_window = self.main_window
|
||||||
|
w.show()
|
||||||
|
|
||||||
#lite window
|
#lite window
|
||||||
self.init_lite()
|
self.init_lite()
|
||||||
|
|
||||||
|
w.load_wallet_file(self.config.get_wallet_path())
|
||||||
|
|
||||||
# plugins interact with main window
|
# plugins interact with main window
|
||||||
run_hook('init_qt', self)
|
run_hook('init_qt', self)
|
||||||
|
|
||||||
w.load_wallet(wallet)
|
|
||||||
|
|
||||||
# initial configuration
|
# initial configuration
|
||||||
if self.config.get('hide_gui') is True and self.tray.isVisible():
|
if self.config.get('hide_gui') is True and self.tray.isVisible():
|
||||||
self.main_window.hide()
|
self.main_window.hide()
|
||||||
|
|
|
@ -65,9 +65,9 @@ class CosignWidget(QWidget):
|
||||||
|
|
||||||
class InstallWizard(QDialog):
|
class InstallWizard(QDialog):
|
||||||
|
|
||||||
def __init__(self, config, network, storage, app):
|
def __init__(self, config, network, storage, parent):
|
||||||
QDialog.__init__(self)
|
QDialog.__init__(self, parent)
|
||||||
self.app = app
|
self.app = parent.app
|
||||||
self.config = config
|
self.config = config
|
||||||
self.network = network
|
self.network = network
|
||||||
self.storage = storage
|
self.storage = storage
|
||||||
|
|
|
@ -219,7 +219,9 @@ class ElectrumWindow(QMainWindow):
|
||||||
self.account_selector.hide()
|
self.account_selector.hide()
|
||||||
|
|
||||||
def close_wallet(self):
|
def close_wallet(self):
|
||||||
self.wallet.stop_threads()
|
if self.wallet:
|
||||||
|
self.wallet.storage.put('accounts_expanded', self.accounts_expanded)
|
||||||
|
self.wallet.stop_threads()
|
||||||
run_hook('close_wallet')
|
run_hook('close_wallet')
|
||||||
|
|
||||||
def load_wallet(self, wallet):
|
def load_wallet(self, wallet):
|
||||||
|
@ -288,12 +290,37 @@ class ElectrumWindow(QMainWindow):
|
||||||
self.wallet.synchronize()
|
self.wallet.synchronize()
|
||||||
|
|
||||||
def open_wallet(self):
|
def open_wallet(self):
|
||||||
wallet_folder = self.wallet.storage.path
|
wallet_folder = self.get_wallet_folder()
|
||||||
filename = unicode(QFileDialog.getOpenFileName(self, "Select your wallet file", wallet_folder))
|
filename = unicode(QFileDialog.getOpenFileName(self, "Select your wallet file", wallet_folder))
|
||||||
if not filename:
|
if not filename:
|
||||||
return
|
return
|
||||||
self.load_wallet_file(filename)
|
self.load_wallet_file(filename)
|
||||||
|
|
||||||
|
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)
|
||||||
|
@ -301,27 +328,26 @@ class ElectrumWindow(QMainWindow):
|
||||||
self.show_message(str(e))
|
self.show_message(str(e))
|
||||||
return
|
return
|
||||||
if not storage.file_exists:
|
if not storage.file_exists:
|
||||||
self.show_message(_("File not found") + ' ' + filename)
|
|
||||||
recent = self.config.get('recently_open', [])
|
recent = self.config.get('recently_open', [])
|
||||||
if filename in recent:
|
if filename in recent:
|
||||||
recent.remove(filename)
|
recent.remove(filename)
|
||||||
self.config.set_key('recently_open', recent)
|
self.config.set_key('recently_open', recent)
|
||||||
return
|
action = 'new'
|
||||||
# read wizard action
|
else:
|
||||||
try:
|
try:
|
||||||
wallet = Wallet(storage)
|
wallet = Wallet(storage)
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
traceback.print_exc(file=sys.stdout)
|
traceback.print_exc(file=sys.stdout)
|
||||||
QMessageBox.warning(None, _('Warning'), str(e), _('OK'))
|
QMessageBox.warning(None, _('Warning'), str(e), _('OK'))
|
||||||
return
|
return
|
||||||
action = wallet.get_action()
|
action = wallet.get_action()
|
||||||
# run wizard
|
# run wizard
|
||||||
if action is not None:
|
if action is not None:
|
||||||
self.hide()
|
self.tabs.hide()
|
||||||
wallet = self.gui_object.run_wizard(storage, action)
|
wallet = self.run_wizard(storage, action)
|
||||||
# keep current wallet
|
# keep current wallet
|
||||||
if not wallet:
|
if not wallet:
|
||||||
self.show()
|
self.tabs.show()
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
wallet.start_threads(self.network)
|
wallet.start_threads(self.network)
|
||||||
|
@ -350,10 +376,12 @@ class ElectrumWindow(QMainWindow):
|
||||||
except (IOError, os.error), reason:
|
except (IOError, os.error), reason:
|
||||||
QMessageBox.critical(None,"Unable to create backup", _("Electrum was unable to copy your wallet file to the specified location.")+"\n" + str(reason))
|
QMessageBox.critical(None,"Unable to create backup", _("Electrum was unable to copy your wallet file to the specified location.")+"\n" + str(reason))
|
||||||
|
|
||||||
|
def get_wallet_folder(self):
|
||||||
|
return os.path.dirname(os.path.abspath(self.wallet.storage.path if self.wallet else self.config.get_wallet_path()))
|
||||||
|
|
||||||
def new_wallet(self):
|
def new_wallet(self):
|
||||||
import installwizard
|
import installwizard
|
||||||
wallet_folder = os.path.dirname(os.path.abspath(self.wallet.storage.path))
|
wallet_folder = self.get_wallet_folder()
|
||||||
i = 1
|
i = 1
|
||||||
while True:
|
while True:
|
||||||
filename = "wallet_%d"%i
|
filename = "wallet_%d"%i
|
||||||
|
@ -369,11 +397,11 @@ class ElectrumWindow(QMainWindow):
|
||||||
if storage.file_exists:
|
if storage.file_exists:
|
||||||
QMessageBox.critical(None, "Error", _("File exists"))
|
QMessageBox.critical(None, "Error", _("File exists"))
|
||||||
return
|
return
|
||||||
self.hide()
|
self.tabs.hide()
|
||||||
wizard = installwizard.InstallWizard(self.config, self.network, storage, self.app)
|
wizard = installwizard.InstallWizard(self.config, self.network, storage, self)
|
||||||
action, wallet_type = wizard.restore_or_create()
|
action, wallet_type = wizard.restore_or_create()
|
||||||
if not action:
|
if not action:
|
||||||
self.show()
|
self.tabs.show()
|
||||||
return
|
return
|
||||||
# close current wallet, but keep a reference to it
|
# close current wallet, but keep a reference to it
|
||||||
self.close_wallet()
|
self.close_wallet()
|
||||||
|
@ -606,6 +634,8 @@ class ElectrumWindow(QMainWindow):
|
||||||
|
|
||||||
def update_wallet(self):
|
def update_wallet(self):
|
||||||
self.update_status()
|
self.update_status()
|
||||||
|
if self.wallet is None:
|
||||||
|
return
|
||||||
if self.wallet.up_to_date or not self.network or not self.network.is_connected():
|
if self.wallet.up_to_date or not self.network or not self.network.is_connected():
|
||||||
self.update_tabs()
|
self.update_tabs()
|
||||||
|
|
||||||
|
@ -2837,7 +2867,6 @@ class ElectrumWindow(QMainWindow):
|
||||||
g = self.geometry()
|
g = self.geometry()
|
||||||
self.config.set_key("winpos-qt", [g.left(),g.top(),g.width(),g.height()])
|
self.config.set_key("winpos-qt", [g.left(),g.top(),g.width(),g.height()])
|
||||||
self.config.set_key("console-history", self.console.history[-50:], True)
|
self.config.set_key("console-history", self.console.history[-50:], True)
|
||||||
self.wallet.storage.put('accounts_expanded', self.accounts_expanded)
|
|
||||||
event.accept()
|
event.accept()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue