From eef1f0b2fd15f7da255b7c7b916dcd7af54c551c Mon Sep 17 00:00:00 2001 From: ThomasV Date: Mon, 13 Mar 2023 08:16:44 +0100 Subject: [PATCH] transaction_dialog: move tx_dialog_fetch_txin_data checkbox into toolbar --- electrum/gui/qt/transaction_dialog.py | 31 ++++++++++++--------------- electrum/gui/qt/util.py | 24 +++++++++++---------- 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/electrum/gui/qt/transaction_dialog.py b/electrum/gui/qt/transaction_dialog.py index 1fb6ad5ce..4a7843e20 100644 --- a/electrum/gui/qt/transaction_dialog.py +++ b/electrum/gui/qt/transaction_dialog.py @@ -56,6 +56,7 @@ from electrum.logging import get_logger from electrum.util import ShortID, get_asyncio_loop from electrum.network import Network +from . import util from .util import (MessageBoxMixin, read_QIcon, Buttons, icon_path, MONOSPACE_FONT, ColorScheme, ButtonsLineEdit, ShowQRLineEdit, text_dialog, char_width_in_lineedit, TRANSACTION_FILE_EXTENSION_FILTER_SEPARATE, @@ -407,6 +408,14 @@ class TxDialog(QDialog, MessageBoxMixin): vbox = QVBoxLayout() self.setLayout(vbox) + toolbar, menu = util.create_toolbar_with_menu(self.config, '') + menu.addConfig( + _('Download missing data'), 'tx_dialog_fetch_txin_data', False, + tooltip=_( + 'Download parent transactions from the network.\n' + 'Allows filling in missing fee and input details.'), + callback=self.maybe_fetch_txin_data) + vbox.addLayout(toolbar) vbox.addWidget(QLabel(_("Transaction ID:"))) self.tx_hash_e = ShowQRLineEdit('', self.config, title='Transaction ID') @@ -419,20 +428,6 @@ class TxDialog(QDialog, MessageBoxMixin): self.io_widget = TxInOutWidget(self.main_window, self.wallet) vbox.addWidget(self.io_widget) - # add "fetch_txin_data" checkbox to io_widget - fetch_txin_data_cb = QCheckBox(_('Download input data')) - fetch_txin_data_cb.setChecked(bool(self.config.get('tx_dialog_fetch_txin_data', False))) - fetch_txin_data_cb.setToolTip(_('Download parent transactions from the network.\n' - 'Allows filling in missing fee and address details.')) - def on_fetch_txin_data_cb(x): - self.config.set_key('tx_dialog_fetch_txin_data', bool(x)) - if x: - self.initiate_fetch_txin_data() - fetch_txin_data_cb.stateChanged.connect(on_fetch_txin_data_cb) - self.io_widget.inheader_hbox.addStretch(1) - self.io_widget.inheader_hbox.addWidget(fetch_txin_data_cb) - self.io_widget.inheader_hbox.addStretch(10) - self.sign_button = b = QPushButton(_("Sign")) b.clicked.connect(self.sign) @@ -517,8 +512,8 @@ class TxDialog(QDialog, MessageBoxMixin): lambda: Network.run_from_another_thread( tx.add_info_from_network(self.wallet.network, timeout=10)), ) - elif self.config.get('tx_dialog_fetch_txin_data', False): - self.initiate_fetch_txin_data() + else: + self.maybe_fetch_txin_data() def do_broadcast(self): self.main_window.push_top_level_window(self) @@ -932,12 +927,14 @@ class TxDialog(QDialog, MessageBoxMixin): def update_fee_fields(self): pass # overridden in subclass - def initiate_fetch_txin_data(self): + def maybe_fetch_txin_data(self): """Download missing input data from the network, asynchronously. Note: we fetch the prev txs, which allows calculating the fee and showing "input addresses". We could also SPV-verify the tx, to fill in missing tx_mined_status (block height, blockhash, timestamp), but this is not done currently. """ + if not self.config.get('tx_dialog_fetch_txin_data', False): + return tx = self.tx if not tx: return diff --git a/electrum/gui/qt/util.py b/electrum/gui/qt/util.py index b0c31c8e9..2b7e267e2 100644 --- a/electrum/gui/qt/util.py +++ b/electrum/gui/qt/util.py @@ -596,6 +596,18 @@ class MyMenu(QMenu): if callback: callback() +def create_toolbar_with_menu(config, title): + menu = MyMenu(config) + toolbar_button = QToolButton() + toolbar_button.setIcon(read_QIcon("preferences.png")) + toolbar_button.setMenu(menu) + toolbar_button.setPopupMode(QToolButton.InstantPopup) + toolbar_button.setFocusPolicy(Qt.NoFocus) + toolbar = QHBoxLayout() + toolbar.addWidget(QLabel(title)) + toolbar.addStretch() + toolbar.addWidget(toolbar_button) + return toolbar, menu class MyTreeView(QTreeView): ROLE_CLIPBOARD_DATA = Qt.UserRole + 100 @@ -783,17 +795,7 @@ class MyTreeView(QTreeView): return hbox def create_toolbar_with_menu(self, title): - menu = MyMenu(self.config) - toolbar_button = QToolButton() - toolbar_button.setIcon(read_QIcon("preferences.png")) - toolbar_button.setMenu(menu) - toolbar_button.setPopupMode(QToolButton.InstantPopup) - toolbar_button.setFocusPolicy(Qt.NoFocus) - toolbar = QHBoxLayout() - toolbar.addWidget(QLabel(title)) - toolbar.addStretch() - toolbar.addWidget(toolbar_button) - return toolbar, menu + return create_toolbar_with_menu(self.config, title) def show_toolbar(self, state, config=None): if state == self.toolbar_shown: