From 79eb790e2726fb6e303c09333cd6bd80fc492a83 Mon Sep 17 00:00:00 2001 From: Kristaps Kaupe Date: Sat, 27 Apr 2019 23:33:37 +0300 Subject: [PATCH] Add QR code support to the GUI --- docs/INSTALL.md | 1 + install.sh | 1 + scripts/joinmarket-qt.py | 28 +++++++++++++++++++++++++++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/docs/INSTALL.md b/docs/INSTALL.md index 8b7ad34..5efdd15 100644 --- a/docs/INSTALL.md +++ b/docs/INSTALL.md @@ -89,6 +89,7 @@ command line scripts as explained in the [scripts README](https://github.com/Ada 6) Setup joinmarket-qt ``` pip install PySide2 + pip install qrcode[pil] pip install https://github.com/sunu/qt5reactor/archive/58410aaead2185e9917ae9cac9c50fe7b70e4a60.zip python setupall.py --all ``` diff --git a/install.sh b/install.sh index b4acaed..400f5c1 100755 --- a/install.sh +++ b/install.sh @@ -427,6 +427,7 @@ qt_deps_install () { pip install \ PySide2 \ + qrcode[pil] \ https://github.com/sunu/qt5reactor/archive/58410aaead2185e9917ae9cac9c50fe7b70e4a60.zip return "$?" diff --git a/scripts/joinmarket-qt.py b/scripts/joinmarket-qt.py index f4f538e..c94c749 100644 --- a/scripts/joinmarket-qt.py +++ b/scripts/joinmarket-qt.py @@ -25,7 +25,7 @@ Some widgets copied and modified from https://github.com/spesmilo/electrum import sys, datetime, os, logging import platform, json, threading, time - +import qrcode from decimal import Decimal from PySide2 import QtCore @@ -34,6 +34,8 @@ from PySide2.QtGui import * from PySide2.QtWidgets import * +from PIL.ImageQt import ImageQt + if platform.system() == 'Windows': MONOSPACE_FONT = 'Lucida Console' elif platform.system() == 'Darwin': @@ -1101,6 +1103,24 @@ class CoinsTab(QWidget): lambda: app.clipboard().setText(txid)) menu.exec_(self.cTW.viewport().mapToGlobal(position)) +class BitcoinQRCodePopup(QDialog): + + def __init__(self, parent, address): + super(BitcoinQRCodePopup, self).__init__(parent) + self.address = address + self.setWindowTitle(address) + img = qrcode.make('bitcoin:' + address) + self.imageLabel = QLabel() + self.imageLabel.setPixmap(QPixmap.fromImage(ImageQt(img))) + layout = QVBoxLayout() + layout.addWidget(self.imageLabel) + self.setLayout(layout) + self.initUI() + + def initUI(self): + self.show() + + class JMWalletTab(QWidget): def __init__(self): @@ -1152,6 +1172,8 @@ class JMWalletTab(QWidget): if address_valid: menu.addAction("Copy address to clipboard", lambda: app.clipboard().setText(txt)) + menu.addAction("Show QR code", + lambda: self.openQRCodePopup(txt)) if xpub_exists: menu.addAction("Copy extended pubkey to clipboard", lambda: app.clipboard().setText(xpub)) @@ -1160,6 +1182,10 @@ class JMWalletTab(QWidget): #TODO add more items to context menu menu.exec_(self.walletTree.viewport().mapToGlobal(position)) + def openQRCodePopup(self, address): + popup = BitcoinQRCodePopup(self, address) + popup.show() + def updateWalletInfo(self, walletinfo=None): l = self.walletTree l.clear()