URI: 
       tstart wizard from main_window. fixes #1250 - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit aedfbd3855cd1e24ab9e4c76b20413a95ac39912
   DIR parent 85c0dda1a94e12f2417ae303750cd206a61724fd
  HTML Author: ThomasV <thomasv@gitorious>
       Date:   Sat, 22 Aug 2015 11:23:54 +0200
       
       start wizard from main_window. fixes #1250
       
       Diffstat:
         M gui/qt/__init__.py                  |      52 ++-----------------------------
         M gui/qt/installwizard.py             |       6 +++---
         M gui/qt/main_window.py               |      69 ++++++++++++++++++++++---------
       
       3 files changed, 55 insertions(+), 72 deletions(-)
       ---
   DIR diff --git a/gui/qt/__init__.py b/gui/qt/__init__.py
       t@@ -142,30 +142,6 @@ class ElectrumGui:
            def set_url(self, 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):
        
       t@@ -173,29 +149,6 @@ class ElectrumGui:
                if last_wallet is not None and self.config.get('wallet_path') is None:
                    if os.path.exists(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
                self.dark_icon = self.config.get("dark_icon", False)
       t@@ -209,15 +162,16 @@ class ElectrumGui:
                # main window
                self.main_window = w = ElectrumWindow(self.config, self.network, self)
                self.current_window = self.main_window
       +        w.show()
        
                #lite window
                self.init_lite()
        
       +        w.load_wallet_file(self.config.get_wallet_path())
       +
                # plugins interact with main window
                run_hook('init_qt', self)
        
       -        w.load_wallet(wallet)
       -
                # initial configuration
                if self.config.get('hide_gui') is True and self.tray.isVisible():
                    self.main_window.hide()
   DIR diff --git a/gui/qt/installwizard.py b/gui/qt/installwizard.py
       t@@ -65,9 +65,9 @@ class CosignWidget(QWidget):
        
        class InstallWizard(QDialog):
        
       -    def __init__(self, config, network, storage, app):
       -        QDialog.__init__(self)
       -        self.app = app
       +    def __init__(self, config, network, storage, parent):
       +        QDialog.__init__(self, parent)
       +        self.app = parent.app
                self.config = config
                self.network = network
                self.storage = storage
   DIR diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py
       t@@ -219,7 +219,9 @@ class ElectrumWindow(QMainWindow):
                    self.account_selector.hide()
        
            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')
        
            def load_wallet(self, wallet):
       t@@ -288,12 +290,37 @@ class ElectrumWindow(QMainWindow):
                    self.wallet.synchronize()
        
            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))
                if not filename:
                    return
                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):
                try:
                    storage = WalletStorage(filename)
       t@@ -301,27 +328,26 @@ class ElectrumWindow(QMainWindow):
                    self.show_message(str(e))
                    return
                if not storage.file_exists:
       -            self.show_message(_("File not found") + ' ' + filename)
                    recent = self.config.get('recently_open', [])
                    if filename in recent:
                        recent.remove(filename)
                        self.config.set_key('recently_open', recent)
       -            return
       -        # read wizard action
       -        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()
       +            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.hide()
       -            wallet = self.gui_object.run_wizard(storage, action)
       +            self.tabs.hide()
       +            wallet = self.run_wizard(storage, action)
                    # keep current wallet
                    if not wallet:
       -                self.show()
       +                self.tabs.show()
                        return
                else:
                    wallet.start_threads(self.network)
       t@@ -350,10 +376,12 @@ class ElectrumWindow(QMainWindow):
                    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))
        
       +    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):
                import installwizard
       -        wallet_folder = os.path.dirname(os.path.abspath(self.wallet.storage.path))
       +        wallet_folder = self.get_wallet_folder()
                i = 1
                while True:
                    filename = "wallet_%d"%i
       t@@ -369,11 +397,11 @@ class ElectrumWindow(QMainWindow):
                if storage.file_exists:
                    QMessageBox.critical(None, "Error", _("File exists"))
                    return
       -        self.hide()
       -        wizard = installwizard.InstallWizard(self.config, self.network, storage, self.app)
       +        self.tabs.hide()
       +        wizard = installwizard.InstallWizard(self.config, self.network, storage, self)
                action, wallet_type = wizard.restore_or_create()
                if not action:
       -            self.show()
       +            self.tabs.show()
                    return
                # close current wallet, but keep a reference to it
                self.close_wallet()
       t@@ -606,6 +634,8 @@ class ElectrumWindow(QMainWindow):
        
            def update_wallet(self):
                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():
                    self.update_tabs()
        
       t@@ -2837,7 +2867,6 @@ class ElectrumWindow(QMainWindow):
                    g = self.geometry()
                    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.wallet.storage.put('accounts_expanded', self.accounts_expanded)
                event.accept()