From 3cc6c0dd2d5d99506650ce2f990a0d69b6579acb Mon Sep 17 00:00:00 2001 From: SomberNight Date: Sat, 14 May 2022 17:17:57 +0200 Subject: [PATCH] qt: start using ButtonsWidget's add_qr_input_button/add_qr_show_button --- electrum/gui/qt/address_dialog.py | 3 +-- electrum/gui/qt/lightning_tx_dialog.py | 13 ++++--------- electrum/gui/qt/main_window.py | 5 +---- electrum/gui/qt/transaction_dialog.py | 6 ++---- electrum/gui/qt/util.py | 6 +++++- 5 files changed, 13 insertions(+), 20 deletions(-) diff --git a/electrum/gui/qt/address_dialog.py b/electrum/gui/qt/address_dialog.py index 2e2b58237..ff36be4ec 100644 --- a/electrum/gui/qt/address_dialog.py +++ b/electrum/gui/qt/address_dialog.py @@ -67,8 +67,7 @@ class AddressDialog(WindowModalDialog): vbox.addWidget(QLabel(_("Address") + ":")) self.addr_e = ButtonsLineEdit(self.address) self.addr_e.addCopyButton(self.app) - icon = "qrcode_white.png" if ColorScheme.dark_scheme else "qrcode.png" - self.addr_e.addButton(icon, self.show_qr, _("Show QR Code")) + self.addr_e.add_qr_show_button(config=self.config, title=_("Address")) self.addr_e.setReadOnly(True) vbox.addWidget(self.addr_e) diff --git a/electrum/gui/qt/lightning_tx_dialog.py b/electrum/gui/qt/lightning_tx_dialog.py index b9bd6529c..ce77bcce5 100644 --- a/electrum/gui/qt/lightning_tx_dialog.py +++ b/electrum/gui/qt/lightning_tx_dialog.py @@ -45,6 +45,7 @@ class LightningTxDialog(WindowModalDialog): def __init__(self, parent: 'ElectrumWindow', tx_item: dict): WindowModalDialog.__init__(self, parent, _("Lightning Payment")) self.parent = parent + self.config = parent.config self.is_sent = bool(tx_item['direction'] == 'sent') self.label = tx_item['label'] self.timestamp = tx_item['timestamp'] @@ -72,14 +73,10 @@ class LightningTxDialog(WindowModalDialog): time_str = datetime.datetime.fromtimestamp(self.timestamp).isoformat(' ')[:-3] vbox.addWidget(QLabel(_("Date") + ": " + time_str)) - qr_icon = "qrcode_white.png" if ColorScheme.dark_scheme else "qrcode.png" - vbox.addWidget(QLabel(_("Payment hash") + ":")) self.hash_e = ButtonsLineEdit(self.payment_hash) self.hash_e.addCopyButton(self.parent.app) - self.hash_e.addButton(qr_icon, - self.show_qr(self.hash_e, _("Payment hash")), - _("Show QR Code")) + self.hash_e.add_qr_show_button(config=self.config, title=_("Payment hash")) self.hash_e.setReadOnly(True) self.hash_e.setFont(QFont(MONOSPACE_FONT)) vbox.addWidget(self.hash_e) @@ -87,15 +84,13 @@ class LightningTxDialog(WindowModalDialog): vbox.addWidget(QLabel(_("Preimage") + ":")) self.preimage_e = ButtonsLineEdit(self.preimage) self.preimage_e.addCopyButton(self.parent.app) - self.preimage_e.addButton(qr_icon, - self.show_qr(self.preimage_e, _("Preimage")), - _("Show QR Code")) + self.preimage_e.add_qr_show_button(config=self.config, title=_("Preimage")) self.preimage_e.setReadOnly(True) self.preimage_e.setFont(QFont(MONOSPACE_FONT)) vbox.addWidget(self.preimage_e) vbox.addWidget(QLabel(_("Lightning Invoice") + ":")) - self.invoice_e = ShowQRTextEdit(self.invoice, config=parent.config) + self.invoice_e = ShowQRTextEdit(self.invoice, config=self.config) self.invoice_e.setMaximumHeight(150) self.invoice_e.addCopyButton(self.parent.app) vbox.addWidget(self.invoice_e) diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py index 32b6eb710..04fa84478 100644 --- a/electrum/gui/qt/main_window.py +++ b/electrum/gui/qt/main_window.py @@ -1190,7 +1190,6 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): #self.receive_URI_e.setFocusPolicy(Qt.ClickFocus) fixedSize = 200 - qr_icon = "qrcode_white.png" if ColorScheme.dark_scheme else "qrcode.png" for e in [self.receive_address_e, self.receive_URI_e, self.receive_lightning_e]: e.setFont(QFont(MONOSPACE_FONT)) e.addCopyButton(self.app) @@ -2676,11 +2675,9 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): "If you want to have recoverable channels, you must create a new wallet with an Electrum seed") grid.addWidget(HelpButton(msg), 5, 3) grid.addWidget(WWLabel(_('Lightning Node ID:')), 7, 0) - # TODO: ButtonsLineEdit should have a addQrButton method nodeid_text = self.wallet.lnworker.node_keypair.pubkey.hex() nodeid_e = ButtonsLineEdit(nodeid_text) - qr_icon = "qrcode_white.png" if ColorScheme.dark_scheme else "qrcode.png" - nodeid_e.addButton(qr_icon, lambda: self.show_qrcode(nodeid_text, _("Node ID")), _("Show QR Code")) + nodeid_e.add_qr_show_button(config=self.config, title=_("Node ID")) nodeid_e.addCopyButton(self.app) nodeid_e.setReadOnly(True) nodeid_e.setFont(QFont(MONOSPACE_FONT)) diff --git a/electrum/gui/qt/transaction_dialog.py b/electrum/gui/qt/transaction_dialog.py index 850c693a1..ae83e66ed 100644 --- a/electrum/gui/qt/transaction_dialog.py +++ b/electrum/gui/qt/transaction_dialog.py @@ -120,10 +120,8 @@ class BaseTxDialog(QDialog, MessageBoxMixin): self.setLayout(vbox) vbox.addWidget(QLabel(_("Transaction ID:"))) - self.tx_hash_e = ButtonsLineEdit() - qr_show = lambda: parent.show_qrcode(str(self.tx_hash_e.text()), 'Transaction ID', parent=self) - qr_icon = "qrcode_white.png" if ColorScheme.dark_scheme else "qrcode.png" - self.tx_hash_e.addButton(qr_icon, qr_show, _("Show as QR code")) + self.tx_hash_e = ButtonsLineEdit() + self.tx_hash_e.add_qr_show_button(config=self.config, title='Transaction ID') self.tx_hash_e.setReadOnly(True) vbox.addWidget(self.tx_hash_e) diff --git a/electrum/gui/qt/util.py b/electrum/gui/qt/util.py index 52e23339b..b605432b9 100644 --- a/electrum/gui/qt/util.py +++ b/electrum/gui/qt/util.py @@ -868,7 +868,10 @@ class ButtonsWidget(QWidget): def on_paste(self): self.setText(self.app.clipboard().text()) - def add_qr_show_button(self, *, config: 'SimpleConfig'): + def add_qr_show_button(self, *, config: 'SimpleConfig', title: Optional[str] = None): + if title is None: + title = _("QR code") + def qr_show(): from .qrcodewidget import QRDialog try: @@ -880,6 +883,7 @@ class ButtonsWidget(QWidget): QRDialog( data=s, parent=self, + title=title, config=config, ).exec_()