URI: 
       tmove methods calling installwizard to main gui class - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit bdb4d3ecb8e6cb741375336bac87efa34bc21b00
   DIR parent 4e458b5639b7bbbeeed70e57951094e7634c89e1
  HTML Author: ThomasV <thomasv@electrum.org>
       Date:   Wed,  2 Sep 2015 12:05:33 +0200
       
       move methods calling installwizard to main gui class
       
       Diffstat:
         M electrum                            |       4 ++--
         M gui/qt/__init__.py                  |     103 ++++++++++++++++++++++++++++++-
         M gui/qt/installwizard.py             |       6 +++---
         M gui/qt/main_window.py               |     104 +------------------------------
       
       4 files changed, 109 insertions(+), 108 deletions(-)
       ---
   DIR diff --git a/electrum b/electrum
       t@@ -296,9 +296,9 @@ class ClientThread(util.DaemonThread):
                cmd = config.get('cmd')
                if cmd == 'gui':
                    if self.server.gui:
       -                if hasattr(server.gui, 'load_wallet_file'):
       +                if hasattr(server.gui, 'new_window'):
                            path = config.get_wallet_path()
       -                    self.server.gui.load_wallet_file(path)
       +                    self.server.gui.new_window(path)
                            response = "ok"
                        else:
                            response = "error: current GUI does not support multiple windows"
   DIR diff --git a/gui/qt/__init__.py b/gui/qt/__init__.py
       t@@ -31,6 +31,7 @@ import PyQt4.QtCore as QtCore
        
        from electrum.i18n import _, set_language
        from electrum.plugins import run_hook
       +from electrum import SimpleConfig, Wallet, WalletStorage
        
        try:
            import icons_rc
       t@@ -113,7 +114,93 @@ class ElectrumGui:
                for window in self.windows:
                    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)
        
            def start_new_window(self, config, path=None):
       t@@ -124,9 +211,19 @@ class ElectrumGui:
                        w.bring_to_top()
                        break
                else:
       +            wallet = self.load_wallet_file(path)
       +            if not wallet:
       +                return
                    w = ElectrumWindow(config, self.network, self)
                    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()
                    self.windows.append(w)
                    self.build_tray_menu()
       t@@ -150,6 +247,8 @@ class ElectrumGui:
        
                # main window
                self.main_window = self.start_new_window(self.config)
       +        if not self.main_window:
       +            return
        
                # plugins interact with main window
                run_hook('init_qt', self)
   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, parent):
       -        QDialog.__init__(self, parent)
       -        self.app = parent.app
       +    def __init__(self, config, network, storage, app):
       +        QDialog.__init__(self)
       +        self.app = 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@@ -301,76 +301,12 @@ class ElectrumWindow(QMainWindow):
                    self.wallet.synchronize()
        
            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))
                if not filename:
                    return
                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):
                path = self.wallet.storage.path
       t@@ -387,41 +323,7 @@ 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.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):
                recent = self.config.get('recently_open', [])
       t@@ -445,7 +347,7 @@ class ElectrumWindow(QMainWindow):
                file_menu = menubar.addMenu(_("&File"))
                self.recently_visited_menu = file_menu.addMenu(_("&Recently 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.addSeparator()
                file_menu.addAction(_("&Quit"), self.close)