From 9547fb7b06b8c1ef03c04bae0a87411f5a58af2f Mon Sep 17 00:00:00 2001 From: SomberNight Date: Tue, 6 Aug 2019 05:20:53 +0200 Subject: [PATCH] qt console: accept kwargs for commands.py methods e.g. make_seed(nbits=264, segwit=True) also allow setting "password" as a kwarg --- electrum/commands.py | 15 +++++++-------- electrum/gui/qt/main_window.py | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/electrum/commands.py b/electrum/commands.py index 77c695c94..7177bc0f0 100644 --- a/electrum/commands.py +++ b/electrum/commands.py @@ -107,21 +107,20 @@ class Commands: self.network = network self._callback = callback - def _run(self, method, args, password_getter): - # this wrapper is called from the python console + def _run(self, method, args, password_getter, **kwargs): + """This wrapper is called from the Qt python console.""" cmd = known_commands[method] - if cmd.requires_password and self.wallet.has_password(): + password = kwargs.get('password', None) + if (cmd.requires_password and self.wallet.has_password() + and password is None): password = password_getter() if password is None: return - else: - password = None f = getattr(self, method) if cmd.requires_password: - result = f(*args, **{'password':password}) - else: - result = f(*args) + kwargs['password'] = password + result = f(*args, **kwargs) if self._callback: self._callback() diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py index d001ba4df..769103005 100644 --- a/electrum/gui/qt/main_window.py +++ b/electrum/gui/qt/main_window.py @@ -2087,7 +2087,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): c = commands.Commands(self.config, self.wallet, self.network, lambda: self.console.set_json(True)) methods = {} def mkfunc(f, method): - return lambda *args: f(method, args, self.password_dialog) + return lambda *args, **kwargs: f(method, args, self.password_dialog, **kwargs) for m in dir(c): if m[0]=='_' or m in ['network','wallet','config']: continue methods[m] = mkfunc(c._run, m)