Browse Source

lightning network dialog

regtest_lnd
ThomasV 6 years ago
committed by SomberNight
parent
commit
2a95afe7b7
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 36
      electrum/gui/qt/__init__.py
  2. 10
      electrum/gui/qt/channels_list.py
  3. 32
      electrum/gui/qt/lightning_dialog.py
  4. 8
      electrum/gui/qt/main_window.py

36
electrum/gui/qt/__init__.py

@ -55,6 +55,7 @@ from .util import get_default_language, read_QIcon, ColorScheme, custom_message_
from .main_window import ElectrumWindow
from .network_dialog import NetworkDialog
from .stylesheet_patcher import patch_qt_stylesheet
from .lightning_dialog import LightningDialog
class OpenFileEventFilter(QObject):
@ -107,8 +108,8 @@ class ElectrumGui(Logger):
self.timer.setSingleShot(False)
self.timer.setInterval(500) # msec
self.nd = None
self.watchtower_window = None
self.network_dialog = None
self.lightning_dialog = None
self.network_updated_signal_obj = QNetworkUpdatedSignalObject()
self._num_wizards_in_progress = 0
self._num_wizards_lock = threading.Lock()
@ -148,7 +149,7 @@ class ElectrumGui(Logger):
m = self.tray.contextMenu()
m.clear()
if self.config.get('lightning'):
m.addAction(_("Watchtower"), self.show_watchtower_dialog)
m.addAction(_("Lightning"), self.show_lightning_dialog)
for window in self.windows:
name = window.wallet.basename()
submenu = m.addMenu(name)
@ -181,33 +182,32 @@ class ElectrumGui(Logger):
def close(self):
for window in self.windows:
window.close()
if self.nd:
self.nd.close()
if self.watchtower_window:
self.watchtower_window.close()
if self.network_dialog:
self.network_dialog.close()
if self.lightning_dialog:
self.lightning_dialog.close()
def new_window(self, path, uri=None):
# Use a signal as can be called from daemon thread
self.app.new_window_signal.emit(path, uri)
def show_watchtower_dialog(self, parent=None):
from .watchtower_window import WatchTowerWindow
if not self.watchtower_window:
self.watchtower_window = WatchTowerWindow(self)
self.watchtower_window.bring_to_top()
def show_lightning_dialog(self):
if not self.lightning_dialog:
self.lightning_dialog = LightningDialog(self)
self.lightning_dialog.bring_to_top()
def show_network_dialog(self, parent):
if not self.daemon.network:
parent.show_warning(_('You are using Electrum in offline mode; restart Electrum if you want to get connected'), title=_('Offline'))
return
if self.nd:
self.nd.on_update()
self.nd.show()
self.nd.raise_()
if self.network_dialog:
self.network_dialog.on_update()
self.network_dialog.show()
self.network_dialog.raise_()
return
self.nd = NetworkDialog(self.daemon.network, self.config,
self.network_dialog = NetworkDialog(self.daemon.network, self.config,
self.network_updated_signal_obj)
self.nd.show()
self.network_dialog.show()
def _create_window_for_wallet(self, wallet):
w = ElectrumWindow(self, wallet)

10
electrum/gui/qt/channels_list.py

@ -23,7 +23,6 @@ class ChannelsList(MyTreeView):
self.main_window = parent
self.update_rows.connect(self.do_update_rows)
self.update_single_row.connect(self.do_update_single_row)
self.status = QLabel('')
def format_fields(self, chan):
labels = {}
@ -98,19 +97,10 @@ class ChannelsList(MyTreeView):
def get_toolbar(self):
h = QHBoxLayout()
h.addWidget(self.status)
h.addStretch()
h.addWidget(EnterButton(_('Open Channel'), self.new_channel_dialog))
return h
def update_status(self):
network = self.parent.network
if network.lngossip is None:
return
channel_db = self.parent.network.channel_db
num_peers = sum([p.initialized.is_set() for p in network.lngossip.peers.values()])
msg = _('{} peers, {} nodes, {} channels.').format(num_peers, channel_db.num_nodes, channel_db.num_channels)
self.status.setText(msg)
def statistics_dialog(self):
channel_db = self.parent.network.channel_db

32
electrum/gui/qt/watchtower_window.py → electrum/gui/qt/lightning_dialog.py

@ -62,23 +62,29 @@ class WatcherList(MyTreeView):
self.model().insertRow(self.model().rowCount(), items)
class WatchTowerWindow(QDialog):
class LightningDialog(QDialog):
def __init__(self, gui_object):
QDialog.__init__(self)
self.gui_object = gui_object
self.config = gui_object.config
self.lnwatcher = gui_object.daemon.network.lnwatcher
self.setWindowTitle(_('Watchtower'))
self.network = gui_object.daemon.network
self.lnwatcher = self.network.lnwatcher
self.setWindowTitle(_('Lightning'))
self.setMinimumSize(600, 20)
watchtower_url = self.config.get('watchtower_url')
self.watchtower_e = QLineEdit(watchtower_url)
self.channel_list = WatcherList(self)
self.watcher_list = WatcherList(self)
# channel_db
network_w = QWidget()
network_vbox = QVBoxLayout(network_w)
self.status = QLabel('')
network_vbox.addWidget(self.status)
# local
local_w = QWidget()
vbox_local = QVBoxLayout(local_w)
vbox_local.addWidget(WWLabel(help_about))
vbox_local.addWidget(self.channel_list)
vbox_local.addWidget(self.watcher_list)
# remote
remote_w = QWidget()
vbox_remote = QVBoxLayout(remote_w)
@ -90,14 +96,24 @@ class WatchTowerWindow(QDialog):
vbox_remote.addStretch(1)
# tabs
tabs = QTabWidget()
tabs.addTab(local_w, _('Local'))
tabs.addTab(remote_w, _('Remote'))
tabs.addTab(network_w, _('Network'))
tabs.addTab(local_w, _('Watchtower'))
tabs.addTab(remote_w, _('Settings'))
vbox = QVBoxLayout(self)
vbox.addWidget(tabs)
b = QPushButton(_('Close'))
b.clicked.connect(self.on_close)
vbox.addLayout(Buttons(b))
self.channel_list.update()
self.watcher_list.update()
self.gui_object.timer.timeout.connect(self.update_status)
def update_status(self):
if self.network.lngossip is None:
return
channel_db = self.network.channel_db
num_peers = sum([p.initialized.is_set() for p in self.network.lngossip.peers.values()])
msg = _('{} peers, {} nodes, {} channels.').format(num_peers, channel_db.num_nodes, channel_db.num_channels)
self.status.setText(msg)
def on_close(self):
url = self.watchtower_e.text()

8
electrum/gui/qt/main_window.py

@ -158,8 +158,6 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
self.create_status_bar()
self.need_update = threading.Event()
self.need_update_ln = threading.Event()
self.decimal_point = config.get('decimal_point', DECIMAL_POINT_DEFAULT)
try:
decimal_point_to_base_unit_name(self.decimal_point)
@ -225,7 +223,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
interests = ['wallet_updated', 'network_updated', 'blockchain_updated',
'new_transaction', 'status',
'banner', 'verified', 'fee', 'fee_histogram', 'on_quotes',
'on_history', 'channel', 'channels', 'ln_status', 'ln_message',
'on_history', 'channel', 'channels', 'ln_message',
'ln_payment_completed']
# To avoid leaking references to "self" that prevent the
# window from being GC-ed when closed, callbacks should be
@ -375,8 +373,6 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
elif event == 'channel':
self.channels_list.update_single_row.emit(*args)
self.update_status()
elif event == 'ln_status':
self.need_update_ln.set()
elif event == 'ln_payment_completed':
# FIXME it is really inefficient to force update the whole GUI
# just for a single LN payment. individual rows in lists should be updated instead.
@ -639,7 +635,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
tools_menu.addAction(_("Electrum preferences") if sys.platform == 'darwin' else _("Preferences"), self.settings_dialog)
tools_menu.addAction(_("&Network"), lambda: self.gui_object.show_network_dialog(self))
if self.config.get('lightning'):
tools_menu.addAction(_("&Watchtower"), lambda: self.gui_object.show_watchtower_dialog(self))
tools_menu.addAction(_("&Lightning"), self.gui_object.show_lightning_dialog)
tools_menu.addAction(_("&Plugins"), self.plugins_dialog)
tools_menu.addSeparator()
tools_menu.addAction(_("&Sign/verify message"), self.sign_verify_message)

Loading…
Cancel
Save