URI: 
       tlazy plugin constructor - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit 778297697ab5fa6a0dda11165d9a7f6ca597ed34
   DIR parent 71046371ecb293a016f5777c3070fbdc933638ff
  HTML Author: ThomasV <thomasv@gitorious>
       Date:   Sun, 24 May 2015 20:37:05 +0200
       
       lazy plugin constructor
       
       Diffstat:
         M gui/qt/main_window.py               |       1 +
         M lib/plugins.py                      |      25 +++++++++++++++----------
         M plugins/__init__.py                 |       6 +++---
         M plugins/btchipwallet.py             |       4 ++--
         M plugins/trezor.py                   |       4 ++--
         M plugins/trustedcoin.py              |       4 ++--
       
       6 files changed, 25 insertions(+), 19 deletions(-)
       ---
   DIR diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py
       t@@ -235,6 +235,7 @@ class ElectrumWindow(QMainWindow):
                self.clear_receive_tab()
                self.update_receive_tab()
                self.show()
       +        run_hook('init_qt', self.gui_object)
                run_hook('load_wallet', wallet)
        
            def import_old_contacts(self):
   DIR diff --git a/lib/plugins.py b/lib/plugins.py
       t@@ -60,15 +60,18 @@ def init_plugins(config, is_local, gui_name):
                electrum_plugins = __import__('electrum_plugins')
                loader = lambda name: __import__('electrum_plugins.' + name, fromlist=['electrum_plugins'])
        
       -    def register_wallet_type(name):
       -        # fixme: load plugins only if really needed
       +    def constructor(name, storage):
       +        if plugins.get(name) is None:
       +            try:
       +                p = loader(name)
       +                plugins[name] = p.Plugin(config, name)
       +            except:
       +                return
       +        return plugins[name].constructor(storage)
       +
       +    def register_wallet_type(name, x, constructor):
                import wallet
       -        try:
       -            p = loader(name)
       -            plugins[name] = p.Plugin(config, name)
       -        except:
       -            return
       -        x = plugins[name].get_wallet_type()
       +        x += (lambda storage: constructor(name, storage),)
                wallet.wallet_types.append(x)
        
            descriptions = electrum_plugins.descriptions
       t@@ -76,8 +79,9 @@ def init_plugins(config, is_local, gui_name):
                name = item['name']
                if gui_name not in item.get('available_for', []):
                    continue
       -        if item.get('registers_wallet_type'):
       -            register_wallet_type(name)
       +        x = item.get('registers_wallet_type')
       +        if x:
       +            register_wallet_type(name, x, constructor)
                if not config.get('use_' + name):
                    continue
                try:
       t@@ -87,6 +91,7 @@ def init_plugins(config, is_local, gui_name):
                    print_msg(_("Error: cannot initialize plugin"), name)
                    traceback.print_exc(file=sys.stdout)
        
       +
        hook_names = set()
        hooks = {}
        
   DIR diff --git a/plugins/__init__.py b/plugins/__init__.py
       t@@ -32,7 +32,7 @@ descriptions = [
                'description': _('Provides support for BTChip hardware wallet'),
                'requires': [('btchip', 'github.com/btchip/btchip-python')],
                'requires_wallet_type': ['btchip'],
       -        'registers_wallet_type': True,
       +        'registers_wallet_type': ('hardware', 'btchip', _("BTChip wallet")),
                'available_for': ['qt'],
            },
            {
       t@@ -88,7 +88,7 @@ descriptions = [
                'available_for': ['qt'],
                'requires': [('trezorlib','github.com/trezor/python-trezor')],
                'requires_wallet_type': ['trezor'],
       -        'registers_wallet_type': True,
       +        'registers_wallet_type': ('hardware', 'trezor', _("Trezor wallet")),
                'available_for': ['qt', 'cmdline'],
            },
            {
       t@@ -100,7 +100,7 @@ descriptions = [
                    " <a href=\"https://api.trustedcoin.com/#/electrum-help\">https://api.trustedcoin.com/#/electrum-help</a>"
                ]),
                'requires_wallet_type': ['2fa'],
       -        'registers_wallet_type': True,
       +        'registers_wallet_type': ('twofactor', '2fa', _("Wallet with two-factor authentication")),
                'available_for': ['qt', 'cmdline'],
            },
            {
   DIR diff --git a/plugins/btchipwallet.py b/plugins/btchipwallet.py
       t@@ -40,8 +40,8 @@ class Plugin(BasePlugin):
                self._is_available = self._init()
                self.wallet = None
        
       -    def get_wallet_type(self):
       -        return ('hardware', 'btchip', _("BTChip wallet"), BTChipWallet)
       +    def constructor(self, s):
       +        return BTChipWallet(s)
        
            def _init(self):
                return BTCHIP
   DIR diff --git a/plugins/trezor.py b/plugins/trezor.py
       t@@ -47,8 +47,8 @@ class Plugin(BasePlugin):
                self._requires_settings = True
                self.wallet = None
        
       -    def get_wallet_type(self):
       -        return ('hardware', 'trezor', _("Trezor wallet"), TrezorWallet)
       +    def constructor(self, s):
       +        return TrezorWallet(s)
        
            def _init(self):
                return TREZOR
   DIR diff --git a/plugins/trustedcoin.py b/plugins/trustedcoin.py
       t@@ -214,8 +214,8 @@ class Plugin(BasePlugin):
                self.billing_info = None
                self.is_billing = False
        
       -    def get_wallet_type(self):
       -        return ('twofactor', '2fa', _("Wallet with two-factor authentication"), Wallet_2fa)
       +    def constructor(self, s):
       +        return Wallet_2fa(s)
        
            def is_available(self):
                if not self.wallet: