SomberNight 6 years ago
parent
commit
4284f4feb3
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 11
      electrum/gui/kivy/main_window.py
  2. 5
      electrum/gui/kivy/uix/dialogs/qr_dialog.py
  3. 5
      electrum/gui/kivy/uix/dialogs/tx_dialog.py
  4. 15
      electrum/gui/kivy/uix/qrcodewidget.py
  5. 8
      electrum/gui/qt/transaction_dialog.py

11
electrum/gui/kivy/main_window.py

@ -391,9 +391,16 @@ class ElectrumWindow(App):
popup.export = self.export_private_keys
popup.open()
def qr_dialog(self, title, data, show_text=False):
def qr_dialog(self, title, data, show_text=False, text_for_clipboard=None):
from .uix.dialogs.qr_dialog import QRDialog
popup = QRDialog(title, data, show_text)
def on_qr_failure():
popup.dismiss()
msg = _('Failed to display QR code.')
if text_for_clipboard:
msg += '\n' + _('Text copied to clipboard.')
self._clipboard.copy(text_for_clipboard)
Clock.schedule_once(lambda dt: self.show_info(msg))
popup = QRDialog(title, data, show_text, on_qr_failure)
popup.open()
def scan_qr(self, on_complete):

5
electrum/gui/kivy/uix/dialogs/qr_dialog.py

@ -36,11 +36,12 @@ Builder.load_string('''
''')
class QRDialog(Factory.Popup):
def __init__(self, title, data, show_text):
def __init__(self, title, data, show_text, failure_cb=None):
Factory.Popup.__init__(self)
self.title = title
self.data = data
self.show_text = show_text
self.failure_cb = failure_cb
def on_open(self):
self.ids.qr.set_data(self.data)
self.ids.qr.set_data(self.data, self.failure_cb)

5
electrum/gui/kivy/uix/dialogs/tx_dialog.py

@ -179,6 +179,7 @@ class TxDialog(Factory.Popup):
def show_qr(self):
from electrum.bitcoin import base_encode, bfh
text = bfh(str(self.tx))
raw_tx = str(self.tx)
text = bfh(raw_tx)
text = base_encode(text, base=43)
self.app.qr_dialog(_("Raw Transaction"), text)
self.app.qr_dialog(_("Raw Transaction"), text, text_for_clipboard=raw_tx)

15
electrum/gui/kivy/uix/qrcodewidget.py

@ -5,6 +5,7 @@ from threading import Thread
from functools import partial
import qrcode
from qrcode import exceptions
from kivy.uix.floatlayout import FloatLayout
from kivy.graphics.texture import Texture
@ -50,15 +51,23 @@ class QRCodeWidget(FloatLayout):
self.data = None
self.qr = None
self._qrtexture = None
self.failure_cb = None
def on_data(self, instance, value):
if not (self.canvas or value):
return
self.update_qr()
def set_data(self, data):
try:
self.update_qr()
except qrcode.exceptions.DataOverflowError:
if self.failure_cb:
self.failure_cb()
else:
raise
def set_data(self, data, failure_cb=None):
if self.data == data:
return
self.failure_cb = failure_cb
MinSize = 210 if len(data) < 128 else 500
self.setMinimumSize((MinSize, MinSize))
self.data = data

8
electrum/gui/qt/transaction_dialog.py

@ -31,6 +31,9 @@ from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import qrcode
from qrcode import exceptions
from electrum.bitcoin import base_encode
from electrum.i18n import _
from electrum.plugin import run_hook
@ -183,8 +186,11 @@ class TxDialog(QDialog, MessageBoxMixin):
text = base_encode(text, base=43)
try:
self.main_window.show_qrcode(text, 'Transaction', parent=self)
except qrcode.exceptions.DataOverflowError:
self.show_error(_('Failed to display QR code.') + '\n' +
_('Transaction is too large in size.'))
except Exception as e:
self.show_message(str(e))
self.show_error(_('Failed to display QR code.') + '\n' + str(e))
def sign(self):
def sign_done(success):

Loading…
Cancel
Save