Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/lib/gui_qt.py b/lib/gui_qt.py
- index 6784481..f0e58f9 100644
- --- a/lib/gui_qt.py
- +++ b/lib/gui_qt.py
- @@ -27,6 +27,12 @@ except:
- print_error("on Linux systems, you may try 'sudo apt-get install python-qt4'")
- sys.exit(1)
- +try:
- + import zbar
- +except ImportError:
- + print_error("Install zbar package to enable QR scans")
- + zbar = None
- +
- from PyQt4.QtGui import *
- from PyQt4.QtCore import *
- import PyQt4.QtCore as QtCore
- @@ -432,6 +438,36 @@ class ElectrumWindow(QMainWindow):
- self.history_list.setCurrentItem(self.history_list.topLevelItem(0))
- + def scan_qr(self):
- + from urlparse import urlparse, parse_qs
- +
- + proc = zbar.Processor()
- + proc.init()
- + proc.visible = True
- +
- + while True:
- + try:
- + proc.process_one()
- + except:
- + # User closed the preview window
- + return {}
- +
- + for r in proc.results:
- + if str(r.type) != 'QRCODE':
- + continue
- +
- + qrcode = r.data
- + if ':' not in qrcode:
- + # It's just an address (not BIP21)
- + return {'address': qrcode}
- +
- + if '//' not in qrcode:
- + # Workaround for urlparse, it don't handle bitcoin: URI properly
- + qrcode = qrcode.replace(':', '://')
- + uri = urlparse(qrcode)
- + print uri
- + return {'address': uri.netloc}#, 'amount': None, 'label': None}
- +
- def create_send_tab(self):
- w = QWidget()
- @@ -443,6 +479,21 @@ class ElectrumWindow(QMainWindow):
- self.payto_e = QLineEdit()
- grid.addWidget(QLabel(_('Pay to')), 1, 0)
- grid.addWidget(self.payto_e, 1, 1, 1, 3)
- +
- + def fill_from_qr():
- + qrcode = self.scan_qr()
- + if 'address' in qrcode:
- + self.payto_e.setText(qrcode['address'])
- + if 'amount' in qrcode:
- + self.amount_e.setText(str(qrcode['amount']))
- + if 'label' in qrcode:
- + self.message_e.setText(qrcode['label'])
- +
- + if zbar:
- + b = QPushButton(_("Scan QR code"))
- + b.clicked.connect(fill_from_qr)
- + grid.addWidget(b, 1, 5)
- +
- grid.addWidget(HelpButton(_('Recipient of the funds.') + '\n\n' + _('You may enter a Bitcoin address, a label from your list of contacts (a list of completions will be proposed), or an alias (email-like address that forwards to a Bitcoin address)')), 1, 4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement