From 2571eeeecdbe6f5d8f695a108ab56b3e66aba31b Mon Sep 17 00:00:00 2001 From: ThomasV Date: Mon, 13 Mar 2023 15:35:35 +0100 Subject: [PATCH] coins tab: add toolbar. --- electrum/gui/qt/utxo_list.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/electrum/gui/qt/utxo_list.py b/electrum/gui/qt/utxo_list.py index 409dc222e..05987d7f3 100644 --- a/electrum/gui/qt/utxo_list.py +++ b/electrum/gui/qt/utxo_list.py @@ -70,12 +70,16 @@ class UTXOList(MyTreeView): self._spend_set = set() self._utxo_dict = {} self.wallet = self.parent.wallet - self.std_model = QStandardItemModel(self) self.setModel(self.std_model) self.setSelectionMode(QAbstractItemView.ExtendedSelection) self.setSortingEnabled(True) - self.update() + + def create_toolbar(self, config): + toolbar, menu = self.create_toolbar_with_menu('') + self.num_coins_label = toolbar.itemAt(0).widget() + menu.addAction(_('Coin control'), lambda: self.add_selection_to_coincontrol()) + return toolbar def update(self): # not calling maybe_defer_update() as it interferes with coincontrol status bar @@ -103,6 +107,7 @@ class UTXOList(MyTreeView): self.refresh_row(name, idx) self.filter() self.update_coincontrol_bar() + self.num_coins_label.setText(_('{} unspent transaction outputs').format(len(utxos))) def update_coincontrol_bar(self): # update coincontrol status bar @@ -142,9 +147,9 @@ class UTXOList(MyTreeView): utxo_item[self.Columns.OUTPOINT].setBackground(ColorScheme.BLUE.as_color(True)) utxo_item[self.Columns.OUTPOINT].setToolTip(f"{key}\n{_('Coin is frozen')}") - def get_selected_outpoints(self) -> Optional[List[str]]: + def get_selected_outpoints(self) -> List[str]: if not self.model(): - return None + return [] items = self.selected_in_column(self.Columns.OUTPOINT) return [x.data(self.ROLE_PREVOUT_STR) for x in items] @@ -172,6 +177,17 @@ class UTXOList(MyTreeView): self._spend_set.clear() self._refresh_coincontrol() + def add_selection_to_coincontrol(self): + if bool(self._spend_set): + self.clear_coincontrol() + return + selected = self.get_selected_outpoints() + coins = [self._utxo_dict[name] for name in selected] + if not coins: + self.parent.show_error(_('You need to select coins from the list first.\nUse ctrl+left mouse button to select multiple items')) + return + self.add_to_coincontrol(coins) + def _refresh_coincontrol(self): self.refresh_all() self.update_coincontrol_bar() @@ -244,8 +260,6 @@ class UTXOList(MyTreeView): def create_menu(self, position): selected = self.get_selected_outpoints() - if selected is None: - return menu = QMenu() menu.setSeparatorsCollapsible(True) # consecutive separators are merged together coins = [self._utxo_dict[name] for name in selected]