mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-09-03 12:30:07 +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)
|
||||
|
||||
|
||||
|
||||
def completions(self):
|
||||
cmd = self.getCommand()
|
||||
lastword = re.split(' |\(|\)',cmd)[-1]
|
||||
beginning = cmd[0:-len(lastword)]
|
||||
|
||||
path = lastword.split('.')
|
||||
prefix = '.'.join(path[:-1])
|
||||
prefix = (prefix + '.') if prefix else prefix
|
||||
ns = self.namespace.keys()
|
||||
|
||||
if len(path) == 1:
|
||||
ns = ns
|
||||
prefix = ''
|
||||
else:
|
||||
assert len(path) > 1
|
||||
obj = self.namespace.get(path[0])
|
||||
prefix = path[0] + '.'
|
||||
ns = dir(obj)
|
||||
|
||||
try:
|
||||
for attr in path[1:-1]:
|
||||
obj = getattr(obj, attr)
|
||||
except AttributeError:
|
||||
ns = []
|
||||
else:
|
||||
ns = dir(obj)
|
||||
|
||||
completions = []
|
||||
for x in ns:
|
||||
if x[0] == '_':continue
|
||||
xx = prefix + x
|
||||
if xx.startswith(lastword):
|
||||
completions.append(xx)
|
||||
for name in ns:
|
||||
if name[0] == '_':continue
|
||||
if name.startswith(path[-1]):
|
||||
completions.append(prefix+name)
|
||||
completions.sort()
|
||||
|
||||
if not completions:
|
||||
|
|
|
@ -42,6 +42,7 @@ from PyQt5.QtCore import *
|
|||
import PyQt5.QtCore as QtCore
|
||||
from PyQt5.QtWidgets import *
|
||||
|
||||
import electrum
|
||||
from electrum import (keystore, simple_config, ecc, constants, util, bitcoin, commands,
|
||||
coinchooser, paymentrequest)
|
||||
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_index = len(console.history)
|
||||
|
||||
console.updateNamespace({'wallet' : self.wallet,
|
||||
'network' : self.network,
|
||||
'plugins' : self.gui_object.plugins,
|
||||
'window': self})
|
||||
console.updateNamespace({'util' : util, 'bitcoin':bitcoin})
|
||||
console.updateNamespace({
|
||||
'wallet': self.wallet,
|
||||
'network': self.network,
|
||||
'plugins': self.gui_object.plugins,
|
||||
'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))
|
||||
methods = {}
|
||||
def mkfunc(f, method):
|
||||
return lambda *args: f(method, args, self.password_dialog)
|
||||
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)
|
||||
|
||||
console.updateNamespace(methods)
|
||||
|
|
Loading…
Add table
Reference in a new issue