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.Layouts 1.0
|
||||||
import QtQuick.Controls.Material 2.0
|
import QtQuick.Controls.Material 2.0
|
||||||
|
|
||||||
|
import org.electrum 1.0
|
||||||
|
|
||||||
ItemDelegate {
|
ItemDelegate {
|
||||||
id: root
|
id: root
|
||||||
height: item.height
|
height: item.height
|
||||||
@@ -10,6 +12,9 @@ ItemDelegate {
|
|||||||
|
|
||||||
font.pixelSize: constants.fontSizeSmall // set default font size for child controls
|
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 {
|
GridLayout {
|
||||||
id: item
|
id: item
|
||||||
|
|
||||||
@@ -36,6 +41,8 @@ ItemDelegate {
|
|||||||
Layout.rowSpan: 3
|
Layout.rowSpan: 3
|
||||||
Layout.preferredWidth: constants.iconSizeLarge
|
Layout.preferredWidth: constants.iconSizeLarge
|
||||||
Layout.preferredHeight: constants.iconSizeLarge
|
Layout.preferredHeight: constants.iconSizeLarge
|
||||||
|
opacity: _closed ? 0.5 : 1.0
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RowLayout {
|
RowLayout {
|
||||||
@@ -46,10 +53,12 @@ ItemDelegate {
|
|||||||
elide: Text.ElideRight
|
elide: Text.ElideRight
|
||||||
wrapMode: Text.Wrap
|
wrapMode: Text.Wrap
|
||||||
maximumLineCount: 2
|
maximumLineCount: 2
|
||||||
|
color: _closed ? constants.mutedForeground : Material.foreground
|
||||||
}
|
}
|
||||||
|
|
||||||
Label {
|
Label {
|
||||||
text: model.state
|
text: model.state
|
||||||
|
color: _closed ? constants.mutedForeground : Material.foreground
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,16 +73,18 @@ ItemDelegate {
|
|||||||
Label {
|
Label {
|
||||||
text: Config.formatSats(model.capacity)
|
text: Config.formatSats(model.capacity)
|
||||||
font.family: FixedFont
|
font.family: FixedFont
|
||||||
|
color: _closed ? constants.mutedForeground : Material.foreground
|
||||||
}
|
}
|
||||||
|
|
||||||
Label {
|
Label {
|
||||||
text: Config.baseUnit
|
text: Config.baseUnit
|
||||||
color: Material.accentColor
|
color: _closed ? constants.mutedForeground : Material.accentColor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
id: chviz
|
id: chviz
|
||||||
|
visible: !_closed
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
height: 10
|
height: 10
|
||||||
onWidthChanged: {
|
onWidthChanged: {
|
||||||
@@ -109,6 +120,12 @@ ItemDelegate {
|
|||||||
color: 'gray'
|
color: 'gray'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Item {
|
||||||
|
visible: _closed
|
||||||
|
Layout.fillWidth: true
|
||||||
|
height: 1
|
||||||
|
}
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
Layout.columnSpan: 2
|
Layout.columnSpan: 2
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
|
|||||||
@@ -6,15 +6,21 @@ from electrum.i18n import _
|
|||||||
from electrum.gui import messages
|
from electrum.gui import messages
|
||||||
from electrum.logging import get_logger
|
from electrum.logging import get_logger
|
||||||
from electrum.lnutil import LOCAL, REMOTE
|
from electrum.lnutil import LOCAL, REMOTE
|
||||||
from electrum.lnchannel import ChanCloseOption
|
from electrum.lnchannel import ChanCloseOption, ChannelState
|
||||||
|
|
||||||
from .qewallet import QEWallet
|
from .qewallet import QEWallet
|
||||||
from .qetypes import QEAmount
|
from .qetypes import QEAmount
|
||||||
from .util import QtEventListener, qt_event_listener, event_listener
|
from .util import QtEventListener, qt_event_listener, event_listener
|
||||||
|
|
||||||
class QEChannelDetails(QObject, QtEventListener):
|
class QEChannelDetails(QObject, QtEventListener):
|
||||||
|
|
||||||
_logger = get_logger(__name__)
|
_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
|
_wallet = None
|
||||||
_channelid = None
|
_channelid = None
|
||||||
_channel = None
|
_channel = None
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from datetime import datetime, timedelta
|
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 PyQt5.QtCore import Qt, QAbstractListModel, QModelIndex
|
||||||
|
|
||||||
from electrum.logging import get_logger
|
from electrum.logging import get_logger
|
||||||
@@ -15,8 +15,8 @@ class QEChannelListModel(QAbstractListModel, QtEventListener):
|
|||||||
_logger = get_logger(__name__)
|
_logger = get_logger(__name__)
|
||||||
|
|
||||||
# define listmodel rolemap
|
# define listmodel rolemap
|
||||||
_ROLE_NAMES=('cid','state','initiator','capacity','can_send','can_receive',
|
_ROLE_NAMES=('cid','state','state_code','initiator','capacity','can_send',
|
||||||
'l_csv_delay','r_csv_delay','send_frozen','receive_frozen',
|
'can_receive','l_csv_delay','r_csv_delay','send_frozen','receive_frozen',
|
||||||
'type','node_id','node_alias','short_cid','funding_tx')
|
'type','node_id','node_alias','short_cid','funding_tx')
|
||||||
_ROLE_KEYS = range(Qt.UserRole, Qt.UserRole + len(_ROLE_NAMES))
|
_ROLE_KEYS = range(Qt.UserRole, Qt.UserRole + len(_ROLE_NAMES))
|
||||||
_ROLE_MAP = dict(zip(_ROLE_KEYS, [bytearray(x.encode()) for x in _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['node_alias'] = lnworker.get_node_alias(lnc.node_id) or lnc.node_id.hex()
|
||||||
item['short_cid'] = lnc.short_id_for_GUI()
|
item['short_cid'] = lnc.short_id_for_GUI()
|
||||||
item['state'] = lnc.get_state_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['capacity'] = QEAmount(amount_sat=lnc.get_capacity())
|
||||||
item['can_send'] = QEAmount(amount_msat=lnc.available_to_spend(LOCAL))
|
item['can_send'] = QEAmount(amount_msat=lnc.available_to_spend(LOCAL))
|
||||||
item['can_receive'] = QEAmount(amount_msat=lnc.available_to_spend(REMOTE))
|
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)
|
item = self.channel_to_model(channel)
|
||||||
channels.append(item)
|
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.clear()
|
||||||
self.beginInsertRows(QModelIndex(), 0, len(channels) - 1)
|
self.beginInsertRows(QModelIndex(), 0, len(channels) - 1)
|
||||||
self.channels = channels
|
self.channels = channels
|
||||||
|
|||||||
Reference in New Issue
Block a user