detect available hardware wallets before listing them in wizard

This commit is contained in:
ThomasV 2015-08-22 08:56:04 +02:00 committed by ThomasV
parent 280b5c79d2
commit 992c70a688
3 changed files with 24 additions and 17 deletions

View File

@ -442,7 +442,17 @@ class InstallWizard(QDialog):
if not wallet_type:
return
elif wallet_type == 'hardware':
hardware_wallets = map(lambda x:(x[1],x[2]), filter(lambda x:x[0]=='hardware', electrum.wallet.wallet_types))
hardware_wallets = []
for item in electrum.wallet.wallet_types:
t, name, description, loader = item
if t == 'hardware':
try:
p = loader()
except:
util.print_error("cannot load plugin for:", name)
continue
if p:
hardware_wallets.append((name, description))
wallet_type = self.choice(_("Hardware Wallet"), 'Select your hardware wallet', hardware_wallets)
if not wallet_type:

View File

@ -49,6 +49,14 @@ def is_available(name, w):
return True
def plugin_loader(config, name):
global plugins
if plugins.get(name) is None:
print_error(_("Loading plugin by constructor:"), name)
p = loader(name)
plugins[name] = p.Plugin(config, name)
return plugins[name]
@profiler
def init_plugins(config, is_local, gui_name):
global plugins, descriptions, loader
@ -60,20 +68,9 @@ def init_plugins(config, is_local, gui_name):
electrum_plugins = __import__('electrum_plugins')
loader = lambda name: __import__('electrum_plugins.' + name, fromlist=['electrum_plugins'])
def constructor(name, storage):
if plugins.get(name) is None:
try:
print_error(_("Loading plugin by constructor:"), name)
p = loader(name)
plugins[name] = p.Plugin(config, name)
except:
print_msg(_("Error: cannot initialize plugin"), name)
return
return plugins[name].constructor(storage)
def register_wallet_type(name, x, constructor):
def register_wallet_type(name, x):
import wallet
x += (lambda storage: constructor(name, storage),)
x += (lambda: plugin_loader(config, name),)
wallet.wallet_types.append(x)
descriptions = electrum_plugins.descriptions
@ -83,7 +80,7 @@ def init_plugins(config, is_local, gui_name):
continue
x = item.get('registers_wallet_type')
if x:
register_wallet_type(name, x, constructor)
register_wallet_type(name, x)
if not config.get('use_' + name):
continue
try:

View File

@ -1925,9 +1925,9 @@ class Wallet(object):
wallet_type = storage.get('wallet_type')
if wallet_type:
for cat, t, name, c in wallet_types:
for cat, t, name, loader in wallet_types:
if t == wallet_type:
WalletClass = c
WalletClass = lambda storage: apply(loader().constructor, (storage,))
break
else:
if re.match('(\d+)of(\d+)', wallet_type):