move methods calling installwizard to main gui class
This commit is contained in:
parent
4e458b5639
commit
bdb4d3ecb8
4
electrum
4
electrum
|
@ -296,9 +296,9 @@ class ClientThread(util.DaemonThread):
|
||||||
cmd = config.get('cmd')
|
cmd = config.get('cmd')
|
||||||
if cmd == 'gui':
|
if cmd == 'gui':
|
||||||
if self.server.gui:
|
if self.server.gui:
|
||||||
if hasattr(server.gui, 'load_wallet_file'):
|
if hasattr(server.gui, 'new_window'):
|
||||||
path = config.get_wallet_path()
|
path = config.get_wallet_path()
|
||||||
self.server.gui.load_wallet_file(path)
|
self.server.gui.new_window(path)
|
||||||
response = "ok"
|
response = "ok"
|
||||||
else:
|
else:
|
||||||
response = "error: current GUI does not support multiple windows"
|
response = "error: current GUI does not support multiple windows"
|
||||||
|
|
|
@ -31,6 +31,7 @@ import PyQt4.QtCore as QtCore
|
||||||
|
|
||||||
from electrum.i18n import _, set_language
|
from electrum.i18n import _, set_language
|
||||||
from electrum.plugins import run_hook
|
from electrum.plugins import run_hook
|
||||||
|
from electrum import SimpleConfig, Wallet, WalletStorage
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import icons_rc
|
import icons_rc
|
||||||
|
@ -113,7 +114,93 @@ class ElectrumGui:
|
||||||
for window in self.windows:
|
for window in self.windows:
|
||||||
window.close()
|
window.close()
|
||||||
|
|
||||||
def load_wallet_file(self, path):
|
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):
|
||||||
|
try:
|
||||||
|
storage = WalletStorage(filename)
|
||||||
|
except Exception as e:
|
||||||
|
QMessageBox.information(None, _('Error'), str(e), _('OK'))
|
||||||
|
return
|
||||||
|
if not storage.file_exists:
|
||||||
|
recent = self.config.get('recently_open', [])
|
||||||
|
if filename in recent:
|
||||||
|
recent.remove(filename)
|
||||||
|
self.config.set_key('recently_open', recent)
|
||||||
|
action = 'new'
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
wallet = Wallet(storage)
|
||||||
|
except BaseException as e:
|
||||||
|
traceback.print_exc(file=sys.stdout)
|
||||||
|
QMessageBox.warning(None, _('Warning'), str(e), _('OK'))
|
||||||
|
return
|
||||||
|
action = wallet.get_action()
|
||||||
|
# run wizard
|
||||||
|
if action is not None:
|
||||||
|
wallet = self.run_wizard(storage, action)
|
||||||
|
# keep current wallet
|
||||||
|
if not wallet:
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
wallet.start_threads(self.network)
|
||||||
|
|
||||||
|
return wallet
|
||||||
|
|
||||||
|
def get_wallet_folder(self):
|
||||||
|
#return os.path.dirname(os.path.abspath(self.wallet.storage.path if self.wallet else self.wallet.storage.path))
|
||||||
|
return os.path.dirname(os.path.abspath(self.config.get_wallet_path()))
|
||||||
|
|
||||||
|
def new_wallet(self):
|
||||||
|
import installwizard
|
||||||
|
wallet_folder = self.get_wallet_folder()
|
||||||
|
i = 1
|
||||||
|
while True:
|
||||||
|
filename = "wallet_%d"%i
|
||||||
|
if filename in os.listdir(wallet_folder):
|
||||||
|
i += 1
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
filename = line_dialog(None, _('New Wallet'), _('Enter file name') + ':', _('OK'), filename)
|
||||||
|
if not filename:
|
||||||
|
return
|
||||||
|
full_path = os.path.join(wallet_folder, filename)
|
||||||
|
storage = WalletStorage(full_path)
|
||||||
|
if storage.file_exists:
|
||||||
|
QMessageBox.critical(None, "Error", _("File exists"))
|
||||||
|
return
|
||||||
|
wizard = installwizard.InstallWizard(self.config, self.network, storage, self.app)
|
||||||
|
action, wallet_type = wizard.restore_or_create()
|
||||||
|
if not action:
|
||||||
|
return
|
||||||
|
wallet = wizard.run(action, wallet_type)
|
||||||
|
if wallet:
|
||||||
|
self.start_new_window(self.config, full_path)
|
||||||
|
|
||||||
|
def new_window(self, path):
|
||||||
self.app.emit(SIGNAL('new_window'), self.config, path)
|
self.app.emit(SIGNAL('new_window'), self.config, path)
|
||||||
|
|
||||||
def start_new_window(self, config, path=None):
|
def start_new_window(self, config, path=None):
|
||||||
|
@ -124,9 +211,19 @@ class ElectrumGui:
|
||||||
w.bring_to_top()
|
w.bring_to_top()
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
|
wallet = self.load_wallet_file(path)
|
||||||
|
if not wallet:
|
||||||
|
return
|
||||||
w = ElectrumWindow(config, self.network, self)
|
w = ElectrumWindow(config, self.network, self)
|
||||||
w.connect_slots(self.timer)
|
w.connect_slots(self.timer)
|
||||||
w.load_wallet_file(path)
|
|
||||||
|
# load new wallet in gui
|
||||||
|
w.load_wallet(wallet)
|
||||||
|
# save path
|
||||||
|
if self.config.get('wallet_path') is None:
|
||||||
|
self.config.set_key('gui_last_wallet', path)
|
||||||
|
# add to recently visited
|
||||||
|
w.update_recently_visited(path)
|
||||||
w.show()
|
w.show()
|
||||||
self.windows.append(w)
|
self.windows.append(w)
|
||||||
self.build_tray_menu()
|
self.build_tray_menu()
|
||||||
|
@ -150,6 +247,8 @@ class ElectrumGui:
|
||||||
|
|
||||||
# main window
|
# main window
|
||||||
self.main_window = self.start_new_window(self.config)
|
self.main_window = self.start_new_window(self.config)
|
||||||
|
if not self.main_window:
|
||||||
|
return
|
||||||
|
|
||||||
# plugins interact with main window
|
# plugins interact with main window
|
||||||
run_hook('init_qt', self)
|
run_hook('init_qt', self)
|
||||||
|
|
|
@ -65,9 +65,9 @@ class CosignWidget(QWidget):
|
||||||
|
|
||||||
class InstallWizard(QDialog):
|
class InstallWizard(QDialog):
|
||||||
|
|
||||||
def __init__(self, config, network, storage, parent):
|
def __init__(self, config, network, storage, app):
|
||||||
QDialog.__init__(self, parent)
|
QDialog.__init__(self)
|
||||||
self.app = parent.app
|
self.app = app
|
||||||
self.config = config
|
self.config = config
|
||||||
self.network = network
|
self.network = network
|
||||||
self.storage = storage
|
self.storage = storage
|
||||||
|
|
|
@ -301,76 +301,12 @@ class ElectrumWindow(QMainWindow):
|
||||||
self.wallet.synchronize()
|
self.wallet.synchronize()
|
||||||
|
|
||||||
def open_wallet(self):
|
def open_wallet(self):
|
||||||
wallet_folder = self.get_wallet_folder()
|
wallet_folder = self.gui_object.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.gui_object.load_wallet_file(filename)
|
self.gui_object.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):
|
|
||||||
try:
|
|
||||||
storage = WalletStorage(filename)
|
|
||||||
except Exception as e:
|
|
||||||
self.show_message(str(e))
|
|
||||||
return
|
|
||||||
if not storage.file_exists:
|
|
||||||
recent = self.config.get('recently_open', [])
|
|
||||||
if filename in recent:
|
|
||||||
recent.remove(filename)
|
|
||||||
self.config.set_key('recently_open', recent)
|
|
||||||
action = 'new'
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
wallet = Wallet(storage)
|
|
||||||
except BaseException as e:
|
|
||||||
traceback.print_exc(file=sys.stdout)
|
|
||||||
QMessageBox.warning(None, _('Warning'), str(e), _('OK'))
|
|
||||||
return
|
|
||||||
action = wallet.get_action()
|
|
||||||
# run wizard
|
|
||||||
if action is not None:
|
|
||||||
self.tabs.hide()
|
|
||||||
wallet = self.run_wizard(storage, action)
|
|
||||||
# keep current wallet
|
|
||||||
if not wallet:
|
|
||||||
self.tabs.show()
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
wallet.start_threads(self.network)
|
|
||||||
# close current wallet
|
|
||||||
self.close_wallet()
|
|
||||||
# load new wallet in gui
|
|
||||||
self.load_wallet(wallet)
|
|
||||||
# save path
|
|
||||||
if self.config.get('wallet_path') is None:
|
|
||||||
self.config.set_key('gui_last_wallet', filename)
|
|
||||||
# add to recently visited
|
|
||||||
self.update_recently_visited(filename)
|
|
||||||
|
|
||||||
def backup_wallet(self):
|
def backup_wallet(self):
|
||||||
path = self.wallet.storage.path
|
path = self.wallet.storage.path
|
||||||
|
@ -387,41 +323,7 @@ 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.wallet.storage.path))
|
|
||||||
|
|
||||||
def new_wallet(self):
|
|
||||||
import installwizard
|
|
||||||
wallet_folder = self.get_wallet_folder()
|
|
||||||
i = 1
|
|
||||||
while True:
|
|
||||||
filename = "wallet_%d"%i
|
|
||||||
if filename in os.listdir(wallet_folder):
|
|
||||||
i += 1
|
|
||||||
else:
|
|
||||||
break
|
|
||||||
filename = line_dialog(self, _('New Wallet'), _('Enter file name') + ':', _('OK'), filename)
|
|
||||||
if not filename:
|
|
||||||
return
|
|
||||||
full_path = os.path.join(wallet_folder, filename)
|
|
||||||
storage = WalletStorage(full_path)
|
|
||||||
if storage.file_exists:
|
|
||||||
QMessageBox.critical(None, "Error", _("File exists"))
|
|
||||||
return
|
|
||||||
self.tabs.hide()
|
|
||||||
wizard = installwizard.InstallWizard(self.config, self.network, storage, self)
|
|
||||||
action, wallet_type = wizard.restore_or_create()
|
|
||||||
if not action:
|
|
||||||
self.tabs.show()
|
|
||||||
return
|
|
||||||
# close current wallet, but keep a reference to it
|
|
||||||
self.close_wallet()
|
|
||||||
wallet = wizard.run(action, wallet_type)
|
|
||||||
if wallet:
|
|
||||||
self.load_wallet(wallet)
|
|
||||||
else:
|
|
||||||
self.wallet.start_threads(self.network)
|
|
||||||
self.load_wallet(self.wallet)
|
|
||||||
|
|
||||||
def update_recently_visited(self, filename=None):
|
def update_recently_visited(self, filename=None):
|
||||||
recent = self.config.get('recently_open', [])
|
recent = self.config.get('recently_open', [])
|
||||||
|
@ -445,7 +347,7 @@ class ElectrumWindow(QMainWindow):
|
||||||
file_menu = menubar.addMenu(_("&File"))
|
file_menu = menubar.addMenu(_("&File"))
|
||||||
self.recently_visited_menu = file_menu.addMenu(_("&Recently open"))
|
self.recently_visited_menu = file_menu.addMenu(_("&Recently open"))
|
||||||
file_menu.addAction(_("&Open"), self.open_wallet).setShortcut(QKeySequence.Open)
|
file_menu.addAction(_("&Open"), self.open_wallet).setShortcut(QKeySequence.Open)
|
||||||
file_menu.addAction(_("&New/Restore"), self.new_wallet).setShortcut(QKeySequence.New)
|
file_menu.addAction(_("&New/Restore"), self.gui_object.new_wallet).setShortcut(QKeySequence.New)
|
||||||
file_menu.addAction(_("&Save Copy"), self.backup_wallet).setShortcut(QKeySequence.SaveAs)
|
file_menu.addAction(_("&Save Copy"), self.backup_wallet).setShortcut(QKeySequence.SaveAs)
|
||||||
file_menu.addSeparator()
|
file_menu.addSeparator()
|
||||||
file_menu.addAction(_("&Quit"), self.close)
|
file_menu.addAction(_("&Quit"), self.close)
|
||||||
|
|
Loading…
Reference in New Issue