diff --git a/pyproject.toml b/pyproject.toml index c00dd27f72e1aa4c4acfb2c56a15964d94320731..3efaa6baf22fa95f6983dbeea1208ceba19a7caf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,6 +22,7 @@ PyQt5 = "5.15.9" PyYAML = "^6.0" substrate-interface = "^1.4.2" python-sql = "^1.4.0" +qrcode = "^7.4.2" [tool.poetry.group.dev.dependencies] black = "22.3.0" diff --git a/tikka/slots/pyqt/entities/qrcode_image.py b/tikka/slots/pyqt/entities/qrcode_image.py new file mode 100644 index 0000000000000000000000000000000000000000..6b13e8a1a836121c775854374b9a0751a2f8eac9 --- /dev/null +++ b/tikka/slots/pyqt/entities/qrcode_image.py @@ -0,0 +1,79 @@ +# Copyright 2021 Vincent Texier <vit@free.fr> +# +# This software is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This software is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# Image class for QR code +from typing import Any + +from PyQt5.QtCore import Qt +from PyQt5.QtGui import QImage, QPainter, QPixmap +from qrcode import QRCode +from qrcode.image.base import BaseImage + + +class QRCodeImage(BaseImage): + + # constructor + def __init__(self, border, width, box_size, *args, **kwargs): + + # assigning border + super().__init__(border, width, box_size, *args, **kwargs) + self.border = border + + # assigning width + self.width = width + + # assigning box size + self.box_size = box_size + + # creating size + size = (width + border * 2) * box_size + + # image + self._image = QImage(size, size, QImage.Format_RGB16) + + # initial image as white + self._image.fill(Qt.white) + + # pixmap method + def pixmap(self): + + # returns image + return QPixmap.fromImage(self._image) + + def drawrect_context(self, row: int, col: int, qr: QRCode): + pass + + # drawrect method for drawing rectangle + def drawrect(self, row, col): + # creating painter object + painter = QPainter(self._image) + + # drawing rectangle + painter.fillRect( + (col + self.border) * self.box_size, + (row + self.border) * self.box_size, + self.box_size, + self.box_size, + Qt.black, + ) + + def save(self, stream, kind=None): + pass + + def new_image(self, **kwargs) -> Any: + pass + + def process(self): + pass diff --git a/tikka/slots/pyqt/resources/gui/widgets/account.ui b/tikka/slots/pyqt/resources/gui/widgets/account.ui index c1b3a69abfde7da778c02ccb09fb38cb3ecd0262..950ba73592a4a0185da4a894df8d22f6a6a5068c 100644 --- a/tikka/slots/pyqt/resources/gui/widgets/account.ui +++ b/tikka/slots/pyqt/resources/gui/widgets/account.ui @@ -20,7 +20,7 @@ <item> <layout class="QHBoxLayout" name="horizontalLayout"> <item> - <widget class="QLabel" name="safeImageLabel"> + <widget class="QLabel" name="QRCodeAddressLabel"> <property name="maximumSize"> <size> <width>100</width> diff --git a/tikka/slots/pyqt/widgets/account.py b/tikka/slots/pyqt/widgets/account.py index 4b5d3b4ded6b99e5bea279ceaff684f31043695e..1bc5695499bb0a21c8562ebcc481d26aded98e41 100644 --- a/tikka/slots/pyqt/widgets/account.py +++ b/tikka/slots/pyqt/widgets/account.py @@ -15,6 +15,7 @@ import sys from typing import Optional +import qrcode from PyQt5.QtCore import QMutex, QPoint from PyQt5.QtGui import QFont, QPixmap from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget @@ -31,6 +32,7 @@ from tikka.slots.pyqt.entities.constants import ( ICON_ACCOUNT_WALLET_LOCKED, ICON_ACCOUNT_WALLET_UNLOCKED, ) +from tikka.slots.pyqt.entities.qrcode_image import QRCodeImage from tikka.slots.pyqt.entities.worker import AsyncQWorker from tikka.slots.pyqt.resources.gui.widgets.account_rc import Ui_AccountWidget from tikka.slots.pyqt.widgets.account_menu import AccountPopupMenu @@ -71,6 +73,14 @@ class AccountWidget(QWidget, Ui_AccountWidget): self.addressValueLabel.setFont(self.monospace_font) self.addressValueLabel.setText(self.account.address) + # creating a pix map of qr code + qr_code_pixmap = qrcode.make( + self.account.address, image_factory=QRCodeImage + ).pixmap() + + # set qrcode to the label + self.QRCodeAddressLabel.setPixmap(qr_code_pixmap) + self._update_ui() ##############################