tqt coin control: introduce second status bar - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 970bd4e95f4a9a6c27850d35d93af699eed5e06c DIR parent 800c05b32f020746ba7d7f4f2c8401ce84055d9c HTML Author: SomberNight <somber.night@protonmail.com> Date: Wed, 13 Nov 2019 19:09:07 +0100 qt coin control: introduce second status bar Diffstat: M electrum/gui/qt/main_window.py | 41 ++++++++++++++++++++++++++++--- M electrum/gui/qt/utxo_list.py | 17 +++++------------ 2 files changed, 43 insertions(+), 15 deletions(-) --- DIR diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py t@@ -174,6 +174,8 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): self.completions = QStringListModel() + coincontrol_sb = self.create_coincontrol_statusbar() + self.tabs = tabs = QTabWidget(self) self.send_tab = self.create_send_tab() self.receive_tab = self.create_receive_tab() t@@ -202,7 +204,14 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): add_optional_tab(tabs, self.console_tab, read_QIcon("tab_console.png"), _("Con&sole"), "console") tabs.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) - self.setCentralWidget(tabs) + + central_widget = QWidget() + vbox = QVBoxLayout(central_widget) + vbox.setContentsMargins(0, 0, 0, 0) + vbox.addWidget(tabs) + vbox.addWidget(coincontrol_sb) + + self.setCentralWidget(central_widget) if self.config.get("is_maximized"): self.showMaximized() t@@ -1759,8 +1768,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): def create_utxo_tab(self): from .utxo_list import UTXOList self.utxo_list = UTXOList(self) - t = self.utxo_list.get_toolbar() - return self.create_list_tab(self.utxo_list, t) + return self.create_list_tab(self.utxo_list) def create_contacts_tab(self): from .contact_list import ContactList t@@ -1948,6 +1956,33 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): run_hook('create_status_bar', sb) self.setStatusBar(sb) + def create_coincontrol_statusbar(self): + self.coincontrol_sb = sb = QStatusBar() + sb.setSizeGripEnabled(False) + sb.setFixedHeight(3 * char_width_in_lineedit()) + sb.setStyleSheet('QStatusBar::item {border: None;} ' + + ColorScheme.GREEN.as_stylesheet(True)) + + self.coincontrol_label = QLabel() + self.coincontrol_label.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) + self.coincontrol_label.setTextInteractionFlags(Qt.TextSelectableByMouse) + sb.addWidget(self.coincontrol_label) + + clear_cc_button = EnterButton(_('Reset'), lambda: self.utxo_list.set_spend_list([])) + clear_cc_button.setStyleSheet("margin-right: 5px;") + sb.addPermanentWidget(clear_cc_button) + + sb.setVisible(False) + return sb + + def set_coincontrol_msg(self, msg: Optional[str]) -> None: + if not msg: + self.coincontrol_label.setText("") + self.coincontrol_sb.setVisible(False) + return + self.coincontrol_label.setText(msg) + self.coincontrol_sb.setVisible(True) + def update_lock_icon(self): icon = read_QIcon("lock.png") if self.wallet.has_password() else read_QIcon("unlock.png") self.password_button.setIcon(icon) DIR diff --git a/electrum/gui/qt/utxo_list.py b/electrum/gui/qt/utxo_list.py t@@ -58,8 +58,6 @@ class UTXOList(MyTreeView): super().__init__(parent, self.create_menu, stretch_column=self.Columns.LABEL, editable_columns=[]) - self.cc_label = QLabel('') - self.clear_cc_button = EnterButton(_('Reset'), lambda: self.set_spend_list([])) self.spend_list = [] # type: Sequence[str] self.setModel(QStandardItemModel(self)) self.setSelectionMode(QAbstractItemView.ExtendedSelection) t@@ -76,14 +74,16 @@ class UTXOList(MyTreeView): for idx, utxo in enumerate(utxos): self.insert_utxo(idx, utxo) self.filter() - self.clear_cc_button.setEnabled(bool(self.spend_list)) - # update cc_label + # update coincontrol status bar coins = [self.utxo_dict[x] for x in self.spend_list] or utxos coins = self._filter_frozen_coins(coins) amount = sum(x.value_sats() for x in coins) amount_str = self.parent.format_amount_and_units(amount) num_outputs_str = _("{} outputs available ({} total)").format(len(coins), len(utxos)) - self.cc_label.setText(f'{num_outputs_str}, {amount_str}') + if self.spend_list: + self.parent.set_coincontrol_msg(_("Coin control active") + f': {num_outputs_str}, {amount_str}') + else: + self.parent.set_coincontrol_msg(None) def insert_utxo(self, idx, utxo: PartialTxInput): address = utxo.address t@@ -145,13 +145,6 @@ class UTXOList(MyTreeView): if not all([prevout_str in utxo_set for prevout_str in self.spend_list]): self.spend_list = [] - def get_toolbar(self): - h = QHBoxLayout() - h.addWidget(self.cc_label) - h.addStretch() - h.addWidget(self.clear_cc_button) - return h - def create_menu(self, position): selected = self.get_selected_outpoints() if not selected: