electrum

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

commit c23b869d3cf99311d4a9c2692454df911b10ee93
parent 5aafcb2875f056627885c4dd971264259f91f9fc
Author: SomberNight <somber.night@protonmail.com>
Date:   Sun, 10 Feb 2019 21:13:53 +0100

qt MyTreeView subclasses: change "headers" from list to dict

Diffstat:
Melectrum/gui/qt/address_list.py | 14++++++++------
Melectrum/gui/qt/contact_list.py | 6+++++-
Melectrum/gui/qt/invoice_list.py | 9++++++++-
Melectrum/gui/qt/request_list.py | 10+++++++++-
Melectrum/gui/qt/util.py | 16++++++++++------
Melectrum/gui/qt/utxo_list.py | 8+++++++-
6 files changed, 47 insertions(+), 16 deletions(-)

diff --git a/electrum/gui/qt/address_list.py b/electrum/gui/qt/address_list.py @@ -81,12 +81,14 @@ class AddressList(MyTreeView): ccy = fx.get_currency() else: ccy = _('Fiat') - headers = [_('Type'), - _('Address'), - _('Label'), - _('Balance'), - ccy + ' ' + _('Balance'), - _('Tx')] + headers = { + self.Columns.TYPE: _('Type'), + self.Columns.ADDRESS: _('Address'), + self.Columns.LABEL: _('Label'), + self.Columns.COIN_BALANCE: _('Balance'), + self.Columns.FIAT_BALANCE: ccy + ' ' + _('Balance'), + self.Columns.NUM_TXS: _('Tx'), + } self.update_headers(headers) def toggle_change(self, state): diff --git a/electrum/gui/qt/contact_list.py b/electrum/gui/qt/contact_list.py @@ -44,6 +44,10 @@ class ContactList(MyTreeView): NAME = 0 ADDRESS = 1 + headers = { + Columns.NAME: _('Name'), + Columns.ADDRESS: _('Address'), + } filter_columns = [Columns.NAME, Columns.ADDRESS] def __init__(self, parent): @@ -101,7 +105,7 @@ class ContactList(MyTreeView): def update(self): current_key = self.current_item_user_role(col=self.Columns.NAME) self.model().clear() - self.update_headers([_('Name'), _('Address')]) + self.update_headers(self.__class__.headers) set_current = None for key in sorted(self.parent.contacts.keys()): contact_type, name = self.parent.contacts[key] diff --git a/electrum/gui/qt/invoice_list.py b/electrum/gui/qt/invoice_list.py @@ -40,6 +40,13 @@ class InvoiceList(MyTreeView): AMOUNT = 3 STATUS = 4 + headers = { + Columns.DATE: _('Expires'), + Columns.REQUESTOR: _('Requestor'), + Columns.DESCRIPTION: _('Description'), + Columns.AMOUNT: _('Amount'), + Columns.STATUS: _('Status'), + } filter_columns = [Columns.DATE, Columns.REQUESTOR, Columns.DESCRIPTION, Columns.AMOUNT] def __init__(self, parent): @@ -54,7 +61,7 @@ class InvoiceList(MyTreeView): def update(self): inv_list = self.parent.invoices.unpaid_invoices() self.model().clear() - self.update_headers([_('Expires'), _('Requestor'), _('Description'), _('Amount'), _('Status')]) + self.update_headers(self.__class__.headers) self.header().setSectionResizeMode(self.Columns.REQUESTOR, QHeaderView.Interactive) for idx, pr in enumerate(inv_list): key = pr.get_id() diff --git a/electrum/gui/qt/request_list.py b/electrum/gui/qt/request_list.py @@ -48,6 +48,14 @@ class RequestList(MyTreeView): AMOUNT = 4 STATUS = 5 + headers = { + Columns.DATE: _('Date'), + Columns.ADDRESS: _('Address'), + Columns.SIGNATURE: '', + Columns.DESCRIPTION: _('Description'), + Columns.AMOUNT: _('Amount'), + Columns.STATUS: _('Status'), + } filter_columns = [Columns.DATE, Columns.ADDRESS, Columns.SIGNATURE, Columns.DESCRIPTION, Columns.AMOUNT] def __init__(self, parent): @@ -102,7 +110,7 @@ class RequestList(MyTreeView): self.parent.new_request_button.setEnabled(addr != current_address) self.model().clear() - self.update_headers([_('Date'), _('Address'), '', _('Description'), _('Amount'), _('Status')]) + self.update_headers(self.__class__.headers) self.hideColumn(self.Columns.ADDRESS) for req in self.wallet.get_sorted_requests(self.config): address = req['address'] diff --git a/electrum/gui/qt/util.py b/electrum/gui/qt/util.py @@ -7,7 +7,7 @@ import queue import traceback from functools import partial, lru_cache -from typing import NamedTuple, Callable, Optional, TYPE_CHECKING +from typing import NamedTuple, Callable, Optional, TYPE_CHECKING, Union, List, Dict from PyQt5.QtGui import * from PyQt5.QtCore import * @@ -466,13 +466,17 @@ class MyTreeView(QTreeView): assert set_current.isValid() self.selectionModel().select(QModelIndex(set_current), QItemSelectionModel.SelectCurrent) - def update_headers(self, headers): + def update_headers(self, headers: Union[List[str], Dict[int, str]]): + # headers is either a list of column names, or a dict: (col_idx->col_name) + if not isinstance(headers, dict): # convert to dict + headers = dict(enumerate(headers)) + col_names = [headers[col_idx] for col_idx in sorted(headers.keys())] model = self.model() - model.setHorizontalHeaderLabels(headers) + model.setHorizontalHeaderLabels(col_names) self.header().setStretchLastSection(False) - for col in range(len(headers)): - sm = QHeaderView.Stretch if col == self.stretch_column else QHeaderView.ResizeToContents - self.header().setSectionResizeMode(col, sm) + for col_idx in headers: + sm = QHeaderView.Stretch if col_idx == self.stretch_column else QHeaderView.ResizeToContents + self.header().setSectionResizeMode(col_idx, sm) def keyPressEvent(self, event): if self.itemDelegate().opened: diff --git a/electrum/gui/qt/utxo_list.py b/electrum/gui/qt/utxo_list.py @@ -39,7 +39,13 @@ class UTXOList(MyTreeView): HEIGHT = 3 OUTPOINT = 4 - headers = [ _('Address'), _('Label'), _('Amount'), _('Height'), _('Output point')] + headers = { + Columns.ADDRESS: _('Address'), + Columns.LABEL: _('Label'), + Columns.AMOUNT: _('Amount'), + Columns.HEIGHT: _('Height'), + Columns.OUTPOINT: _('Output point'), + } filter_columns = [Columns.ADDRESS, Columns.LABEL] def __init__(self, parent=None):