Skip to content
Snippets Groups Projects
Commit 95ed09f1 authored by Vincent Texier's avatar Vincent Texier
Browse files

[feat] display qrcode of address in account widget

parent 3fcbf36a
Branches
Tags
No related merge requests found
...@@ -22,6 +22,7 @@ PyQt5 = "5.15.9" ...@@ -22,6 +22,7 @@ PyQt5 = "5.15.9"
PyYAML = "^6.0" PyYAML = "^6.0"
substrate-interface = "^1.4.2" substrate-interface = "^1.4.2"
python-sql = "^1.4.0" python-sql = "^1.4.0"
qrcode = "^7.4.2"
[tool.poetry.group.dev.dependencies] [tool.poetry.group.dev.dependencies]
black = "22.3.0" black = "22.3.0"
......
# 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
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>
<widget class="QLabel" name="safeImageLabel"> <widget class="QLabel" name="QRCodeAddressLabel">
<property name="maximumSize"> <property name="maximumSize">
<size> <size>
<width>100</width> <width>100</width>
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
import sys import sys
from typing import Optional from typing import Optional
import qrcode
from PyQt5.QtCore import QMutex, QPoint from PyQt5.QtCore import QMutex, QPoint
from PyQt5.QtGui import QFont, QPixmap from PyQt5.QtGui import QFont, QPixmap
from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget
...@@ -31,6 +32,7 @@ from tikka.slots.pyqt.entities.constants import ( ...@@ -31,6 +32,7 @@ from tikka.slots.pyqt.entities.constants import (
ICON_ACCOUNT_WALLET_LOCKED, ICON_ACCOUNT_WALLET_LOCKED,
ICON_ACCOUNT_WALLET_UNLOCKED, 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.entities.worker import AsyncQWorker
from tikka.slots.pyqt.resources.gui.widgets.account_rc import Ui_AccountWidget from tikka.slots.pyqt.resources.gui.widgets.account_rc import Ui_AccountWidget
from tikka.slots.pyqt.widgets.account_menu import AccountPopupMenu from tikka.slots.pyqt.widgets.account_menu import AccountPopupMenu
...@@ -71,6 +73,14 @@ class AccountWidget(QWidget, Ui_AccountWidget): ...@@ -71,6 +73,14 @@ class AccountWidget(QWidget, Ui_AccountWidget):
self.addressValueLabel.setFont(self.monospace_font) self.addressValueLabel.setFont(self.monospace_font)
self.addressValueLabel.setText(self.account.address) 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() self._update_ui()
############################## ##############################
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment