Merge branch '1153' into upstream-v0.6

This commit is contained in:
Peter Šurda 2018-03-14 13:59:21 +01:00
commit 9bd60c4a0f
Signed by untrusted user: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87
4 changed files with 109 additions and 108 deletions

View File

@ -112,8 +112,7 @@ if __name__ == "__main__":
zip_safe=False,
entry_points={
'bitmessage.gui.menu': [
'popMenuYourIdentities.qrcode = '
'pybitmessage.plugins.qrcodeui [qrcode]'
'address.qrcode = pybitmessage.plugins.menu_qrcode [qrcode]'
],
'bitmessage.notification.message': [
'notify2 = pybitmessage.plugins.notification_notify2'

View File

@ -255,6 +255,18 @@ class MyForm(settingsmixin.SMainWindow):
'customContextMenuRequested(const QPoint&)'),
self.on_context_menuYourIdentities)
# load all gui.menu plugins with prefix 'address'
self.menu_plugins = {'address': []}
for plugin in get_plugins('gui.menu', 'address'):
try:
handler, title = plugin(self)
except TypeError:
continue
self.menu_plugins['address'].append(
self.ui.addressContextMenuToolbarYourIdentities.addAction(
title, handler
))
def init_chan_popup_menu(self, connectSignal=True):
# Popup menu for the Channels tab
self.ui.addressContextMenuToolbar = QtGui.QToolBar()
@ -3421,6 +3433,10 @@ class MyForm(settingsmixin.SMainWindow):
self.popMenuSubscriptions.addSeparator()
self.popMenuSubscriptions.addAction(self.actionsubscriptionsClipboard)
self.popMenuSubscriptions.addSeparator()
# preloaded gui.menu plugins with prefix 'address'
for plugin in self.menu_plugins['address']:
self.popMenuSubscriptions.addAction(plugin)
self.popMenuSubscriptions.addSeparator()
self.popMenuSubscriptions.addAction(self.actionMarkAllRead)
self.popMenuSubscriptions.exec_(
self.ui.treeWidgetSubscriptions.mapToGlobal(point))
@ -3831,13 +3847,13 @@ class MyForm(settingsmixin.SMainWindow):
self.popMenuYourIdentities.addAction(self.actionSpecialAddressBehaviorYourIdentities)
self.popMenuYourIdentities.addAction(self.actionEmailGateway)
self.popMenuYourIdentities.addSeparator()
if currentItem.type != AccountMixin.ALL:
# preloaded gui.menu plugins with prefix 'address'
for plugin in self.menu_plugins['address']:
self.popMenuYourIdentities.addAction(plugin)
self.popMenuYourIdentities.addSeparator()
self.popMenuYourIdentities.addAction(self.actionMarkAllRead)
if get_plugins:
for plugin in get_plugins(
'gui.menu', 'popMenuYourIdentities'):
plugin(self)
self.popMenuYourIdentities.exec_(
self.ui.treeWidgetYourIdentities.mapToGlobal(point))
@ -3857,6 +3873,10 @@ class MyForm(settingsmixin.SMainWindow):
self.popMenu.addAction(self.actionEnable)
self.popMenu.addAction(self.actionSetAvatar)
self.popMenu.addSeparator()
# preloaded gui.menu plugins with prefix 'address'
for plugin in self.menu_plugins['address']:
self.popMenu.addAction(plugin)
self.popMenu.addSeparator()
self.popMenu.addAction(self.actionMarkAllRead)
self.popMenu.exec_(
self.ui.treeWidgetChans.mapToGlobal(point))

View File

@ -0,0 +1,83 @@
# -*- coding: utf-8 -*-
"""
A menu plugin showing QR-Code for bitmessage address in modal dialog.
"""
from PyQt4 import QtGui, QtCore
import qrcode
from pybitmessage.tr import _translate
# http://stackoverflow.com/questions/20452486
class Image(qrcode.image.base.BaseImage):
"""Image output class for qrcode using QPainter"""
def __init__(self, border, width, box_size):
self.border = border
self.width = width
self.box_size = box_size
size = (width + border * 2) * box_size
self._image = QtGui.QImage(
size, size, QtGui.QImage.Format_RGB16)
self._image.fill(QtCore.Qt.white)
def pixmap(self):
"""Get image pixmap"""
return QtGui.QPixmap.fromImage(self._image)
def drawrect(self, row, col):
"""Draw a single rectangle - implementation"""
painter = QtGui.QPainter(self._image)
painter.fillRect(
(col + self.border) * self.box_size,
(row + self.border) * self.box_size,
self.box_size, self.box_size,
QtCore.Qt.black)
class QRCodeDialog(QtGui.QDialog):
"""The dialog"""
def __init__(self, parent):
super(QRCodeDialog, self).__init__(parent)
self.image = QtGui.QLabel(self)
self.label = QtGui.QLabel(self)
font = QtGui.QFont()
font.setBold(True)
font.setWeight(75)
self.label.setFont(font)
self.label.setAlignment(
QtCore.Qt.AlignCenter | QtCore.Qt.AlignVCenter)
buttonBox = QtGui.QDialogButtonBox(self)
buttonBox.setOrientation(QtCore.Qt.Horizontal)
buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Ok)
buttonBox.accepted.connect(self.accept)
layout = QtGui.QVBoxLayout(self)
layout.addWidget(self.image)
layout.addWidget(self.label)
layout.addWidget(buttonBox)
self.retranslateUi()
def retranslateUi(self):
"""A conventional Qt Designer method for dynamic l10n"""
self.setWindowTitle(_translate("QRCodeDialog", "QR-code"))
def render(self, text):
"""Draw QR-code and address in labels"""
self.label.setText(text)
self.image.setPixmap(
qrcode.make(text, image_factory=Image).pixmap())
self.setFixedSize(QtGui.QWidget.sizeHint(self))
def connect_plugin(form):
"""Plugin entry point"""
def on_action_ShowQR():
"""A slot for popup menu action"""
try:
dialog = form.qrcode_dialog
except AttributeError:
form.qrcode_dialog = dialog = QRCodeDialog(form)
dialog.render('bitmessage:' + str(form.getCurrentAccount()))
dialog.exec_()
return on_action_ShowQR, _translate("MainWindow", "Show QR-code")

View File

@ -1,101 +0,0 @@
# -*- coding: utf-8 -*-
from PyQt4 import QtGui, QtCore
import qrcode
from pybitmessage.tr import translateText
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s
# http://stackoverflow.com/questions/20452486
class Image(qrcode.image.base.BaseImage):
def __init__(self, border, width, box_size):
self.border = border
self.width = width
self.box_size = box_size
size = (width + border * 2) * box_size
self._image = QtGui.QImage(
size, size, QtGui.QImage.Format_RGB16)
self._image.fill(QtCore.Qt.white)
def pixmap(self):
return QtGui.QPixmap.fromImage(self._image)
def drawrect(self, row, col):
painter = QtGui.QPainter(self._image)
painter.fillRect(
(col + self.border) * self.box_size,
(row + self.border) * self.box_size,
self.box_size, self.box_size,
QtCore.Qt.black)
def save(self, stream, kind=None):
pass
class Ui_qrcodeDialog(object):
def setupUi(self, qrcodeDialog):
qrcodeDialog.setObjectName(_fromUtf8("qrcodeDialog"))
self.image = QtGui.QLabel(qrcodeDialog)
self.label = QtGui.QLabel(qrcodeDialog)
font = QtGui.QFont()
font.setBold(True)
font.setWeight(75)
self.label.setFont(font)
self.label.setAlignment(
QtCore.Qt.AlignCenter | QtCore.Qt.AlignVCenter)
self.buttonBox = QtGui.QDialogButtonBox(qrcodeDialog)
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Ok)
layout = QtGui.QVBoxLayout(qrcodeDialog)
layout.addWidget(self.image)
layout.addWidget(self.label)
layout.addWidget(self.buttonBox)
self.retranslateUi(qrcodeDialog)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(
_fromUtf8("accepted()")), qrcodeDialog.accept)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(
_fromUtf8("rejected()")), qrcodeDialog.reject)
QtCore.QMetaObject.connectSlotsByName(qrcodeDialog)
def retranslateUi(self, qrcodeDialog):
qrcodeDialog.setWindowTitle(QtGui.QApplication.translate(
"qrcodeDialog", "QR-code",
None, QtGui.QApplication.UnicodeUTF8
))
def render(self, text):
self.label.setText(text)
self.image.setPixmap(
qrcode.make(text, image_factory=Image).pixmap())
class qrcodeDialog(QtGui.QDialog):
def __init__(self, parent):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_qrcodeDialog()
self.ui.setupUi(self)
self.parent = parent
QtGui.QWidget.resize(self, QtGui.QWidget.sizeHint(self))
def connect_plugin(form):
def on_action_ShowQR():
form.qrcodeDialogInstance = qrcodeDialog(form)
form.qrcodeDialogInstance.ui.render(
str(form.getCurrentAccount())
)
form.qrcodeDialogInstance.exec_()
form.actionShowQRCode = \
form.ui.addressContextMenuToolbarYourIdentities.addAction(
translateText("MainWindow", "Show QR-code"),
on_action_ShowQR
)
form.popMenuYourIdentities.addAction(form.actionShowQRCode)