Browse Source

qt tx_dialog: share btn: replace nested menus with checkboxes

Incidentally, the checkboxes are using the config, so their state is persisted.
master
SomberNight 2 years ago
parent
commit
b7ed016f3c
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
  1. 6
      electrum/gui/qt/my_treeview.py
  2. 47
      electrum/gui/qt/transaction_dialog.py
  3. 8
      electrum/simple_config.py

6
electrum/gui/qt/my_treeview.py

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

47
electrum/gui/qt/transaction_dialog.py

@ -65,7 +65,7 @@ from .util import (MessageBoxMixin, read_QIcon, Buttons, icon_path,
BlockingWaitingDialog, getSaveFileName, ColorSchemeItem,
get_iconname_qrcode, VLine)
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:
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.setMinimumWidth(640)
self.psbt_only_widgets = [] # type: List[QWidget]
self.psbt_only_widgets = [] # type: List[Union[QWidget, QAction]]
vbox = QVBoxLayout()
self.setLayout(vbox)
@ -502,15 +502,15 @@ class TxDialog(QDialog, MessageBoxMixin):
b.clicked.connect(self.close)
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)
export_actions_menu.addSeparator()
export_submenu = export_actions_menu.addMenu(_("For CoinJoin; strip privates"))
self.add_export_actions_to_menu(export_submenu, gettx=self._gettx_for_coinjoin)
self.psbt_only_widgets.append(export_submenu)
export_submenu = export_actions_menu.addMenu(_("For hardware device; include xpubs"))
self.add_export_actions_to_menu(export_submenu, gettx=self._gettx_for_hardware_device)
self.psbt_only_widgets.append(export_submenu)
export_option = export_actions_menu.addConfig(
self.config.cv.GUI_QT_TX_DIALOG_EXPORT_STRIP_SENSITIVE_METADATA)
self.psbt_only_widgets.append(export_option)
export_option = export_actions_menu.addConfig(
self.config.cv.GUI_QT_TX_DIALOG_EXPORT_INCLUDE_GLOBAL_XPUBS)
self.psbt_only_widgets.append(export_option)
self.export_actions_button = QToolButton()
self.export_actions_button.setText(_("Share"))
@ -604,9 +604,17 @@ class TxDialog(QDialog, MessageBoxMixin):
# Override escape-key to close normally (and invoke closeEvent)
self.close()
def add_export_actions_to_menu(self, menu: QMenu, *, gettx: Callable[[], Transaction] = None) -> None:
if gettx is None:
gettx = lambda: None
def add_export_actions_to_menu(self, menu: QMenu) -> None:
def gettx() -> Transaction:
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.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()))
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):
if tx is None:
tx = self.tx

8
electrum/simple_config.py

@ -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'
'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_TAB_QR_VISIBLE = ConfigVar('receive_qr_visible', default=False, type_=bool)
GUI_QT_TX_EDITOR_SHOW_IO = ConfigVar(

Loading…
Cancel
Save