1 from PyQt4.QtGui import *
2 from PyQt4.QtCore import *
3 import PyQt4.QtCore as QtCore
4 import PyQt4.QtGui as QtGui
6 from electrum import bmp, pyqrnative
9 class QRCodeWidget(QWidget):
11 def __init__(self, data = None):
12 QWidget.__init__(self)
19 def set_addr(self, addr):
25 self.setMinimumSize(MinSize, MinSize)
31 if self.addr and not self.qr:
32 for size in range(len(pyqrnative.QRUtil.PATTERN_POSITION_TABLE)): # [4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32]:
34 self.qr = pyqrnative.QRCode(size, pyqrnative.QRErrorCorrectLevel.L)
35 self.qr.addData(self.addr)
43 def paintEvent(self, e):
48 black = QColor(0, 0, 0, 255)
49 white = QColor(255, 255, 255, 255)
56 qp.drawRect(0, 0, 198, 198)
60 k = self.qr.getModuleCount()
64 boxsize = min(r.width(), r.height())*0.8/k
66 left = (r.width() - size)/2
67 top = (r.height() - size)/2
69 # Make a white margin around the QR in case of dark theme use:
72 qp.drawRect(left-margin, top-margin, size+(margin*2), size+(margin*2))
76 if self.qr.isDark(r, c):
82 qp.drawRect(left+c*boxsize, top+r*boxsize, boxsize, boxsize)
87 from electrum.i18n import _
89 class QRDialog(QDialog):
91 def __init__(self, data, parent=None, title = "", show_text=False):
92 QDialog.__init__(self, parent)
96 d.setWindowTitle(title)
97 d.setMinimumSize(270, 300)
99 qrw = QRCodeWidget(data)
100 vbox.addWidget(qrw, 1)
104 text.setReadOnly(True)
110 self.config = parent.config
111 filename = os.path.join(self.config.path, "qrcode.bmp")
114 bmp.save_qrcode(qrw.qr, filename)
115 QMessageBox.information(None, _('Message'), _("QR code saved to file") + " " + filename, _('OK'))
117 def copy_to_clipboard():
118 bmp.save_qrcode(qrw.qr, filename)
119 self.parent().app.clipboard().setImage(QImage(filename))
120 QMessageBox.information(None, _('Message'), _("QR code saved to clipboard"), _('OK'))
122 b = QPushButton(_("Copy"))
124 b.clicked.connect(copy_to_clipboard)
126 b = QPushButton(_("Save"))
128 b.clicked.connect(print_qr)
130 b = QPushButton(_("Close"))
132 b.clicked.connect(d.accept)