qt ChannelsList: (trivial) format_fields should not know column order
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import traceback
|
import traceback
|
||||||
from enum import IntEnum
|
from enum import IntEnum
|
||||||
from typing import Sequence, Optional
|
from typing import Sequence, Optional, Dict
|
||||||
|
|
||||||
from PyQt5 import QtCore, QtGui
|
from PyQt5 import QtCore, QtGui
|
||||||
from PyQt5.QtCore import Qt
|
from PyQt5.QtCore import Qt
|
||||||
@@ -68,7 +68,7 @@ class ChannelsList(MyTreeView):
|
|||||||
self.lnbackups = self.parent.wallet.lnbackups
|
self.lnbackups = self.parent.wallet.lnbackups
|
||||||
self.setSortingEnabled(True)
|
self.setSortingEnabled(True)
|
||||||
|
|
||||||
def format_fields(self, chan: AbstractChannel) -> Sequence[str]:
|
def format_fields(self, chan: AbstractChannel) -> Dict['ChannelsList.Columns', str]:
|
||||||
labels = {}
|
labels = {}
|
||||||
for subject in (REMOTE, LOCAL):
|
for subject in (REMOTE, LOCAL):
|
||||||
if isinstance(chan, Channel):
|
if isinstance(chan, Channel):
|
||||||
@@ -90,14 +90,14 @@ class ChannelsList(MyTreeView):
|
|||||||
capacity_str = self.parent.format_amount(chan.constraints.capacity)
|
capacity_str = self.parent.format_amount(chan.constraints.capacity)
|
||||||
else:
|
else:
|
||||||
capacity_str = ''
|
capacity_str = ''
|
||||||
return [
|
return {
|
||||||
chan.short_id_for_GUI(),
|
self.Columns.SHORT_CHANID: chan.short_id_for_GUI(),
|
||||||
node_alias,
|
self.Columns.NODE_ALIAS: node_alias,
|
||||||
capacity_str,
|
self.Columns.CAPACITY: capacity_str,
|
||||||
'' if closed else labels[LOCAL],
|
self.Columns.LOCAL_BALANCE: '' if closed else labels[LOCAL],
|
||||||
'' if closed else labels[REMOTE],
|
self.Columns.REMOTE_BALANCE: '' if closed else labels[REMOTE],
|
||||||
status
|
self.Columns.CHANNEL_STATUS: status,
|
||||||
]
|
}
|
||||||
|
|
||||||
def on_success(self, txid):
|
def on_success(self, txid):
|
||||||
self.main_window.show_error('Channel closed' + '\n' + txid)
|
self.main_window.show_error('Channel closed' + '\n' + txid)
|
||||||
@@ -237,7 +237,7 @@ class ChannelsList(MyTreeView):
|
|||||||
item = self.model().item(row, self.Columns.NODE_ALIAS)
|
item = self.model().item(row, self.Columns.NODE_ALIAS)
|
||||||
if item.data(ROLE_CHANNEL_ID) != chan.channel_id:
|
if item.data(ROLE_CHANNEL_ID) != chan.channel_id:
|
||||||
continue
|
continue
|
||||||
for column, v in enumerate(self.format_fields(chan)):
|
for column, v in self.format_fields(chan).items():
|
||||||
self.model().item(row, column).setData(v, QtCore.Qt.DisplayRole)
|
self.model().item(row, column).setData(v, QtCore.Qt.DisplayRole)
|
||||||
items = [self.model().item(row, column) for column in self.Columns]
|
items = [self.model().item(row, column) for column in self.Columns]
|
||||||
self._update_chan_frozen_bg(chan=chan, items=items)
|
self._update_chan_frozen_bg(chan=chan, items=items)
|
||||||
@@ -259,7 +259,8 @@ class ChannelsList(MyTreeView):
|
|||||||
self.model().clear()
|
self.model().clear()
|
||||||
self.update_headers(self.headers)
|
self.update_headers(self.headers)
|
||||||
for chan in channels + backups:
|
for chan in channels + backups:
|
||||||
items = [QtGui.QStandardItem(x) for x in self.format_fields(chan)]
|
field_map = self.format_fields(chan)
|
||||||
|
items = [QtGui.QStandardItem(field_map[col]) for col in sorted(field_map)]
|
||||||
self.set_editability(items)
|
self.set_editability(items)
|
||||||
if self._default_item_bg_brush is None:
|
if self._default_item_bg_brush is None:
|
||||||
self._default_item_bg_brush = items[self.Columns.NODE_ALIAS].background()
|
self._default_item_bg_brush = items[self.Columns.NODE_ALIAS].background()
|
||||||
|
|||||||
Reference in New Issue
Block a user