qml: visually dim channels in CLOSED and REDEEMED states, apply simple sort on channel state
to put channels in closed/redeemed state at bottom of list
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject
|
||||
from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject, Q_ENUMS
|
||||
from PyQt5.QtCore import Qt, QAbstractListModel, QModelIndex
|
||||
|
||||
from electrum.logging import get_logger
|
||||
@@ -15,8 +15,8 @@ class QEChannelListModel(QAbstractListModel, QtEventListener):
|
||||
_logger = get_logger(__name__)
|
||||
|
||||
# define listmodel rolemap
|
||||
_ROLE_NAMES=('cid','state','initiator','capacity','can_send','can_receive',
|
||||
'l_csv_delay','r_csv_delay','send_frozen','receive_frozen',
|
||||
_ROLE_NAMES=('cid','state','state_code','initiator','capacity','can_send',
|
||||
'can_receive','l_csv_delay','r_csv_delay','send_frozen','receive_frozen',
|
||||
'type','node_id','node_alias','short_cid','funding_tx')
|
||||
_ROLE_KEYS = range(Qt.UserRole, Qt.UserRole + len(_ROLE_NAMES))
|
||||
_ROLE_MAP = dict(zip(_ROLE_KEYS, [bytearray(x.encode()) for x in _ROLE_NAMES]))
|
||||
@@ -78,7 +78,7 @@ class QEChannelListModel(QAbstractListModel, QtEventListener):
|
||||
item['node_alias'] = lnworker.get_node_alias(lnc.node_id) or lnc.node_id.hex()
|
||||
item['short_cid'] = lnc.short_id_for_GUI()
|
||||
item['state'] = lnc.get_state_for_GUI()
|
||||
item['state_code'] = lnc.get_state()
|
||||
item['state_code'] = int(lnc.get_state())
|
||||
item['capacity'] = QEAmount(amount_sat=lnc.get_capacity())
|
||||
item['can_send'] = QEAmount(amount_msat=lnc.available_to_spend(LOCAL))
|
||||
item['can_receive'] = QEAmount(amount_msat=lnc.available_to_spend(REMOTE))
|
||||
@@ -103,6 +103,11 @@ class QEChannelListModel(QAbstractListModel, QtEventListener):
|
||||
item = self.channel_to_model(channel)
|
||||
channels.append(item)
|
||||
|
||||
# sort, for now simply by state
|
||||
def chan_sort_score(c):
|
||||
return c['state_code']
|
||||
channels.sort(key=chan_sort_score)
|
||||
|
||||
self.clear()
|
||||
self.beginInsertRows(QModelIndex(), 0, len(channels) - 1)
|
||||
self.channels = channels
|
||||
|
||||
Reference in New Issue
Block a user