1
0

qt: start using ButtonsWidget's add_qr_input_button/add_qr_show_button

This commit is contained in:
SomberNight
2022-05-14 17:17:57 +02:00
parent 5398b9d9c9
commit 3cc6c0dd2d
5 changed files with 13 additions and 20 deletions

View File

@@ -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)

View File

@@ -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)

View File

@@ -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))

View File

@@ -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)

View File

@@ -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_()