init plugins before gui. register wallet types in plugin constructor
This commit is contained in:
parent
337a20b815
commit
79588eb4da
4
electrum
4
electrum
|
@ -47,6 +47,9 @@ from electrum import util
|
||||||
from electrum import SimpleConfig, Network, Wallet, WalletStorage, NetworkProxy, Commands, known_commands, pick_random_server
|
from electrum import SimpleConfig, Network, Wallet, WalletStorage, NetworkProxy, Commands, known_commands, pick_random_server
|
||||||
from electrum.util import print_msg, print_stderr, print_json, set_verbosity
|
from electrum.util import print_msg, print_stderr, print_json, set_verbosity
|
||||||
from electrum.daemon import get_daemon
|
from electrum.daemon import get_daemon
|
||||||
|
from electrum.plugins import init_plugins
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# get password routine
|
# get password routine
|
||||||
def prompt_password(prompt, confirm=True):
|
def prompt_password(prompt, confirm=True):
|
||||||
|
@ -173,6 +176,7 @@ if __name__ == '__main__':
|
||||||
set_verbosity(config_options.get('verbose'))
|
set_verbosity(config_options.get('verbose'))
|
||||||
|
|
||||||
config = SimpleConfig(config_options)
|
config = SimpleConfig(config_options)
|
||||||
|
init_plugins(config)
|
||||||
|
|
||||||
if len(args) == 0:
|
if len(args) == 0:
|
||||||
url = None
|
url = None
|
||||||
|
|
|
@ -44,7 +44,6 @@ except Exception:
|
||||||
|
|
||||||
from util import *
|
from util import *
|
||||||
from main_window import ElectrumWindow
|
from main_window import ElectrumWindow
|
||||||
from electrum.plugins import init_plugins
|
|
||||||
|
|
||||||
|
|
||||||
class OpenFileEventFilter(QObject):
|
class OpenFileEventFilter(QObject):
|
||||||
|
@ -70,7 +69,6 @@ class ElectrumGui:
|
||||||
if app is None:
|
if app is None:
|
||||||
self.app = QApplication(sys.argv)
|
self.app = QApplication(sys.argv)
|
||||||
self.app.installEventFilter(self.efilter)
|
self.app.installEventFilter(self.efilter)
|
||||||
init_plugins(self)
|
|
||||||
|
|
||||||
|
|
||||||
def build_tray_menu(self):
|
def build_tray_menu(self):
|
||||||
|
@ -193,7 +191,7 @@ class ElectrumGui:
|
||||||
self.go_full()
|
self.go_full()
|
||||||
|
|
||||||
# plugins that need to change the GUI do it here
|
# plugins that need to change the GUI do it here
|
||||||
run_hook('init')
|
run_hook('init_qt', self)
|
||||||
|
|
||||||
w.load_wallet(wallet)
|
w.load_wallet(wallet)
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ from PyQt4.QtGui import *
|
||||||
from PyQt4.QtCore import *
|
from PyQt4.QtCore import *
|
||||||
import PyQt4.QtCore as QtCore
|
import PyQt4.QtCore as QtCore
|
||||||
|
|
||||||
|
import electrum
|
||||||
from electrum.i18n import _
|
from electrum.i18n import _
|
||||||
from electrum import Wallet, Wallet_2of2, Wallet_2of3
|
from electrum import Wallet, Wallet_2of2, Wallet_2of3
|
||||||
from electrum import bitcoin
|
from electrum import bitcoin
|
||||||
|
@ -96,13 +97,7 @@ class InstallWizard(QDialog):
|
||||||
grid.addWidget(gb2, 3, 0)
|
grid.addWidget(gb2, 3, 0)
|
||||||
group2 = QButtonGroup()
|
group2 = QButtonGroup()
|
||||||
|
|
||||||
self.wallet_types = [
|
self.wallet_types = filter(lambda x: x[0] not in ['old','xpub','imported'], electrum.wallet.wallet_types)
|
||||||
('standard', _("Standard wallet"), Wallet),
|
|
||||||
('2of2', _("Multisig wallet (2 of 2)"), Wallet_2of2),
|
|
||||||
('2of3', _("Multisig wallet (2 of 3)"), Wallet_2of3)
|
|
||||||
]
|
|
||||||
run_hook('add_wallet_types', self.wallet_types)
|
|
||||||
|
|
||||||
for i, (t,l,c) in enumerate(self.wallet_types):
|
for i, (t,l,c) in enumerate(self.wallet_types):
|
||||||
button = QRadioButton(gb2)
|
button = QRadioButton(gb2)
|
||||||
button.setText(l)
|
button.setText(l)
|
||||||
|
|
|
@ -6,7 +6,7 @@ from i18n import _
|
||||||
plugins = []
|
plugins = []
|
||||||
|
|
||||||
|
|
||||||
def init_plugins(self):
|
def init_plugins(config):
|
||||||
import imp, pkgutil, __builtin__, os
|
import imp, pkgutil, __builtin__, os
|
||||||
global plugins
|
global plugins
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ def init_plugins(self):
|
||||||
|
|
||||||
for name, p in zip(plugin_names, plugin_modules):
|
for name, p in zip(plugin_names, plugin_modules):
|
||||||
try:
|
try:
|
||||||
plugins.append( p.Plugin(self, name) )
|
plugins.append( p.Plugin(config, name) )
|
||||||
except Exception:
|
except Exception:
|
||||||
print_msg(_("Error: cannot initialize plugin"),p)
|
print_msg(_("Error: cannot initialize plugin"),p)
|
||||||
traceback.print_exc(file=sys.stdout)
|
traceback.print_exc(file=sys.stdout)
|
||||||
|
@ -61,10 +61,9 @@ def run_hook(name, *args):
|
||||||
|
|
||||||
class BasePlugin:
|
class BasePlugin:
|
||||||
|
|
||||||
def __init__(self, gui, name):
|
def __init__(self, config, name):
|
||||||
self.gui = gui
|
|
||||||
self.name = name
|
self.name = name
|
||||||
self.config = gui.config
|
self.config = config
|
||||||
# add self to hooks
|
# add self to hooks
|
||||||
for k in dir(self):
|
for k in dir(self):
|
||||||
if k in hook_names:
|
if k in hook_names:
|
||||||
|
|
|
@ -1559,6 +1559,17 @@ class OldWallet(Deterministic_Wallet):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
wallet_types = [
|
||||||
|
('old', ("Old wallet"), OldWallet),
|
||||||
|
('xpub', ("BIP32 Import"), BIP32_Simple_Wallet),
|
||||||
|
('standard', ("Standard wallet"), NewWallet),
|
||||||
|
('imported', ("Imported wallet"), Imported_Wallet),
|
||||||
|
('2of2', ("Multisig wallet (2 of 2)"), Wallet_2of2),
|
||||||
|
('2of3', ("Multisig wallet (2 of 3)"), Wallet_2of3)
|
||||||
|
]
|
||||||
|
|
||||||
# former WalletFactory
|
# former WalletFactory
|
||||||
class Wallet(object):
|
class Wallet(object):
|
||||||
"""The main wallet "entry point".
|
"""The main wallet "entry point".
|
||||||
|
@ -1568,19 +1579,14 @@ class Wallet(object):
|
||||||
def __new__(self, storage):
|
def __new__(self, storage):
|
||||||
config = storage.config
|
config = storage.config
|
||||||
|
|
||||||
self.wallet_types = [
|
run_hook('add_wallet_types', wallet_types)
|
||||||
('old', ("Old wallet"), OldWallet),
|
wallet_type = storage.get('wallet_type')
|
||||||
('xpub', ("BIP32 Import"), BIP32_Simple_Wallet),
|
if wallet_type:
|
||||||
('standard', ("Standard wallet"), NewWallet),
|
for t, l, WalletClass in wallet_types:
|
||||||
('imported', ("Imported wallet"), Imported_Wallet),
|
if t == wallet_type:
|
||||||
('2of2', ("Multisig wallet (2 of 2)"), Wallet_2of2),
|
return WalletClass(storage)
|
||||||
('2of3', ("Multisig wallet (2 of 3)"), Wallet_2of3)
|
else:
|
||||||
]
|
raise BaseException('unknown wallet type', wallet_type)
|
||||||
run_hook('add_wallet_types', self.wallet_types)
|
|
||||||
|
|
||||||
for t, l, WalletClass in self.wallet_types:
|
|
||||||
if t == storage.get('wallet_type'):
|
|
||||||
return WalletClass(storage)
|
|
||||||
|
|
||||||
if not storage.file_exists:
|
if not storage.file_exists:
|
||||||
seed_version = NEW_SEED_VERSION
|
seed_version = NEW_SEED_VERSION
|
||||||
|
|
|
@ -7,6 +7,7 @@ from sys import stderr
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from base64 import b64encode, b64decode
|
from base64 import b64encode, b64decode
|
||||||
|
|
||||||
|
import electrum
|
||||||
from electrum_gui.qt.password_dialog import make_password_dialog, run_password_dialog
|
from electrum_gui.qt.password_dialog import make_password_dialog, run_password_dialog
|
||||||
from electrum_gui.qt.util import ok_cancel_buttons
|
from electrum_gui.qt.util import ok_cancel_buttons
|
||||||
from electrum.account import BIP32_Account
|
from electrum.account import BIP32_Account
|
||||||
|
@ -41,14 +42,18 @@ def give_error(message):
|
||||||
|
|
||||||
class Plugin(BasePlugin):
|
class Plugin(BasePlugin):
|
||||||
|
|
||||||
def fullname(self): return 'BTChip Wallet'
|
def fullname(self):
|
||||||
|
return 'BTChip Wallet'
|
||||||
|
|
||||||
def description(self): return 'Provides support for BTChip hardware wallet\n\nRequires github.com/btchip/btchip-python'
|
def description(self):
|
||||||
|
return 'Provides support for BTChip hardware wallet\n\nRequires github.com/btchip/btchip-python'
|
||||||
|
|
||||||
def __init__(self, gui, name):
|
def __init__(self, gui, name):
|
||||||
BasePlugin.__init__(self, gui, name)
|
BasePlugin.__init__(self, gui, name)
|
||||||
self._is_available = self._init()
|
self._is_available = self._init()
|
||||||
self.wallet = None
|
self.wallet = None
|
||||||
|
electrum.wallet.wallet_types.append(('btchip', _("BTChip wallet"), BTChipWallet))
|
||||||
|
|
||||||
|
|
||||||
def _init(self):
|
def _init(self):
|
||||||
return BTCHIP
|
return BTCHIP
|
||||||
|
@ -76,12 +81,12 @@ class Plugin(BasePlugin):
|
||||||
return BasePlugin.enable(self)
|
return BasePlugin.enable(self)
|
||||||
|
|
||||||
@hook
|
@hook
|
||||||
def load_wallet(self, wallet):
|
def init_qt(self, gui):
|
||||||
self.wallet = wallet
|
self.gui = gui
|
||||||
|
|
||||||
@hook
|
@hook
|
||||||
def add_wallet_types(self, wallet_types):
|
def load_wallet(self, wallet):
|
||||||
wallet_types.append(('btchip', _("BTChip wallet"), BTChipWallet))
|
self.wallet = wallet
|
||||||
|
|
||||||
@hook
|
@hook
|
||||||
def installwizard_restore(self, wizard, storage):
|
def installwizard_restore(self, wizard, storage):
|
||||||
|
|
|
@ -52,6 +52,10 @@ class Plugin(BasePlugin):
|
||||||
def _init(self):
|
def _init(self):
|
||||||
return loaded_qweb
|
return loaded_qweb
|
||||||
|
|
||||||
|
@hook
|
||||||
|
def init_qt(self, gui):
|
||||||
|
self.gui = gui
|
||||||
|
|
||||||
def is_available(self):
|
def is_available(self):
|
||||||
return self._is_available
|
return self._is_available
|
||||||
|
|
||||||
|
|
|
@ -90,8 +90,8 @@ class Plugin(BasePlugin):
|
||||||
return description
|
return description
|
||||||
|
|
||||||
@hook
|
@hook
|
||||||
def init(self):
|
def init_qt(self, gui):
|
||||||
self.win = self.gui.main_window
|
self.win = gui.main_window
|
||||||
self.win.connect(self.win, SIGNAL('cosigner:receive'), self.on_receive)
|
self.win.connect(self.win, SIGNAL('cosigner:receive'), self.on_receive)
|
||||||
if self.listener is None:
|
if self.listener is None:
|
||||||
self.listener = Listener(self)
|
self.listener = Listener(self)
|
||||||
|
|
|
@ -339,7 +339,8 @@ class Plugin(BasePlugin):
|
||||||
self.exchanges = [self.config.get('use_exchange', "Blockchain")]
|
self.exchanges = [self.config.get('use_exchange', "Blockchain")]
|
||||||
|
|
||||||
@hook
|
@hook
|
||||||
def init(self):
|
def init_qt(self, gui):
|
||||||
|
self.gui = gui
|
||||||
self.win = self.gui.main_window
|
self.win = self.gui.main_window
|
||||||
self.win.connect(self.win, SIGNAL("refresh_currencies()"), self.win.update_status)
|
self.win.connect(self.win, SIGNAL("refresh_currencies()"), self.win.update_status)
|
||||||
self.btc_rate = Decimal("0.0")
|
self.btc_rate = Decimal("0.0")
|
||||||
|
|
|
@ -44,9 +44,9 @@ class Plugin(BasePlugin):
|
||||||
return decoded_message
|
return decoded_message
|
||||||
|
|
||||||
@hook
|
@hook
|
||||||
def init(self):
|
def init_qt(self, gui):
|
||||||
self.target_host = 'labelectrum.herokuapp.com'
|
self.target_host = 'labelectrum.herokuapp.com'
|
||||||
self.window = self.gui.main_window
|
self.window = gui.main_window
|
||||||
|
|
||||||
@hook
|
@hook
|
||||||
def load_wallet(self, wallet):
|
def load_wallet(self, wallet):
|
||||||
|
@ -154,7 +154,7 @@ class Plugin(BasePlugin):
|
||||||
def enable(self):
|
def enable(self):
|
||||||
if not self.auth_token(): # First run, throw plugin settings in your face
|
if not self.auth_token(): # First run, throw plugin settings in your face
|
||||||
self.init()
|
self.init()
|
||||||
self.load_wallet(self.gui.main_window.wallet)
|
self.load_wallet(self.window.wallet)
|
||||||
if self.settings_dialog():
|
if self.settings_dialog():
|
||||||
self.set_enabled(True)
|
self.set_enabled(True)
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -6,6 +6,7 @@ from sys import stderr
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from base64 import b64encode, b64decode
|
from base64 import b64encode, b64decode
|
||||||
|
|
||||||
|
import electrum
|
||||||
from electrum_gui.qt.password_dialog import make_password_dialog, run_password_dialog
|
from electrum_gui.qt.password_dialog import make_password_dialog, run_password_dialog
|
||||||
from electrum_gui.qt.util import ok_cancel_buttons, EnterButton
|
from electrum_gui.qt.util import ok_cancel_buttons, EnterButton
|
||||||
from electrum.account import BIP32_Account
|
from electrum.account import BIP32_Account
|
||||||
|
@ -36,15 +37,18 @@ def give_error(message):
|
||||||
|
|
||||||
class Plugin(BasePlugin):
|
class Plugin(BasePlugin):
|
||||||
|
|
||||||
def fullname(self): return 'Trezor Wallet'
|
def fullname(self):
|
||||||
|
return 'Trezor Wallet'
|
||||||
|
|
||||||
def description(self): return 'Provides support for Trezor hardware wallet\n\nRequires github.com/trezor/python-trezor'
|
def description(self):
|
||||||
|
return 'Provides support for Trezor hardware wallet\n\nRequires github.com/trezor/python-trezor'
|
||||||
|
|
||||||
def __init__(self, gui, name):
|
def __init__(self, config, name):
|
||||||
BasePlugin.__init__(self, gui, name)
|
BasePlugin.__init__(self, config, name)
|
||||||
self._is_available = self._init()
|
self._is_available = self._init()
|
||||||
self._requires_settings = True
|
self._requires_settings = True
|
||||||
self.wallet = None
|
self.wallet = None
|
||||||
|
electrum.wallet.wallet_types.append(('trezor', _("Trezor wallet"), TrezorWallet))
|
||||||
|
|
||||||
def _init(self):
|
def _init(self):
|
||||||
return TREZOR
|
return TREZOR
|
||||||
|
@ -78,10 +82,6 @@ class Plugin(BasePlugin):
|
||||||
def load_wallet(self, wallet):
|
def load_wallet(self, wallet):
|
||||||
self.wallet = wallet
|
self.wallet = wallet
|
||||||
|
|
||||||
@hook
|
|
||||||
def add_wallet_types(self, wallet_types):
|
|
||||||
wallet_types.append(('trezor', _("Trezor wallet"), TrezorWallet))
|
|
||||||
|
|
||||||
@hook
|
@hook
|
||||||
def installwizard_restore(self, wizard, storage):
|
def installwizard_restore(self, wizard, storage):
|
||||||
if storage.get('wallet_type') != 'trezor':
|
if storage.get('wallet_type') != 'trezor':
|
||||||
|
|
|
@ -11,7 +11,9 @@ class Plugin(BasePlugin):
|
||||||
def description(self):
|
def description(self):
|
||||||
return '%s\n%s' % (_("Add an optional virtual keyboard to the password dialog."), _("Warning: do not use this if it makes you pick a weaker password."))
|
return '%s\n%s' % (_("Add an optional virtual keyboard to the password dialog."), _("Warning: do not use this if it makes you pick a weaker password."))
|
||||||
|
|
||||||
def init(self):
|
@hook
|
||||||
|
def init_qt(self, gui):
|
||||||
|
self.gui = gui
|
||||||
self.vkb = None
|
self.vkb = None
|
||||||
self.vkb_index = 0
|
self.vkb_index = 0
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue