1
0

qt tx_dialog: share btn: replace nested menus with checkboxes

Incidentally, the checkboxes are using the config, so their state is persisted.
This commit is contained in:
SomberNight
2024-02-05 14:31:29 +00:00
parent 0925f15280
commit b7ed016f3c
3 changed files with 31 additions and 30 deletions

View File

@@ -71,9 +71,9 @@ if TYPE_CHECKING:
from .main_window import ElectrumWindow from .main_window import ElectrumWindow
class MyMenu(QMenu): class QMenuWithConfig(QMenu):
def __init__(self, config): def __init__(self, config: 'SimpleConfig'):
QMenu.__init__(self) QMenu.__init__(self)
self.setToolTipsVisible(True) self.setToolTipsVisible(True)
self.config = config self.config = config
@@ -113,7 +113,7 @@ class MyMenu(QMenu):
def create_toolbar_with_menu(config: 'SimpleConfig', title): def create_toolbar_with_menu(config: 'SimpleConfig', title):
menu = MyMenu(config) menu = QMenuWithConfig(config)
toolbar_button = QToolButton() toolbar_button = QToolButton()
toolbar_button.setIcon(read_QIcon("preferences.png")) toolbar_button.setIcon(read_QIcon("preferences.png"))
toolbar_button.setMenu(menu) toolbar_button.setMenu(menu)

View File

@@ -65,7 +65,7 @@ from .util import (MessageBoxMixin, read_QIcon, Buttons, icon_path,
BlockingWaitingDialog, getSaveFileName, ColorSchemeItem, BlockingWaitingDialog, getSaveFileName, ColorSchemeItem,
get_iconname_qrcode, VLine) get_iconname_qrcode, VLine)
from .rate_limiter import rate_limited from .rate_limiter import rate_limited
from .my_treeview import create_toolbar_with_menu from .my_treeview import create_toolbar_with_menu, QMenuWithConfig
if TYPE_CHECKING: if TYPE_CHECKING:
from .main_window import ElectrumWindow from .main_window import ElectrumWindow
@@ -456,7 +456,7 @@ class TxDialog(QDialog, MessageBoxMixin):
self.desc = self.wallet.get_label_for_txid(txid) or None self.desc = self.wallet.get_label_for_txid(txid) or None
self.setMinimumWidth(640) self.setMinimumWidth(640)
self.psbt_only_widgets = [] # type: List[QWidget] self.psbt_only_widgets = [] # type: List[Union[QWidget, QAction]]
vbox = QVBoxLayout() vbox = QVBoxLayout()
self.setLayout(vbox) self.setLayout(vbox)
@@ -502,15 +502,15 @@ class TxDialog(QDialog, MessageBoxMixin):
b.clicked.connect(self.close) b.clicked.connect(self.close)
b.setDefault(True) b.setDefault(True)
self.export_actions_menu = export_actions_menu = QMenu() self.export_actions_menu = export_actions_menu = QMenuWithConfig(config=self.config)
self.add_export_actions_to_menu(export_actions_menu) self.add_export_actions_to_menu(export_actions_menu)
export_actions_menu.addSeparator() export_actions_menu.addSeparator()
export_submenu = export_actions_menu.addMenu(_("For CoinJoin; strip privates")) export_option = export_actions_menu.addConfig(
self.add_export_actions_to_menu(export_submenu, gettx=self._gettx_for_coinjoin) self.config.cv.GUI_QT_TX_DIALOG_EXPORT_STRIP_SENSITIVE_METADATA)
self.psbt_only_widgets.append(export_submenu) self.psbt_only_widgets.append(export_option)
export_submenu = export_actions_menu.addMenu(_("For hardware device; include xpubs")) export_option = export_actions_menu.addConfig(
self.add_export_actions_to_menu(export_submenu, gettx=self._gettx_for_hardware_device) self.config.cv.GUI_QT_TX_DIALOG_EXPORT_INCLUDE_GLOBAL_XPUBS)
self.psbt_only_widgets.append(export_submenu) self.psbt_only_widgets.append(export_option)
self.export_actions_button = QToolButton() self.export_actions_button = QToolButton()
self.export_actions_button.setText(_("Share")) self.export_actions_button.setText(_("Share"))
@@ -604,9 +604,17 @@ class TxDialog(QDialog, MessageBoxMixin):
# Override escape-key to close normally (and invoke closeEvent) # Override escape-key to close normally (and invoke closeEvent)
self.close() self.close()
def add_export_actions_to_menu(self, menu: QMenu, *, gettx: Callable[[], Transaction] = None) -> None: def add_export_actions_to_menu(self, menu: QMenu) -> None:
if gettx is None: def gettx() -> Transaction:
gettx = lambda: None if not isinstance(self.tx, PartialTransaction):
return self.tx
tx = copy.deepcopy(self.tx)
if self.config.GUI_QT_TX_DIALOG_EXPORT_INCLUDE_GLOBAL_XPUBS:
Network.run_from_another_thread(
tx.prepare_for_export_for_hardware_device(self.wallet))
if self.config.GUI_QT_TX_DIALOG_EXPORT_STRIP_SENSITIVE_METADATA:
tx.prepare_for_export_for_coinjoin()
return tx
action = QAction(_("Copy to clipboard"), self) action = QAction(_("Copy to clipboard"), self)
action.triggered.connect(lambda: self.copy_to_clipboard(tx=gettx())) action.triggered.connect(lambda: self.copy_to_clipboard(tx=gettx()))
@@ -620,21 +628,6 @@ class TxDialog(QDialog, MessageBoxMixin):
action.triggered.connect(lambda: self.export_to_file(tx=gettx())) action.triggered.connect(lambda: self.export_to_file(tx=gettx()))
menu.addAction(action) menu.addAction(action)
def _gettx_for_coinjoin(self) -> PartialTransaction:
if not isinstance(self.tx, PartialTransaction):
raise Exception("Can only export partial transactions for coinjoins.")
tx = copy.deepcopy(self.tx)
tx.prepare_for_export_for_coinjoin()
return tx
def _gettx_for_hardware_device(self) -> PartialTransaction:
if not isinstance(self.tx, PartialTransaction):
raise Exception("Can only export partial transactions for hardware device.")
tx = copy.deepcopy(self.tx)
Network.run_from_another_thread(
tx.prepare_for_export_for_hardware_device(self.wallet))
return tx
def copy_to_clipboard(self, *, tx: Transaction = None): def copy_to_clipboard(self, *, tx: Transaction = None):
if tx is None: if tx is None:
tx = self.tx tx = self.tx

View File

@@ -1082,6 +1082,14 @@ This will result in longer routes; it might increase your fees and decrease the
'Download parent transactions from the network.\n' 'Download parent transactions from the network.\n'
'Allows filling in missing fee and input details.'), 'Allows filling in missing fee and input details.'),
) )
GUI_QT_TX_DIALOG_EXPORT_STRIP_SENSITIVE_METADATA = ConfigVar(
'gui_qt_tx_dialog_export_strip_sensitive_metadata', default=False, type_=bool,
short_desc=lambda: _('For CoinJoin; strip privates'),
)
GUI_QT_TX_DIALOG_EXPORT_INCLUDE_GLOBAL_XPUBS = ConfigVar(
'gui_qt_tx_dialog_export_include_global_xpubs', default=False, type_=bool,
short_desc=lambda: _('For hardware device; include xpubs'),
)
GUI_QT_RECEIVE_TABS_INDEX = ConfigVar('receive_tabs_index', default=0, type_=int) GUI_QT_RECEIVE_TABS_INDEX = ConfigVar('receive_tabs_index', default=0, type_=int)
GUI_QT_RECEIVE_TAB_QR_VISIBLE = ConfigVar('receive_qr_visible', default=False, type_=bool) GUI_QT_RECEIVE_TAB_QR_VISIBLE = ConfigVar('receive_qr_visible', default=False, type_=bool)
GUI_QT_TX_EDITOR_SHOW_IO = ConfigVar( GUI_QT_TX_EDITOR_SHOW_IO = ConfigVar(