mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-09-05 05:15:12 +00:00
qt console: expose more refs, and fix auto-complete for >2 depth
This commit is contained in:
parent
9037f25da1
commit
5e0179dac4
2 changed files with 27 additions and 17 deletions
|
@ -309,31 +309,34 @@ class Console(QtWidgets.QPlainTextEdit):
|
||||||
|
|
||||||
super(Console, self).keyPressEvent(event)
|
super(Console, self).keyPressEvent(event)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def completions(self):
|
def completions(self):
|
||||||
cmd = self.getCommand()
|
cmd = self.getCommand()
|
||||||
lastword = re.split(' |\(|\)',cmd)[-1]
|
lastword = re.split(' |\(|\)',cmd)[-1]
|
||||||
beginning = cmd[0:-len(lastword)]
|
beginning = cmd[0:-len(lastword)]
|
||||||
|
|
||||||
path = lastword.split('.')
|
path = lastword.split('.')
|
||||||
|
prefix = '.'.join(path[:-1])
|
||||||
|
prefix = (prefix + '.') if prefix else prefix
|
||||||
ns = self.namespace.keys()
|
ns = self.namespace.keys()
|
||||||
|
|
||||||
if len(path) == 1:
|
if len(path) == 1:
|
||||||
ns = ns
|
ns = ns
|
||||||
prefix = ''
|
|
||||||
else:
|
else:
|
||||||
|
assert len(path) > 1
|
||||||
obj = self.namespace.get(path[0])
|
obj = self.namespace.get(path[0])
|
||||||
prefix = path[0] + '.'
|
try:
|
||||||
ns = dir(obj)
|
for attr in path[1:-1]:
|
||||||
|
obj = getattr(obj, attr)
|
||||||
|
except AttributeError:
|
||||||
|
ns = []
|
||||||
|
else:
|
||||||
|
ns = dir(obj)
|
||||||
|
|
||||||
completions = []
|
completions = []
|
||||||
for x in ns:
|
for name in ns:
|
||||||
if x[0] == '_':continue
|
if name[0] == '_':continue
|
||||||
xx = prefix + x
|
if name.startswith(path[-1]):
|
||||||
if xx.startswith(lastword):
|
completions.append(prefix+name)
|
||||||
completions.append(xx)
|
|
||||||
completions.sort()
|
completions.sort()
|
||||||
|
|
||||||
if not completions:
|
if not completions:
|
||||||
|
|
|
@ -42,6 +42,7 @@ from PyQt5.QtCore import *
|
||||||
import PyQt5.QtCore as QtCore
|
import PyQt5.QtCore as QtCore
|
||||||
from PyQt5.QtWidgets import *
|
from PyQt5.QtWidgets import *
|
||||||
|
|
||||||
|
import electrum
|
||||||
from electrum import (keystore, simple_config, ecc, constants, util, bitcoin, commands,
|
from electrum import (keystore, simple_config, ecc, constants, util, bitcoin, commands,
|
||||||
coinchooser, paymentrequest)
|
coinchooser, paymentrequest)
|
||||||
from electrum.bitcoin import COIN, is_address, TYPE_ADDRESS
|
from electrum.bitcoin import COIN, is_address, TYPE_ADDRESS
|
||||||
|
@ -1950,18 +1951,24 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
||||||
console.history = self.config.get("console-history",[])
|
console.history = self.config.get("console-history",[])
|
||||||
console.history_index = len(console.history)
|
console.history_index = len(console.history)
|
||||||
|
|
||||||
console.updateNamespace({'wallet' : self.wallet,
|
console.updateNamespace({
|
||||||
'network' : self.network,
|
'wallet': self.wallet,
|
||||||
'plugins' : self.gui_object.plugins,
|
'network': self.network,
|
||||||
'window': self})
|
'plugins': self.gui_object.plugins,
|
||||||
console.updateNamespace({'util' : util, 'bitcoin':bitcoin})
|
'window': self,
|
||||||
|
'config': self.config,
|
||||||
|
'electrum': electrum,
|
||||||
|
'daemon': self.gui_object.daemon,
|
||||||
|
'util': util,
|
||||||
|
'bitcoin': bitcoin,
|
||||||
|
})
|
||||||
|
|
||||||
c = commands.Commands(self.config, self.wallet, self.network, lambda: self.console.set_json(True))
|
c = commands.Commands(self.config, self.wallet, self.network, lambda: self.console.set_json(True))
|
||||||
methods = {}
|
methods = {}
|
||||||
def mkfunc(f, method):
|
def mkfunc(f, method):
|
||||||
return lambda *args: f(method, args, self.password_dialog)
|
return lambda *args: f(method, args, self.password_dialog)
|
||||||
for m in dir(c):
|
for m in dir(c):
|
||||||
if m[0]=='_' or m in ['network','wallet']: continue
|
if m[0]=='_' or m in ['network','wallet','config']: continue
|
||||||
methods[m] = mkfunc(c._run, m)
|
methods[m] = mkfunc(c._run, m)
|
||||||
|
|
||||||
console.updateNamespace(methods)
|
console.updateNamespace(methods)
|
||||||
|
|
Loading…
Add table
Reference in a new issue