electrum

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

commit 01108d8b47b24b05a54e5c45383d3f9e1dd4a232
parent fefcd7bbcd80171d6d36ea4a19fc87797a7d8fdd
Author: ThomasV <thomasv@electrum.org>
Date:   Fri,  6 Oct 2017 15:22:18 +0200

address tab: replace tree view with buttons

Diffstat:
Mgui/qt/address_list.py | 110++++++++++++++++++++++++++++++++++++++++++++-----------------------------------
Mgui/qt/main_window.py | 12++++++++----
2 files changed, 70 insertions(+), 52 deletions(-)

diff --git a/gui/qt/address_list.py b/gui/qt/address_list.py @@ -45,6 +45,17 @@ class AddressList(MyTreeWidget): MyTreeWidget.__init__(self, parent, self.create_menu, [], 1) self.refresh_headers() self.setSelectionMode(QAbstractItemView.ExtendedSelection) + self.show_change = False + self.show_used = 3 + self.change_button = QToolButton(self) + self.used_button = QToolButton(self) + self.change_button.clicked.connect(self.toggle_change) + self.used_button.clicked.connect(self.toggle_used) + self.set_change_button_text() + self.set_used_button_text() + + def get_buttons(self): + return self.change_button, self.used_button def refresh_headers(self): headers = [ _('Address'), _('Label'), _('Balance')] @@ -54,59 +65,62 @@ class AddressList(MyTreeWidget): headers.extend([_('Tx')]) self.update_headers(headers) + def toggle_change(self): + self.show_change = not self.show_change + self.set_change_button_text() + self.on_update() + + def set_change_button_text(self): + s = [_('Receiving'), _('Change')] + self.change_button.setText(s[self.show_change]) + + def toggle_used(self): + self.show_used = (self.show_used + 1) % 4 + self.set_used_button_text() + self.on_update() + + def set_used_button_text(self): + s = [_('Unused'), _('Funded'), _('Used'), _('All')] + self.used_button.setText(s[self.show_used]) + def on_update(self): self.wallet = self.parent.wallet item = self.currentItem() current_address = item.data(0, Qt.UserRole) if item else None + addr_list = self.wallet.get_change_addresses() if self.show_change else self.wallet.get_receiving_addresses() self.clear() - receiving_addresses = self.wallet.get_receiving_addresses() - change_addresses = self.wallet.get_change_addresses() - if True: - account_item = self - sequences = [0,1] if change_addresses else [0] - for is_change in sequences: - if len(sequences) > 1: - name = _("Receiving") if not is_change else _("Change") - seq_item = QTreeWidgetItem( [ name, '', '', '', ''] ) - account_item.addChild(seq_item) - if not is_change: - seq_item.setExpanded(True) - else: - seq_item = account_item - used_item = QTreeWidgetItem( [ _("Used"), '', '', '', ''] ) - used_flag = False - addr_list = change_addresses if is_change else receiving_addresses - for address in addr_list: - num = len(self.wallet.history.get(address,[])) - is_used = self.wallet.is_used(address) - label = self.wallet.labels.get(address,'') - c, u, x = self.wallet.get_addr_balance(address) - balance = self.parent.format_amount(c + u + x) - fx = self.parent.fx - if fx and fx.get_fiat_address_config(): - rate = fx.exchange_rate() - fiat_balance = fx.value_str(c + u + x, rate) - address_item = QTreeWidgetItem([address, label, balance, fiat_balance, "%d"%num]) - address_item.setTextAlignment(3, Qt.AlignRight) - else: - address_item = QTreeWidgetItem([address, label, balance, "%d"%num]) - address_item.setTextAlignment(2, Qt.AlignRight) - address_item.setFont(0, QFont(MONOSPACE_FONT)) - address_item.setData(0, Qt.UserRole, address) - address_item.setData(0, Qt.UserRole+1, True) # label can be edited - if self.wallet.is_frozen(address): - address_item.setBackground(0, ColorScheme.BLUE.as_color(True)) - if self.wallet.is_beyond_limit(address, is_change): - address_item.setBackground(0, ColorScheme.RED.as_color(True)) - if is_used: - if not used_flag: - seq_item.insertChild(0, used_item) - used_flag = True - used_item.addChild(address_item) - else: - seq_item.addChild(address_item) - if address == current_address: - self.setCurrentItem(address_item) + for address in addr_list: + num = len(self.wallet.history.get(address,[])) + is_used = self.wallet.is_used(address) + label = self.wallet.labels.get(address, '') + c, u, x = self.wallet.get_addr_balance(address) + balance = c + u + x + if self.show_used == 0 and (balance or is_used): + continue + if self.show_used == 1 and balance == 0: + continue + if self.show_used == 2 and not is_used: + continue + balance_text = self.parent.format_amount(balance) + fx = self.parent.fx + if fx and fx.get_fiat_address_config(): + rate = fx.exchange_rate() + fiat_balance = fx.value_str(balance, rate) + address_item = QTreeWidgetItem([address, label, balance_text, fiat_balance, "%d"%num]) + address_item.setTextAlignment(3, Qt.AlignRight) + else: + address_item = QTreeWidgetItem([address, label, balance_text, "%d"%num]) + address_item.setTextAlignment(2, Qt.AlignRight) + address_item.setFont(0, QFont(MONOSPACE_FONT)) + address_item.setData(0, Qt.UserRole, address) + address_item.setData(0, Qt.UserRole+1, True) # label can be edited + if self.wallet.is_frozen(address): + address_item.setBackground(0, ColorScheme.BLUE.as_color(True)) + if self.wallet.is_beyond_limit(address, self.show_change): + address_item.setBackground(0, ColorScheme.RED.as_color(True)) + self.addChild(address_item) + if address == current_address: + self.setCurrentItem(address_item) def create_menu(self, position): from electrum.wallet import Multisig_Wallet diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py @@ -1563,22 +1563,26 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): self.utxo_list.update() self.update_fee() - def create_list_tab(self, l): + def create_list_tab(self, l, buttons=None): w = QWidget() w.searchable_list = l vbox = QVBoxLayout() w.setLayout(vbox) vbox.setContentsMargins(0, 0, 0, 0) vbox.setSpacing(0) + if buttons: + hbox = QHBoxLayout() + for b in buttons: + hbox.addWidget(b) + hbox.addStretch() + vbox.addLayout(hbox) vbox.addWidget(l) - buttons = QWidget() - vbox.addWidget(buttons) return w def create_addresses_tab(self): from .address_list import AddressList self.address_list = l = AddressList(self) - return self.create_list_tab(l) + return self.create_list_tab(l, l.get_buttons()) def create_utxo_tab(self): from .utxo_list import UTXOList