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)