electrum

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

commit 356a0a2865a4ee319e7cc03dabd0ffd1c34e3077
parent 18c64515188494f05e517a099a7356d378a14bda
Author: SomberNight <somber.night@protonmail.com>
Date:   Sun, 19 Jan 2020 07:02:48 +0100

qt: clean-up in some MyTreeView children (mv code from update to init)

Diffstat:
Melectrum/gui/qt/address_list.py | 4++--
Melectrum/gui/qt/request_list.py | 3+--
Melectrum/gui/qt/utxo_list.py | 20++++++++++++--------
3 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/electrum/gui/qt/address_list.py b/electrum/gui/qt/address_list.py @@ -78,8 +78,9 @@ class AddressList(MyTreeView): filter_columns = [Columns.TYPE, Columns.ADDRESS, Columns.LABEL, Columns.COIN_BALANCE] - def __init__(self, parent=None): + def __init__(self, parent): super().__init__(parent, self.create_menu, stretch_column=self.Columns.LABEL) + self.wallet = self.parent.wallet self.setSelectionMode(QAbstractItemView.ExtendedSelection) self.setSortingEnabled(True) self.show_change = AddressTypeFilter.ALL # type: AddressTypeFilter @@ -136,7 +137,6 @@ class AddressList(MyTreeView): @profiler def update(self): - self.wallet = self.parent.wallet current_address = self.current_item_user_role(col=self.Columns.LABEL) if self.show_change == AddressTypeFilter.RECEIVING: addr_list = self.wallet.get_receiving_addresses() diff --git a/electrum/gui/qt/request_list.py b/electrum/gui/qt/request_list.py @@ -61,6 +61,7 @@ class RequestList(MyTreeView): super().__init__(parent, self.create_menu, stretch_column=self.Columns.DESCRIPTION, editable_columns=[]) + self.wallet = self.parent.wallet self.setModel(QStandardItemModel(self)) self.setSortingEnabled(True) self.update() @@ -106,8 +107,6 @@ class RequestList(MyTreeView): status_item.setIcon(read_QIcon(pr_icons.get(status))) def update(self): - self.wallet = self.parent.wallet - domain = self.wallet.get_receiving_addresses() self.parent.update_receive_address_styling() self.model().clear() self.update_headers(self.__class__.headers) diff --git a/electrum/gui/qt/utxo_list.py b/electrum/gui/qt/utxo_list.py @@ -38,6 +38,8 @@ from .util import MyTreeView, ColorScheme, MONOSPACE_FONT, EnterButton class UTXOList(MyTreeView): + _spend_set: Optional[Set[str]] # coins selected by the user to spend from + _utxo_dict: Dict[str, PartialTxInput] # coin name -> coin class Columns(IntEnum): OUTPOINT = 0 @@ -55,21 +57,23 @@ class UTXOList(MyTreeView): } filter_columns = [Columns.ADDRESS, Columns.LABEL, Columns.OUTPOINT] - def __init__(self, parent=None): + def __init__(self, parent): super().__init__(parent, self.create_menu, stretch_column=self.Columns.LABEL, editable_columns=[]) - self._spend_set = None # type: Optional[Set[str]] # coins selected by the user to spend from + self._spend_set = None + self._utxo_dict = {} + self.wallet = self.parent.wallet + self.setModel(QStandardItemModel(self)) self.setSelectionMode(QAbstractItemView.ExtendedSelection) self.setSortingEnabled(True) self.update() def update(self): - self.wallet = self.parent.wallet utxos = self.wallet.get_utxos() self._maybe_reset_spend_list(utxos) - self.utxo_dict = {} # type: Dict[str, PartialTxInput] + self._utxo_dict = {} self.model().clear() self.update_headers(self.__class__.headers) for idx, utxo in enumerate(utxos): @@ -77,7 +81,7 @@ class UTXOList(MyTreeView): self.filter() # update coincontrol status bar if self._spend_set is not None: - coins = [self.utxo_dict[x] for x in self._spend_set] + coins = [self._utxo_dict[x] for x in self._spend_set] coins = self._filter_frozen_coins(coins) amount = sum(x.value_sats() for x in coins) amount_str = self.parent.format_amount_and_units(amount) @@ -91,7 +95,7 @@ class UTXOList(MyTreeView): height = utxo.block_height name = utxo.prevout.to_str() name_short = utxo.prevout.txid.hex()[:16] + '...' + ":%d" % utxo.prevout.out_idx - self.utxo_dict[name] = utxo + self._utxo_dict[name] = utxo label = self.wallet.get_label(utxo.prevout.txid.hex()) amount = self.parent.format_amount(utxo.value_sats(), whitespaces=True) labels = [name_short, address, label, amount, '%d'%height] @@ -142,7 +146,7 @@ class UTXOList(MyTreeView): def get_spend_list(self) -> Optional[Sequence[PartialTxInput]]: if self._spend_set is None: return None - utxos = [self.utxo_dict[x] for x in self._spend_set] + utxos = [self._utxo_dict[x] for x in self._spend_set] return copy.deepcopy(utxos) # copy so that side-effects don't affect utxo_dict def _maybe_reset_spend_list(self, current_wallet_utxos: Sequence[PartialTxInput]) -> None: @@ -159,7 +163,7 @@ class UTXOList(MyTreeView): return menu = QMenu() menu.setSeparatorsCollapsible(True) # consecutive separators are merged together - coins = [self.utxo_dict[name] for name in selected] + coins = [self._utxo_dict[name] for name in selected] if len(coins) == 0: menu.addAction(_("Spend (select none)"), lambda: self.set_spend_list(coins)) else: