commit 814792eee1a26ecc6b3438ccc8255d8f26e7ee3c
parent a39e270bd3b1789f6e87000efd2d9243b0fad05d
Author: ThomasV <thomasv@electrum.org>
Date: Tue, 18 Jul 2017 21:37:04 +0200
show only active chains
Diffstat:
2 files changed, 27 insertions(+), 22 deletions(-)
diff --git a/gui/qt/network_dialog.py b/gui/qt/network_dialog.py
@@ -94,31 +94,28 @@ class NodesListWidget(QTreeWidget):
def update(self, network):
self.clear()
+ self.addChild = self.addTopLevelItem
checkpoint = network.get_checkpoint()
- n_chains = len(network.blockchains)
- if n_chains > 1:
- for b in network.blockchains.values():
- items = filter(lambda i: i.blockchain==b, network.interfaces.values())
- if items:
- name = network.get_blockchain_name(b)
- x = QTreeWidgetItem([name + '@%d'%checkpoint, '%d'%b.height()])
- x.setData(0, Qt.UserRole, 1)
- x.setData(1, Qt.UserRole, b.checkpoint)
- for i in items:
- star = ' *' if i == network.interface else ''
- item = QTreeWidgetItem([i.host + star, '%d'%i.tip])
- item.setData(0, Qt.UserRole, 0)
- item.setData(1, Qt.UserRole, i.server)
- x.addChild(item)
- self.addTopLevelItem(x)
- x.setExpanded(True)
- else:
- for i in network.interfaces.values():
+ chains = network.get_blockchains()
+ n_chains = len(chains)
+ for k, items in chains.items():
+ b = network.blockchains[k]
+ name = network.get_blockchain_name(b)
+ if n_chains >1:
+ x = QTreeWidgetItem([name + '@%d'%checkpoint, '%d'%b.height()])
+ x.setData(0, Qt.UserRole, 1)
+ x.setData(1, Qt.UserRole, b.checkpoint)
+ else:
+ x = self
+ for i in items:
star = ' *' if i == network.interface else ''
item = QTreeWidgetItem([i.host + star, '%d'%i.tip])
item.setData(0, Qt.UserRole, 0)
item.setData(1, Qt.UserRole, i.server)
- self.addTopLevelItem(item)
+ x.addChild(item)
+ if n_chains>1:
+ self.addTopLevelItem(x)
+ x.setExpanded(True)
h = self.header()
h.setStretchLastSection(False)
@@ -361,7 +358,8 @@ class NetworkChoiceLayout(object):
n = len(self.network.get_interfaces())
status = _("Connected to %d nodes.")%n if n else _("Not connected")
self.status_label.setText(status)
- if len(self.network.blockchains)>1:
+ chains = self.network.get_blockchains()
+ if len(chains)>1:
chain = self.network.blockchain()
checkpoint = self.network.get_checkpoint()
name = self.network.get_blockchain_name(self.network.blockchain())
diff --git a/lib/network.py b/lib/network.py
@@ -1001,9 +1001,16 @@ class Network(util.DaemonThread):
if self.interface and self.interface.blockchain is not None:
self.blockchain_index = self.interface.blockchain.checkpoint
self.config.set_key('blockchain_index', self.blockchain_index)
-
return self.blockchains[self.blockchain_index]
+ def get_blockchains(self):
+ out = {}
+ for k, b in self.blockchains.items():
+ r = filter(lambda i: i.blockchain==b, self.interfaces.values())
+ if r:
+ out[k] = r
+ return out
+
def get_blockchain_name(self, blockchain):
checkpoint = self.get_checkpoint()
_hash = blockchain.get_hash(checkpoint)