electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit dd37151d65c628271d0161b315a81741ef2ce27b
parent bf7129d57e26709288e052c7649e96e8534b806d
Author: SomberNight <somber.night@protonmail.com>
Date:   Mon,  1 Mar 2021 16:28:18 +0100

qt ChannelsList: (trivial) format_fields should not know column order

Diffstat:
Melectrum/gui/qt/channels_list.py | 25+++++++++++++------------
1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/electrum/gui/qt/channels_list.py b/electrum/gui/qt/channels_list.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- import traceback from enum import IntEnum -from typing import Sequence, Optional +from typing import Sequence, Optional, Dict from PyQt5 import QtCore, QtGui from PyQt5.QtCore import Qt @@ -68,7 +68,7 @@ class ChannelsList(MyTreeView): self.lnbackups = self.parent.wallet.lnbackups self.setSortingEnabled(True) - def format_fields(self, chan: AbstractChannel) -> Sequence[str]: + def format_fields(self, chan: AbstractChannel) -> Dict['ChannelsList.Columns', str]: labels = {} for subject in (REMOTE, LOCAL): if isinstance(chan, Channel): @@ -90,14 +90,14 @@ class ChannelsList(MyTreeView): capacity_str = self.parent.format_amount(chan.constraints.capacity) else: capacity_str = '' - return [ - chan.short_id_for_GUI(), - node_alias, - capacity_str, - '' if closed else labels[LOCAL], - '' if closed else labels[REMOTE], - status - ] + return { + self.Columns.SHORT_CHANID: chan.short_id_for_GUI(), + self.Columns.NODE_ALIAS: node_alias, + self.Columns.CAPACITY: capacity_str, + self.Columns.LOCAL_BALANCE: '' if closed else labels[LOCAL], + self.Columns.REMOTE_BALANCE: '' if closed else labels[REMOTE], + self.Columns.CHANNEL_STATUS: status, + } def on_success(self, 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) if item.data(ROLE_CHANNEL_ID) != chan.channel_id: 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) items = [self.model().item(row, column) for column in self.Columns] self._update_chan_frozen_bg(chan=chan, items=items) @@ -259,7 +259,8 @@ class ChannelsList(MyTreeView): self.model().clear() self.update_headers(self.headers) 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) if self._default_item_bg_brush is None: self._default_item_bg_brush = items[self.Columns.NODE_ALIAS].background()