electrum

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

commit ccc1897f36b3f8017b669dd15e38c96534a6d524
parent 86bd3839df5bd31780ed86ff2f099d9e0b2d648d
Author: SomberNight <somber.night@protonmail.com>
Date:   Mon,  9 Sep 2019 00:24:22 +0200

qt addresses list: use IntEnum for dropdown filters

Diffstat:
Melectrum/gui/qt/address_list.py | 62+++++++++++++++++++++++++++++++++++++++++++++-----------------
1 file changed, 45 insertions(+), 17 deletions(-)

diff --git a/electrum/gui/qt/address_list.py b/electrum/gui/qt/address_list.py @@ -38,6 +38,34 @@ from electrum.wallet import InternalAddressCorruption from .util import MyTreeView, MONOSPACE_FONT, ColorScheme, webopen +class AddressUsageStateFilter(IntEnum): + ALL = 0 + UNUSED = 1 + FUNDED = 2 + USED_AND_EMPTY = 3 + + def ui_text(self) -> str: + return { + self.ALL: _('All'), + self.UNUSED: _('Unused'), + self.FUNDED: _('Funded'), + self.USED_AND_EMPTY: _('Used'), + }[self] + + +class AddressTypeFilter(IntEnum): + ALL = 0 + RECEIVING = 1 + CHANGE = 2 + + def ui_text(self) -> str: + return { + self.ALL: _('All'), + self.RECEIVING: _('Receiving'), + self.CHANGE: _('Change'), + }[self] + + class AddressList(MyTreeView): class Columns(IntEnum): @@ -54,16 +82,16 @@ class AddressList(MyTreeView): super().__init__(parent, self.create_menu, stretch_column=self.Columns.LABEL) self.setSelectionMode(QAbstractItemView.ExtendedSelection) self.setSortingEnabled(True) - self.show_change = 0 - self.show_used = 0 + self.show_change = AddressTypeFilter.ALL # type: AddressTypeFilter + self.show_used = AddressUsageStateFilter.ALL # type: AddressUsageStateFilter self.change_button = QComboBox(self) self.change_button.currentIndexChanged.connect(self.toggle_change) - for t in [_('All'), _('Receiving'), _('Change')]: - self.change_button.addItem(t) + for addr_type in AddressTypeFilter.__members__.values(): # type: AddressTypeFilter + self.change_button.addItem(addr_type.ui_text()) self.used_button = QComboBox(self) self.used_button.currentIndexChanged.connect(self.toggle_used) - for t in [_('All'), _('Unused'), _('Funded'), _('Used')]: - self.used_button.addItem(t) + for addr_usage_state in AddressUsageStateFilter.__members__.values(): # type: AddressUsageStateFilter + self.used_button.addItem(addr_usage_state.ui_text()) self.setModel(QStandardItemModel(self)) self.update() @@ -71,8 +99,8 @@ class AddressList(MyTreeView): return QLabel(_("Filter:")), self.change_button, self.used_button def on_hide_toolbar(self): - self.show_change = 0 - self.show_used = 0 + self.show_change = AddressTypeFilter.ALL # type: AddressTypeFilter + self.show_used = AddressUsageStateFilter.ALL # type: AddressUsageStateFilter self.update() def save_toolbar_state(self, state, config): @@ -94,25 +122,25 @@ class AddressList(MyTreeView): } self.update_headers(headers) - def toggle_change(self, state): + def toggle_change(self, state: int): if state == self.show_change: return - self.show_change = state + self.show_change = AddressTypeFilter(state) self.update() - def toggle_used(self, state): + def toggle_used(self, state: int): if state == self.show_used: return - self.show_used = state + self.show_used = AddressUsageStateFilter(state) self.update() @profiler def update(self): self.wallet = self.parent.wallet current_address = self.current_item_user_role(col=self.Columns.LABEL) - if self.show_change == 1: + if self.show_change == AddressTypeFilter.RECEIVING: addr_list = self.wallet.get_receiving_addresses() - elif self.show_change == 2: + elif self.show_change == AddressTypeFilter.CHANGE: addr_list = self.wallet.get_change_addresses() else: addr_list = self.wallet.get_addresses() @@ -126,11 +154,11 @@ class AddressList(MyTreeView): c, u, x = self.wallet.get_addr_balance(address) balance = c + u + x is_used_and_empty = self.wallet.is_used(address) and balance == 0 - if self.show_used == 1 and (balance or is_used_and_empty): + if self.show_used == AddressUsageStateFilter.UNUSED and (balance or is_used_and_empty): continue - if self.show_used == 2 and balance == 0: + if self.show_used == AddressUsageStateFilter.FUNDED and balance == 0: continue - if self.show_used == 3 and not is_used_and_empty: + if self.show_used == AddressUsageStateFilter.USED_AND_EMPTY and not is_used_and_empty: continue balance_text = self.parent.format_amount(balance, whitespaces=True) # create item