Browse Source

qt: MyTreeView: small clean-up for WatcherList and ContactList

master
SomberNight 3 years ago
parent
commit
acc1f22442
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
  1. 5
      electrum/gui/qt/contact_list.py
  2. 25
      electrum/gui/qt/watchtower_dialog.py

5
electrum/gui/qt/contact_list.py

@ -110,7 +110,10 @@ class ContactList(MyTreeView):
set_current = None set_current = None
for key in sorted(self.main_window.contacts.keys()): for key in sorted(self.main_window.contacts.keys()):
contact_type, name = self.main_window.contacts[key] contact_type, name = self.main_window.contacts[key]
items = [QStandardItem(x) for x in (name, key)] labels = [""] * len(self.Columns)
labels[self.Columns.NAME] = name
labels[self.Columns.ADDRESS] = key
items = [QStandardItem(x) for x in labels]
items[self.Columns.NAME].setEditable(contact_type != 'openalias') items[self.Columns.NAME].setEditable(contact_type != 'openalias')
items[self.Columns.ADDRESS].setEditable(False) items[self.Columns.ADDRESS].setEditable(False)
items[self.Columns.NAME].setData(key, self.ROLE_CONTACT_KEY) items[self.Columns.NAME].setData(key, self.ROLE_CONTACT_KEY)

25
electrum/gui/qt/watchtower_dialog.py

@ -23,6 +23,8 @@
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE. # SOFTWARE.
import enum
from PyQt5.QtGui import QStandardItemModel, QStandardItem from PyQt5.QtGui import QStandardItemModel, QStandardItem
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import (QDialog, QVBoxLayout, QPushButton, QLabel) from PyQt5.QtWidgets import (QDialog, QVBoxLayout, QPushButton, QLabel)
@ -32,10 +34,22 @@ from .util import MyTreeView, Buttons
class WatcherList(MyTreeView): class WatcherList(MyTreeView):
class Columns(MyTreeView.BaseColumnsEnum):
OUTPOINT = enum.auto()
TX_COUNT = enum.auto()
STATUS = enum.auto()
headers = {
Columns.OUTPOINT: _('Outpoint'),
Columns.TX_COUNT: _('Tx'),
Columns.STATUS: _('Status'),
}
def __init__(self, parent: 'WatchtowerDialog'): def __init__(self, parent: 'WatchtowerDialog'):
super().__init__( super().__init__(
parent=parent, parent=parent,
stretch_column=0, stretch_column=self.Columns.OUTPOINT,
) )
self.parent = parent self.parent = parent
self.setModel(QStandardItemModel(self)) self.setModel(QStandardItemModel(self))
@ -46,13 +60,18 @@ class WatcherList(MyTreeView):
if self.parent.lnwatcher is None: if self.parent.lnwatcher is None:
return return
self.model().clear() self.model().clear()
self.update_headers({0:_('Outpoint'), 1:_('Tx'), 2:_('Status')}) self.update_headers(self.__class__.headers)
lnwatcher = self.parent.lnwatcher lnwatcher = self.parent.lnwatcher
l = lnwatcher.list_sweep_tx() l = lnwatcher.list_sweep_tx()
for outpoint in l: for outpoint in l:
n = lnwatcher.get_num_tx(outpoint) n = lnwatcher.get_num_tx(outpoint)
status = lnwatcher.get_channel_status(outpoint) status = lnwatcher.get_channel_status(outpoint)
items = [QStandardItem(e) for e in [outpoint, "%d"%n, status]] labels = [""] * len(self.Columns)
labels[self.Columns.OUTPOINT] = outpoint
labels[self.Columns.TX_COUNT] = str(n)
labels[self.Columns.STATUS] = status
items = [QStandardItem(e) for e in labels]
self.set_editability(items)
self.model().insertRow(self.model().rowCount(), items) self.model().insertRow(self.model().rowCount(), items)
size = lnwatcher.sweepstore.filesize() size = lnwatcher.sweepstore.filesize()
self.parent.size_label.setText('Database size: %.2f Mb'%(size/1024/1024.)) self.parent.size_label.setText('Database size: %.2f Mb'%(size/1024/1024.))

Loading…
Cancel
Save