From e6f3e520142e8620e0e4d2c0c5bfb30a5424045d Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Wed, 14 Mar 2018 18:57:27 +0200 Subject: [PATCH] qrcode plugin: added address label and adjusted formatting --- src/plugins/menu_qrcode.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/plugins/menu_qrcode.py b/src/plugins/menu_qrcode.py index 3831e89b..f4a21460 100644 --- a/src/plugins/menu_qrcode.py +++ b/src/plugins/menu_qrcode.py @@ -3,8 +3,10 @@ A menu plugin showing QR-Code for bitmessage address in modal dialog. """ -from PyQt4 import QtGui, QtCore +import urllib + import qrcode +from PyQt4 import QtGui, QtCore from pybitmessage.tr import _translate @@ -46,7 +48,7 @@ class QRCodeDialog(QtGui.QDialog): font.setWeight(75) self.label.setFont(font) self.label.setAlignment( - QtCore.Qt.AlignCenter | QtCore.Qt.AlignVCenter) + QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter) buttonBox = QtGui.QDialogButtonBox(self) buttonBox.setOrientation(QtCore.Qt.Horizontal) buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Ok) @@ -63,9 +65,11 @@ class QRCodeDialog(QtGui.QDialog): def render(self, text): """Draw QR-code and address in labels""" + pixmap = qrcode.make(text, image_factory=Image).pixmap() + self.image.setPixmap(pixmap) self.label.setText(text) - self.image.setPixmap( - qrcode.make(text, image_factory=Image).pixmap()) + self.label.setToolTip(text) + self.label.setFixedWidth(pixmap.width()) self.setFixedSize(QtGui.QWidget.sizeHint(self)) @@ -77,7 +81,13 @@ def connect_plugin(form): dialog = form.qrcode_dialog except AttributeError: form.qrcode_dialog = dialog = QRCodeDialog(form) - dialog.render('bitmessage:' + str(form.getCurrentAccount())) + account = form.getCurrentItem() + label = account._getLabel() + dialog.render( + 'bitmessage:%s' % account.address + ( + '?' + urllib.urlencode({'label': label.encode('utf-8')}) + if label != account.address else '') + ) dialog.exec_() return on_action_ShowQR, _translate("MainWindow", "Show QR-code")