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:
@@ -3,6 +3,8 @@ import QtQuick.Controls 2.0
|
||||
import QtQuick.Layouts 1.0
|
||||
import QtQuick.Controls.Material 2.0
|
||||
|
||||
import org.electrum 1.0
|
||||
|
||||
ItemDelegate {
|
||||
id: root
|
||||
height: item.height
|
||||
@@ -10,6 +12,9 @@ ItemDelegate {
|
||||
|
||||
font.pixelSize: constants.fontSizeSmall // set default font size for child controls
|
||||
|
||||
property bool _closed: model.state_code == ChannelDetails.Closed
|
||||
|| model.state_code == ChannelDetails.Redeemed
|
||||
|
||||
GridLayout {
|
||||
id: item
|
||||
|
||||
@@ -36,6 +41,8 @@ ItemDelegate {
|
||||
Layout.rowSpan: 3
|
||||
Layout.preferredWidth: constants.iconSizeLarge
|
||||
Layout.preferredHeight: constants.iconSizeLarge
|
||||
opacity: _closed ? 0.5 : 1.0
|
||||
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
@@ -46,10 +53,12 @@ ItemDelegate {
|
||||
elide: Text.ElideRight
|
||||
wrapMode: Text.Wrap
|
||||
maximumLineCount: 2
|
||||
color: _closed ? constants.mutedForeground : Material.foreground
|
||||
}
|
||||
|
||||
Label {
|
||||
text: model.state
|
||||
color: _closed ? constants.mutedForeground : Material.foreground
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,16 +73,18 @@ ItemDelegate {
|
||||
Label {
|
||||
text: Config.formatSats(model.capacity)
|
||||
font.family: FixedFont
|
||||
color: _closed ? constants.mutedForeground : Material.foreground
|
||||
}
|
||||
|
||||
Label {
|
||||
text: Config.baseUnit
|
||||
color: Material.accentColor
|
||||
color: _closed ? constants.mutedForeground : Material.accentColor
|
||||
}
|
||||
}
|
||||
|
||||
Item {
|
||||
id: chviz
|
||||
visible: !_closed
|
||||
Layout.fillWidth: true
|
||||
height: 10
|
||||
onWidthChanged: {
|
||||
@@ -109,6 +120,12 @@ ItemDelegate {
|
||||
color: 'gray'
|
||||
}
|
||||
}
|
||||
Item {
|
||||
visible: _closed
|
||||
Layout.fillWidth: true
|
||||
height: 1
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
Layout.columnSpan: 2
|
||||
Layout.fillWidth: true
|
||||
|
||||
@@ -6,15 +6,21 @@ from electrum.i18n import _
|
||||
from electrum.gui import messages
|
||||
from electrum.logging import get_logger
|
||||
from electrum.lnutil import LOCAL, REMOTE
|
||||
from electrum.lnchannel import ChanCloseOption
|
||||
from electrum.lnchannel import ChanCloseOption, ChannelState
|
||||
|
||||
from .qewallet import QEWallet
|
||||
from .qetypes import QEAmount
|
||||
from .util import QtEventListener, qt_event_listener, event_listener
|
||||
|
||||
class QEChannelDetails(QObject, QtEventListener):
|
||||
|
||||
_logger = get_logger(__name__)
|
||||
|
||||
class State: # subset, only ones we currently need in UI
|
||||
Closed = ChannelState.CLOSED
|
||||
Redeemed = ChannelState.REDEEMED
|
||||
|
||||
Q_ENUMS(State)
|
||||
|
||||
_wallet = None
|
||||
_channelid = None
|
||||
_channel = None
|
||||
|
||||
@@ -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