Browse Source

qt: start using ButtonsWidget's add_qr_input_button/add_qr_show_button

patch-4
SomberNight 3 years ago
parent
commit
3cc6c0dd2d
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 3
      electrum/gui/qt/address_dialog.py
  2. 13
      electrum/gui/qt/lightning_tx_dialog.py
  3. 5
      electrum/gui/qt/main_window.py
  4. 6
      electrum/gui/qt/transaction_dialog.py
  5. 6
      electrum/gui/qt/util.py

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

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

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

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

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

Loading…
Cancel
Save